toku-mac opened a new pull request, #18883: URL: https://github.com/apache/nuttx/pull/18883
## Summary * Add macOS support to the `hello_rust_cargo` CMake build configuration. * Depends on apps PR: apps:cmake: Add APPLE to a build target for sim's configuration using CMake * Although the C compiler included in Xcode is named `gcc`, its actual implementation is `clang`. ``` ❯ /usr/bin/gcc --version Apple clang version 21.0.0 (clang-2100.1.1.101) Target: arm64-apple-darwin25.5.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin ``` ### About `macho_call_saved_init_funcs()` Issue - The issue occurs when `save_and_replace_init_funcs()` does not appear at the head of `__mod_init_func`. For example, consider this sequence: ```text [0] constructor A [1] save_and_replace_init_funcs [2] constructor B ... ``` - Since dyld calls `__mod_init_func` entries in the order they appear, `constructor A` has already executed before `save_and_replace_init_funcs()` is called. - In this state, the original implementation enters the `else` branch until it finds `save_and_replace_init_funcs()`, where it executes `g_saved_init_funcs[i - 1] = *fp;`. - With the first entry, `i == 0`, so `i - 1` becomes out-of-bounds when interpreted without sign, or `-1` even as an `int`, resulting in an invalid write to `g_saved_init_funcs[-1]`. - This leads to either an invalid reference or crash in the `macho_call_saved_init_funcs()` side. ## Impact * Impact on build: enables building with cargo and cmake. ## Testing I confirm that changes are verified on local setup and works as intended: * Build Host(s): OS (macOS 26.5), CPU(Apple M1), compiler(Apple clang version 21.0.0) * Target(s): arch(sim) * Ensure your PATH environment variable is properly configured to allow execution of: menuconfig, olddefconfig, savedefconfig, and setconfig. * Use the Rust toolchain version prior to nightly-2026-04-29 to avoid errors related to lib/rustlib/src/rust/library/std/src/sys/net/connection/socket/unix.rs. See the [apps PR #3482](https://github.com/apache/nuttx-apps/pull/3482) . ## PR verification Self-Check * [x] My PR adheres to Contributing [Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md) and [Documentation](https://nuttx.apache.org/docs/latest/contributing/index.html) (git commit title and message, coding standard, etc). * [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]
