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


The following commit(s) were added to refs/heads/master by this push:
     new 295f0e373cc tools/nxflat: Leave ARM unwind tables out of an NXFLAT 
module.
295f0e373cc is described below

commit 295f0e373cc8165466fe343497ced5269bdd5cb2
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Sep 28 14:49:02 2026 +0200

    tools/nxflat: Leave ARM unwind tables out of an NXFLAT module.
    
    CONFIG_UNWINDER_ARM compiles everything with -funwind-tables, modules
    included, so each module carries .ARM.exidx and .ARM.extab.  The NXFLAT
    link scripts do not name them, and ldnxflat placed them in D-Space, where
    the first R_ARM_PREL31 entry stopped the conversion:
    
      ldnxflat: arm relocation 42 at D-Space 00000018 is not handled
    
    That relocation cannot be handled: an exidx entry is an offset from itself
    to a function in I-Space, and the distance between the two segments is only
    known when the loader places them.  Nothing unwinds through a module
    either, since the unwinder only reads the firmware's own table.
    
    So ldnxflat leaves both sections out of the images, and with them the
    relocations against them, as it already does for sections it does not
    place.  A module without unwind tables converts exactly as before.
    
    On mps3-an547:nsh under QEMU with CONFIG_UNWINDER_ARM and examples/nxflat,
    the modules failed to convert; now they convert and errno, hello, mutex,
    pthread and struct run.  The eleven modules of tools/nxflat/testsuite.sh
    convert to the same bytes as before.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 tools/nxflat/ldnxflat.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/nxflat/ldnxflat.c b/tools/nxflat/ldnxflat.c
index 6d7fb721811..845358f8966 100644
--- a/tools/nxflat/ldnxflat.c
+++ b/tools/nxflat/ldnxflat.c
@@ -193,6 +193,7 @@ static struct elf32_shdr_s   *g_shdr;
 static struct elf32_sym_s    *g_syms;
 static size_t                 g_nsyms;
 static const char            *g_strtab;
+static const char            *g_shstrtab;
 static enum segment_e        *g_segof;   /* Per section */
 
 static const struct nxflat_arch_s *g_arch;
@@ -279,6 +280,7 @@ static void read_elf(void)
   g_syms     = elf.syms;
   g_nsyms    = elf.nsyms;
   g_strtab   = elf.strtab;
+  g_shstrtab = elf.shstrtab;
 
   if (g_ehdr->e_type != ET_REL)
     {
@@ -311,6 +313,10 @@ static void read_elf(void)
  *   Executable is I-Space; everything else allocated is D-Space, read-only
  *   data included, because the model reaches that through the GOT.
  *
+ *   ARM unwind tables are left out.  Their entries are PC-relative from
+ *   D-Space into I-Space, which the container cannot express, and nothing
+ *   unwinds through a module.
+ *
  ****************************************************************************/
 
 static void place_sections(void)
@@ -330,7 +336,9 @@ static void place_sections(void)
       struct elf32_shdr_s *s = &g_shdr[i];
       uint32_t end = s->sh_addr + s->sh_size;
 
-      if ((s->sh_flags & SHF_ALLOC) == 0)
+      if ((s->sh_flags & SHF_ALLOC) == 0 ||
+          strncmp(g_shstrtab + s->sh_name, ".ARM.exidx", 10) == 0 ||
+          strncmp(g_shstrtab + s->sh_name, ".ARM.extab", 10) == 0)
         {
           continue;
         }

Reply via email to