anjiahao1 opened a new pull request, #22247:
URL: https://github.com/apache/nuttx/pull/22247
## Summary
The CMake build for the simulator did not pass `-r` when linking loadable
modules. The ELF application link step already used `-r`, but the module
link step was left without it, so the resulting object was not linked in
the relocatable form expected by the ELF loader.
Add `nuttx_mod_link_options(-r)` next to the existing ELF link options.
## Impact
* Is new feature added? NO
* Impact on user: NO
* Impact on build: YES - simulator CMake builds now link loadable
applications as relocatable objects.
* Impact on hardware: NO
* Impact on documentation: NO
* Impact on security: NO
* Impact on compatibility: NO
## Testing
Build host: Linux x86_64 (Ubuntu 24.04), GCC 13.3.0, CMake 3.28.3
Target: sim (CMake build)
Before this change, the generated link command for the `sotest` dynlib
target did not include `-r`:
```
ld -T .../gnu-elf.ld --wrap=__emutls_get_address ... \
--start-group --whole-archive .../libELF_sotest.a ... -o .../sotest
ld: ... undefined reference to `modprint'
ld: ... undefined reference to `__gcov_init'
```
After this change, the same command includes `-r` and the dynlib link
succeeds:
```
ld -T .../gnu-elf.ld -r --wrap=__emutls_get_address ... \
--start-group --whole-archive .../libELF_sotest.a ... -o .../sotest
[100%] Built target ELF_sotest
```
The standard `sim:nsh` CMake build passes with the change:
```
cmake -S . -B build-nsh -DBOARD_CONFIG=sim:nsh -DNUTTX_APPS_DIR=...
cmake --build build-nsh -j20
[100%] Built target nuttx
```
The SOTEST configuration is based on `sim:nsh` plus:
```
CONFIG_FS_HOSTFS=y
CONFIG_SIM_HOSTFS=y
CONFIG_LIBC_DLFCN=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_NSH_FILE_APPS=y
CONFIG_EXAMPLES_SOTEST=y
CONFIG_EXAMPLES_SOTEST_BINDIR="/host"
```
How to repeat:
```
cmake -S . -B build-sotest -DBOARD_CONFIG=sim:<config> \
-DNUTTX_APPS_DIR=<apps>
cmake --build build-sotest -j
```
Note: the runtime `sotest` load was not used as a gate. The CMake sim
build does not generate the exec symbol table, so `dlopen` of a module
with unresolved libc symbols fails independently of this link option.
## PR verification
* [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.
* [ ] 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]