Skip to content

Commit

Permalink
configure: add endian check
Browse files Browse the repository at this point in the history
Will remove guesswork and manual hacking in the OS headers.

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Jan 23, 2013
1 parent 37adbfc commit 0dcebdf
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 64 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ endif
ifdef CONFIG_32BIT
CFLAGS += -DBITS_PER_LONG=32
endif
ifdef CONFIG_BIG_ENDIAN
CFLAGS += -DCONFIG_BIG_ENDIAN
endif
ifdef CONFIG_LITTLE_ENDIAN
CFLAGS += -DCONFIG_LITTLE_ENDIAN
endif
ifdef CONFIG_LIBAIO
CFLAGS += -DCONFIG_LIBAIO
SOURCE += engines/libaio.c
Expand Down
22 changes: 22 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,25 @@ fi

cc="${CC-${cross_prefix}gcc}"

##########################################
# check endianness
bigendian="no"
cat > $TMPC <<EOF
#include <inttypes.h>
int main(void)
{
volatile uint32_t i=0x01234567;
return (*((uint8_t*)(&i))) == 0x67;
}
EOF
if compile_prog "" "" "endian"; then
$TMPE && bigendian="yes"
fi


echo "Operating system $targetos"
echo "CPU $cpu"
echo "Big endian $bigendian"
echo "Compiler $cc"
echo

Expand Down Expand Up @@ -783,6 +800,11 @@ else
echo "Unknown wordsize!"
exit 1
fi
if test "$bigendian" = "yes" ; then
echo "CONFIG_BIG_ENDIAN=y" >> $config_host_mak
else
echo "CONFIG_LITTLE_ENDIAN=y" >> $config_host_mak
fi
if test "$libaio" = "yes" ; then
echo "CONFIG_LIBAIO=y" >> $config_host_mak
fi
Expand Down
4 changes: 2 additions & 2 deletions fio.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ static int endian_check(void)
else if (u.c[0] == 0x12)
le = 1;

#if defined(FIO_LITTLE_ENDIAN)
#if defined(CONFIG_LITTLE_ENDIAN)
if (be)
return 1;
#elif defined(FIO_BIG_ENDIAN)
#elif defined(CONFIG_BIG_ENDIAN)
if (le)
return 1;
#else
Expand Down
2 changes: 1 addition & 1 deletion lib/bswap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <inttypes.h>

#if __BYTE_ORDER == __LITTLE_ENDIAN
#ifdef CONFIG_LITTLE_ENDIAN
static inline uint32_t __be32_to_cpu(uint32_t val)
{
uint32_t c1, c2, c3, c4;
Expand Down
6 changes: 0 additions & 6 deletions os/os-aix.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
#define OS_MAP_ANON MAP_ANON
#define OS_MSG_DONTWAIT 0

#if BYTE_ORDER == BIG_ENDIAN
#define FIO_BIG_ENDIAN
#else
#define FIO_LITTLE_ENDIAN
#endif

#define FIO_USE_GENERIC_SWAP

static inline int blockdev_invalidate_cache(struct fio_file *f)
Expand Down
9 changes: 0 additions & 9 deletions os/os-android.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <sched.h>
#include <linux/unistd.h>
#include <linux/major.h>
#include <endian.h>

#include "binject.h"
#include "../file.h"
Expand Down Expand Up @@ -134,14 +133,6 @@ static inline long os_random_long(os_random_state_t *rs)
#define FIO_O_NOATIME 0
#endif

#if __BYTE_ORDER == __LITTLE_ENDIAN
#define FIO_LITTLE_ENDIAN
#elif __BYTE_ORDER == __BIG_ENDIAN
#define FIO_BIG_ENDIAN
#else
#error "Unknown endianness"
#endif

#define fio_swap16(x) __bswap_16(x)
#define fio_swap32(x) __bswap_32(x)
#define fio_swap64(x) __bswap_64(x)
Expand Down
7 changes: 0 additions & 7 deletions os/os-freebsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <sys/sysctl.h>
#include <sys/disk.h>
#include <sys/thr.h>
#include <sys/endian.h>
#include <sys/socket.h>

#include "../file.h"
Expand All @@ -20,12 +19,6 @@

#define OS_MAP_ANON MAP_ANON

#if BYTE_ORDER == LITTLE_ENDIAN
#define FIO_LITTLE_ENDIAN
#else
#define FIO_BIG_ENDIAN
#endif

#define fio_swap16(x) bswap16(x)
#define fio_swap32(x) bswap32(x)
#define fio_swap64(x) bswap64(x)
Expand Down
6 changes: 0 additions & 6 deletions os/os-hpux.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
#define MSG_WAITALL 0x40
#endif

#ifdef LITTLE_ENDIAN
#define FIO_LITTLE_ENDIAN
#else
#define FIO_BIG_ENDIAN
#endif

#define FIO_USE_GENERIC_SWAP

#define FIO_OS_HAVE_AIOCB_TYPEDEF
Expand Down
9 changes: 0 additions & 9 deletions os/os-linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <linux/unistd.h>
#include <linux/raw.h>
#include <linux/major.h>
#include <endian.h>

#include "binject.h"
#include "../file.h"
Expand Down Expand Up @@ -194,14 +193,6 @@ static inline int fio_lookup_raw(dev_t dev, int *majdev, int *mindev)
#define FIO_MADV_FREE MADV_REMOVE
#endif

#if __BYTE_ORDER == __LITTLE_ENDIAN
#define FIO_LITTLE_ENDIAN
#elif __BYTE_ORDER == __BIG_ENDIAN
#define FIO_BIG_ENDIAN
#else
#error "Unknown endianness"
#endif

#define fio_swap16(x) __bswap_16(x)
#define fio_swap32(x) __bswap_32(x)
#define fio_swap64(x) __bswap_64(x)
Expand Down
8 changes: 0 additions & 8 deletions os/os-mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@

#define OS_MAP_ANON MAP_ANON

#if defined(__LITTLE_ENDIAN__)
#define FIO_LITTLE_ENDIAN
#elif defined(__BIG_ENDIAN__)
#define FIO_BIG_ENDIAN
#else
#error "Undefined byte order"
#endif

#define fio_swap16(x) OSSwapInt16(x)
#define fio_swap32(x) OSSwapInt32(x)
#define fio_swap64(x) OSSwapInt64(x)
Expand Down
7 changes: 0 additions & 7 deletions os/os-netbsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <errno.h>
#include <lwp.h>
#include <sys/param.h>
#include <sys/endian.h>
/* XXX hack to avoid confilcts between rbtree.h and <sys/rb.h> */
#define rb_node _rb_node
#include <sys/sysctl.h>
Expand All @@ -30,12 +29,6 @@
#define PTHREAD_STACK_MIN 4096
#endif

#if BYTE_ORDER == LITTLE_ENDIAN
#define FIO_LITTLE_ENDIAN
#else
#define FIO_BIG_ENDIAN
#endif

#define fio_swap16(x) bswap16(x)
#define fio_swap32(x) bswap32(x)
#define fio_swap64(x) bswap64(x)
Expand Down
6 changes: 0 additions & 6 deletions os/os-solaris.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
#define OS_MAP_ANON MAP_ANON
#define OS_RAND_MAX 2147483648UL

#if defined(_BIG_ENDIAN)
#define FIO_BIG_ENDIAN
#else
#define FIO_LITTLE_ENDIAN
#endif

#define fio_swap16(x) BSWAP_16(x)
#define fio_swap32(x) BSWAP_32(x)
#define fio_swap64(x) BSWAP_64(x)
Expand Down
1 change: 0 additions & 1 deletion os/os-windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

#define OS_MAP_ANON MAP_ANON

#define FIO_LITTLE_ENDIAN
#define fio_swap16(x) _byteswap_ushort(x)
#define fio_swap32(x) _byteswap_ulong(x)
#define fio_swap64(x) _byteswap_uint64(x)
Expand Down
2 changes: 1 addition & 1 deletion os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static inline uint64_t fio_swap64(uint64_t val)
#endif

#ifndef FIO_HAVE_BYTEORDER_FUNCS
#ifdef FIO_LITTLE_ENDIAN
#ifdef CONFIG_LITTLE_ENDIAN
#define __le16_to_cpu(x) (x)
#define __le32_to_cpu(x) (x)
#define __le64_to_cpu(x) (x)
Expand Down
2 changes: 1 addition & 1 deletion server.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ static int handle_probe_cmd(struct fio_net_cmd *cmd)

memset(&probe, 0, sizeof(probe));
gethostname((char *) probe.hostname, sizeof(probe.hostname));
#ifdef FIO_BIG_ENDIAN
#ifdef CONFIG_BIG_ENDIAN
probe.bigendian = 1;
#endif
strncpy((char *) probe.fio_version, fio_version_string, sizeof(probe.fio_version));
Expand Down

0 comments on commit 0dcebdf

Please sign in to comment.