casaroli opened a new pull request, #20814:
URL: https://github.com/apache/nuttx/pull/20814
## Summary
With LTO, arm, arm64 and risc-v set `CMAKE_LD` to gcc, and
`nuttx_add_application()` links each loadable module (`MODULE m`) with the
compiler driver. That link fails in two ways:
- The ELF link options of arm64 (`--gc-sections`, `-Bstatic`), risc-v
(`--oformat`) and arm (`-Bstatic`, and `--unresolved-symbols`, `--emit-relocs`
with `CONFIG_PIC`) are linker options. gcc stops with `unrecognized
command-line option '--gc-sections'`.
- The module objects and crt0 (`STARTUP_OBJS`) are compiled with `-flto`,
and the partial link (`-r`) cannot give the loader machine code. On arm the
link stops with `uses VFP register arguments, ... does not`, because gcc
compiles the LTO crt0 without the options of the target.
This PR gives the linker options with `-Wl,` when `CMAKE_LD` is gcc, as arm
already did for `--gc-sections`. An FDPIC module of arm is linked by the FDPIC
linker, so its options stay as they are. When LTO is on, the objects of a
loadable module and `STARTUP_OBJS` are compiled with `${NO_LTO}`. The image
keeps LTO.
## Impact
CMake builds with LTO and loadable modules: the modules link and load.
Builds without LTO, or with ld as `CMAKE_LD`, get the same options as before.
## Testing
`qemu-armv8a:nsh` (flat, CMake, Arm GNU 14.2 aarch64-none-elf, QEMU HVF),
`CONFIG_ELF`, `CONFIG_EXECFUNCS_SYSTEM_SYMTAB`, TLS test programs and `hello`
as `MODULE m`, loaded from a 9p share:
| | master | this PR |
|---|---|---|
| `CONFIG_LTO_FULL` | build fails: `unrecognized command-line option
'--gc-sections'` | tlsgroup, tls4, tlsmany, uctls, tlscxx PASS; `Hello,
World!!` |
| `CONFIG_LTO_NONE` | PASS | PASS |
With `CONFIG_LTO_FULL` the module link is `aarch64-none-elf-gcc ... -r
-Wl,--gc-sections -e _start -Wl,--defsym ...`, and crt0 and the module objects
are compiled with `-fno-lto`.
`mps2-an500:nsh` (CMake, arm-none-eabi 13.2, `CONFIG_LTO_FULL`): the modules
now link (`Tag_ABI_VFP_args: VFP registers`, `_start` defined). They could not
run: the CMake LTO link of the image itself fails, also on master (on master it
makes an empty image: `cannot find entry symbol __start`).
The tests ran with #20723 and #20807 for the TLS programs and
`get_environ_ptr`, and with apache/nuttx-apps#3883 for `hello`. "master" in the
table is master with these PRs.
`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]