pangzhen1xiaomi opened a new pull request, #22100:
URL: https://github.com/apache/nuttx/pull/22100
## Summary
* Why: `NUTTX_EXTRA_FLAGS` (the directory compile options that are passed to
the final link and to steps that call the compiler directly) is built by a
block copied into the `platform.cmake` of six arches, and two existing
mechanisms around it do not work:
* `libs/libbuiltin/libgcc` removes `-fprofile-arcs -ftest-coverage
-fno-inline`
from it under `CONFIG_COVERAGE_MINI` and stores the result in the GLOBAL
property `NUTTX_EXTRA_FLAGS`, but the final link reads the plain
variable,
so the coverage flags still reach the link.
* `arm/clang.cmake` appends `-pg` to `COMPILE_ONLY_FLAGS` under
`CONFIG_PROFILE_ALL` (#21840), but nothing reads that list, so `-pg`
still
reaches the link and clang warns that it is unused.
* What:
1. `cmake: read and write NUTTX_EXTRA_FLAGS through a GLOBAL property` -
every arch that collects the flags publishes them as the GLOBAL
property,
and the final link reads the property back.
2. `arch/cmake: add COMPILE_ONLY_FLAGS` - the collection skips the flags
listed in `COMPILE_ONLY_FLAGS`.
3. `arch: share NUTTX_EXTRA_FLAGS collection across arches` - the copied
block becomes `nuttx_collect_extra_flags()` in
`cmake/nuttx_collect_extra_flags.cmake`, used by arm, risc-v, tricore,
x86_64, xtensa, rh850 and sim. tricore and rh850 keep the `-nostdlib`
exclusion through `EXCLUDE`. sim now publishes its flags too (e.g.
`-m32`),
so custom commands get the flags the image is built with. rh850 now
reads
the options from `NUTTX_DIR` and removes duplicates like the other
arches. arm64 is not changed: it collects into `CMAKE_C_FLAG_ARGS`.
The three commits are kept together because 2 and 3 build on 1, and all of
them change the same collection code.
* Related: #21840, #20610
## Impact
* Is new feature added? Is existing feature changed? YES. The final link no
longer gets the flags removed by libgcc (`CONFIG_COVERAGE_MINI`) or listed
in
`COMPILE_ONLY_FLAGS` (`-pg` with clang and `CONFIG_PROFILE_ALL`). Other
configurations get the same commands as before (see Testing).
* Impact on user (will user need to adapt to change)? NO.
* Impact on build (will build process change)? YES, CMake only: new helper
`cmake/nuttx_collect_extra_flags.cmake`; link flags change only in the two
cases above. Make is not affected.
* Impact on hardware (will arch(s) / board(s) / driver(s) change)? NO code
change; CMake files of arm, arm64, risc-v, tricore, x86_64, xtensa, rh850
and
sim.
* Impact on documentation (is update required / provided)? NO.
* Impact on security (any sort of implications)? NO.
* Impact on compatibility (backward/forward/interoperability)? NO. The
`NUTTX_EXTRA_FLAGS` variable is still set in the top-level scope.
* Anything else to consider or add? Not tested on rh850 and xtensa: there is
no `v850-elf-gcc` / xtensa GCC on my host.
## Testing
I confirm that changes are verified on local setup and works as intended:
* Build Host(s): Ubuntu 22.04.5 LTS, x86_64, host gcc 13.4.0, cmake 3.23.0,
ninja 1.10.1, arm-none-eabi-gcc 13.2.1, riscv-none-elf-gcc 13.4.0,
aarch64-none-elf-gcc 13.4.0, tricore-elf-gcc 11.3.1,
x86_64-none-elf-gcc 13.4.0, clang 21.1.1 (Arm Toolchain for Embedded).
* Target(s): sim:nsh, sim:smp, qemu-armv7a:nsh, rv-virt:nsh, qemu-armv8a:nsh,
a2g-tc397-5v-tft:nsh, qemu-intel64:nsh, mps3-an547:clang.
1. Regression: `tools/checkpatch.sh` on all commits; make build and `ostest`
on sim:nsh and sim:smp; full CMake build of sim:nsh, qemu-armv7a:nsh and
rv-virt:nsh. Every commit configures on its own (qemu-armv7a:nsh,
sim:nsh).
2. Unchanged commands: CMake configure on master and on this branch, then
compare `ninja -t commands` and the link statement of `nuttx` in
`build.ninja` (build directory and depfile hashes normalized). Identical
for
qemu-armv7a:nsh, rv-virt:nsh, qemu-armv8a:nsh, a2g-tc397-5v-tft:nsh,
qemu-intel64:nsh, sim:nsh, sim:nsh + `CONFIG_SIM_M32` and
mps3-an547:clang.
3. Changed link flags, same comparison:
* qemu-armv7a:nsh + `CONFIG_COVERAGE_ALL` + `CONFIG_COVERAGE_MINI`
* mps3-an547:clang + `CONFIG_PROFILE_ALL` + `CONFIG_FRAME_POINTER`, also
built with ninja on both sides (`-pg` needs a frame pointer with clang)
4. sim:nsh + `CONFIG_SIM_M32`: `-m32` is in the GLOBAL property
(`cmake --trace-expand` on `nuttx_collect_extra_flags.cmake`).
Testing logs before change:
```
# flags in the link statement of nuttx
qemu-armv7a:nsh + COVERAGE_MINI : -mcpu=cortex-a7 ... -fprofile-arcs
-ftest-coverage -fno-inline ...
mps3-an547:clang + PROFILE_ALL : ... -pg ...
# mps3-an547:clang + PROFILE_ALL build
clang++: warning: argument unused during compilation: '-pg'
[-Wunused-command-line-argument]
```
Testing logs after change:
```
# flags in the link statement of nuttx
qemu-armv7a:nsh + COVERAGE_MINI : -mcpu=cortex-a7 ... (no coverage flags)
mps3-an547:clang + PROFILE_ALL : ... (no -pg)
# mps3-an547:clang + PROFILE_ALL build: no unused-argument warning, nuttx
linked
# sim:nsh + SIM_M32
set_property(GLOBAL PROPERTY NUTTX_EXTRA_FLAGS ...;-m32;...)
```
Regression summary:
```
checkpatch: rc=0
[sim:nsh] make build: rc=0
[sim:nsh] ostest: Exiting with status 0
[sim:smp] make build: rc=0
[sim:smp] ostest: Exiting with status 0
[sim:nsh] cmake build: rc=0
[qemu-armv7a:nsh] cmake build: rc=0
[rv-virt:nsh] cmake build: rc=0
```
Only sim and QEMU targets were tested; this change only affects the CMake
build scripts, not code that runs on a target.
## PR verification Self-Check
* [x] This PR introduces only one functional change.
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
* [ ] My PR is still work in progress (not ready for review).
* [x] My PR is ready for review and can be safely merged into a codebase.
--
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]