Swatantra-66 opened a new pull request, #20711:
URL: https://github.com/apache/nuttx/pull/20711

   ## Summary
   Resolves the remaining open items in issue #19509 ("*[BUG] CMake build: 
CONFIG_PIC gives ELF applications contradictory register flags and no -fpic, 
and never reserves r10 in the base firmware*"):
   
   Following PR #19600 which transitioned the PIC base register to `r9`, two 
issues remained in the CMake build when `CONFIG_PIC=y`:
   
   1. **Position-Independent Flags for ELF Applications:**
      In `arch/arm/src/cmake/elf.cmake`, the `elseif(CONFIG_PIC)` branch 
previously passed only `-mpic-register=r9`, causing the compiler warning:
      `cc1: warning: '-mpic-register=' is useless without '-fpic'`
      This patch passes `${PICFLAGS} -mpic-register=r9` to 
`nuttx_elf_compile_options` (with fallback definition if `PICFLAGS` is 
undefined), matching `CELFFLAGS` in `arch/arm/src/common/Toolchain.defs`.
   
   2. **Reserve r9 in Base Firmware:**
      Under `CONFIG_PIC`, base firmware routines could clobber `r9`. When 
firmware calls back into module code (e.g. `qsort()` with a module comparator), 
the module's data base was corrupted.
      This patch adds `-ffixed-r9` to base firmware across GCC and Clang via:
      
`add_compile_options($<$<NOT:$<BOOL:$<TARGET_PROPERTY:ELF_BINARY>>>:-ffixed-r9>)`
      in `arch/arm/src/cmake/gcc.cmake` and `arch/arm/src/cmake/clang.cmake`, 
reserving `r9` for firmware while cleanly excluding all ELF targets.
   
   3. **Mark `STARTUP_OBJS` as ELF Target:**
      In `arch/arm/src/common/CMakeLists.txt`, set `ELF_BINARY TRUE` on 
`STARTUP_OBJS` (`crt0.c`) so it receives PIC compilation options and is 
excluded from `-ffixed-r9`.
   
   ## Impact
   - **Build system:** Brings CMake ARM build under `CONFIG_PIC=y` into 
functional parity with the Makefile build 
(`arch/arm/src/common/Toolchain.defs`).
   - **Compiler output:** Silences the `'-mpic-register=' is useless without 
'-fpic'` warning when compiling `crt0.c` and ELF applications.
   - **Runtime correctness:** Protects PIC module callbacks from data base 
register corruption when invoked by base firmware routines.
   - **Compatibility:** Strictly adheres to standard GCC and Clang 
`-ffixed-reg` syntax.
   
   ## Testing
   - Verified codebase style:
     `./tools/checkpatch.sh -u`: 0 errors, 0 warnings.
   - Target configuration:
     `mps3-an547:picostest` (`CONFIG_PIC=y`).
   
   Fixes #19509
   


-- 
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]

Reply via email to