-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PACKED attribute unnecessarily (IDFGH-14532) #15295
Comments
it's same
struct contains only single-byte types, but the
|
Just out of morbid curiosity, did you check generated asm for memory access to see how gcc handles it? I'd like to know if it honors or ignores the attribute in this case. |
The problem that if the structure ever changes, somebody might forget to think about padding. Preemptively adding the attribute for certain structures (typically the ones which have to be transmitted over wire or exchanged with hardware) prevents this mistake.
Seems to me to be not necessary to remove it. Why do you suggest that? |
I'm not sure if that indirectly answers my question, which is itself the the only reasonable reason for removing the attribute. Yay or nay, @igrr ? |
@KaeLL I don't understand your original comment, sorry. Could you clarify what exactly do you mean by "honors or ignores" in "I'd like to know if it honors or ignores the attribute in this case." |
In the cases which the attribute is redundant due to the struct not needing any padding in practice, is GCC aware of this and ignores the attribute? |
|
then they'll have to think about alignment (access to packed memes) anyway |
@safocl One more concern that was considered while adding this PACKED_ATTR attribute is that this structure is shared with the ROM code and the esp-idf sdk. If the structure ever changes due to padding by compiler (maybe in future some reserved bytes are used) and the compiler padding is missed at the time (which is easy to miss). Then it may create bigger issue in maintaining compatibility across multiple revisions of key manager. @KaeLL, since we have defined the attribute, the compiler must always honour it. In this case as the packed struct would be same as the unpacked struct, the compiler won't make any changes. But we shouldn't remove the attribute due to this reasoning as it may be required in future. I hope this resolves relevant comments on this issue, Please help to close the issue if no more concerns. |
however, developers will still have to carefully monitor such code, since access to unaligned memory is undefined behavior. I am closing this issue and hope that the above will not happen -- and we will all keep a close eye on this if possible -- thanks to everyone for the discussion. |
Answers checklist.
General issue report
Some structures are defined with
PACKED_ATTR
, but have a valid offset within themselves (no padding):esp-idf/components/hal/include/hal/key_mgr_types.h
Line 88 in c586527
esp-idf/components/hal/include/hal/key_mgr_types.h
Line 95 in c586527
esp-idf/components/hal/include/hal/key_mgr_types.h
Line 101 in c586527
384/4=96
64/4=16
(4+4+16)/4=6, (4+4+16+384+4)/4=103
guaranteed with no padding.
maybe remove the
PACKED_ATTR
?The text was updated successfully, but these errors were encountered: