Skip to content

pico-sdk: Switch to picolibc #12

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

Merged
merged 1 commit into from
Jun 27, 2025

Conversation

keith-packard
Copy link

This selects picolibc by using --specs=picolibc.specs for compiling and linking. The linker scripts are adjusted to add KEEP to ensure that --gc-sections doesn't remove the contents of the files.

Copy link
Member

@soburi soburi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, how should it behave if CONFIG_PICOLIBC is not selected?

Usually, we use PICOLIBC, so I think it's generally fine.

@@ -43,15 +43,16 @@ function(pico_define_boot_stage2 NAME SOURCES)
if (PICO_C_COMPILER_IS_CLANG)
target_link_options(${NAME} PRIVATE "-nostdlib")
elseif (PICO_C_COMPILER_IS_GNU)
target_link_options(${NAME} PRIVATE "--specs=nosys.specs")
target_compile_options(${NAME} PRIVATE "--specs=picolibc.specs")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a history about this change to ChangeLog.zephyr.md.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done.

This selects picolibc by using --specs=picolibc.specs for compiling
and linking. The linker scripts are adjusted to add KEEP to ensure
that --gc-sections doesn't remove the contents of the files.

Signed-off-by: Keith Packard <keithp@keithp.com>
@keith-packard
Copy link
Author

Just wondering, how should it behave if CONFIG_PICOLIBC is not selected?

The boot loader can use picolibc even if the app needs newlib for some reason; we still get the picolibc benefits in the boot loader.

target_link_options(${NAME} PRIVATE "-nostartfiles")
endif ()

# boot2_helpers include dir
target_include_directories(${NAME} PRIVATE ${PICO_BOOT_STAGE2_DIR}/asminclude)

target_link_libraries(${NAME} hardware_regs boot_stage2_headers)
target_link_options(${NAME} PRIVATE "LINKER:--script=${PICO_BOOT_STAGE2_DIR}/boot_stage2.ld")
target_link_options(${NAME} PRIVATE "-T${PICO_BOOT_STAGE2_DIR}/boot_stage2.ld")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a minor point, but I think long options are easier to read in scripts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

picolibc's spec fragments only look for the -T version of this option, so we must use the short variant to prevent addition of the picolibc linker script here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I got it.
Thank you for your clarification.

@soburi soburi self-assigned this Jun 26, 2025
@soburi soburi requested a review from ajf58 June 26, 2025 21:27
@soburi
Copy link
Member

soburi commented Jun 26, 2025

@ajf58 @ThreeEights

Could you take a look, please?

@ajf58
Copy link
Collaborator

ajf58 commented Jun 26, 2025

Just wondering, how should it behave if CONFIG_PICOLIBC is not selected?

The boot loader can use picolibc even if the app needs newlib for some reason; we still get the picolibc benefits in the boot loader.

Can you expand on this? What's the benefit? I've read the commit message and it has the what, but not the why of this.

@keith-packard
Copy link
Author

Can you expand on this? What's the benefit? I've read the commit message and it has the what, but not the why of this.

Probably the most visible benefit is a reduction in memory usage -- picolibc has smaller implementations of many core parts of the C library (stdio, ctype, locales) as well as general memory saving architectural changes (eliminating struct reent).

It's also routinely tested for the target systems. I'll be enabling these tests within the Zephyr SDK build to catch bugs introduced in any part of the system (binutils, compiler, linker, libraries). Newlib lacks any visible CI system.

Copy link
Collaborator

@ajf58 ajf58 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation/rationale. It's a bit of a nit to say I'd prefer to see it in the commit message, but it's here in the PR instead.

@soburi soburi merged commit b547a36 into zephyrproject-rtos:zephyr Jun 27, 2025
4 checks passed
@soburi
Copy link
Member

soburi commented Jun 27, 2025

@keith-packard

Merged. Please update west.yml.

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 this pull request may close these issues.

3 participants