configure: add endian check
Will remove guesswork and manual hacking in the OS headers.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/Makefile b/Makefile
index 967996d..22ea022 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,12 @@
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 e45ae39..795c220 100755
--- a/configure
+++ b/configure
@@ -238,8 +238,25 @@
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
@@ -783,6 +800,11 @@
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 24af397..a408727 100644
--- a/fio.c
+++ b/fio.c
@@ -53,10 +53,10 @@
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 30fcac5..1fe5194 100644
--- a/lib/bswap.h
+++ b/lib/bswap.h
@@ -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;
diff --git a/os/os-aix.h b/os/os-aix.h
index 01b2bdb..3d67765 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 e78a95b..e436f8f 100644
--- a/os/os-android.h
+++ b/os/os-android.h
@@ -13,7 +13,6 @@
#include <sched.h>
#include <linux/unistd.h>
#include <linux/major.h>
-#include <endian.h>
#include "binject.h"
#include "../file.h"
@@ -134,14 +133,6 @@
#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 5012600..c55a7c3 100644
--- a/os/os-freebsd.h
+++ b/os/os-freebsd.h
@@ -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"
@@ -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 266f0f1..82acd11 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 d7eec0f..4e837da 100644
--- a/os/os-linux.h
+++ b/os/os-linux.h
@@ -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"
@@ -194,14 +193,6 @@
#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 6ed26c5..d202e99 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 1753226..4b0269e 100644
--- a/os/os-netbsd.h
+++ b/os/os-netbsd.h
@@ -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>
@@ -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 7dd62a7..de59f77 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 6862226..18de839 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 a14d7f0..fb544a1 100644
--- a/os/os.h
+++ b/os/os.h
@@ -165,7 +165,7 @@
#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 ffa6ed4..bb03c77 100644
--- a/server.c
+++ b/server.c
@@ -403,7 +403,7 @@
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));