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

cmake: libc: minimal: Avoid linking against other libc implementations #79629

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonathonpenix
Copy link
Contributor

The minimal libc is currently built as a zephyr_library and will be included in the final link line as such. However, the c_library property will still be set as "-lc" (for most linkers) and will be added to the link line. This effectively requires that a separate libc implementation be available in the toolchain and makes it possible to accidentally pull from the non-minimal libc.

This doesn't seem desirable, so try to prevent this by clearing the c_library property if we are using the minimal libc.

The minimal libc is currently built as a zephyr_library and will be
included in the final link line as such. However, the c_library property
will still be set as "-lc" (for most linkers) and will be added to the
link line. This effectively requires that a separate libc implementation
be available in the toolchain and makes it possible to accidentally pull
from the non-minimal libc.

This doesn't seem desirable, so try to prevent this by clearing the
c_library property if we are using the minimal libc.

Signed-off-by: Jonathon Penix <jpenix@quicinc.com>
@@ -1,5 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

# As minimal libc will be built as a zephyr_library, clear c_library to
# prevent accidentally requiring or linking against another libc implementation.
set_property(TARGET linker PROPERTY c_library "")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One other idea was to modify link_order_library in the various linker_libraries.cmake files to omit c if we're building with CONFIG_MINIMAL_LIBC. That did seem to work (and seems analogous to what was done for CONFIG_MINIMAL_LIBCPP), but this was a smaller change (and is somewhat similar to what is done for picolibc-as-a-module) so I ended up doing this instead--not sure if one is better than the other otherwise or if there is something entirely different that would be preferred!

Copy link
Collaborator

Choose a reason for hiding this comment

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

You probably need to also change math_library and c++_library to make sure we don't mix other incompatible bits. This way we'll get a build error rather than a runtime error.

@jonathonpenix jonathonpenix marked this pull request as ready for review October 9, 2024 23:06
@zephyrbot zephyrbot added the area: C Library C Standard Library label Oct 9, 2024
@jonathonpenix
Copy link
Contributor Author

I'm not able to add reviewers, but please take a look @tejlmand too if possible!

@jonathonpenix
Copy link
Contributor Author

Gentle ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C Library C Standard Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants