-
Notifications
You must be signed in to change notification settings - Fork 1.6k
sim/posix: Add APPLE to a build target for sim's configuration using CMake. #18883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ | |
| #include <sys/mman.h> | ||
|
|
||
| #include <assert.h> | ||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
| #include <stdlib.h> | ||
| #include <unistd.h> | ||
|
|
||
|
|
@@ -78,11 +80,12 @@ static void save_and_replace_init_funcs(int argc, const char *argv[], | |
| const char *apple[]) | ||
| { | ||
| init_func_t *fp; | ||
| bool found_self = false; | ||
| unsigned int i; | ||
| unsigned int nfuncs = &mod_init_func_end - &mod_init_func_start; | ||
|
|
||
| assert(nfuncs > 0); | ||
| g_num_saved_init_funcs = nfuncs - 1; | ||
| if (g_num_saved_init_funcs == 0) | ||
| if (nfuncs == 1) | ||
| { | ||
| /* This function is the only constructor in the binary. | ||
| * no need to apply the following hack. | ||
|
|
@@ -96,23 +99,28 @@ static void save_and_replace_init_funcs(int argc, const char *argv[], | |
| g_saved_envp = envp; | ||
| g_saved_apple = apple; | ||
|
|
||
| g_saved_init_funcs = malloc(g_num_saved_init_funcs * | ||
| sizeof(*g_saved_init_funcs)); | ||
| g_saved_init_funcs = malloc((nfuncs - 1) * sizeof(*g_saved_init_funcs)); | ||
| allow_write(&mod_init_func_start, &mod_init_func_end); | ||
| int i = 0; | ||
| i = 0; | ||
| for (fp = &mod_init_func_start; fp < &mod_init_func_end; fp++) | ||
| { | ||
| if (*fp == save_and_replace_init_funcs) | ||
| { | ||
| assert(i == 0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. save_and_replace_init_funcs must be the first entry, so it can move all constructors to new array and call them after nuttx kernel finish the basic initialization.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On macOS Mach-O, a function registered with attribute((constructor)) is not guaranteed to be placed at the beginning of the __DATA,__mod_init_func section. When CMake, Apple’s toolchain, coverage runtime, or initialization functions originating from Rust/Cargo are involved, another constructor may be placed before save_and_replace_init_funcs. If assert(i == 0); is kept in that situation, the program may fail with an assertion failure at startup, or the old logic may handle g_saved_init_funcs incorrectly because its assumption is no longer valid.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please study the code to understand how the thing work: you must find a method to ensure save_and_replace_init_funcs come to first, otherwise all constructors before save_and_replace_init_funcs get executed too early. That's why the origin author add assert in the code.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or we need find other different solution to fix this problem.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About PR #18886. In my environment, it didn't work without making several modifications. Thanks.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about let's work on #18886 and close this pr? it's better to open a new pr for tokio library issue. |
||
| found_self = true; | ||
| continue; | ||
| } | ||
| else | ||
|
|
||
| if (found_self) | ||
| { | ||
| g_saved_init_funcs[i - 1] = *fp; | ||
| assert(i < nfuncs - 1); | ||
| g_saved_init_funcs[i] = *fp; | ||
| *fp = noop; | ||
| i++; | ||
| } | ||
| i++; | ||
| } | ||
|
|
||
| assert(found_self); | ||
| g_num_saved_init_funcs = i; | ||
| } | ||
|
|
||
| /**************************************************************************** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,20 @@ | |
| # include "clock/clock_timekeeping.h" | ||
| #endif | ||
|
|
||
| /**************************************************************************** | ||
| * Pre-processor Definitions | ||
| ****************************************************************************/ | ||
|
|
||
| #if defined(CONFIG_ARCH_SIM) && defined(CONFIG_HOST_MACOS) | ||
| /* Rust code built for the macOS host uses Darwin's libc clock IDs. When it | ||
| * is linked into the NuttX simulator, those values are passed to NuttX's | ||
| * clock_gettime() implementation instead of Darwin's one. | ||
| */ | ||
|
|
||
| # define DARWIN_CLOCK_MONOTONIC 6 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why add macos specific code in common module? all macos specific code should be in arch/sim/.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to fix the dependency issue using |
||
| # define DARWIN_CLOCK_UPTIME_RAW 8 | ||
| #endif | ||
|
|
||
| /**************************************************************************** | ||
| * Private Functions | ||
| ****************************************************************************/ | ||
|
|
@@ -97,7 +111,12 @@ int nxclock_gettime(clockid_t clock_id, FAR struct timespec *tp) | |
| return -EINVAL; | ||
| } | ||
|
|
||
| if (clock_id == CLOCK_MONOTONIC) | ||
| if (clock_id == CLOCK_MONOTONIC | ||
| #if defined(CONFIG_ARCH_SIM) && defined(CONFIG_HOST_MACOS) | ||
| || clock_id == DARWIN_CLOCK_MONOTONIC | ||
| || clock_id == DARWIN_CLOCK_UPTIME_RAW | ||
| #endif | ||
| ) | ||
| { | ||
| /* The the time elapsed since the timer was initialized at power on | ||
| * reset, excluding the time that the system is suspended. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge with line 84