From a40b2767c5c9b855f5d20b4b6c167a2263914bbc Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 30 Mar 2020 18:30:19 +0200 Subject: [PATCH] Fix endian check for little endian PowerPC and maybe others This fixes various subtle breakage on ppc64le at very least. --- src/include/janet.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/include/janet.h b/src/include/janet.h index 6d5b7de0..9fb9f416 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -97,7 +97,14 @@ extern "C" { #endif /* Check big endian */ -#if defined(__MIPSEB__) /* MIPS 32-bit */ \ +#if defined(__LITTLE_ENDIAN__) || \ + (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) +/* If we know the target is LE, always use that - e.g. ppc64 little endian + * defines the __LITTLE_ENDIAN__ macro in the ABI spec, so we can rely + * on that and if that's not defined, fall back to big endian assumption + */ +#define JANET_LITTLE_ENDIAN 1 +#elif defined(__MIPSEB__) /* MIPS 32-bit */ \ || defined(__ppc__) || defined(__PPC__) /* CPU(PPC) - PowerPC 32-bit */ \ || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) \ || defined(_M_PPC) || defined(__PPC) \