nuttx/libs/libc/elf
Marco Casaroli 04dc50e71a libs/libc/elf: Fix two ways an FDPIC module failed to relocate.
Running one for the first time turned up two holes in the ET_DYN path.
Neither shows up in a build.

An undefined symbol is resolved with libelf_findglobal(), which searches
only the table of globally registered symbols.  The export table that
exec() hands its caller went no further than the ET_REL path, so an
ET_DYN module could not import anything the caller supplied.  Invisible
while such modules resolved everything internally; an FDPIC module
imports its libc, and every import failed with "Unable to resolve addr of
ext ref printf" although the caller had passed a table containing printf.
The export table is now threaded into libelf_relocatedyn() and consulted
when the global table has no answer, leaving the existing lookup order
intact.

A relocation naming a symbol defined inside the object was dropped
silently.  The code handles a relocation with no symbol, and one against
an undefined symbol, but a defined symbol fell through both.  That was
harmless while every dynamic relocation arriving here had symbol index
zero, which is the case for R_ARM_RELATIVE.  FDPIC brings the first ones
that do not: a pointer to a static function is emitted against the
*section* symbol, so the value is the section base and the offset within
it -- including the Thumb bit -- is carried as the addend.  Deriving a
value from the word being patched, as the no-symbol case does, would
translate that addend as though it were an address.  Confirmed against a
real module: .text at 0x23c plus an addend of 0x95 gives 0x2d1, which is
the function with its Thumb bit.

Also stop libelf_symname() reporting a nameless symbol as an error.  A
section symbol has no name, and libelf_findsymbol() walks the whole table
looking for optional entries such as nx_stacksize, so it meets these
routinely and checks for -ESRCH itself.  At error level it printed ten or
more lines per module load and buried the diagnostics that matter.

Built and run on lm3s6965-ek with the examples/elf ROMFS.  The ET_REL
test modules load as before, and an FDPIC module now loads, relocates,
resolves printf and puts from the table exec() supplied, and calls
through a function descriptor of its own.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-09-08 16:31:16 -03: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: Fix two ways an FDPIC module failed to relocate. 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 libc/elf: rename modlib to libelf 2025-04-11 09:43:22 +08:00
elf_init.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
elf_insert.c libc/dlfcn: Count opens so a library can be shared. 2026-08-04 11:12:49 -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: Read the dynamic tags an FDPIC object needs. 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: Fix two ways an FDPIC module failed to relocate. 2026-09-08 16:31:16 -03:00
elf_symtab.c libc/elf: rename modlib to libelf 2025-04-11 09:43:22 +08:00
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 libc/elf: rename modlib to libelf 2025-04-11 09:43:22 +08:00
Kconfig libc/elf: rename modlib to libelf 2025-04-11 09:43:22 +08:00
Make.defs libc/elf: rename modlib to libelf 2025-04-11 09:43:22 +08:00
Makefile libc/elf: rename modlib to libelf 2025-04-11 09:43:22 +08:00