diff --git a/expected/wasm32-wasi/posix/defined-symbols.txt b/expected/wasm32-wasi/posix/defined-symbols.txt index d1544592b..d92bcbd88 100644 --- a/expected/wasm32-wasi/posix/defined-symbols.txt +++ b/expected/wasm32-wasi/posix/defined-symbols.txt @@ -90,6 +90,7 @@ __getopt_msg __gmtime_r __hwcap __inet_aton +__init_tp __intscan __invtrigl_R __isalnum_l @@ -324,6 +325,7 @@ __wasi_fd_seek __wasi_fd_sync __wasi_fd_tell __wasi_fd_write +__wasi_init_tp __wasi_path_create_directory __wasi_path_filestat_get __wasi_path_filestat_set_times diff --git a/expected/wasm32-wasi/single/defined-symbols.txt b/expected/wasm32-wasi/single/defined-symbols.txt index f8f445707..23ff87197 100644 --- a/expected/wasm32-wasi/single/defined-symbols.txt +++ b/expected/wasm32-wasi/single/defined-symbols.txt @@ -275,6 +275,7 @@ __wasi_fd_seek __wasi_fd_sync __wasi_fd_tell __wasi_fd_write +__wasi_init_tp __wasi_path_create_directory __wasi_path_filestat_get __wasi_path_filestat_set_times diff --git a/libc-bottom-half/crt/crt1-command.c b/libc-bottom-half/crt/crt1-command.c index 6e2bcd942..3bcad84ba 100644 --- a/libc-bottom-half/crt/crt1-command.c +++ b/libc-bottom-half/crt/crt1-command.c @@ -1,3 +1,4 @@ +#include "libc.h" #include extern void __wasm_call_ctors(void); extern int __main_void(void); @@ -7,6 +8,11 @@ extern void __wasm_call_dtors(void); // that the `_start` function isn't started more than once. static volatile int started = 0; +static void dummy_0() +{ +} +weak_alias(dummy_0, __wasi_init_tp); + __attribute__((export_name("_start"))) void _start(void) { // Don't allow the program to be called multiple times. @@ -15,6 +21,8 @@ void _start(void) { } started = 1; + __wasi_init_tp(); + // The linker synthesizes this to call constructors. __wasm_call_ctors(); diff --git a/libc-top-half/musl/src/env/__init_tls.c b/libc-top-half/musl/src/env/__init_tls.c index bd041b2c7..ee785bc11 100644 --- a/libc-top-half/musl/src/env/__init_tls.c +++ b/libc-top-half/musl/src/env/__init_tls.c @@ -15,16 +15,23 @@ volatile int __thread_list_lock; -#ifdef __wasilibc_unmodified_upstream +#ifndef __wasilibc_unmodified_upstream +void __wasi_init_tp() { + __init_tp((void *)__get_tp()); +} +#endif + int __init_tp(void *p) { pthread_t td = p; td->self = td; +#ifdef __wasilibc_unmodified_upstream int r = __set_thread_area(TP_ADJ(p)); if (r < 0) return -1; if (!r) libc.can_do_threads = 1; td->detach_state = DT_JOINABLE; td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock); +#endif td->locale = &libc.global_locale; td->robust_list.head = &td->robust_list.head; td->sysinfo = __sysinfo; @@ -32,6 +39,8 @@ int __init_tp(void *p) return 0; } +#ifdef __wasilibc_unmodified_upstream + static struct builtin_tls { char c; struct pthread pt;