From f26dbe787090fde0e41e0bafcd4751a12ea48f3c Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Tue, 6 Oct 2026 19:10:02 +0200 Subject: [PATCH] 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 --- 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)