move __BYTE_ORDER definition to alltypes.h
authorRich Felker <dalias@aerifal.cx>
Thu, 17 Oct 2019 19:40:16 +0000 (15:40 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 17 Oct 2019 19:55:15 +0000 (15:55 -0400)
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.

34 files changed:
arch/aarch64/bits/alltypes.h.in
arch/aarch64/bits/endian.h [deleted file]
arch/arm/bits/alltypes.h.in
arch/arm/bits/endian.h [deleted file]
arch/i386/bits/alltypes.h.in
arch/i386/bits/endian.h [deleted file]
arch/m68k/bits/alltypes.h.in
arch/m68k/bits/endian.h [deleted file]
arch/microblaze/bits/alltypes.h.in
arch/microblaze/bits/endian.h [deleted file]
arch/mips/bits/alltypes.h.in
arch/mips/bits/endian.h [deleted file]
arch/mips64/bits/alltypes.h.in
arch/mips64/bits/endian.h [deleted file]
arch/mipsn32/bits/alltypes.h.in
arch/mipsn32/bits/endian.h [deleted file]
arch/or1k/bits/alltypes.h.in
arch/or1k/bits/endian.h [deleted file]
arch/powerpc/bits/alltypes.h.in
arch/powerpc/bits/endian.h [deleted file]
arch/powerpc64/bits/alltypes.h.in
arch/powerpc64/bits/endian.h [deleted file]
arch/riscv64/bits/alltypes.h.in
arch/riscv64/bits/endian.h [deleted file]
arch/s390x/bits/alltypes.h.in
arch/s390x/bits/endian.h [deleted file]
arch/sh/bits/alltypes.h.in
arch/sh/bits/endian.h [deleted file]
arch/x32/bits/alltypes.h.in
arch/x32/bits/endian.h [deleted file]
arch/x86_64/bits/alltypes.h.in
arch/x86_64/bits/endian.h [deleted file]
include/alltypes.h.in
include/endian.h

index cb2f4b052506db13f50f2e8258bfda394ea306f8..ab2c6a2628512715e301215236590b77353f8764 100644 (file)
@@ -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 (file)
index 7a74d2f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#if __AARCH64EB__
-#define __BYTE_ORDER __BIG_ENDIAN
-#else
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#endif
index b92ca732d94261b89048c16f3a4aa2493dab5196..42825bff4234ce7139c56f1c1a58b1db841b35ff 100644 (file)
@@ -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 (file)
index 5953724..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#if __ARMEB__
-#define __BYTE_ORDER __BIG_ENDIAN
-#else
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#endif
index c852313caad07d9f7f418a4a5d2e1d74e9d5a5f5..95491e4b8473848a3db60303d513644ad39b333d 100644 (file)
@@ -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 (file)
index 172c338..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#define __BYTE_ORDER __LITTLE_ENDIAN
index 6e9ee3fbfc55a601291944f693b2568375daad96..75595f2453164cb26ebdc98685deba5ea19e95f3 100644 (file)
@@ -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 (file)
index ef074b7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#define __BYTE_ORDER __BIG_ENDIAN
index 0c7d4917e7f0c4052674ddb472eda3e5c77ef15d..daea3fcb79b5b782bfd46a9b74f1871874c50583 100644 (file)
@@ -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 (file)
index d82a92a..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#if __MICROBLAZEEL__
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#else
-#define __BYTE_ORDER __BIG_ENDIAN
-#endif
index 0c7d4917e7f0c4052674ddb472eda3e5c77ef15d..d5d512898264e9d61b69979fb6516c22c24482c9 100644 (file)
@@ -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 (file)
index 5399dcb..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#if _MIPSEL || __MIPSEL || __MIPSEL__
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#else
-#define __BYTE_ORDER __BIG_ENDIAN
-#endif
index c3ab9676284b39aba095d0cae3af28ced5b96270..34776f071a545b75d5f0e29a1edf7460dc6f3cf8 100644 (file)
@@ -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 (file)
index 5399dcb..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#if _MIPSEL || __MIPSEL || __MIPSEL__
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#else
-#define __BYTE_ORDER __BIG_ENDIAN
-#endif
index 0c7d4917e7f0c4052674ddb472eda3e5c77ef15d..d5d512898264e9d61b69979fb6516c22c24482c9 100644 (file)
@@ -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 (file)
index 5399dcb..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#if _MIPSEL || __MIPSEL || __MIPSEL__
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#else
-#define __BYTE_ORDER __BIG_ENDIAN
-#endif
index b92ca732d94261b89048c16f3a4aa2493dab5196..a2cae2b6667612f3e00994b844545357840967cb 100644 (file)
@@ -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 (file)
index ef074b7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#define __BYTE_ORDER __BIG_ENDIAN
index 618f374cf133af2491dc89ea0edf8814395de76d..60c7f1ee42406876c91506f97ca94cd44824b31a 100644 (file)
@@ -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 (file)
index 4442abf..0000000
+++ /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
index d525bdc890921cea1ae800243ab56d56e10c7b65..395cd7cca09f47000274713cda7e2073a8273699 100644 (file)
@@ -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 (file)
index 2016cb2..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#if __BIG_ENDIAN__
-#define __BYTE_ORDER __BIG_ENDIAN
-#else
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#endif
index 70c4fe7628d9053748218013b305a3efe787dbd1..54dfc7db4080fb9ba739641cda76512b97eaffaf 100644 (file)
@@ -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 (file)
index 172c338..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#define __BYTE_ORDER __LITTLE_ENDIAN
index 92845ce0595965291d9cbb902d3d62827afa617a..1f392b1a67e2d9300080c58dba043ec2d6524e72 100644 (file)
@@ -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 (file)
index ef074b7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#define __BYTE_ORDER __BIG_ENDIAN
index 618f374cf133af2491dc89ea0edf8814395de76d..5952e9e6ac0407960f1cb323ecfd0fdcabed61f9 100644 (file)
@@ -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 (file)
index 2016cb2..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#if __BIG_ENDIAN__
-#define __BYTE_ORDER __BIG_ENDIAN
-#else
-#define __BYTE_ORDER __LITTLE_ENDIAN
-#endif
index c71f2468153d6d151a7964d2fed8466f3b690084..5d7a1279293a31a6aada9c770fab32f6fc3c3deb 100644 (file)
@@ -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 (file)
index 172c338..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#define __BYTE_ORDER __LITTLE_ENDIAN
index a484f17796ecda3ab27c9f9343740221e509282b..b815b438d59aad2aa17ee026741444507a81e6de 100644 (file)
@@ -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 (file)
index 172c338..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#define __BYTE_ORDER __LITTLE_ENDIAN
index 8e76c83908d5d28c970226bd6a2130b0ac5b7226..1ab40395ac20d0f112de93a90813e741a2d2ea37 100644 (file)
@@ -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;
index 1bd444518ab5febecb6cec6e2e7693c29359d082..2c2ad5f4ec0162a5ded561d88d0973e216a24e4a 100644 (file)
@@ -3,15 +3,9 @@
 
 #include <features.h>
 
-#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 <bits/endian.h>
-#endif
+#include <bits/alltypes.h>
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)