Skip to content

sim/posix: Add APPLE to a build target for sim's configuration using CMake.#18883

Open
toku-mac wants to merge 2 commits into
apache:masterfrom
toku-mac:add_apple_cargo_cmake
Open

sim/posix: Add APPLE to a build target for sim's configuration using CMake.#18883
toku-mac wants to merge 2 commits into
apache:masterfrom
toku-mac:add_apple_cargo_cmake

Conversation

@toku-mac
Copy link
Copy Markdown

@toku-mac toku-mac commented May 15, 2026

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

Provides: apache/nuttx-apps#3483.

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:
[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 .

PR verification Self-Check

  • My PR adheres to Contributing Guidelines and Documentation (git commit title and message, coding standard, etc).
  • My PR is ready for review and can be safely merged into a codebase.

@github-actions github-actions Bot added Arch: simulator Issues related to the SIMulator Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels May 15, 2026
@lupyuen
Copy link
Copy Markdown
Member

lupyuen commented May 15, 2026

@no1wudi Could you help to review the PR thanks :-)

@lupyuen lupyuen requested a review from simbit18 May 15, 2026 07:22
@lupyuen
Copy link
Copy Markdown
Member

lupyuen commented May 15, 2026

@toku-mac Could you check CMakeLists.txt thanks :-)

ERROR __main__.py:618: Check failed: /home/runner/work/nuttx/nuttx/nuttx/arch/sim/src/sim/CMakeLists.txt
cmake-format check failed, run following command to update the style:
  $ cmake-format <src> -o <dst>

@toku-mac
Copy link
Copy Markdown
Author

Sorry, I fixed in commit 118d09c.

@lupyuen
Copy link
Copy Markdown
Member

lupyuen commented May 15, 2026

@toku-mac Remember to add "Signed-off-by" thanks :-)

…CMake.

* Adjust macOS coverage linker configuration settings.
* Resolve linker errors caused by the absence of `-lgcov`.
* Fix an issue where `macho_call_saved_init_funcs()` on macOS could improperly reference `g_saved_init_funcs`.
* Eliminate the Rust/Tokio `clock_gettime()` panic that occurred when running `hello_rust_cargo` on the NuttX sim on macOS.
* Add support for treating Darwin's `CLOCK_MONOTONIC=6` and `CLOCK_UPTIME_RAW=8` as NuttX's monotonic clock in `sched/clock/clock_gettime.c` (limited to sim/macOS environments).

Signed-off-by: Shoji Tokunaga <toku@mac.com>
@toku-mac toku-mac force-pushed the add_apple_cargo_cmake branch from 118d09c to e14a952 Compare May 15, 2026 08:03
@toku-mac
Copy link
Copy Markdown
Author

I squashed at commit e14a952 :-)

@toku-mac
Copy link
Copy Markdown
Author

@lupyuen

failing checks
    Build / msys2 (msys2) (pull_request)Cancelled after 365 minutes 

It appears the process is stuck at this point. Could you please review the details?

@lupyuen
Copy link
Copy Markdown
Member

lupyuen commented May 16, 2026

@simbit18 Any idea what's wrong with the Windows build? I restarted but it didn't help thanks!

@simbit18
Copy link
Copy Markdown
Contributor

simbit18 commented May 16, 2026

Hi @lupyuen ,
the problem is here

 ‘[’ '!‘ -f /d/a/nuttx/nuttx/sources/tools/kconfig-frontends/bin/kconfig-conf ’]'
+ git clone --depth 1 https://bitbucket.org/nuttx/tools.git /d/a/nuttx/nuttx/sources/tools/nuttx-tools
Cloning into ‘/d/a/nuttx/nuttx/sources/tools/nuttx-tools’...

Repository not found
https://bitbucket.org/nuttx/tools.git

it's the same URL that we use to build the Nuttx docker image

RUN curl -s -L https://bitbucket.org/nuttx/tools/get/9ad3e1ee75c7.tar.gz \

https://nuttx.apache.org/docs/latest/quickstart/install.html#kconfig-frontend

Maybe the kconfig-frontends sources need to be moved to the https://github.com/orgs/NuttX/repositories

@simbit18
Copy link
Copy Markdown
Contributor

Hi @patacongo, we can no longer access the repository https://bitbucket.org/nuttx/tools.git. Could you please have a look?

@toku-mac
Copy link
Copy Markdown
Author

Sorry, I made a mistake with git operations at apps PR.
Replaces / follows up: #3483

Comment thread sched/clock/clock_gettime.c Outdated
Comment thread arch/sim/src/sim/posix/sim_macho_init.c Outdated
Comment thread arch/sim/src/sim/posix/sim_macho_init.c
@patacongo
Copy link
Copy Markdown
Contributor

patacongo commented May 16, 2026 via email

…CMake.

* Adjust macOS coverage linker configuration settings.
* Resolve linker errors caused by the absence of `-lgcov`.
* Fix an issue where `macho_call_saved_init_funcs()` on macOS could improperly reference `g_saved_init_funcs`.
* Eliminate the Rust/Tokio `clock_gettime()` panic that occurred when running `hello_rust_cargo` on the NuttX sim on macOS.
* Add support for treating Darwin's `CLOCK_MONOTONIC=6` and `CLOCK_UPTIME_RAW=8` as NuttX's monotonic clock (limited to sim/macOS environments).

Signed-off-by: Shoji Tokunaga <toku@mac.com>
@toku-mac toku-mac requested a review from masayuki2009 as a code owner May 17, 2026 12:27
@github-actions github-actions Bot added Size: M The size of the change in this PR is medium and removed Size: S The size of the change in this PR is small labels May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: simulator Issues related to the SIMulator Area: OS Components OS Components issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants