xiaoxiang781216 opened a new pull request, #18886:
URL: https://github.com/apache/nuttx/pull/18886
## Summary
Replace the macOS sim C++ global constructor runtime hack
(`sim_macho_init.c`)
with a post-link Mach-O section patching scheme so dyld no longer auto-runs
constructors before NuttX is initialized.
## Impact
- **Area**: arch/sim (macOS host only). Linux behavior is unchanged.
## Testing
- **Build host**: macOS (Ventura VM)
- **Target**: sim:nsh with `CONFIG_HAVE_CXX=y` /
`CONFIG_HAVE_CXXINITIALIZE=y`
- Verified via standalone test (`test_sinit7`) that the C++ constructor is
deferred past `main()` and is only invoked when explicitly called through
the `_sinit[]/_einit[]` loop in `lib_cxx_initialize()`.
## Details
1. Link with `-Wl,-ld_classic,-no_fixup_chains` to keep the classic
`__mod_init_func` pointer format (prevents ld64 from converting it to
`__init_offsets`).
2. Post-link, run `patch_macho_initsection.py` (python3 + `lief`) to patch
the Mach-O section type flags from `MOD_INIT_FUNC_POINTERS` /
`INIT_FUNC_OFFSETS` to `REGULAR`, so dyld skips them.
3. Use the Mach-O auto-generated boundary symbols
`section$start$__DATA_CONST$__mod_init_func` /
`section$end$__DATA_CONST$__mod_init_func`, mapped via `__asm()` labels in
`arch/sim/include/arch.h` to the common `_sinit[]`/`_einit[]` names used
by `lib_cxx_initialize()`.
4. Delete the old `sim_macho_init.c` runtime hack and the macOS-specific
`macho_call_saved_init_funcs()` path in `lib_cxx_initialize.c`.
Dependency: `pip install lief` on the build host when
`CONFIG_HAVE_CXXINITIALIZE=y`.
--
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]