Skip to content

Commit 85edb9c

Browse files
committed
Fix IAR compiler endianness detection in alignment.h
The IAR C/C++ compiler always defines both __LITTLE_ENDIAN__ and __BIG_ENDIAN__ macros internally, assigning '1' to the active endianness and '0' to the inactive one. The previous check defined(__LITTLE_ENDIAN__) always evaluated to true on IAR, causing big-endian targets to be incorrectly treated as little-endian. This commit updates the check to verify the value (__XXXX_ENDIAN__ == 1) Signed-off-by: nzzlinh <dlinhvn@gmail.com>
1 parent 8572c4a commit 85edb9c

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

ChangeLog.d/fix_iar_endianess.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Bugfix
2+
* Fix incorrect big-endian detection for the IAR compiler in library/alignment.h which caused big-endian targets to be misidentified.

library/alignment.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ static inline uint64_t mbedtls_bswap64(uint64_t x)
400400

401401
#if !defined(__BYTE_ORDER__)
402402

403-
#if defined(__LITTLE_ENDIAN__)
403+
#if defined(__LITTLE_ENDIAN__) && (__LITTLE_ENDIAN__ == 1)
404404
/* IAR defines __xxx_ENDIAN__, but not __BYTE_ORDER__ */
405405
#define MBEDTLS_IS_BIG_ENDIAN 0
406-
#elif defined(__BIG_ENDIAN__)
406+
#elif defined(__BIG_ENDIAN__) && (__BIG_ENDIAN__ == 1)
407407
#define MBEDTLS_IS_BIG_ENDIAN 1
408408
#else
409409
static const uint16_t mbedtls_byte_order_detector = { 0x100 };

0 commit comments

Comments
 (0)