Fix IAR compiler endianness detection in alignment.h - #838
Open
nzzlinh wants to merge 3 commits into
Open
Conversation
Author
|
Related issue in MbedTLS repo: Mbed-TLS/mbedtls#10381 |
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: Linh D. Nguyen <dlinhvn@gmail.com>
nzzlinh
force-pushed
the
fix-iar-endianness
branch
from
July 14, 2026 15:04
a24fdd7 to
df9bddb
Compare
gilles-peskine-arm
previously approved these changes
Jul 20, 2026
gilles-peskine-arm
left a comment
Contributor
There was a problem hiding this comment.
LGTM on code reading.
(I haven't tested because I don't have a big-endian arm testing environment readily available, and I do have access to IAR for arm but the license server is down at the moment.)
5 tasks
Signed-off-by: Linh D. Nguyen <dlinhvn@gmail.com>
5 tasks
Signed-off-by: Linh D. Nguyen <dlinhvn@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a critical bug where the IAR compiler always triggers the Little-Endian code path, even when compiling for Big-Endian CPU. Fix Mbed-TLS/mbedtls#10381
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 checkdefined(__BIG_ENDIAN__)always evaluated to true on IAR. This commit updates the check to verify the actual value:(__BIG_ENDIAN__ == 1).References from IAR Development Guide for several MCU families
[1] ARM: https://wwwfiles.iar.com/arm/webic/doc/EWARM_DevelopmentGuide.ENU.pdf - p.494
[2] Renesas RX: https://wwwfiles.iar.com/RX/webic/doc/EWRX_DevelopmentGuide.ENU.pdf - p. 428
[3] Renesas RL78: https://wwwfiles.iar.com/rl78/EWRL78_DevelopmentGuide.ENU.pdf -p.389
[4] STM8: https://wwwfiles.iar.com/stm8/guides/EWSTM8_DevelopmentGuide.pdf - p.334
PR checklist