Repository navigation
cmake: Link the emutls calls of an ELF program to libc. - #20812
Merged
Merged
Conversation
cederom
previously approved these changes
Oct 19, 2026
|
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): |
casaroli
marked this pull request as draft
October 19, 2026 18:41
casaroli
marked this pull request as ready for review
October 19, 2026 18:47
A toolchain without native TLS, such as the Arm GNU toolchain for aarch64-none-elf or arm-none-eabi 13, compiles a __thread variable into calls to __emutls_get_address(). nuttx_add_application() links the extra libraries, libgcc too, into each loadable module, shared library and program of a kernel build. The linker then took emutls.o from libgcc into the program. That copy keeps one instance of each variable for all threads. With CONFIG_TLS_EMUTLS, link these programs with "--wrap=__emutls_get_address --wrap=__emutls_register_common", as the image. The calls then go to __wrap___emutls_get_address(): a program of a kernel build takes it from libc, and a module keeps it undefined and the loader binds it to libc through the system symbol table. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): |
casaroli
force-pushed
the
cmake-module-emutls
branch
from
October 19, 2026 23:04
f65f763 to
b8e2e9b
Compare
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): |
xiaoxiang781216
approved these changes
Oct 20, 2026
cederom
approved these changes
Oct 20, 2026
casaroli
marked this pull request as draft
October 20, 2026 23:05
xiaoxiang781216
approved these changes
Nov 15, 2026
casaroli
marked this pull request as ready for review
November 17, 2026 07:34
casaroli
marked this pull request as draft
November 17, 2026 13:04
casaroli
marked this pull request as ready for review
November 17, 2026 13:04
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.
Summary
A toolchain without native TLS (for example the Arm GNU toolchain for aarch64-none-elf, or arm-none-eabi 13 as in CI) compiles a
__threadvariable into calls to__emutls_get_address().nuttx_add_application()links the extra libraries, libgcc too, into each loadable module (MODULE m), shared library (DYNLIB y) and program of a kernel build. The linker putsemutls.oof libgcc into the program. That copy is built with the single thread model: all threads share one instance of each__threadvariable.With
CONFIG_TLS_EMUTLS(from #20723), this PR links these programs with--wrap=__emutls_get_address --wrap=__emutls_register_common, as #20723 does for the image. The calls then go to__wrap___emutls_get_address(), the per-thread version of libc. A program of a kernel build takes it from libc. A module keeps it undefined, and the loader binds it to libc through the system symbol table. The module still takes all the other helpers from libgcc.This builds on #20723, now merged (it adds
CONFIG_TLS_EMUTLSand the__wrap_functions, and exports them in libc.csv). The Make build has the same options from #20723 (LDELFFLAGSandLDMODULEFLAGS).Impact
__thread: each thread now has its own copy, and the module is smaller (noemutls.o).__threadvariables: no change.CONFIG_TLS_EMUTLS(toolchains with native TLS, other compilers): no change.Testing
qemu-armv8a:nsh(flat, CMake, Arm GNU 14.2 aarch64-none-elf, QEMU HVF) withCONFIG_ELF,CONFIG_EXECFUNCS_SYSTEM_SYMTABandCONFIG_TLS_NELEM=4, nuttx with #20723 andget_environ_ptrin libc.csv (#20807). The test programs are built withMODULE mand loaded from a 9p share of the build directory.thread_local)nmof a module: master hasT __emutls_get_address(from libgcc); this PR hasU __wrap___emutls_get_address. The module link command has--wrap=__emutls_get_address --wrap=__emutls_register_common.tools/checkpatch.sh -c -u -m -gpasses.