LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH, RFC] byteorder: sanity check toolchain vs kernel endianess
@ 2019-04-12 14:35 Christoph Hellwig
  2019-04-12 14:53 ` Arnd Bergmann
  2019-05-30  1:46 ` Maciej Rozycki
  0 siblings, 2 replies; 14+ messages in thread
From: Christoph Hellwig @ 2019-04-12 14:35 UTC (permalink / raw)
  To: torvalds, akpm; +Cc: arnd, linux-arch, mick, linux-kernel

When removing some dead big endian checks in the RISC-V code Nick
suggested that we should have some generic sanity checks.  I don't think
we should have thos inside the RISC-V code, but maybe it might make
sense to have these in the generic byteorder headers.  Note that these
are UAPI headers and some compilers might not actually define
__BYTE_ORDER__, so we first check that it actually exists.

Suggested-by: Nick Kossifidis <mick@ics.forth.gr>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/uapi/linux/byteorder/big_endian.h    | 4 ++++
 include/uapi/linux/byteorder/little_endian.h | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/include/uapi/linux/byteorder/big_endian.h b/include/uapi/linux/byteorder/big_endian.h
index 2199adc6a6c2..34a5864526d2 100644
--- a/include/uapi/linux/byteorder/big_endian.h
+++ b/include/uapi/linux/byteorder/big_endian.h
@@ -2,6 +2,10 @@
 #ifndef _UAPI_LINUX_BYTEORDER_BIG_ENDIAN_H
 #define _UAPI_LINUX_BYTEORDER_BIG_ENDIAN_H
 
+#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__
+#error "Unsupported endianess, check your toolchain"
+#endif
+
 #ifndef __BIG_ENDIAN
 #define __BIG_ENDIAN 4321
 #endif
diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
index 601c904fd5cd..0cdf3583e19f 100644
--- a/include/uapi/linux/byteorder/little_endian.h
+++ b/include/uapi/linux/byteorder/little_endian.h
@@ -2,6 +2,10 @@
 #ifndef _UAPI_LINUX_BYTEORDER_LITTLE_ENDIAN_H
 #define _UAPI_LINUX_BYTEORDER_LITTLE_ENDIAN_H
 
+#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ !=  __ORDER_LITTLE_ENDIAN__
+#error "Unsupported endianess, check your toolchain"
+#endif
+
 #ifndef __LITTLE_ENDIAN
 #define __LITTLE_ENDIAN 1234
 #endif
-- 
2.20.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-05-30  6:41 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12 14:35 [PATCH, RFC] byteorder: sanity check toolchain vs kernel endianess Christoph Hellwig
2019-04-12 14:53 ` Arnd Bergmann
2019-04-12 14:55   ` Christoph Hellwig
2019-04-12 15:22     ` Arnd Bergmann
2019-04-12 16:05   ` Nick Kossifidis
2019-05-10 10:53     ` Dmitry Vyukov
2019-05-11  0:51       ` Arnd Bergmann
2019-05-13  7:39         ` Dmitry Vyukov
2019-05-13 11:33           ` Michael Ellerman
2019-05-13 11:50             ` Dmitry Vyukov
2019-05-13 12:04               ` Christoph Hellwig
2019-05-15  6:53                 ` Arnd Bergmann
2019-05-30  1:46 ` Maciej Rozycki
2019-05-30  6:41   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).