You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2026/10/07 14:45:17 UTC

(nuttx) branch master updated (9e8c81cf4c2 -> ebabdd57f3b)

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

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


    from 9e8c81cf4c2 arm/nrf54l: add SPIM support
     new 602affafe87 boards/mps2-an500: Use the common ELF link flags.
     new ba1ae7947a6 libs/libc/elf: Find the symbols of a stripped shared object.
     new f26dbe78709 arch/arm/cmake: Link an FDPIC shared library as a shared object.
     new 1a186463750 libs/libc/elf: Lay out the PLT of an FDPIC module as the linker expects.
     new 00e51b847ab arch/arm: Pass --fdpic to the assembler for an FDPIC module.
     new ebabdd57f3b arch/arm: Keep GCC from making tail calls in an FDPIC module.

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/arm/src/cmake/elf.cmake                | 23 +++++++++++++++++--
 arch/arm/src/common/Toolchain.defs          | 18 +++++++++++----
 boards/arm/mps/mps2-an500/scripts/Make.defs |  5 -----
 libs/libc/elf/elf_symbols.c                 | 12 +++++++++-
 libs/libc/elf/gnu-elf.ld.in                 | 34 +++++++++++++++++++++++++++++
 5 files changed, 80 insertions(+), 12 deletions(-)


(nuttx) 05/06: arch/arm: Pass --fdpic to the assembler for an FDPIC module.

Posted by ac...@apache.org.
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 00e51b847ab3e9414335c418d04b2324bbfa47e8
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Tue Oct 6 22:55:17 2026 +0200

    arch/arm: Pass --fdpic to the assembler for an FDPIC module.
    
    GCC before 14 does not pass --fdpic to the assembler when it compiles
    with -mfdpic.  The assembler then rejects every FDPIC relocation with
    "Relocation supported only in FDPIC mode".  The NuttX CI image has GCC
    13.2, so the crt0.o of an FDPIC configuration does not build there.
    
    Pass -Wa,--fdpic with -mfdpic, in the make build and the CMake build.  A
    newer GCC passes the same option itself.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 arch/arm/src/cmake/elf.cmake       |  7 +++++--
 arch/arm/src/common/Toolchain.defs | 11 +++++++----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/arch/arm/src/cmake/elf.cmake b/arch/arm/src/cmake/elf.cmake
index 2a0b3f61ccb..465f442ae3f 100644
--- a/arch/arm/src/cmake/elf.cmake
+++ b/arch/arm/src/cmake/elf.cmake
@@ -56,14 +56,17 @@ if(CONFIG_FDPIC)
       "${FDPIC_LD}"
       CACHE INTERNAL "Linker for FDPIC modules")
 
-  nuttx_elf_compile_options(-mfdpic -fPIC -Wa,--noexecstack)
+  # GCC before 14 does not pass --fdpic to the assembler for -mfdpic, and the
+  # assembler then rejects the FDPIC relocations, so pass it here.
+
+  nuttx_elf_compile_options(-mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic)
 
   nuttx_elf_link_options(-m armelf_linux_fdpiceabi -shared -z now)
 
   # A shared library is an FDPIC shared object too, as LDMODULEFLAGS makes it in
   # common/Toolchain.defs
 
-  nuttx_mod_compile_options(-mfdpic -fPIC -Wa,--noexecstack)
+  nuttx_mod_compile_options(-mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic)
 
   nuttx_mod_link_options(-m armelf_linux_fdpiceabi -shared -z now)
 
diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs
index 6325df91cb7..d681cd17278 100644
--- a/arch/arm/src/common/Toolchain.defs
+++ b/arch/arm/src/common/Toolchain.defs
@@ -684,8 +684,11 @@ ifeq ($(CONFIG_FDPIC),y)
     MODULELD = $(SHELL) -c 'echo "ERROR: $(FDPIC_NO_LD_MSG)" 1>&2; exit 1' --
   endif
 
-  CELFFLAGS += -mfdpic -fPIC -Wa,--noexecstack
-  CXXELFFLAGS += -mfdpic -fPIC -Wa,--noexecstack
+  # GCC before 14 does not pass --fdpic to the assembler for -mfdpic, and the
+  # assembler then rejects the FDPIC relocations, so pass it here.
+
+  CELFFLAGS += -mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic
+  CXXELFFLAGS += -mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic
 
   LDELFFLAGS += -m armelf_linux_fdpiceabi -shared -z now
 
@@ -697,8 +700,8 @@ ifeq ($(CONFIG_FDPIC),y)
   # The entry point is left to the caller:  a module is entered at _start,
   # a library is only called into.
 
-  CMODULEFLAGS += -mfdpic -fPIC -Wa,--noexecstack
-  CXXMODULEFLAGS += -mfdpic -fPIC -Wa,--noexecstack
+  CMODULEFLAGS += -mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic
+  CXXMODULEFLAGS += -mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic
 
   LDMODULEFLAGS = -m armelf_linux_fdpiceabi -shared -z now \
                   -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/elf/gnu-elf.ld)


(nuttx) 01/06: boards/mps2-an500: Use the common ELF link flags.

Posted by ac...@apache.org.
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 602affafe875a00dcfa40205e002dee15714242d
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Tue Oct 6 18:55:03 2026 +0200

    boards/mps2-an500: Use the common ELF link flags.
    
    The board set LDELFFLAGS to "-r -e main" after it included Toolchain.defs.
    This replaced the flags that Toolchain.defs sets for a loadable module.
    With CONFIG_FDPIC, a module then links as a relocatable object and not as
    an FDPIC shared object.  A module that names a library does not link at
    all: "attempted static link of dynamic object".
    
    9ed93c6b1ee moved these flags into Toolchain.defs for all boards, and
    dae3b8e5516 removed the same lines from mps3-an547.  Remove them here
    too.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 boards/arm/mps/mps2-an500/scripts/Make.defs | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/boards/arm/mps/mps2-an500/scripts/Make.defs b/boards/arm/mps/mps2-an500/scripts/Make.defs
index e5954786f0b..fcf783fcb09 100644
--- a/boards/arm/mps/mps2-an500/scripts/Make.defs
+++ b/boards/arm/mps/mps2-an500/scripts/Make.defs
@@ -62,8 +62,3 @@ AFLAGS := $(CFLAGS) -D__ASSEMBLY__
 NXFLATLDFLAGS1 = -r -d -warn-common
 NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)$(DELIM)binfmt$(DELIM)libnxflat$(DELIM)gnu-nxflat-pcrel.ld -no-check-sections
 LDNXFLATFLAGS = -e main -s 2048
-
-# ELF module definitions
-
-LDELFFLAGS = -r -e main
-LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/elf/gnu-elf.ld)


(nuttx) 02/06: libs/libc/elf: Find the symbols of a stripped shared object.

Posted by ac...@apache.org.
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 ba1ae7947a69067e670ab6ffcf63bdbe39f78525
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Tue Oct 6 19:02:04 2026 +0200

    libs/libc/elf: Find the symbols of a stripped shared object.
    
    libelf_findsymtab() accepted only a SHT_SYMTAB section.  A shared object
    that strip has processed has no SHT_SYMTAB: only its SHT_DYNSYM remains.
    With CONFIG_DEBUG_SYMBOLS the application build strips each module in
    bin/, so every FDPIC module that it builds fails to load with "No symbols
    in ELF file".
    
    Use the dynamic symbol table of a shared object when it has no other
    symbol table.  It holds every symbol that the object imports or exports,
    which is what the loader looks up.  An object with SHT_SYMTAB still uses
    it.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 libs/libc/elf/elf_symbols.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/libs/libc/elf/elf_symbols.c b/libs/libc/elf/elf_symbols.c
index 84143b68ba3..d5f537e3b0e 100644
--- a/libs/libc/elf/elf_symbols.c
+++ b/libs/libc/elf/elf_symbols.c
@@ -254,7 +254,10 @@ int libelf_findsymtab(FAR struct mod_loadinfo_s *loadinfo)
 {
   int i;
 
-  /* Find the symbol table section header and its associated string table */
+  /* Find the symbol table section header and its associated string table.
+   * A stripped shared object keeps only its dynamic symbol table, which
+   * holds every symbol that it imports or exports.
+   */
 
   for (i = 1; i < loadinfo->ehdr.e_shnum; i++)
     {
@@ -264,6 +267,13 @@ int libelf_findsymtab(FAR struct mod_loadinfo_s *loadinfo)
           loadinfo->strtabidx = loadinfo->shdr[i].sh_link;
           break;
         }
+
+      if (loadinfo->shdr[i].sh_type == SHT_DYNSYM &&
+          loadinfo->ehdr.e_type == ET_DYN)
+        {
+          loadinfo->symtabidx = i;
+          loadinfo->strtabidx = loadinfo->shdr[i].sh_link;
+        }
     }
 
   /* Verify that there is a symbol and string table */


(nuttx) 04/06: libs/libc/elf: Lay out the PLT of an FDPIC module as the linker expects.

Posted by ac...@apache.org.
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 1a1864637507f6211b85e807e1e0241276025101
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Tue Oct 6 19:44:25 2026 +0200

    libs/libc/elf: Lay out the PLT of an FDPIC module as the linker expects.
    
    gnu-elf.ld.in named neither .rel.plt nor .got.plt, and the linker placed
    them where its FDPIC code does not expect them.
    
    It merged .rel.plt into .rel.dyn but still set DT_JMPREL as if .rel.plt
    came last, so the loader bound each PLT slot with the symbol of another
    relocation.  And .got.plt came after .got: the offsets that the linker
    gave the local function descriptors did not match where it put them, and
    the first call through one jumped into data.
    
    A module without a PLT has neither section, so neither problem showed
    until a module called its imports through a PLT.
    
    Give .rel.dyn and .rel.plt output sections of their own, and put .got.plt
    first in .got, both as in the linker's own script.  Only CONFIG_FDPIC
    changes.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 libs/libc/elf/gnu-elf.ld.in | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/libs/libc/elf/gnu-elf.ld.in b/libs/libc/elf/gnu-elf.ld.in
index a43d20efded..51a79640211 100644
--- a/libs/libc/elf/gnu-elf.ld.in
+++ b/libs/libc/elf/gnu-elf.ld.in
@@ -69,6 +69,12 @@
 #  define PHDR_DATA :data
 #  define DATA_ALIGN . = ALIGN(0x1000);
 
+/* .got.plt comes first, as in the linker's own script.  The linker places
+ * the function descriptors of a lazy PLT on that assumption.
+ */
+
+#  define GOT_PLT *(.got.plt) *(.igot.plt)
+
 PHDRS
 {
   text    PT_LOAD FLAGS(5);    /* Read and execute */
@@ -80,6 +86,7 @@ PHDRS
 #  define PHDR_TEXT
 #  define PHDR_DATA
 #  define DATA_ALIGN
+#  define GOT_PLT
 #endif
 
 SECTIONS
@@ -125,6 +132,32 @@ SECTIONS
       *(.eh_frame.*)
     } PHDR_TEXT
 
+#ifdef CONFIG_FDPIC
+  /* DT_JMPREL names .rel.plt, so it is an output section of its own, after
+   * the other dynamic relocations, as in the linker's own script.
+   */
+
+  .rel.dyn :
+    {
+      *(.rel.init)
+      *(.rel.text .rel.text.*)
+      *(.rel.fini)
+      *(.rel.rodata .rel.rodata.*)
+      *(.rel.data.rel.ro .rel.data.rel.ro.*)
+      *(.rel.data .rel.data.*)
+      *(.rel.ctors)
+      *(.rel.dtors)
+      *(.rel.got)
+      *(.rel.bss .rel.bss.*)
+      *(.rel.iplt)
+    } PHDR_TEXT
+
+  .rel.plt :
+    {
+      *(.rel.plt)
+    } PHDR_TEXT
+#endif
+
   DATA_ALIGN
 
   .data DATA_START :
@@ -170,6 +203,7 @@ SECTIONS
 
   .got :
     {
+      GOT_PLT
       *(.got*)
     } PHDR_DATA
 


(nuttx) 06/06: arch/arm: Keep GCC from making tail calls in an FDPIC module.

Posted by ac...@apache.org.
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 ebabdd57f3bd8a98fb4c5091319b907522445a8a
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Wed Oct 7 08:09:50 2026 +0200

    arch/arm: Keep GCC from making tail calls in an FDPIC module.
    
    With -mfdpic and -mlong-calls, GCC turns a call to an imported function
    in tail position into "ldr r3, [r9, #off]; bx r3".  The GOT slot holds
    the address of the function descriptor, so the branch goes to the
    descriptor in RAM instead of through it, and the core faults.  A normal
    call loads the code address and the data base from the descriptor
    first.  GCC 13.2 and 15.3 both do this.
    
    Only an optimized build makes tail calls.  The C++ library of
    apps/testing/fs/xipfs then faults in its constructor, which ends in a
    call to syslog(), and the test stops at "stage the C++ module".
    
    Pass -fno-optimize-sibling-calls with the other FDPIC flags, in the make
    build and the CMake build.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 arch/arm/src/cmake/elf.cmake       | 11 +++++++++--
 arch/arm/src/common/Toolchain.defs | 15 +++++++++++----
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/arch/arm/src/cmake/elf.cmake b/arch/arm/src/cmake/elf.cmake
index 465f442ae3f..45fb444a814 100644
--- a/arch/arm/src/cmake/elf.cmake
+++ b/arch/arm/src/cmake/elf.cmake
@@ -58,15 +58,22 @@ if(CONFIG_FDPIC)
 
   # GCC before 14 does not pass --fdpic to the assembler for -mfdpic, and the
   # assembler then rejects the FDPIC relocations, so pass it here.
+  #
+  # With -mlong-calls, GCC turns a call in tail position into a branch to the
+  # function descriptor rather than through it, which faults.  Keep it from
+  # making tail calls.
 
-  nuttx_elf_compile_options(-mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic)
+  set(FDPIC_FLAGS -mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic
+                  -fno-optimize-sibling-calls)
+
+  nuttx_elf_compile_options(${FDPIC_FLAGS})
 
   nuttx_elf_link_options(-m armelf_linux_fdpiceabi -shared -z now)
 
   # A shared library is an FDPIC shared object too, as LDMODULEFLAGS makes it in
   # common/Toolchain.defs
 
-  nuttx_mod_compile_options(-mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic)
+  nuttx_mod_compile_options(${FDPIC_FLAGS})
 
   nuttx_mod_link_options(-m armelf_linux_fdpiceabi -shared -z now)
 
diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs
index d681cd17278..787e048fcd9 100644
--- a/arch/arm/src/common/Toolchain.defs
+++ b/arch/arm/src/common/Toolchain.defs
@@ -686,9 +686,16 @@ ifeq ($(CONFIG_FDPIC),y)
 
   # GCC before 14 does not pass --fdpic to the assembler for -mfdpic, and the
   # assembler then rejects the FDPIC relocations, so pass it here.
+  #
+  # With -mlong-calls, GCC turns a call in tail position into a branch to the
+  # function descriptor rather than through it, which faults.  Keep it from
+  # making tail calls.
+
+  FDPICFLAGS = -mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic \
+               -fno-optimize-sibling-calls
 
-  CELFFLAGS += -mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic
-  CXXELFFLAGS += -mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic
+  CELFFLAGS += $(FDPICFLAGS)
+  CXXELFFLAGS += $(FDPICFLAGS)
 
   LDELFFLAGS += -m armelf_linux_fdpiceabi -shared -z now
 
@@ -700,8 +707,8 @@ ifeq ($(CONFIG_FDPIC),y)
   # The entry point is left to the caller:  a module is entered at _start,
   # a library is only called into.
 
-  CMODULEFLAGS += -mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic
-  CXXMODULEFLAGS += -mfdpic -fPIC -Wa,--noexecstack -Wa,--fdpic
+  CMODULEFLAGS += $(FDPICFLAGS)
+  CXXMODULEFLAGS += $(FDPICFLAGS)
 
   LDMODULEFLAGS = -m armelf_linux_fdpiceabi -shared -z now \
                   -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/elf/gnu-elf.ld)


(nuttx) 03/06: arch/arm/cmake: Link an FDPIC shared library as a shared object.

Posted by ac...@apache.org.
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 f26dbe787090fde0e41e0bafcd4751a12ea48f3c
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Tue Oct 6 19:10:02 2026 +0200

    arch/arm/cmake: Link an FDPIC shared library as a shared object.
    
    With CONFIG_FDPIC, the CMake build gave the FDPIC options to a loadable
    module only.  A shared library (DYNLIB) got neither -mfdpic nor the FDPIC
    link, but the "-r" link of the non-FDPIC case.  So the library was a
    relocatable object, and a module that named it in DT_NEEDED did not link:
    "multiple definition" and "dangerous relocation".
    
    Give a shared library the same options as a module, as LDMODULEFLAGS and
    CMODULEFLAGS in common/Toolchain.defs already do for the make build.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 arch/arm/src/cmake/elf.cmake | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/arm/src/cmake/elf.cmake b/arch/arm/src/cmake/elf.cmake
index ab09828847c..2a0b3f61ccb 100644
--- a/arch/arm/src/cmake/elf.cmake
+++ b/arch/arm/src/cmake/elf.cmake
@@ -60,6 +60,13 @@ if(CONFIG_FDPIC)
 
   nuttx_elf_link_options(-m armelf_linux_fdpiceabi -shared -z now)
 
+  # A shared library is an FDPIC shared object too, as LDMODULEFLAGS makes it in
+  # common/Toolchain.defs
+
+  nuttx_mod_compile_options(-mfdpic -fPIC -Wa,--noexecstack)
+
+  nuttx_mod_link_options(-m armelf_linux_fdpiceabi -shared -z now)
+
 elseif(CONFIG_PIC)
 
   # An ELF module needs r9 as its PIC base, so it must not also have the
@@ -81,7 +88,9 @@ if(CONFIG_BINFMT_ELF_RELOCATABLE AND NOT CONFIG_PIC)
   nuttx_elf_link_options(-r)
 endif()
 
-nuttx_mod_link_options(-r)
+if(NOT CONFIG_FDPIC)
+  nuttx_mod_link_options(-r)
+endif()
 
 nuttx_elf_link_options_ifdef(CONFIG_BUILD_KERNEL -Bstatic)