-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
CONFIG_PICOLIBC + sparse = zephyr/posix/sys/stat.h:40:11: error: unable to open 'sys/_timespec.h' #63003
Comments
@keith-packard can you help? |
Oh this is fun! We don't have picolibc in our west manifest... Yet we have this CONFIG_ by default and compilation "almost works".
More precisely:
The case where |
This was briefly touched on during the picolibc-by-default discussions in the Zephyr TSC where the general opinion was that having modules that were required to be in the west manifest was deemed "ok". Error handling when it's missing could definitely be improved though... |
Sorry I just read some picolibc documentation for the first time and I realized there's a picolibc in the Zephyr SDK 0.16.1. No need for the module, my bad. I finally debugged this issue a little bit using the most effective build debug tool: breaking the build in various ways. So the regular (non-sparse) build gets I confirmed this breaking the FDEV_SETUP_STREAM definition in that file. (this identical and duplicate (!) Another important build debug trick: using
Again, I confirmed that Examining the command lines I noticed the suspicious I made the small change below and it makes the regular build fail just like the sparse build: --- picolibc.specs 2023/09/23 08:39:05 1.1
+++ picolibc.specs 2023/09/23 08:39:13
@@ -4,7 +4,7 @@
%rename cc1plus picolibc_cc1plus
*cpp:
--isystem %{-picolibc-prefix=*:%*/picolibc/include/; -picolibc-buildtype=*:%:getenv(GCC_EXEC_PREFIX ../../picolibc/include/%*); :%:getenv(GCC_EXEC_PREFIX ../../picolibc/include)} %(picolibc_cpp)
+-isystem %{-picolibc-prefix=*:%*/picolibc/include/; -picolibc-buildtype=*:%:getenv(GCC_EXEC_PREFIX ../../picolibc/include/%*); :%:getenv(GCC_EXEC_PREFIX ../../picolibc/includeBREAKIT)} %(picolibc_cpp)
*cc1:
%(picolibc_cc1) Does all this make sense? |
Starting from Zephyr commit f0daf904bb02, CONFIG_PICOLIBC is on by default. PICOLIBC does not seem compatible with sparse yet: zephyrproject-rtos/zephyr#63003 Even if it were compatible with sparse, it seems like a pretty big change that we should not immediately and blindly accept. Signed-off-by: Marc Herbert <[email protected]>
Yup, if sparse isn't parsing the .specs file to pull in the picolibc header path, it's not going to work very well. If you know you're using the Zephyr SDK, you can probably hard-code the picolibc header path for sparse to use. Otherwise, figuring out where the headers are will require digging through whatever toolchain is in use. |
Starting from Zephyr commit f0daf904bb02, CONFIG_PICOLIBC is on by default. PICOLIBC does not seem compatible with sparse yet: zephyrproject-rtos/zephyr#63003 Even if it were compatible with sparse, it seems like a pretty big change that we should not immediately and blindly accept. Signed-off-by: Marc Herbert <[email protected]>
If we switched the SDK to use picolibc by default with newlib as an option requiring additional configuration, then this would work as expected. The alternative is to figure out how to extract include path information from the toolchain and pass that to sparse? |
Correction: we can use EDIT: successfully added to SOF CI in thesofproject/sof@0061953a595 |
Add a sparse-specific workaround for the incompatibility with picolibc (the new Zephyr default) zephyrproject-rtos/zephyr#63003 Also fix comment in commit 2a9473a ("app/prj.conf: disable PICOLIBC with CONFIG_MINIMAL_LIBC=y"): we don't need to disable PICOLIBC _everywhere_; we only need to disable it when using sparse. Signed-off-by: Marc Herbert <[email protected]>
Add a sparse-specific workaround for the incompatibility with picolibc (the new Zephyr default) zephyrproject-rtos/zephyr#63003 Also fix comment in commit 2a9473a ("app/prj.conf: disable PICOLIBC with CONFIG_MINIMAL_LIBC=y"): we don't need to disable PICOLIBC _everywhere_; we only need to disable it when using sparse. Signed-off-by: Marc Herbert <[email protected]>
I don't think this should be closed, as it does seem to be something we should fix. |
It works with newlib nano because newlib nano uses almost identical headers, so sparse ends up using the regular newlib headers. With picolibc, we really need the picolibc headers instead. When using sparse and the Zephyr SDK, we could probably compute the required include path:
|
This incompatibility between CONFIG_PICOLIBC and sparse does actually not require SOF at all. I just edited the description at the top so anyone can reproduce it from a plain Zephyr tree with the most basic build command:
Funny enough EDIT: infinite loop reported in #63417 and fixed in sparse. |
sparse needs a lot of help finding all of the necessary include directories. I'm unclear how this works for newlib; presumably it's loading a bunch of glibc headers and somehow that works? Mysterious. In any case, I hacked the xtensa module and the Zephyr cmake file to insert a bunch of additional include paths. modules/hal/xtensa:
zephyr:
With those paths, sparse at least runs to completion, although it does emit a pile of warnings. |
Thanks @keith-packard for still trying. BTW I agree with @jhedberg's that this is "low" priority (at least for SOF) as we can very simply turn off PICOLIBC only when using sparse - and I just did.
You probably knew this already but this missing
Isn't that how every C/C++ project in the universe works? I mean even before sparse.
I'm afraid every static analyzer is a hack. A number of analyzers have a "preparation" step where they just observe the regular build first. I'm surprised sparse does not seem to have that step? Maybe it's putting itself at a disadvantage here...
That is the feature. |
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
This bug was auto-closed. It's still valid. @tejlmand do you want to take another look? It's much easier to debug now that sparse has just been fixed and
|
Great, then it sounds like there is hope. |
I reproduced again with today's commit 6df6935. Workaround learned in different (and fixed) sparse issue #63417:
That was when trying to use a different, proprietary toolchain. Ignore, absolutely not needed. |
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
Describe the bug
CONFIG_PICOLIBC is currently incompatible with sparse due to some .h files complexities.
EDIT October 2nd with newer, simpler, SOF-free reproduction
Slower, -j1 version that does not bury the relevant error:
OLDER, initial and more complex reproduction that requires SOF. Kept here for completeness, you can probably skip it.
Commit f0daf90 switched CONFIG_PICOLIBC on by default. This broke the "sparse" analyzer used in the SOF project:
https://github.com/thesofproject/sof/actions/runs/6247162197/job/16959223474?pr=8235
Note this is not just a sparse warning or false positive: compilation with sparse actually FAILS, it cannot even complete.
To Reproduce
Detailed steps at
Expected behavior
Sparse can still sparse.
Impact
Broken SOF CI
Logs and console output
Environment (please complete the following information):
Github runner Ubuntu 22.04 LTS
Zephyr CI image with Zephyr SDK + marc-hb/sparse@3848a76ba49f336
zephyr commit 3415905 and SOF commit 75337b41eb51)
Additional context
These two workarounds were tested successfully:
git revert f0daf90
CONFIG_MINIMAL_LIBC=y as in
~/SOF/sof/scripts/xtensa-build-zephyr.py -p mtl --cmake-args=-DZEPHYR_SCA_VARIANT=sparse --cmake-args=-DCONFIG_LOG_USE_VLA=n --cmake-args=-DCONFIG_MINIMAL_LIBC=y
The text was updated successfully, but these errors were encountered: