| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Sorry, something went wrong.
The board set LDELFFLAGS to "-r -e main" after it included Toolchain.defs. This replaced the flags that Toolchain.defs sets for a loadable module. With CONFIG_FDPIC, a module then links as a relocatable object and not as an FDPIC shared object. A module that names a library does not link at all: "attempted static link of dynamic object". 9ed93c6 moved these flags into Toolchain.defs for all boards, and dae3b8e removed the same lines from mps3-an547. Remove them here too. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
libelf_findsymtab() accepted only a SHT_SYMTAB section. A shared object that strip has processed has no SHT_SYMTAB: only its SHT_DYNSYM remains. With CONFIG_DEBUG_SYMBOLS the application build strips each module in bin/, so every FDPIC module that it builds fails to load with "No symbols in ELF file". Use the dynamic symbol table of a shared object when it has no other symbol table. It holds every symbol that the object imports or exports, which is what the loader looks up. An object with SHT_SYMTAB still uses it. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
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>
gnu-elf.ld.in named neither .rel.plt nor .got.plt, and the linker placed them where its FDPIC code does not expect them. It merged .rel.plt into .rel.dyn but still set DT_JMPREL as if .rel.plt came last, so the loader bound each PLT slot with the symbol of another relocation. And .got.plt came after .got: the offsets that the linker gave the local function descriptors did not match where it put them, and the first call through one jumped into data. A module without a PLT has neither section, so neither problem showed until a module called its imports through a PLT. Give .rel.dyn and .rel.plt output sections of their own, and put .got.plt first in .got, both as in the linker's own script. Only CONFIG_FDPIC changes. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
GCC before 14 does not pass --fdpic to the assembler when it compiles with -mfdpic. The assembler then rejects every FDPIC relocation with "Relocation supported only in FDPIC mode". The NuttX CI image has GCC 13.2, so the crt0.o of an FDPIC configuration does not build there. Pass -Wa,--fdpic with -mfdpic, in the make build and the CMake build. A newer GCC passes the same option itself. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
With -mfdpic and -mlong-calls, GCC turns a call to an imported function in tail position into "ldr r3, [r9, #off]; bx r3". The GOT slot holds the address of the function descriptor, so the branch goes to the descriptor in RAM instead of through it, and the core faults. A normal call loads the code address and the data base from the descriptor first. GCC 13.2 and 15.3 both do this. Only an optimized build makes tail calls. The C++ library of apps/testing/fs/xipfs then faults in its constructor, which ends in a call to syslog(), and the test stops at "stage the C++ module". Pass -fno-optimize-sibling-calls with the other FDPIC flags, in the make build and the CMake build. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
| Back | FazBrowse Home | New Git URL |
Summary
apache/nuttx-apps#3762 builds the FDPIC test modules of examples/fdpicxip and testing/fs/xipfs the normal way, with MODULE = m and DYNLIB = y. That puts a stripped module, a CMake shared library and a lazy PLT through the FDPIC path for the first time, and four defects show. Two more show with #20132, the first FDPIC configuration in CI, and the first one built with optimization. Each commit fixes one:
Impact
Only CONFIG_FDPIC changes, except in the first commit, which gives mps2-an500 the common ELF link flags that the other boards use. Five boards still set their own LDELFFLAGS and so still cannot build an FDPIC module: devebox-stm32h743, weact-stm32h750, weact-stm32h743, openh743i and linum-stm32h753bi. They also name binfmt/elf/gnu-elf.ld, which no longer exists. I did not change them, because I cannot test them.
Testing
Host: macOS arm64, Arm GNU Toolchain 15.3.rel1 and 13.2.rel1 (the CI version), arm-uclinuxfdpiceabi binutils, QEMU 11.0.0.
mps2-an500:xipfs with CONFIG_FDPIC, on master with apache/nuttx-apps#3762, the same with both compilers:
Without each commit:
Under CMake, every module and library now links as an FDPIC shared object. The image itself does not link, because CMake does not generate the CONFIG_EXECFUNCS_SYSTEM_SYMTAB table. That is the same on master.
mps2-an500:xipfs and mps2-an521:xipfs, which do not set CONFIG_FDPIC, build. tools/checkpatch.sh -c -u -m -g passes.