Skip to content

[zep fromtree] [1.1] Fix alignment problems with IAR and Zephyr#7

Open
zejiang0jason wants to merge 1 commit into
zephyrproject-rtos:zephyr_tf-psa-crypto_v1.1.0from
zejiang0jason:fix_iar_packed_conflict
Open

[zep fromtree] [1.1] Fix alignment problems with IAR and Zephyr#7
zejiang0jason wants to merge 1 commit into
zephyrproject-rtos:zephyr_tf-psa-crypto_v1.1.0from
zejiang0jason:fix_iar_packed_conflict

Conversation

@zejiang0jason
Copy link
Copy Markdown

@zejiang0jason zejiang0jason commented Apr 12, 2026

In IAR __packed can be used for type definition, as described: https://mypages.iar.com/s/article/Accessing-Unaligned-Data

Zephyr defined __packed as __attribute__((__packed__)), which makes __packed can't be used for typedef. THe error is:

Recover the __packed temporarily, make it can be used for typedef.

The error can reproduced by project samples/drivers/crypto/

@zejiang0jason
Copy link
Copy Markdown
Author

Not sure whether this is a good fix, the root cause is, Zephyr's __packed conflicts with IAR's keyword.

https://github.com/zephyrproject-rtos/zephyr/blob/b9b37edd2cc561cad6f782465a2a5bf5da44df4b/include/zephyr/toolchain/iar/iccarm.h#L153-L155

Copy link
Copy Markdown
Collaborator

@tomi-font tomi-font left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please submit this fix upstream: https://github.com/Mbed-TLS/TF-PSA-Crypto
And then cherry-pick it here.

@zejiang0jason
Copy link
Copy Markdown
Author

Hi @tomi-font , I also consider push to upstream.

My main consideration is, this __packed definition is done in Zephyr code,
https://github.com/zephyrproject-rtos/zephyr/blob/b9b37edd2cc561cad6f782465a2a5bf5da44df4b/include/zephyr/toolchain/iar/iccarm.h#L153-L155

#ifndef __packed
#define __packed        __attribute__((__packed__))
#endif

Should it be handled in Zephyr? thanks.

@tomi-font
Copy link
Copy Markdown
Collaborator

I think this change is generic enough that it could be accepted upstream. We want to avoid local patches in this repo whenever you can.
@valeriosetti can assist you with moving the PR forward upstream

@valeriosetti
Copy link
Copy Markdown
Collaborator

Wait, I think the concern raised by @zejiang0jason is correct. Upstream TF-PSA-Crypto follows what's being suggested by IAR compiler for when it comes to access unaligned data, so I think this is fine.

I suspect that as @zejiang0jason stated the problem in Zephyr is in https://github.com/zephyrproject-rtos/zephyr/blob/b9b37edd2cc561cad6f782465a2a5bf5da44df4b/include/zephyr/toolchain/iar/iccarm.h#L153-L155, which is in the main Zephyr repo. There __packed is being defined as __attribute__((__packed__)) which is OK for GCC but not for IAR. Somehow when that header is parsed __packed is not defined so it gets redefined in the wrong way.
The commit that introduced this support claims it to be "experimental". Perhaps @RobinKastberg (who worked on that commit) can help us on this?

@RobinKastberg
Copy link
Copy Markdown

Yes, we had a lot of issues with IAR-aware modules using __packed in the expected IAR-way, but rest of zephyr expecing a __packed from GNU.

I will defer this to @LoveKarlsson who has been trying to fix this upstream here: Mbed-TLS#410

@LoveKarlsson
Copy link
Copy Markdown

My fixes for this has now been merged and backported to 1.1 and mbedtls3.6

@valeriosetti
Copy link
Copy Markdown
Collaborator

@zejiang0jason can you please replace the commit in this PR with the cherry-pick -x of Mbed-TLS#779?

@zejiang0jason zejiang0jason force-pushed the fix_iar_packed_conflict branch from 1c16831 to d98c5ce Compare May 6, 2026 03:15
@zejiang0jason zejiang0jason requested a review from tomi-font May 6, 2026 03:16
@zejiang0jason
Copy link
Copy Markdown
Author

@zejiang0jason can you please replace the commit in this PR with the cherry-pick -x of Mbed-TLS#779?

updated, thanks.

@zejiang0jason zejiang0jason force-pushed the fix_iar_packed_conflict branch from d98c5ce to c8080e3 Compare May 6, 2026 07:29
@valeriosetti
Copy link
Copy Markdown
Collaborator

Now you only need to change the commit title to have the [zep fromtree] at the beginning and then we can merge it

@zejiang0jason zejiang0jason force-pushed the fix_iar_packed_conflict branch from c8080e3 to eba804c Compare May 6, 2026 09:59
@zejiang0jason
Copy link
Copy Markdown
Author

Thanks, added.

Now you only need to change the commit title to have the [zep fromtree] at the [beginning]

Copy link
Copy Markdown
Collaborator

@tomi-font tomi-font left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the [1.1] and we're good

@tomi-font tomi-font changed the title [zep noup] Recover IAR __packed temporarily for typedef [zep fromtree] Recover IAR __packed temporarily for typedef May 6, 2026
@valeriosetti
Copy link
Copy Markdown
Collaborator

remove the [1.1] and we're good

I thought about this as well, but [1.1] is part of the upstream commit to the 1.1 branch. No strong preference on this, I just wanted to let you know

@tomi-font
Copy link
Copy Markdown
Collaborator

ah 😄 we're good then

@tomi-font tomi-font changed the title [zep fromtree] Recover IAR __packed temporarily for typedef [zep fromtree] [1.1] Fix alignment problems with IAR and Zephyr May 6, 2026
@tomi-font
Copy link
Copy Markdown
Collaborator

I would just put a space between the two brackets.

Since __packed is a reserved keyword for IAR compilers, and
Zephyr defines it to attribute(__packed__), some typedef constructs
in TF-PSA-Crypto does not work with attribute(packed), only with the
keyword __packed.

Added changelog entry.

This fix temporary undefs the macro and restores it after the typedefs.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@qt.io>
(cherry picked from commit e544d70)
@zejiang0jason zejiang0jason force-pushed the fix_iar_packed_conflict branch from eba804c to b67ce56 Compare May 6, 2026 10:24
@zejiang0jason
Copy link
Copy Markdown
Author

I would just put a space between the two brackets.

done

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants