casaroli commented on code in PR #19940:
URL: https://github.com/apache/nuttx/pull/19940#discussion_r3916130832


##########
libs/libc/elf/gnu-elf.ld.in:
##########
@@ -111,12 +141,19 @@ SECTIONS
       *(COMMON)
       . = ALIGN(SECTIONS_ALIGN);
       _ebss = . ;
-    }
+    } PHDR_DATA
+
+#ifdef CONFIG_FDPIC
+  .dynamic :
+    {
+      *(.dynamic)
+    } :data :dynamic

Review Comment:
   it is one section in two segments, not two sections. `PT_DYNAMIC` has to 
cover `.dynamic`, which is also part of the writable `PT_LOAD`. with an 
explicit `PHDRS` block `ld` only places a section in the segments it is named 
in, so I think both are needed.



##########
arch/arm/src/cmake/elf.cmake:
##########
@@ -27,17 +27,54 @@ nuttx_mod_compile_options(-fvisibility=hidden -mlong-calls)
 nuttx_elf_compile_options_ifdef(CONFIG_UNWINDER_ARM -fno-unwind-tables
                                 -fno-asynchronous-unwind-tables)
 
-# An ELF module needs r9 as its PIC base, so it must not also have the register
-# fixed: GCC rejects that pair with "unable to use 'r9' for PIC register".  
This
-# mirrors CELFFLAGS in common/Toolchain.defs, which filters --fixed-r9 back out
-# of the inherited CFLAGS for the same reason.
+# -fno-use-cxa-atexit, because the default registers each static object's
+# destructor with __cxa_atexit(dtor, obj, &__dso_handle), and __dso_handle 
comes
+# from crtbegin, which a module does not link.  Turning it off also puts the
+# destructors in .fini_array, which is where the loader looks for them when the
+# module is unloaded.  This mirrors CXXELFFLAGS in common/Toolchain.defs.
 
-nuttx_elf_compile_options_ifdef(CONFIG_PIC -mpic-register=r9)
+nuttx_elf_compile_options(-fno-use-cxa-atexit)
 
-nuttx_elf_link_options_ifdef(
-  CONFIG_PIC --unresolved-symbols=ignore-in-object-files --emit-relocs)
+if(CONFIG_FDPIC)
 
-nuttx_elf_link_options_ifdef(CONFIG_BINFMT_ELF_RELOCATABLE -r)
+  # An FDPIC module is a shared object whose two segments the loader places
+  # independently.  The stock compiler emits correct FDPIC objects for both C
+  # and C++, so only the link needs the arm-uclinuxfdpiceabi linker: the stock
+  # one carries the armelf emulation alone and would turn every import into a
+  # jump slot where the ABI wants a function descriptor.
+
+  if(NOT FDPIC_CROSSDEV)
+    set(FDPIC_CROSSDEV arm-uclinuxfdpiceabi-)
+  endif()
+
+  set(CMAKE_ELF_LD
+      "${FDPIC_CROSSDEV}ld"
+      CACHE INTERNAL "Linker for FDPIC modules")
+
+  nuttx_elf_compile_options(-mfdpic -fPIC -Wa,--noexecstack)
+
+  nuttx_elf_link_options(-m armelf_linux_fdpiceabi -shared -z now)
+
+else()

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to