sim: posix: add platform-specific timer handling for macOS and Linux#18331
sim: posix: add platform-specific timer handling for macOS and Linux#18331aditya0yadav wants to merge 1 commit intoapache:masterfrom
Conversation
|
Hi @aditya0yadav , I converted PR into draft. @FelipeMdeO @lupyuen @aviralgarg05 What do you think? |
|
please remove the merge commit ! |
Hi @simbit18, thanks for tagging me, the core approach of using |
|
@aviralgarg05 I’ve removed the #define _POSIX_C_SOURCE 200809L in macOS and Ubuntu-based code spaces and it’s working properly. Mind taking a look? |
|
@simbit18 One more thing, what should we do with the linker in macOS? Every time I have to disable the configuration toolchain related to Gcov. Any suggestions? |
Thanks for the update @aditya0yadav, I checked the latest changes, the approach looks correct. There might be an issue with the |
|
Thanks for the review, @aviralgarg05.
I will look into it .
|
A long time ago, it was possible to build sim:nsh for Linux, macOS, and Windows . Of course, this is just my opinion! :) |
I think is makes sense, maybe using git bisect it could be possible to identify which symbols cases the breaking and open an issue to track it. |
|
Hi @raiden00pl, The changes in this PR cause errors in sim:citest. Can you check it? |
|
@simbit18 @aditya0yadav sim/citest is broken, NTFC detects that device is broken at init or doesn't boot at all. When I run binary from this PR, NSH is not functional and it stucks on NSH prompt (not sure what is this init error and if it's realted):
probably not everyone knows about it, but you can download built binaries directly from CI:
|
|
with this PR |
|
@raiden00pl, thank you very much. |
I just want to check if I’m understanding correctly: The linker issue seems to happen only on macOS, not on Linux. On Linux, it works fine and uses Gcov as expected, but on macOS, I always have to disable the Gcov-related toolchain in the configuration. If I wanted to find the specific symbol that is causing the linker to fail, doing a git bisect over 2–4 years of changes seems impractical because there’s been too much change in the repository. One idea I had is to use Docker with Linux to build NuttX, since Linux doesn’t hit the macOS linker problem. But of course, that wouldn’t reproduce the macOS-specific issue. Do you have any suggestions on how to approach this efficiently for macOS? |
|
Hello all,
Sorry for late reply.
I am very busy during this week but this weekend I will be available to
help. Let me try execute de bisec and find the valid commit.
*Felipe Moura de Oliveira*
*Universidade Federal de Minas Gerais*
Linkedin <https://www.linkedin.com/in/felipe-oliveira-75a651a0>
<https://twitter.com/FelipeMOliveir?lang=pt-br>
…On Thu, 5 Feb 2026 at 19:04 Aditya Yadav ***@***.***> wrote:
*aditya0yadav* left a comment (apache/nuttx#18331)
<#18331 (comment)>
@simbit18 <https://github.com/simbit18> One more thing, what should we do
with the linker in macOS? I know it will work perfectly with Linux but not
with macOS.
Every time I have to disable the configuration toolchain related to Gcov.
Any suggestions?
A long time ago, it was possible to build sim:nsh for Linux, macOS, and
Windows . Currently, it does not work on macOS and Windows with
MSYS2/Cygwin (the latest version I was able to build and test was 10.2
<https://github.com/simbit18/nuttx-msys2>), so I personally think it is
right to restore the build by modifying the defconfig file.
Of course, this is just my opinion! :)
I think is makes sense, maybe using git bisect it could be possible to
identify which symbols cases the breaking and open an issue to track it.
I just want to check if I’m understanding correctly:
@simbit18 <https://github.com/simbit18> @acassis
<https://github.com/acassis>
The linker issue seems to happen only on macOS, not on Linux. On Linux, it
works fine and uses Gcov as expected, but on macOS, I always have to
disable the Gcov-related toolchain in the configuration.
If I wanted to find the specific symbol that is causing the linker to
fail, doing a git bisect over 2–4 years of changes seems impractical
because there’s been too much change in the repository.
One idea I had is to use Docker with Linux to build NuttX, since Linux
doesn’t hit the macOS linker problem. But of course, that wouldn’t
reproduce the macOS-specific issue.
Do you have any suggestions on how to approach this efficiently for macOS?
—
Reply to this email directly, view it on GitHub
<#18331 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADNC5ZRBKU6VDMZIY5VHU634KO47NAVCNFSM6AAAAACTY7CVNWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTQNJWGUZDMOBSHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
Hello @aditya0yadav , @acassis , @simbit18 , @raiden00pl, @linguini1 . I did several build to try get first macOS build break. The last OK macOS build (commit sha): Crash Commit SHA: Using this SHA, the build output is: |
|
@aditya0yadav I don't get it why you try to use gcc when gcc is not supported on your host. Just change Lines 57 to 62 in e836067 |
|
why not just change this: Lines 38 to 49 in e836067 to this: I'm not sure if |
|
@raiden00pl However, the build-system tweaks are still necessary to fix hardcoded GCC-isms—like the forced search for x86_64-elf-gcc and the -lgcov link—which currently break the build even when Clang is explicitly selected. |
|
@aditya0yadav |
|
Thank you for the guidance; these technical discussions are incredibly valuable for my learning. I understand that COVERAGE_TOOLCHAIN is currently gated by ARCH_TOOLCHAIN_GCC. However, the current logic assumes that coverage is a GCC-only feature. My goal is to decouple this so that macOS users can leverage Clang’s native profiling (-fprofile-instr-generate). Rather than forcing macOS users to disable coverage entirely, these changes allow the build system to select the correct instrumentation based on the host toolchain. I am still looking into the best way to handle the Kconfig dependencies. Consider these current tweaks as a way to identify the conflict; I'll continue investigating this over the next few days to propose a cleaner, more permanent solution that satisfies the configuration requirements. |
|
@aditya0yadav what about these options dedicated for Clang: Lines 39 to 55 in e836067
|
|
@raiden00pl Really thanks for your help |
|
@aditya0yadav Quick tip: use "git grep" to search for keywords you're working with. It's the most useful tool for working with the nuttx codebase :) |
|
hello @aditya0yadav , can I help you to finish this fix? |
|
Please do that
Thanks
…On Tue, 17 Feb, 2026, 4:59 am Felipe Oliveira, ***@***.***> wrote:
*FelipeMdeO* left a comment (apache/nuttx#18331)
<#18331 (comment)>
hello @aditya0yadav <https://github.com/aditya0yadav> , can I help you to
finish this fix?
This fix is very important for us.
—
Reply to this email directly, view it on GitHub
<#18331 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/BHWNCTJOK5KBCBOLRTFCJP34MJHHPAVCNFSM6AAAAACTY7CVNWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSMJQHE3TQNJVGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
Hello @aditya0yadav , @raiden00pl I did some changes on my side, can you check it and if it is ok add it to your PR, please? https://github.com/FelipeMdeO/nuttx |
|
@FelipeMdeO lgtm |
| * | ||
| ****************************************************************************/ | ||
|
|
||
| int host_settimer(uint64_t nsec) |
There was a problem hiding this comment.
@aditya0yadav please keep the function description. If you think the description is wrong, please fix it.
|
@raiden00pl @FelipeMdeO Or @FelipeMdeO can merge his commit if that’s okay. |
@aditya0yadav no, just learn how to use "git rebase -i" :-) |
|
Congratulations @aditya0yadav. |
arch/sim/Kconfig
Outdated
|
|
||
| choice | ||
| prompt "Toolchain Selection" | ||
| default SIM_TOOLCHAIN_GCC if HOST_LINUX |
|
|
||
| now = host_gettime(false); | ||
|
|
||
| usec = (nsec <= now) ? 1 : (nsec - now) / 1000; |
There was a problem hiding this comment.
| usec = (nsec <= now) ? 1 : (nsec - now) / 1000; | |
| usec = (nsec <= now ? 1 : (nsec - now + 99) / 1000); |
and remove line 126
|
@aditya0yadav please squash your change into one patch |
now setimer is shared between linux and macos and remove the use of #define _POSIX_C_SOURCE 200809L fix the word problem enhance toolchain selection for simulation: set defaults for GCC on Linux and Clang on macOS document host_settimer function: add description and parameter details fix: adjust timer calculation in host_settimer for accurate timing
|
@xiaoxiang781216 Please check now |
|
@simbit18 @raiden00pl any idea what is this error: I just restarted the CI, let's see if it helps |
|
@acassis because this change breaks sim and nuttx sim doesn't even boot on CI linux ( |
|
@acassis you can download sim elf here and run on linux: https://github.com/apache/nuttx/actions/runs/22508690590/job/65219879041#step:14:25 NSH boots OK, but the system is not functional (you can press ENTER and nothing happen, the same issue like before) |
Thank you @raiden00pl so it is not a false positive. @aditya0yadav @FelipeMdeO did you test it? |
|
Simple sim/nsh config boots fine, but sim/citest config is broken |



PLEASE DONT MERGE THIS PR
Summary
This change updates the POSIX simulator host timer implementation to
handle platform differences between macOS (Darwin) and Linux.
macOS does not provide full support for POSIX timers such as
timer_create()andtimer_settime(). To address this, the simulatornow uses
setitimer()on macOS while retaining POSIX timers withabsolute-time scheduling on Linux and other POSIX systems.
The platform selection is handled via the
NUTTX_DARWINmacro, keepingthe simulator core logic unchanged while improving portability and
correctness on macOS.
Impact
Testing
Tested on macOS (Darwin):
SIGALRMand simulatorscheduling behaves as expected.
Linux testing:
Since this change affects host timer handling, additional testing on
Linux systems would be valuable before merging.
If anyone is able to test this change on a Linux PC and confirm that the
POSIX simulator builds and runs correctly, that feedback and any logs
would be greatly appreciated.
One more thing ,
For supporting macos, multiple things need to be done like docs and linker too .