Skip to content
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

Using picolibc with libstdc++_nano.a #860

Open
Damian-Nordic opened this issue Feb 13, 2025 · 3 comments · May be fixed by #863
Open

Using picolibc with libstdc++_nano.a #860

Damian-Nordic opened this issue Feb 13, 2025 · 3 comments · May be fixed by #863

Comments

@Damian-Nordic
Copy link

Hi,

I wanted to switch a bunch of C++ applications from newlibc nano to picolibc but I noticed it resulted in ~4 kB flash usage growth. I realized it was because nano.specs replaces -lstdc++ flag with -lstdc++_nano, while picolibc.specs does not. The full libstdc++ contains a lot of code for handling exceptions and stack unwinding, which is often not needed in embedded applications.

I forced the build system to use -lstdc++_nano by adding set_linker_property(PROPERTY c++_library "-lstdc++_nano") in CMakeLists, and the flash usage dropped by ~10kB.

Would it make sense to default to lstdc++_nano when linking with picolibc or at least support the nano variant to be used by applications that disable C++ exceptions?

@keith-packard
Copy link
Collaborator

Good idea. We'll have to re-build libstdc++ to use the picolibc ABI though; libstdc++_nano is built against newlib-nano, which has a different ABI.

@LuDuda
Copy link

LuDuda commented Feb 17, 2025

This looks like a pretty nice optimization!

@keith-packard would you be able to help with re-building process? Is this something we can plan for next releases of the Zephyr toolchain?

@keith-packard
Copy link
Collaborator

This looks like a pretty nice optimization!

@keith-packard would you be able to help with re-building process? Is this something we can plan for next releases of the Zephyr toolchain?

It's pretty easy to adapt crosstool-ng to build another version of any library; it would be great if you'd dig in and take a look; I'd be happy to provide some guidance.

@adigie adigie linked a pull request Feb 17, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants