nuttx/libs/libc/elf
Marco Casaroli 4cdd3cdbda arch/arm, libs/libc/elf: Build FDPIC modules in the normal ELF build.
With CONFIG_FDPIC selected, a module built by apps/Application.mk is now an
FDPIC shared object.  Nothing about how a module is written or built
changes: the same MODULE = m in the same Makefile, the same crt0 and the
same linker script.

Two things differ from the position independent build beside it.  The
compiler is told -mfdpic -fPIC, and the link is done by an
arm-uclinuxfdpiceabi linker.  The stock arm-none-eabi compiler emits correct
FDPIC objects for both C and C++, so only the link needs it: the stock
linker carries the armelf emulation alone and would turn every import into
an R_ARM_JUMP_SLOT, one word, where the ABI wants an R_ARM_FUNCDESC_VALUE,
which is two, a code address and the data base that goes with it.  Such a
module links cleanly and then calls out of itself with the caller's data
base still in r9.  That linker is in the CI image.

gnu-elf.ld.in gains the two segments an FDPIC module needs, under
CONFIG_FDPIC, because the loader places its read-only and writable segments
independently, and names .dynamic, because a shared object is bound through
it.  The sections themselves are untouched and so are the symbols crt0.c
walks, so one script serves both and both build systems get it.

.bss moves to the end of the script, for every configuration and not only
FDPIC.  It held no file content but sat ahead of .got and .dynamic, which
do, so the writable segment's p_filesz had to span it and the module file
carried the whole of .bss.  A module with 16 KiB of .bss went from 26724 to
10340 bytes, and its writable segment from p_filesz 0x40ac to 0xac against
an unchanged p_memsz.  The loader reads p_filesz off the media, so it read
those bytes too.

Built for mps3-an547:picostest with apps/examples/elf, CONFIG_FDPIC both
ways.  With it on, every module in apps/bin is ARM FDPIC with two PT_LOAD
segments and enters at _start; hello++3, which has a static C++ object,
carries DT_INIT_ARRAY and DT_FINI_ARRAY.  With it off the generated script
has no PHDRS and the modules are what they were.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-09-09 10:21:21 +08:00
..
CMakeLists.txt cmake: Use NUTTX(_DIR/_BIN_DIR) instead CMAKE(_SRC_DIR/_BIN_DIR) 2026-08-09 11:13:08 -03:00
elf.h libs/libc/elf: Place an FDPIC object's segments independently. 2026-09-08 16:31:16 -03:00
elf_addrenv.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_bind.c libs/libc/elf, binfmt: Describe the GOT by base and size, not by index. 2026-09-08 16:31:16 -03:00
elf_depend.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_gethandle.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_getsymbol.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_globals.S
elf_init.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_insert.c libs/libc/elf: Fix the nxstyle errors around the FDPIC changes. 2026-09-08 16:31:16 -03:00
elf_iobuffer.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_load.c libs/libc/elf, binfmt: Describe the GOT by base and size, not by index. 2026-09-08 16:31:16 -03:00
elf_loadhdrs.c libs/libc/elf: Place an FDPIC object's segments independently. 2026-09-08 16:31:16 -03:00
elf_read.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_registry.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_remove.c libc/dlfcn: Count opens so a library can be shared. 2026-08-04 11:12:49 -03:00
elf_sections.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_symbols.c libs/libc/elf, binfmt: Describe the GOT by base and size, not by index. 2026-09-08 16:31:16 -03:00
elf_symtab.c
elf_uninit.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_unload.c libs/libc/elf: Place an FDPIC object's segments independently. 2026-09-08 16:31:16 -03:00
elf_verify.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
gnu-elf.ld.in arch/arm, libs/libc/elf: Build FDPIC modules in the normal ELF build. 2026-09-09 10:21:21 +08:00
Kconfig
Make.defs
Makefile