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

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

commit 5fe956734a6bab013c7abcc2dbe185773c569dd2
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Oct 19 10:01:50 2026 +0200

    tools/nxflat/ldnxflat: Refuse native TLS with a clear message.
    
    A toolchain with native TLS, such as Arm GNU 15.3 for arm-none-eabi,
    puts __thread variables in .tdata and .tbss and reaches them with
    __tls_get_addr() and R_ARM_TLS_GD32.  NXFLAT has no thread pointer and
    no TLS relocations, so such a module cannot work.  ldnxflat refused it
    only at the first TLS relocation, with "arm relocation 104 at I-Space
    00000118 is not handled", which does not say why.
    
    Refuse a module with a TLS section and say what to do: build it with a
    toolchain that emulates TLS.  There, __thread compiles into calls to
    __emutls_get_address(), which the module imports like any other
    function.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 tools/nxflat/ldnxflat.c   | 11 +++++++++++
 tools/nxflat/nxflat_elf.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/tools/nxflat/ldnxflat.c b/tools/nxflat/ldnxflat.c
index 469d19faea0..aea9d9e3f40 100644
--- a/tools/nxflat/ldnxflat.c
+++ b/tools/nxflat/ldnxflat.c
@@ -365,6 +365,17 @@ static void place_sections(void)
                "NXFLAT module cannot run", g_shstrtab + s->sh_name);
         }
 
+      /* A __thread variable compiled for native TLS needs a thread pointer
+       * and TLS relocations, which NXFLAT does not have.
+       */
+
+      if ((s->sh_flags & SHF_TLS) != 0)
+        {
+          fail("%s holds native TLS, which an NXFLAT module cannot use; "
+               "build it with a toolchain that emulates TLS",
+               g_shstrtab + s->sh_name);
+        }
+
       if ((s->sh_flags & SHF_EXECINSTR) != 0)
         {
           g_segof[i]  = SEG_TEXT;
diff --git a/tools/nxflat/nxflat_elf.h b/tools/nxflat/nxflat_elf.h
index 04d8485fd8f..99f88eb5418 100644
--- a/tools/nxflat/nxflat_elf.h
+++ b/tools/nxflat/nxflat_elf.h
@@ -57,6 +57,7 @@
 #define SHF_WRITE               0x1
 #define SHF_ALLOC               0x2
 #define SHF_EXECINSTR           0x4
+#define SHF_TLS                 0x400
 
 #define SHN_UNDEF               0
 #define SHN_COMMON              0xfff2

Reply via email to