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 <marco.casaroli@gmail.com>
This commit is contained in:
Marco Casaroli 2026-10-06 19:10:02 +02:00 • committed by Alan C. Assis
parent ba1ae7947a
commit f26dbe7870

View file

@ -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)