Skip to content

Backport v3.6: Fix IAR endianness detection in alignment.h - #10840

Open
nzzlinh wants to merge 2 commits into
Mbed-TLS:mbedtls-3.6from
nzzlinh:fix_iar_endianess_detection
Open

Backport v3.6: Fix IAR endianness detection in alignment.h#10840
nzzlinh wants to merge 2 commits into
Mbed-TLS:mbedtls-3.6from
nzzlinh:fix_iar_endianess_detection

Conversation

@nzzlinh

@nzzlinh nzzlinh commented Jul 23, 2026

Copy link
Copy Markdown

Description

This is a backport of Mbed-TLS/TF-PSA-Crypto#838.

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 #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(__BIG_ENDIAN__) always evaluated to true on IAR. This commit updates the check to verify the actual value: (__BIG_ENDIAN__ == 1).
image

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

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>
Signed-off-by: nzzlinh <dlinhvn@gmail.com>
@bensze01 bensze01 self-assigned this Jul 23, 2026
@nzzlinh

nzzlinh commented Aug 17, 2026

Copy link
Copy Markdown
Author

Dear @bensze01 ,

Just a quick question. We will need this fix to be merged into the mainstream before we can pull it back into our work, so we are trying to adjust our plan accordingly.

Could you please let us know which MbedTLS release this MR is currently targeted for, and if possible, the tentative timeline for merging?

Thank you 😄

@gilles-peskine-arm gilles-peskine-arm added needs-review Every commit must be reviewed by at least two team members, needs-backports Backports are missing or are pending review and approval. needs-reviewer This PR needs someone to pick it up for review priority-medium Medium priority - this can be reviewed as time permits size-xs Estimated task size: extra small (a few hours at most) labels Aug 17, 2026
@gilles-peskine-arm

Copy link
Copy Markdown
Contributor

@nzzlinh There is no target release. We lack review bandwidth and this pull request is competing with a lot of others.

Applications for becoming a maintainer are open. Serious enquiries only please — in practice, you need to work on features you don't care about in order to make time for the features you don't care about.

@nzzlinh

nzzlinh commented Aug 18, 2026

Copy link
Copy Markdown
Author

@gilles-peskine-arm Thank you for the clarification.

Just to be clear, I was not asking for a target date nor trying to rush the review process. I simply wanted to understand whether there was any plan to include this fix in a future release.

I completely understand that maintainers have limited review bandwidth and many competing priorities. We're happy to wait and appreciate the work that goes into keeping the project healthy.

In any case, thank you for taking the time to respond, and hopefully this fix will find its way into a future release when bandwidth permits.

Many thanks and have a good day 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-backports Backports are missing or are pending review and approval. needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review priority-medium Medium priority - this can be reviewed as time permits size-xs Estimated task size: extra small (a few hours at most)

Projects

Status: In Development

Development

Successfully merging this pull request may close these issues.

3 participants