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 <root@stephanos.io>
This commit is contained in:
Stephanos Ioannidis 2019-09-09 20:59:45 +09:00 committed by Carles Cufí
commit 91e75075ae

View file

@ -41,4 +41,18 @@
#include <toolchain/other.h>
#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_ */