From 91e75075aec3bacf06b9e3ed91b1de1ec9dd6a67 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Mon, 9 Sep 2019 20:59:45 +0900 Subject: [PATCH] toolchain: Add global check for endianness preprocessor definitions. This commit adds a global check for __BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__ and __ORDER_BIG_ENDIAN__ preprocessor definitions that are used throughout the Zephyr codebase. These preprocessor definitions being not defined can easily go unnoticed and cause unexpected behaviours, as detailed in PR #18922. Signed-off-by: Stephanos Ioannidis --- include/toolchain.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/toolchain.h b/include/toolchain.h index 88cedb0fb3b..adc8c2c1101 100644 --- a/include/toolchain.h +++ b/include/toolchain.h @@ -41,4 +41,18 @@ #include #endif +/* + * Ensure that __BYTE_ORDER__ and related preprocessor definitions are defined, + * as these are often used without checking for definition and doing so can + * cause unexpected behaviours. + */ +#ifndef _LINKER +#if !defined(__BYTE_ORDER__) || !defined(__ORDER_BIG_ENDIAN__) || \ + !defined(__ORDER_LITTLE_ENDIAN__) + +#error "__BYTE_ORDER__ is not defined" + +#endif +#endif /* !_LINKER */ + #endif /* ZEPHYR_INCLUDE_TOOLCHAIN_H_ */