casaroli commented on issue #19509:
URL: https://github.com/apache/nuttx/issues/19509#issuecomment-6068717110
Status, to give a starting point:
1. Contradictory register flags: fixed. #19600 moved the PIC base register
to _r9_, and the `elseif(CONFIG_PIC)` branch of
**arch/arm/src/cmake/elf.cmake** now gives ELF applications only
`-mpic-register=r9` (no `--fixed-r10`). The title still says r10; since #19600
the register is `r9`.
Two parts are still open, both in the CMake build only. The Make build
(**arch/arm/src/common/Toolchain.defs**) already does both and is the reference.
2. ELF applications get no `-fpic`. The `elseif(CONFIG_PIC)` branch in
**elf.cmake** passes only `-mpic-register=r9`, so GCC warns "-mpic-register= is
useless without -fpic". Make adds `$(PICFLAGS) -mpic-register=r9` to
`CELFFLAGS`/`CXXELFFLAGS`. `PICFLAGS` (`-fpic -fPIE
-mno-pic-data-is-text-relative -msingle-pic-base`) is already defined in
**arch/arm/src/cmake/gcc.cmake**, so the fix there is probably
`nuttx_elf_compile_options(${PICFLAGS} -mpic-register=r9)`.
3. The base firmware does not reserve _r9_. Make adds `--fixed-r9` to
`ARCHCFLAGS` under `CONFIG_PIC` and filters it back out of the ELF and module
flags. CMake has nothing like this for a flat build:
`NUTTX_KERNEL_COMPILE_OPTIONS` is applied only to split kernel libraries
(**cmake/nuttx_add_library.cmake**). The flag must reach the firmware and libc
but not the ELF applications, otherwise GCC rejects the pair again ("unable to
use 'r9' for PIC register"). One possible way is a generator expression keyed
on a property that only ELF targets have. `ELF_BINARY` in
**cmake/nuttx_add_application.cmake** may work, but check that every ELF path
sets it. This part matters when firmware code calls back into module code, for
example `qsort()` with a comparator in the module.
To test: `cmake -B build -DBOARD_CONFIG=mps3-an547:picostest -GNinja
-DCMAKE_EXPORT_COMPILE_COMMANDS=1`. `picostest` is the only defconfig with
`CONFIG_PIC=y`. In **compile_commands.json**, firmware objects should have
`--fixed-r9`, and ELF application objects should have the `PICFLAGS`,
`-mpic-register=r9` and no `--fixed-r9`. The build should not print the
"useless without -fpic" warning.
--
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]