-
Notifications
You must be signed in to change notification settings - Fork 322
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
module_adapter: Fix compilation error with Xtensa toolchain #7841
Conversation
We get the following error using Xtensa toolchain on i.MX: src/audio/module_adapter/module_adapter.c: In function ‘module_adapter_sink_src_prepare’: src/audio/module_adapter/module_adapter.c:207: error: ‘for’ loop initial declaration used outside C99 mode src/audio/module_adapter/module_adapter.c:211: error: redefinition of ‘i’ src/audio/module_adapter/module_adapter.c:207: error: previous definition of ‘i’ was here src/audio/module_adapter/module_adapter.c:211: error: ‘for’ loop initial declaration used outside C99 mode Fix this by declaring `i` at the top of the function. Fixes: fa77edf ("pipeline2.0: change module prepare API to use sink/src.c") Signed-off-by: Daniel Baluta <[email protected]>
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.
Thanks. I've been slipping C99'isms through in recent reviews as it seems all our targets we have in our CI accept them (and we seem to have more and more SOF developers customed to C99), but this has not really been discussed anywhere. And we are not enforcing C99 for SOF (we are not building with std=c99), so stricly speaking we should not be using C99 features (or we should enforce C99).
It's still an issue if we don't have any compilers that would complain about this in our PR CI. I wonder if we should just bump the req to C99. I think @dbaluta your Xtensa toolchain would accept this code if you pass std=c99 .
FYI to @aborisovich @marc-hb
@dbaluta "outside C99 mode" - does it mean that the compiler in principle supports C99 but the flags are wrong? Maybe fix the flags instead? |
Note the SOF codebase has had some C99 declarations NOT located at the top of a EDIT: discussed in https://github.com/orgs/thesofproject/discussions/7395 and elsewhere. Same thing with C99 comments Of course this is not a proof that all C99 features never caused any problem to anyone - but it's a pretty good indication. |
@dbaluta Can you try compilation with "-std=c99" with this toolchain? Given Zephyr does depend on many C99 features explicitly (https://docs.zephyrproject.org/latest/develop/languages/c/index.html ) , it would seem to make sense to bump to align in SOF as well. |
For the command line Zephyr has Of course you can also put it in some |
Let me try " "-std=c99" with our toolchain. |
The specific problem here are not the C99 declarations at the top, but actually it looks like C89 isn't smart enough to recognize the scope of the Anyhow, Using: XTENSA_TOOLS_ROOT=~/work/repos/imx-audio-toolchain/Xtensa_Tool/ EXTRA_CFLAGS="-std=gnu99" ./scripts/xtensa-build-all.sh imx8 fixes the problem. We can fix that in our build env. Should we turn on c99 by default? |
Yes and pretty sure this is another... C99 feature. I can't imagine any toolchain supporting one of these C99 features but not the other, they're very similar.
It would make sense considering SOF has been using (some) C99 features since forever. BTW we're in 2023 :-) BTW even the Linux kernel is finally relaxing (a bit) its "C89 declarations" code style. It was getting in the way of another modern feature: https://lwn.net/Articles/934679/ |
Enabling some more components I get this error:
Do you see any problems like this with your private Cadence toolchain? |
I think we generally don't use -Werror with Cadence toolchains but no, I don't remember seeing these warnings or any other warning for that matter. @dbaluta you can see Cadence compilation logs in every PR, click on "sof-ci/jenkins/pr-fw-build". For instance here: https://sof-ci.01.org/sofpr/PR7841/build9926/build/mtl_zph_ipc4.txt What gcc version is yours based on? Our oldest Cadence toolchain still used on the main branch is based on gcc 4: #7114 There may be older ones still in use on stable-v2.2. Just open any recent stable-v2.2 PR and open the same link. |
Not sure how to figure out which gcc is your xtensa compiler based on. ./Xtensa_Tool/tools/RG-2017.8-linux/XtensaTools/bin/xt-xcc -v Anyhow, for now I fixed the problem EXTRA_CFLAGS="-std=gnu99 -fgnu89-inline" I want to understand if you build DRC component which by default is N and caused the troubles mentioned above. Later edit: Your Cadence compilation logs do not show DRC component being built. As far as I can figure out from the logs. Most likely you will get the same issue if you do CONFIG_DRC=y |
The Zephyr build system always runs "CC --version". Example From https://sof-ci.01.org/sofpr/PR7841/build9926/build/tgl_zph.txt
|
I tried No need for any Cadence toolchain to reproduce, the compilation failures are the same with the open-source Zephyr SDK. This is enough to fail:
cc: @andyross, @cujomalainey |
On the other hand,
|
We are using 2 version of Xtensa Toolchain:
This gives us the compilation problem. And we fixed it by EXTRA_CFLAGS="-std=gnu99 -fgnu89-inline"
We are planning to deprecate 1) and will already have a work around for the compilation issue so closing this PR! |
@dbaluta FWIW https://gcc.gnu.org/legacy-ml/gcc/2006-11/msg00006.html in short - |
We get the following error using Xtensa toolchain on i.MX:
Fix this by declaring
i
at the top of the function.Fixes: fa77edf ("pipeline2.0: change module prepare API to use sink/src.c")