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 <[email protected]>
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 <[email protected]>
---
 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
 

Reply via email to