-
Notifications
You must be signed in to change notification settings - Fork 318
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
[RFC]: zephyr: CMakeLists: disable packed-related warnings #8521
Conversation
This commit disables the potential missalignment warnings caused by code using address of packed structure member. Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
@@ -830,6 +830,8 @@ if (NOT CONFIG_COMPILER_INLINE_FUNCTION_OPTION) | |||
target_compile_options(SOF INTERFACE -fno-inline-functions) | |||
endif() | |||
|
|||
target_compile_options(SOF INTERFACE -Wno-address-of-packed-member) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its better we keep this, what errors do you see, there may be other/better ways to resolve ? i.e. a snippet from the CC errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mostly stuff like:
/zep_workspace/sof/src/include/sof/coherent.h: In function '__coherent_init_thread':
/zep_workspace/sof/src/include/sof/coherent.h:433:19: warning: taking address of packed member of 'struct coherent' may result in an unaligned pointer value [-Waddress-of-packed-member]
433 | list_init(&c->list);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- no, no idea why
struct coherent
has to be packed, I'd say it doesn't. It was that way from day one of the coherent API - we currently have only one used of the coherent API: src/lib/ams.c - is ams used at all, are there plans to use it? Does it really need and benefit from the coherent API? @kfrydryx
- removing that warning seems like not the right fix for this. I found this explanation on [1] why this warning is useful:
When a program accesses a misaligned member of a packed struct, the compiler generates whatever code is necessary to read or write the correct value.
If the address of a misaligned member is stored in a pointer object, dereferencing that pointer doesn't give the compiler an opportunity to generate that extra code.
64bits warnings can be found in any daily build, example: |
This warning is indeed important in other configurations. It should be at most disabled for LP64 only with something like this: --- a/.github/workflows/zephyr.yml
+++ b/.github/workflows/zephyr.yml
@@ -88,7 +88,7 @@ jobs:
# four 32bits parameters.
cd workspace && ./sof/zephyr/docker-run.sh /bin/sh -c \
'ln -s /opt/toolchains/zephyr-sdk-* ~/;
- west build --board mimx93_evk_a55 sof/app'
+ west build --board mimx93_evk_a55 sof/app -- -DEXTRA_CFLAGS=-Wno...' But even that looks bad. |
Good question. There seems to be a trend to pack everything by default in SOF without justification. It makes sense of course for IPC, storage and other protocols but is it really needed here? The DSP cores have obviously all the same It's often possible to pack "by hand", without using an attribute Have you tried removing Commit 8188387 was especially suspicious because it added a Another option could be to move SOF objects with well defined sizes at the start of the struct and move the mutex at the end? |
Some answers thanks to 32 bits MTL:
When trying to run Anyway, after adding a
Because 24 is 4 bytes aligned whereas 36 is NOT 8 bytes aligned |
"packed" should probably be dropped there. It feels strange to me to misalign fields in a struct named "coherent". Without looking at it in detail, I would intuitively expect something named "coherent" to be "fast and atomic" - assuming misaligned field access is allowed at all. On 32bits systems, On the 64 bits system
|
On 64-bit systems (i.e: i.MX93), marking "struct coherent" as packed leads to compilation warnings such as: "warning: taking address of packed member of 'struct coherent' may result in an unaligned pointer value" This is because the "list" attribute is found at offset 36, which is not 8B-aligned. Since marking "struct coherent" as packed doesn't seem to be necessary, remove this to fix the compilation warnings. A more detailed discussion regarding this issue can be found here: thesofproject#8521. Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
@marc-hb @lyakh thanks for the clarifications ! For now, I submitted #8528 in which we remove the
|
On 64-bit systems (i.e: i.MX93), marking "struct coherent" as packed leads to compilation warnings such as: "warning: taking address of packed member of 'struct coherent' may result in an unaligned pointer value" This is because the "list" attribute is found at offset 36, which is not 8B-aligned. In contrast, 32-bit systems don't have this problem as the "list" attribute is found at offset 24 which is 4B-aligned. Since marking "struct coherent" as packed doesn't seem to be necessary, remove this to fix the compilation warnings. On 32-bit systems, 'pahole' shows no difference between the 'packed' and the non-'packed' cases as the fields are already naturally aligned at the moment. A more detailed discussion regarding this issue can be found here: thesofproject#8521. Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
@LaurentiuM1234 that should anyway be the case, why would one include headers that one doesn't need (*)? (*) the definition of "need" is a bit special here: you include those and only those headers types, prototypes, definitions and declarations from which are used in this file. The only exception is pointers to structures, for those you can just forward-declare those structures and avoid pulling in respective headers. This definition might be incomplete, but it should be pretty close. |
On 64-bit systems (i.e: i.MX93), marking "struct coherent" as packed leads to compilation warnings such as: "warning: taking address of packed member of 'struct coherent' may result in an unaligned pointer value" This is because the "list" attribute is found at offset 36, which is not 8B-aligned. In contrast, 32-bit systems don't have this problem as the "list" attribute is found at offset 24 which is 4B-aligned. Since marking "struct coherent" as packed doesn't seem to be necessary, remove this to fix the compilation warnings. On 32-bit systems, 'pahole' shows no difference between the 'packed' and the non-'packed' cases as the fields are already naturally aligned at the moment. A more detailed discussion regarding this issue can be found here: #8521. Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
I've been requested to review this, and my two cents are that approaches where the structure remains packed yet you take the address of a field are sloppy at best and outright undefined. So if I'd actually review, I'd only approve of the separate pull request that removes "packed" (which was merged as of me finding this thread). You can still consider reordering the structure fields on top of having the packed attribute removed, so that you don't have a hole in the middle of the structure, especially if it helps reducing, if not outright removing, the padding at the end. So: Do not remove warning, remove the need for "packed" and possibly reorder fields to reduce the size of the struct (removing a hole). |
I think we also have some consensus on not #including unused .h files. I've never seen a problem with so many, non-mutually exclusive solutions! :-D |
@LaurentiuM1234 fix is to remove the packing from struct coherent, which I think is now merged ? |
I'm 99% sure this can be closed, @LaurentiuM1234 please re-open if not. |
This is an attempt to reduce the compilation warnings on i.MX93 which is a 64-bit platform.
Frankly I doubt this fix is the way to go, but it's a good opportunity to open a discussion. There's a couple of questions that I have:
Ideally, we should try and fix this as it's become very difficult to find the compilation warnings caused by the introduction of new features with the incredible amount of already existing compilation warnings.
EDIT: example of such a compilation warning:
warning: taking address of packed member of 'struct coherent' may result in an unaligned pointer value