From 97d35a552ec5b6ddf7923dd2f9a8eb973526acea Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 17 Oct 2019 15:40:16 -0400 Subject: [PATCH] move __BYTE_ORDER definition to alltypes.h this change is motivated by the intersection of several factors. presently, despite being a nonstandard header, endian.h is exposing the unprefixed byte order macros and functions only if _BSD_SOURCE or _GNU_SOURCE is defined. this is to accommodate use of endian.h from other headers, including bits headers, which need to define structure layout in terms of endianness. with time64 switch-over, even more headers will need to do this. at the same time, the resolution of Austin Group issue 162 makes endian.h a standard header for POSIX-future, requiring that it expose the unprefixed macros and the functions even in standards-conforming profiles. changes to meet this new requirement would break existing internal usage of endian.h by causing it to violate namespace where it's used. instead, have the arch's alltypes.h define __BYTE_ORDER, either as a fixed constant or depending on the right arch-specific predefined macros for determining endianness. explicit literals 1234 and 4321 are used instead of __LITTLE_ENDIAN and __BIG_ENDIAN so that there's no danger of getting the wrong result if a macro is undefined and implicitly evaluates to 0 at the preprocessor level. the powerpc (32-bit) bits/endian.h being removed had logic for varying endianness, but our powerpc arch has never supported that and has always been big-endian-only. this logic is not carried over to the new __BYTE_ORDER definition in alltypes.h. --- arch/aarch64/bits/alltypes.h.in | 6 ++++++ arch/aarch64/bits/endian.h | 5 ----- arch/arm/bits/alltypes.h.in | 6 ++++++ arch/arm/bits/endian.h | 5 ----- arch/i386/bits/alltypes.h.in | 2 ++ arch/i386/bits/endian.h | 1 - arch/m68k/bits/alltypes.h.in | 2 ++ arch/m68k/bits/endian.h | 1 - arch/microblaze/bits/alltypes.h.in | 6 ++++++ arch/microblaze/bits/endian.h | 5 ----- arch/mips/bits/alltypes.h.in | 6 ++++++ arch/mips/bits/endian.h | 5 ----- arch/mips64/bits/alltypes.h.in | 6 ++++++ arch/mips64/bits/endian.h | 5 ----- arch/mipsn32/bits/alltypes.h.in | 6 ++++++ arch/mipsn32/bits/endian.h | 5 ----- arch/or1k/bits/alltypes.h.in | 2 ++ arch/or1k/bits/endian.h | 1 - arch/powerpc/bits/alltypes.h.in | 2 ++ arch/powerpc/bits/endian.h | 15 --------------- arch/powerpc64/bits/alltypes.h.in | 6 ++++++ arch/powerpc64/bits/endian.h | 5 ----- arch/riscv64/bits/alltypes.h.in | 2 ++ arch/riscv64/bits/endian.h | 1 - arch/s390x/bits/alltypes.h.in | 2 ++ arch/s390x/bits/endian.h | 1 - arch/sh/bits/alltypes.h.in | 6 ++++++ arch/sh/bits/endian.h | 5 ----- arch/x32/bits/alltypes.h.in | 2 ++ arch/x32/bits/endian.h | 1 - arch/x86_64/bits/alltypes.h.in | 2 ++ arch/x86_64/bits/endian.h | 1 - include/alltypes.h.in | 3 +++ include/endian.h | 8 +------- 34 files changed, 68 insertions(+), 69 deletions(-) delete mode 100644 arch/aarch64/bits/endian.h delete mode 100644 arch/arm/bits/endian.h delete mode 100644 arch/i386/bits/endian.h delete mode 100644 arch/m68k/bits/endian.h delete mode 100644 arch/microblaze/bits/endian.h delete mode 100644 arch/mips/bits/endian.h delete mode 100644 arch/mips64/bits/endian.h delete mode 100644 arch/mipsn32/bits/endian.h delete mode 100644 arch/or1k/bits/endian.h delete mode 100644 arch/powerpc/bits/endian.h delete mode 100644 arch/powerpc64/bits/endian.h delete mode 100644 arch/riscv64/bits/endian.h delete mode 100644 arch/s390x/bits/endian.h delete mode 100644 arch/sh/bits/endian.h delete mode 100644 arch/x32/bits/endian.h delete mode 100644 arch/x86_64/bits/endian.h diff --git a/arch/aarch64/bits/alltypes.h.in b/arch/aarch64/bits/alltypes.h.in index cb2f4b05..ab2c6a26 100644 --- a/arch/aarch64/bits/alltypes.h.in +++ b/arch/aarch64/bits/alltypes.h.in @@ -2,6 +2,12 @@ #define _Int64 long #define _Reg long +#if __AARCH64EB__ +#define __BYTE_ORDER 4321 +#else +#define __BYTE_ORDER 1234 +#endif + #ifndef __cplusplus TYPEDEF unsigned wchar_t; #endif diff --git a/arch/aarch64/bits/endian.h b/arch/aarch64/bits/endian.h deleted file mode 100644 index 7a74d2fe..00000000 --- a/arch/aarch64/bits/endian.h +++ /dev/null @@ -1,5 +0,0 @@ -#if __AARCH64EB__ -#define __BYTE_ORDER __BIG_ENDIAN -#else -#define __BYTE_ORDER __LITTLE_ENDIAN -#endif diff --git a/arch/arm/bits/alltypes.h.in b/arch/arm/bits/alltypes.h.in index b92ca732..42825bff 100644 --- a/arch/arm/bits/alltypes.h.in +++ b/arch/arm/bits/alltypes.h.in @@ -2,6 +2,12 @@ #define _Int64 long long #define _Reg int +#if __ARMEB__ +#define __BYTE_ORDER 4321 +#else +#define __BYTE_ORDER 1234 +#endif + #ifndef __cplusplus TYPEDEF unsigned wchar_t; #endif diff --git a/arch/arm/bits/endian.h b/arch/arm/bits/endian.h deleted file mode 100644 index 5953724a..00000000 --- a/arch/arm/bits/endian.h +++ /dev/null @@ -1,5 +0,0 @@ -#if __ARMEB__ -#define __BYTE_ORDER __BIG_ENDIAN -#else -#define __BYTE_ORDER __LITTLE_ENDIAN -#endif diff --git a/arch/i386/bits/alltypes.h.in b/arch/i386/bits/alltypes.h.in index c852313c..95491e4b 100644 --- a/arch/i386/bits/alltypes.h.in +++ b/arch/i386/bits/alltypes.h.in @@ -2,6 +2,8 @@ #define _Int64 long long #define _Reg int +#define __BYTE_ORDER 1234 + #ifndef __cplusplus #ifdef __WCHAR_TYPE__ TYPEDEF __WCHAR_TYPE__ wchar_t; diff --git a/arch/i386/bits/endian.h b/arch/i386/bits/endian.h deleted file mode 100644 index 172c338f..00000000 --- a/arch/i386/bits/endian.h +++ /dev/null @@ -1 +0,0 @@ -#define __BYTE_ORDER __LITTLE_ENDIAN diff --git a/arch/m68k/bits/alltypes.h.in b/arch/m68k/bits/alltypes.h.in index 6e9ee3fb..75595f24 100644 --- a/arch/m68k/bits/alltypes.h.in +++ b/arch/m68k/bits/alltypes.h.in @@ -2,6 +2,8 @@ #define _Int64 long long #define _Reg int +#define __BYTE_ORDER 4321 + #ifndef __cplusplus #ifdef __WCHAR_TYPE__ TYPEDEF __WCHAR_TYPE__ wchar_t; diff --git a/arch/m68k/bits/endian.h b/arch/m68k/bits/endian.h deleted file mode 100644 index ef074b77..00000000 --- a/arch/m68k/bits/endian.h +++ /dev/null @@ -1 +0,0 @@ -#define __BYTE_ORDER __BIG_ENDIAN diff --git a/arch/microblaze/bits/alltypes.h.in b/arch/microblaze/bits/alltypes.h.in index 0c7d4917..daea3fcb 100644 --- a/arch/microblaze/bits/alltypes.h.in +++ b/arch/microblaze/bits/alltypes.h.in @@ -2,6 +2,12 @@ #define _Int64 long long #define _Reg int +#if __MICROBLAZEEL__ +#define __BYTE_ORDER 1234 +#else +#define __BYTE_ORDER 4321 +#endif + #ifndef __cplusplus TYPEDEF int wchar_t; #endif diff --git a/arch/microblaze/bits/endian.h b/arch/microblaze/bits/endian.h deleted file mode 100644 index d82a92ac..00000000 --- a/arch/microblaze/bits/endian.h +++ /dev/null @@ -1,5 +0,0 @@ -#if __MICROBLAZEEL__ -#define __BYTE_ORDER __LITTLE_ENDIAN -#else -#define __BYTE_ORDER __BIG_ENDIAN -#endif diff --git a/arch/mips/bits/alltypes.h.in b/arch/mips/bits/alltypes.h.in index 0c7d4917..d5d51289 100644 --- a/arch/mips/bits/alltypes.h.in +++ b/arch/mips/bits/alltypes.h.in @@ -2,6 +2,12 @@ #define _Int64 long long #define _Reg int +#if _MIPSEL || __MIPSEL || __MIPSEL__ +#define __BYTE_ORDER 1234 +#else +#define __BYTE_ORDER 4321 +#endif + #ifndef __cplusplus TYPEDEF int wchar_t; #endif diff --git a/arch/mips/bits/endian.h b/arch/mips/bits/endian.h deleted file mode 100644 index 5399dcb5..00000000 --- a/arch/mips/bits/endian.h +++ /dev/null @@ -1,5 +0,0 @@ -#if _MIPSEL || __MIPSEL || __MIPSEL__ -#define __BYTE_ORDER __LITTLE_ENDIAN -#else -#define __BYTE_ORDER __BIG_ENDIAN -#endif diff --git a/arch/mips64/bits/alltypes.h.in b/arch/mips64/bits/alltypes.h.in index c3ab9676..34776f07 100644 --- a/arch/mips64/bits/alltypes.h.in +++ b/arch/mips64/bits/alltypes.h.in @@ -2,6 +2,12 @@ #define _Int64 long #define _Reg long +#if _MIPSEL || __MIPSEL || __MIPSEL__ +#define __BYTE_ORDER 1234 +#else +#define __BYTE_ORDER 4321 +#endif + #ifndef __cplusplus TYPEDEF int wchar_t; #endif diff --git a/arch/mips64/bits/endian.h b/arch/mips64/bits/endian.h deleted file mode 100644 index 5399dcb5..00000000 --- a/arch/mips64/bits/endian.h +++ /dev/null @@ -1,5 +0,0 @@ -#if _MIPSEL || __MIPSEL || __MIPSEL__ -#define __BYTE_ORDER __LITTLE_ENDIAN -#else -#define __BYTE_ORDER __BIG_ENDIAN -#endif diff --git a/arch/mipsn32/bits/alltypes.h.in b/arch/mipsn32/bits/alltypes.h.in index 0c7d4917..d5d51289 100644 --- a/arch/mipsn32/bits/alltypes.h.in +++ b/arch/mipsn32/bits/alltypes.h.in @@ -2,6 +2,12 @@ #define _Int64 long long #define _Reg int +#if _MIPSEL || __MIPSEL || __MIPSEL__ +#define __BYTE_ORDER 1234 +#else +#define __BYTE_ORDER 4321 +#endif + #ifndef __cplusplus TYPEDEF int wchar_t; #endif diff --git a/arch/mipsn32/bits/endian.h b/arch/mipsn32/bits/endian.h deleted file mode 100644 index 5399dcb5..00000000 --- a/arch/mipsn32/bits/endian.h +++ /dev/null @@ -1,5 +0,0 @@ -#if _MIPSEL || __MIPSEL || __MIPSEL__ -#define __BYTE_ORDER __LITTLE_ENDIAN -#else -#define __BYTE_ORDER __BIG_ENDIAN -#endif diff --git a/arch/or1k/bits/alltypes.h.in b/arch/or1k/bits/alltypes.h.in index b92ca732..a2cae2b6 100644 --- a/arch/or1k/bits/alltypes.h.in +++ b/arch/or1k/bits/alltypes.h.in @@ -2,6 +2,8 @@ #define _Int64 long long #define _Reg int +#define __BYTE_ORDER 4321 + #ifndef __cplusplus TYPEDEF unsigned wchar_t; #endif diff --git a/arch/or1k/bits/endian.h b/arch/or1k/bits/endian.h deleted file mode 100644 index ef074b77..00000000 --- a/arch/or1k/bits/endian.h +++ /dev/null @@ -1 +0,0 @@ -#define __BYTE_ORDER __BIG_ENDIAN diff --git a/arch/powerpc/bits/alltypes.h.in b/arch/powerpc/bits/alltypes.h.in index 618f374c..60c7f1ee 100644 --- a/arch/powerpc/bits/alltypes.h.in +++ b/arch/powerpc/bits/alltypes.h.in @@ -2,6 +2,8 @@ #define _Int64 long long #define _Reg int +#define __BYTE_ORDER 4321 + #ifndef __cplusplus #ifdef __WCHAR_TYPE__ TYPEDEF __WCHAR_TYPE__ wchar_t; diff --git a/arch/powerpc/bits/endian.h b/arch/powerpc/bits/endian.h deleted file mode 100644 index 4442abf4..00000000 --- a/arch/powerpc/bits/endian.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifdef __BIG_ENDIAN__ - #if __BIG_ENDIAN__ - #define __BYTE_ORDER __BIG_ENDIAN - #endif -#endif /* __BIG_ENDIAN__ */ - -#ifdef __LITTLE_ENDIAN__ - #if __LITTLE_ENDIAN__ - #define __BYTE_ORDER __LITTLE_ENDIAN - #endif -#endif /* __LITTLE_ENDIAN__ */ - -#ifndef __BYTE_ORDER - #define __BYTE_ORDER __BIG_ENDIAN -#endif diff --git a/arch/powerpc64/bits/alltypes.h.in b/arch/powerpc64/bits/alltypes.h.in index d525bdc8..395cd7cc 100644 --- a/arch/powerpc64/bits/alltypes.h.in +++ b/arch/powerpc64/bits/alltypes.h.in @@ -2,6 +2,12 @@ #define _Int64 long #define _Reg long +#if __BIG_ENDIAN__ +#define __BYTE_ORDER 4321 +#else +#define __BYTE_ORDER 1234 +#endif + #ifndef __cplusplus TYPEDEF int wchar_t; #endif diff --git a/arch/powerpc64/bits/endian.h b/arch/powerpc64/bits/endian.h deleted file mode 100644 index 2016cb20..00000000 --- a/arch/powerpc64/bits/endian.h +++ /dev/null @@ -1,5 +0,0 @@ -#if __BIG_ENDIAN__ -#define __BYTE_ORDER __BIG_ENDIAN -#else -#define __BYTE_ORDER __LITTLE_ENDIAN -#endif diff --git a/arch/riscv64/bits/alltypes.h.in b/arch/riscv64/bits/alltypes.h.in index 70c4fe76..54dfc7db 100644 --- a/arch/riscv64/bits/alltypes.h.in +++ b/arch/riscv64/bits/alltypes.h.in @@ -2,6 +2,8 @@ #define _Int64 long #define _Reg long +#define __BYTE_ORDER 1234 + #ifndef __cplusplus TYPEDEF int wchar_t; #endif diff --git a/arch/riscv64/bits/endian.h b/arch/riscv64/bits/endian.h deleted file mode 100644 index 172c338f..00000000 --- a/arch/riscv64/bits/endian.h +++ /dev/null @@ -1 +0,0 @@ -#define __BYTE_ORDER __LITTLE_ENDIAN diff --git a/arch/s390x/bits/alltypes.h.in b/arch/s390x/bits/alltypes.h.in index 92845ce0..1f392b1a 100644 --- a/arch/s390x/bits/alltypes.h.in +++ b/arch/s390x/bits/alltypes.h.in @@ -2,6 +2,8 @@ #define _Int64 long #define _Reg long +#define __BYTE_ORDER 4321 + #ifndef __cplusplus TYPEDEF int wchar_t; #endif diff --git a/arch/s390x/bits/endian.h b/arch/s390x/bits/endian.h deleted file mode 100644 index ef074b77..00000000 --- a/arch/s390x/bits/endian.h +++ /dev/null @@ -1 +0,0 @@ -#define __BYTE_ORDER __BIG_ENDIAN diff --git a/arch/sh/bits/alltypes.h.in b/arch/sh/bits/alltypes.h.in index 618f374c..5952e9e6 100644 --- a/arch/sh/bits/alltypes.h.in +++ b/arch/sh/bits/alltypes.h.in @@ -2,6 +2,12 @@ #define _Int64 long long #define _Reg int +#if __BIG_ENDIAN__ +#define __BYTE_ORDER 4321 +#else +#define __BYTE_ORDER 1234 +#endif + #ifndef __cplusplus #ifdef __WCHAR_TYPE__ TYPEDEF __WCHAR_TYPE__ wchar_t; diff --git a/arch/sh/bits/endian.h b/arch/sh/bits/endian.h deleted file mode 100644 index 2016cb20..00000000 --- a/arch/sh/bits/endian.h +++ /dev/null @@ -1,5 +0,0 @@ -#if __BIG_ENDIAN__ -#define __BYTE_ORDER __BIG_ENDIAN -#else -#define __BYTE_ORDER __LITTLE_ENDIAN -#endif diff --git a/arch/x32/bits/alltypes.h.in b/arch/x32/bits/alltypes.h.in index c71f2468..5d7a1279 100644 --- a/arch/x32/bits/alltypes.h.in +++ b/arch/x32/bits/alltypes.h.in @@ -2,6 +2,8 @@ #define _Int64 long long #define _Reg long long +#define __BYTE_ORDER 1234 + #ifndef __cplusplus #ifdef __WCHAR_TYPE__ TYPEDEF __WCHAR_TYPE__ wchar_t; diff --git a/arch/x32/bits/endian.h b/arch/x32/bits/endian.h deleted file mode 100644 index 172c338f..00000000 --- a/arch/x32/bits/endian.h +++ /dev/null @@ -1 +0,0 @@ -#define __BYTE_ORDER __LITTLE_ENDIAN diff --git a/arch/x86_64/bits/alltypes.h.in b/arch/x86_64/bits/alltypes.h.in index a484f177..b815b438 100644 --- a/arch/x86_64/bits/alltypes.h.in +++ b/arch/x86_64/bits/alltypes.h.in @@ -2,6 +2,8 @@ #define _Int64 long #define _Reg long +#define __BYTE_ORDER 1234 + #ifndef __cplusplus TYPEDEF int wchar_t; #endif diff --git a/arch/x86_64/bits/endian.h b/arch/x86_64/bits/endian.h deleted file mode 100644 index 172c338f..00000000 --- a/arch/x86_64/bits/endian.h +++ /dev/null @@ -1 +0,0 @@ -#define __BYTE_ORDER __LITTLE_ENDIAN diff --git a/include/alltypes.h.in b/include/alltypes.h.in index 8e76c839..1ab40395 100644 --- a/include/alltypes.h.in +++ b/include/alltypes.h.in @@ -1,3 +1,6 @@ +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 + TYPEDEF unsigned _Addr size_t; TYPEDEF unsigned _Addr uintptr_t; TYPEDEF _Addr ptrdiff_t; diff --git a/include/endian.h b/include/endian.h index 1bd44451..2c2ad5f4 100644 --- a/include/endian.h +++ b/include/endian.h @@ -3,15 +3,9 @@ #include -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 #define __PDP_ENDIAN 3412 -#if defined(__GNUC__) && defined(__BYTE_ORDER__) -#define __BYTE_ORDER __BYTE_ORDER__ -#else -#include -#endif +#include #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -- 2.25.1