Provide per-core thread local variables when using picolibc#2846
Open
keith-packard wants to merge 7 commits intoraspberrypi:developfrom
Open
Provide per-core thread local variables when using picolibc#2846keith-packard wants to merge 7 commits intoraspberrypi:developfrom
keith-packard wants to merge 7 commits intoraspberrypi:developfrom
Conversation
nosys.specs controls how newlib performs linking, so it's not relevant to other C libraries. Signed-off-by: Keith Packard <keithp@keithp.com>
Picolibc doesn't provide __printflike, instead it provides a more general __picolibc_format for either scanf or printf. Use that to define our own __printflike version. Signed-off-by: Keith Packard <keithp@keithp.com> Gbp-Pq: Name 0005-pico_platform_compiler-Picolibc-compatibility-fix.patch
The kitchen_sink test enables -Wredundant-decls which generates a warning about the stdout and stderr alias definitions. Disable the warning as it is incorrect in this case. Signed-off-by: Keith Packard <keithp@keithp.com>
Using -Wl,--script= hides this option from the compiler driver causing it to insert it's own linker script when it uses picolibc. Using the -T option asks it to skip adding its own. Signed-off-by: Keith Packard <keithp@keithp.com>
Picolibc may combine the preinit and init arrays into a single list, in which case it will use __bothinit_array_start and __bothinit_array_end symbols instead of the separate __preinit_array_start, __preinit_array_end and __init_array_start, __init_array_end pairs. Define both so that either method works. Signed-off-by: Keith Packard <keithp@keithp.com>
When using pico_printf_compiler with picolibc, map the various RUNTIME_INCLUDE_PRINTF_* options into the matching picolibc link flags. Signed-off-by: Keith Packard <keithp@keithp.com>
Change the linker scripts to statically allocate thread local storage space for each core and to initialize that using picolibc's _init_tls instead wedging it between .data and .bss. Implement pico-specific __aeabi_read_tp and_set_tls functions which use the core ID register at 0xd0000000 to index an array of TLS base pointers. Perform per-core TLS region setup, calling _init_tls and _set_tls using the areas allocated by the linker script. Signed-off-by: Keith Packard <keithp@keithp.com>
|
Please do not submit against |
will-v-pi
reviewed
Mar 5, 2026
Comment on lines
+222
to
+235
| # Thread local storage static allocations, one per core | ||
|
|
||
| .tls0 (NOLOAD) : { | ||
| . = ALIGN(__tls_align); | ||
| PROVIDE(__tls0_base = .); | ||
| . = . + __tls_size_align; | ||
| } > RAM | ||
|
|
||
| .tls1 (NOLOAD) : { | ||
| . = ALIGN(__tls_align); | ||
| PROVIDE(__tls1_base = .); | ||
| . = . + __tls_size_align; | ||
| } > RAM | ||
|
|
Contributor
There was a problem hiding this comment.
Would it be possible to put these sections between data and bss, so that bss and heap are contiguous? Otherwise, this may break compatibility with some other changes that are being worked on.
Author
There was a problem hiding this comment.
Sure, but that might break code which assumes that data and bss are contiguous?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains a single patch atop #2840 to allocate per-core thread local storage which is necessary for safe thread local variable usage (like errno).
Change the linker scripts to statically allocate thread local storage space for each core and to initialize that using picolibc's _init_tls instead wedging it between .data and .bss.
Implement pico-specific __aeabi_read_tp and_set_tls functions which use the core ID register at 0xd0000000 to index an array of TLS base pointers.
Perform per-core TLS region setup, calling _init_tls and _set_tls using the areas allocated by the linker script.