From c5a1cefac3e38f39de7e590bb2a0d4db8a23479a Mon Sep 17 00:00:00 2001 From: Andrew Haberlandt Date: Fri, 27 Dec 2024 03:05:45 -0500 Subject: [PATCH] Add __attribute__((constructor)) to macos builds for _init --- core/unix/os.c | 3 ++- core/unix/preload.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/unix/os.c b/core/unix/os.c index 9d9becdb14f..b075dfa6cce 100644 --- a/core/unix/os.c +++ b/core/unix/os.c @@ -784,7 +784,7 @@ static init_fn_t #else /* If we're a normal shared object, then we override _init. */ -int +IF_MACOS(__attribute__((constructor))) int _init(int argc, char **argv, char **envp) { # ifdef ANDROID @@ -1143,6 +1143,7 @@ get_application_name_helper(bool ignore_cache, bool full_path) #else /* OSX kernel puts full app exec path above envp */ char *c, **env = our_environ; + ASSERT(our_environ != NULL && "our_environ is not set in get_application_name_helper"); do { env++; } while (*env != NULL); diff --git a/core/unix/preload.c b/core/unix/preload.c index 3bf55bb3dce..2f457490da3 100644 --- a/core/unix/preload.c +++ b/core/unix/preload.c @@ -137,7 +137,7 @@ take_over(const char *pname) return true; } -__attribute__((constructor)) int +IF_MACOS(__attribute__((constructor))) int #if INIT_BEFORE_LIBC _init(int argc, char *arg0, ...) {