This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new db819042e43 cmake: Link the emutls calls of an ELF program to libc.
db819042e43 is described below

commit db819042e43d06deb2bb57ba53904150de050bf1
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Oct 19 22:24:42 2026 +0200

    cmake: Link the emutls calls of an ELF program to libc.
    
    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]>
---
 cmake/nuttx_add_application.cmake | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/cmake/nuttx_add_application.cmake 
b/cmake/nuttx_add_application.cmake
index 5d6d67dc154..92ef9450d47 100644
--- a/cmake/nuttx_add_application.cmake
+++ b/cmake/nuttx_add_application.cmake
@@ -185,6 +185,13 @@ function(nuttx_add_application)
                             nx_mode=${MODE})
           endif()
         endif()
+        # send the emulated TLS calls to libc, see tools/Config.mk
+        if(CONFIG_TLS_EMUTLS)
+          set(EMUTLS_WRAP
+              $<$<NOT:$<BOOL:${USE_LINKER}>>:-Wl,>--wrap=__emutls_get_address
+              
$<$<NOT:$<BOOL:${USE_LINKER}>>:-Wl,>--wrap=__emutls_register_common
+          )
+        endif()
         add_custom_command(
           TARGET ${TARGET}
           POST_BUILD
@@ -197,7 +204,7 @@ function(nuttx_add_application)
             
$<$<OR:$<BOOL:${KERNEL_ELF_MODE}>,$<BOOL:${LOADABLE_ELF_MODE}>>:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_LINK_OPTIONS>>
             # add local link option last
             ${LINK_FLAGS} ${SYMBOL_STACKSIZE} ${SYMBOL_PRIORITY} ${SYMBOL_UID}
-            ${SYMBOL_GID} ${SYMBOL_MODE}
+            ${SYMBOL_GID} ${SYMBOL_MODE} ${EMUTLS_WRAP}
             # link startup obj if m&kernel link
             
$<$<AND:$<TARGET_EXISTS:STARTUP_OBJS>,$<NOT:$<BOOL:${DYNLIB_ELF_MODE}>>>:$<TARGET_OBJECTS:STARTUP_OBJS>>
             $<$<NOT:$<BOOL:${USE_LINKER}>>:-Wl,>--start-group

Reply via email to