casaroli opened a new pull request, #20816:
URL: https://github.com/apache/nuttx/pull/20816
## Summary
CMake saves `CMAKE_AR` and `CMAKE_RANLIB` of the first configure in
`CMakeFiles/<version>/CMake<LANG>Compiler.cmake`. On each later configure,
CMake reads this file after the toolchain file, so the saved tools replace the
tools that the toolchain file selects.
The arm, arm64 and risc-v GCC toolchain files select `gcc-ar` (arm and
risc-v also `gcc-ranlib`) only when LTO is on. When LTO is enabled in an
existing build directory (menuconfig, kconfig-tweak), the archive rules keep
the plain `ar` and `ranlib`. Without the LTO plugin, the archive index has no
symbols of the LTO objects, and the linker takes no member from the libraries.
On arm the link warns `cannot find entry symbol __start` and writes an empty
`nuttx`, or stops with `undefined reference to 'arm_boot'` from `arm_head.S`.
This PR puts the tools that the toolchain file selects in the archive rules
(`${CMAKE_AR}`, `${CMAKE_RANLIB}`) instead of the `<CMAKE_AR>` and
`<CMAKE_RANLIB>` placeholders. The toolchain file runs on each configure after
`.config` is read, so the rules follow the current LTO options.
## Impact
CMake builds that enable LTO after the first configure: the libraries get an
LTO symbol index and the image links. A first configure gives the same rules as
before, so builds without LTO and defconfigs with LTO do not change. arm64
always runs `gcc-ranlib`, so it linked correctly before; it now also archives
with `gcc-ar`. risc-v linked correctly before only with a toolchain that
installs the LTO plugin in `lib/bfd-plugins` (xPack does, Arm GNU does not). No
documentation change is necessary.
## Testing
CMake, configure the defconfig, then `kconfig-tweak --enable LTO_FULL
--disable LTO_NONE` and build. Arm GNU 13.2.rel1 (arm-none-eabi), 14.2.rel1
(aarch64-none-elf), xPack 14.3.0-1 (riscv-none-elf), CMake 4.3.1, macOS.
| config | master | this PR |
|---|---|---|
| `mps2-an500:nsh` (armv7-m) | `cannot find entry symbol __start`, text 0 |
text 348968, boots, `hello` runs, `ostest` runs as without LTO |
| `mps2-an521:nsh` (armv8-m) | `cannot find entry symbol __start`, text 0 |
text 322060, boots, `hello` runs |
| `nucleo-f429zi:nsh` (armv7-m) | `cannot find entry symbol __start`, text 0
| text 166888, `__start` and `_vectors` present |
| `nucleo-l552ze:nsh` (armv8-m) | `cannot find entry symbol __start`, text 0
| text 204848, `__start` and `_vectors` present |
| `qemu-armv7a:nsh` | `undefined reference to 'arm_boot'`, `'nx_start'` |
text 315372, boots, `hello` runs |
| `qemu-armv8a:nsh` | text 294506 | text 294506, boots, `hello` runs |
| `rv-virt:nsh` | text 207906 | text 207906, boots, `hello` runs |
The archive rule on master is `arm-none-eabi-ar rcs ... &&
arm-none-eabi-ranlib`; with this PR it is `arm-none-eabi-gcc-ar rcs ... &&
arm-none-eabi-gcc-ranlib`.
No change for the other builds (master and this PR give the same sizes):
CMake without LTO for `mps2-an500:nsh`, `qemu-armv7a:nsh`, `qemu-armv8a:nsh`
and `rv-virt:nsh`; Make with LTO for `mps2-an500:nsh` (text 347050); and CMake
`nucleo-g431rb:nsh`, which has LTO in its defconfig (text 129090).
`ostest` on `mps2-an500:nsh` stops at the same assertion with and without
LTO (`perf_gettime.c:132`, the performance counter reads 0 under QEMU), so this
PR does not cause it. On `mps2-an521:nsh`, `hello` sometimes hangs under QEMU
also without LTO (1 run in 5).
`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]