casaroli opened a new pull request, #20789: URL: https://github.com/apache/nuttx/pull/20789
## Summary The linker makes no GOT for a relocatable object, but its code can still use the GOT relocations: all code built with `-fPIC` does, and code that takes the address of an undefined weak symbol. The arm64 module loader did not know `R_AARCH64_ADR_GOT_PAGE` and `R_AARCH64_LD64_GOT_LO12_NC`, so such a module did not load: `exec()` failed with `EINVAL`. This PR makes the loader build a GOT for a relocatable (`ET_REL`) object: - Before the data is sized, the loader counts the symbols that the GOT relocations name, and reserves one slot for each symbol behind the data. - At relocation time it writes S + A in the slot of the symbol, and relocates the instruction against the address of the slot. - An architecture names its GOT relocations with `ARCH_ELF_RELOC_GOT()` in `arch/elf.h`. Only arm64 does this now. Other architectures and other object types (FDPIC, `ET_DYN`, `ET_EXEC`) do not change. ## Impact arm64 modules (ELF programs and `insmod` modules) can now contain code built with `-fPIC`, and code that tests the address of a weak symbol. An object without GOT relocations loads as before. The GOT uses 8 bytes per symbol, in the data of the module. ## Testing A test program built with `-fPIC` (5 GOT relocations), run on `qemu-armv8a:knsh` (QEMU 11 with HVF on an Apple M4): | Check | master | this PR | |---|---|---| | Load the program | `exec failed: 22` | runs | | GOT slot holds the address of the data (by hand: `adrp :got:` + `ldr :got_lo12:`, against `adrp` + `add :lo12:`) | - | PASS | | A write through the slot reaches the data | - | PASS | | libc function address through the GOT | - | PASS | | Undefined weak data and function are NULL | - | PASS | `ostest` on `qemu-armv8a:knsh` and `qemu-armv8a:nsh` ends with `ostest_main: Exiting with status 0`. `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
