-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Picolibc optimizations #39564
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
Picolibc optimizations #39564
Changes from all commits
7fe9b3f
96c1017
16ea72e
a0d98b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * Copyright (c) 2020 Intel Corporation | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <toolchain.h> | ||
|
|
||
| _ASM_FILE_PROLOGUE | ||
|
|
||
| GTEXT(__aeabi_read_tp) | ||
|
|
||
| SECTION_FUNC(text, __aeabi_read_tp) | ||
| /* | ||
| * Load TLS base address, which is stored in the TPIDRURO register, also | ||
| * known as the "Process ID" register. Refer to the code in z_arm_pendsv | ||
| * to see where this register is set. | ||
| */ | ||
| mrc 15, 0, r0, c13, c0, 3 | ||
| bx lr | ||
|
Comment on lines
+19
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add a comment on what this is doing. |
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -29,6 +29,15 @@ config MINIMAL_LIBC | |||
| help | ||||
| Build with minimal C library. | ||||
|
|
||||
| config PICOLIBC | ||||
| bool "Picolibc library" | ||||
| depends on !NATIVE_APPLICATION | ||||
| select THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE | ||||
|
||||
| config TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE |
so maybe we should ensure that this value defaults to y when a toolchain with picolib is enabled.
Extra question, will using PICOLIBC break if TREAD_LOCAL_STORAGE is disabled ?
Reason i'm asking is because that will indicate whether a select or default y if XYZ is the best way to go.
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.
The only support picolibc has for thread local variables, including 'errno', is by using the underlying native TLS support. If the toolchain doesn't have TLS support, then all thread local variables in picolibc are simple globals.
As a result, by default, picolibc uses TLS whenever the toolchain has TLS support. What Zephyr needs to do is enable TLS whenever picolibc was built to use it.
We could check whether picolibc was built to use TLS by looking at the picolibc.h header file to see if PICOLIBC_TLS is defined, but I'm not sure how to do that with cmake. Right now, the checks I've added assume that picolibc was built in the default mode and uses TLS iff the toolchain has TLS support.
I'd appreciate whatever help you can offer to clean up the cmake bits here; I'm very unsure of how to use cmake in complicated projects like this.
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.
fwiw, this review series relates to changes proposed in #39563
Outdated
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.
here you are selecting a Kconfig setting from Kernel, but the name of this setting is LIBC_ERRNO, so maybe it should live in this Kconfig.
For example like:
config LIBC_ERRNO
bool
help
The libc library provides a errno implementation.
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.
Are you saying that LIBC_ERRNO should move to lib/libc/Kconfig? Happy to move it there, of course.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| zephyr_library() | ||
| zephyr_library_sources(libc-hooks.c) | ||
|
|
||
| # Zephyr normally uses -ffreestanding, which with current GNU toolchains | ||
| # means that the flag macros used by picolibc <inttypes.h> to signal | ||
| # support for PRI.64 macros are not present. To make them available we | ||
| # need to hook into the include path before the system files and | ||
| # explicitly include the picolibc header that provides those macros. | ||
| zephyr_include_directories(include) | ||
|
|
||
| # define __LINUX_ERRNO_EXTENSIONS__ so we get errno defines like -ESHUTDOWN | ||
| # used by the network stack | ||
| zephyr_compile_definitions(__LINUX_ERRNO_EXTENSIONS__) | ||
|
|
||
| zephyr_link_libraries( | ||
| m | ||
| c | ||
| gcc # Lib C depends on libgcc. | ||
| ) | ||
|
|
||
| # The -T/dev/null avoids pulling in picolibc.ld | ||
| zephyr_link_libraries( | ||
| --specs=picolibc.specs | ||
| -T/dev/null | ||
| ) | ||
|
|
||
| zephyr_compile_options( | ||
| --specs=picolibc.specs | ||
| -D_GNU_SOURCE | ||
| ) | ||
|
|
||
| if(CONFIG_PICOLIBC_INTEGER_PRINTF) | ||
| zephyr_compile_options( | ||
| -DPICOLIBC_INTEGER_PRINTF_SCANF | ||
| ) | ||
| zephyr_link_libraries( | ||
| -DPICOLIBC_INTEGER_PRINTF_SCANF | ||
| ) | ||
| endif() |
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.
Got curios because of this old copyright like.
I assume it's actually this file: https://github.com/zephyrproject-rtos/zephyr/blob/main/arch/arm/core/aarch32/cortex_m/__aeabi_read_tp.S that has been copied and modified, correct ?