-
Notifications
You must be signed in to change notification settings - Fork 135
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
Add picolibc to existing newlib/newlib-nano configurations #287
Add picolibc to existing newlib/newlib-nano configurations #287
Conversation
Not exactly a direct comment on this PR, but I wanted to bring up another question. Zephyr depends on newlib (or possibly picolibc). Right now we build newlib as part of our SDK. This makes finding and fixing issues caused by the C library fairly challenging, even though we depend on quite a bit of our posix behavior coming from this library. What do people think of the idea of putting the C library as a module that gets built as part of Zephyr builds. |
Does zephyr support submodules? Picolibc currently builds using meson; would it be useful to add cmake support to build for a single target be useful for this? |
Not "submodules" as in the git sense, but we support external modules through something called "west". See https://github.com/zephyrproject-rtos/zephyr/blob/main/west.yml
As briefly noted in the chat, for newlib which is the default C library for the Zephyr SDK, it is not really feasible for multiple reasons described there. As for the picolibc though, I think it might be of use to add it as a module so we can have a more fully featured toolchain independent C library besides the "minimal libc" we currently have in Zephyr (of course, the "toolchain independent" part would need to be further investigated). |
picolibc builds with three compilers at present: gcc, clang and compcert's compiler, and is tested with gcc and clang. Adding cmake build infra to work as a git submodule within Zephyr should be straightforward, and could be upstreamed and tested in picolibc's usual testing framework. |
I didn't know west could do that! Let me know how I could help make this work. |
How we bring in various modules depends a bit on the build system of that module. In some cases, we use their CMake files. In other cases (such as Mbed TLS, currently) we have our own CMake files that describe that build. One concern about doing this that was raised on discord was concerning the increase in build time due to having to build the C library. It is an argument for continuing to provide the C library through the SDK. |
I'm happy to integrate CMake files into picolibc, although just using meson would be easiest for me.
Picolibc builds for a single architecture take only a few seconds, including configuration. Prob ably worth it just to reduce the complexity of the SDK. |
56efff2
to
ad1cf52
Compare
This change is still useful as crosstool-ng has the infrastructure necessary to build libstdc++ as well as libc, so I think it's reasonable to include picolibc in the SDK, especially now that crosstool-ng has picolibc support available. |
ad1cf52
to
a32f53b
Compare
Zephyr also supports C++ development, and libstdc++ must be built against the matching libc. That's quite a trick, which crosstool-ng handles by rebuilding (parts of) gcc against each of the libc versions. As long as Zephyr supports applications using C++ including libstdc++, we're going to probably want to support crosstool-ng toolchains. |
a32f53b
to
fca7eac
Compare
fca7eac
to
75d100a
Compare
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.
I am in favour of including the picolibc as a Zephyr module with the goal of ultimately replacing the Zephyr's current minimal libc.
75d100a
to
038eab5
Compare
As discussed in discord, this PR is still useful in providing C++ support using picolibc as that requires the toolchain to provide libstdc++ that works with a specific build of the C library. |
f4648ad
to
8bfa479
Compare
Hi @keith-packard , just noted that you add this improvement for Or it's just WIP and I'm checking it too soon? :) |
I haven't tried arc64 yet; have you? |
bd5bb9a
to
69a3c35
Compare
The picolibc configs are being (silently) disabled because the build machine is missing ninja and meson:
ct-ng should really warn about selected, but set to UPDATE: see #538 |
69a3c35
to
1af0cc0
Compare
1af0cc0
to
99906d4
Compare
re https://github.com/zephyrproject-rtos/sdk-ng/actions/runs/3175967978/jobs/5182793630
So the Windows test failure is indeed due to insufficient disk space on the GitHub default WIndows runners. #568 should fix that issue. |
e0de5f0
to
81a093a
Compare
Even though the build failed when it ran out of space doing the Windows testing, I was able to extract the canadian cross built aarch64 linux toolchain for arm targets and test that on a debian aarch64 VM here. The picolibc bits worked correctly, which means I think this is ready to merge whenever the SDK is also ready. |
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 looks like this PR is not building picolibc for the following targets:
- arc64-zephyr-elf
- nios2-zephyr-elf
- x86_64-zephyr-elf
- xtensa-*_zephyr-elf
I recall that it was a deliberate decision to drop nios2-zephyr-elf
because there were some issues and the arch is effectively dead so it was not worth the effort.
What about the rest?
81a093a
to
b446bef
Compare
Requires setjmp/longjmp bits which picolibc doesn't have yet.
Skipped as not interesting anymore.
Needs some fixes in picocrt code (or just skipping it, maybe?)
I'm not sure what the state of these architectures are in picolibc, will need to go investigate. |
I found the ARC ABI specs and it looks like the arc32 setjmp/longjmp bits present in picolibc will |
Nope -- needed to fix stuff so that multilib x86 builds worked at all. Upstream PR is pending, when that works, I'll update picolibc bits and enable x86 here. |
b446bef
to
7baed01
Compare
For xtensa to work, we need setjmp/longjmp so we can have libstdc++ built. Does anyone have the ABI spec for these chips who can make that happen? Alternatively, we could disable libstdc++ in the SDK. |
Not exactly a spec, but the information on the "windowed" and "CALL0" ABIs are in the "Xtensa Instruction Set Architecture (ISA) Reference Manual.". Also there is an existing implementation in the Zephyr newlib fork: |
I had it stuck in my brain that the older xtensa 8266 architecture was completely different from esp32, but they're actually very similar and the same code mostly works on both. I'll pull the newer xtensa machine-specific bits into picolibc and see about building them into a toolchain for all of the xtensa targets. |
7baed01
to
907b38f
Compare
Signed-off-by: Keith Packard <[email protected]>
907b38f
to
e69554d
Compare
Bits merged from the newlib-esp32 project into picolibc. Xtensa libraries are now being built with the rest of the toolchains. Btw, picolibc now uses zephyr SDK to build xtensa libraries during CI, which should at least detect compile issues. |
Picolibc already had nios2 support, it just needed fixing for multilib configurations to work around the gcc flags for FPU configuration which forcibly set -fsingle-precision-constants, breaking the double precision math functions. I've hacked around that and pushed changes to picolibc upstream for merging there. Once merged, I'll add that to his PR. |
Signed-off-by: Keith Packard <[email protected]>
This builds both picolibc and libstdc++ with picolibc support using the crosstool-ng support for those configurations. Signed-off-by: Keith Packard <[email protected]>
e69554d
to
3b08cae
Compare
Nios2 added; "should" build cleanly. |
This takes advantage of a PR I posted to the zephyr crosstool-ng project which changes picolibc into a companion library, allowing it to be added to any existing build without changing anything else.