From 0dcebdf4a70ef0d8144b8fcba763ae87e7fc74b5 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 23 Jan 2013 15:42:16 -0700 Subject: [PATCH] configure: add endian check Will remove guesswork and manual hacking in the OS headers. Signed-off-by: Jens Axboe --- Makefile | 6 ++++++ configure | 22 ++++++++++++++++++++++ fio.c | 4 ++-- lib/bswap.h | 2 +- os/os-aix.h | 6 ------ os/os-android.h | 9 --------- os/os-freebsd.h | 7 ------- os/os-hpux.h | 6 ------ os/os-linux.h | 9 --------- os/os-mac.h | 8 -------- os/os-netbsd.h | 7 ------- os/os-solaris.h | 6 ------ os/os-windows.h | 1 - os/os.h | 2 +- server.c | 2 +- 15 files changed, 33 insertions(+), 64 deletions(-) diff --git a/Makefile b/Makefile index 967996d7..22ea022a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/configure b/configure index e45ae394..795c2203 100755 --- a/configure +++ b/configure @@ -238,8 +238,25 @@ fi cc="${CC-${cross_prefix}gcc}" +########################################## +# check endianness +bigendian="no" +cat > $TMPC < +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 @@ -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 diff --git a/fio.c b/fio.c index 24af397a..a4087273 100644 --- a/fio.c +++ b/fio.c @@ -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 diff --git a/lib/bswap.h b/lib/bswap.h index 30fcac54..1fe51947 100644 --- a/lib/bswap.h +++ b/lib/bswap.h @@ -3,7 +3,7 @@ #include -#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; diff --git a/os/os-aix.h b/os/os-aix.h index 01b2bdbb..3d677650 100644 --- a/os/os-aix.h +++ b/os/os-aix.h @@ -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) diff --git a/os/os-android.h b/os/os-android.h index e78a95bf..e436f8fb 100644 --- a/os/os-android.h +++ b/os/os-android.h @@ -13,7 +13,6 @@ #include #include #include -#include #include "binject.h" #include "../file.h" @@ -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) diff --git a/os/os-freebsd.h b/os/os-freebsd.h index 50126009..c55a7c31 100644 --- a/os/os-freebsd.h +++ b/os/os-freebsd.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "../file.h" @@ -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) diff --git a/os/os-hpux.h b/os/os-hpux.h index 266f0f1f..82acd110 100644 --- a/os/os-hpux.h +++ b/os/os-hpux.h @@ -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 diff --git a/os/os-linux.h b/os/os-linux.h index d7eec0f2..4e837da9 100644 --- a/os/os-linux.h +++ b/os/os-linux.h @@ -15,7 +15,6 @@ #include #include #include -#include #include "binject.h" #include "../file.h" @@ -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) diff --git a/os/os-mac.h b/os/os-mac.h index 6ed26c57..d202e99d 100644 --- a/os/os-mac.h +++ b/os/os-mac.h @@ -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) diff --git a/os/os-netbsd.h b/os/os-netbsd.h index 1753226e..4b0269e6 100644 --- a/os/os-netbsd.h +++ b/os/os-netbsd.h @@ -6,7 +6,6 @@ #include #include #include -#include /* XXX hack to avoid confilcts between rbtree.h and */ #define rb_node _rb_node #include @@ -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) diff --git a/os/os-solaris.h b/os/os-solaris.h index 7dd62a71..de59f774 100644 --- a/os/os-solaris.h +++ b/os/os-solaris.h @@ -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) diff --git a/os/os-windows.h b/os/os-windows.h index 6862226a..18de8398 100644 --- a/os/os-windows.h +++ b/os/os-windows.h @@ -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) diff --git a/os/os.h b/os/os.h index a14d7f0c..fb544a17 100644 --- a/os/os.h +++ b/os/os.h @@ -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) diff --git a/server.c b/server.c index ffa6ed4b..bb03c779 100644 --- a/server.c +++ b/server.c @@ -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)); -- 2.25.1