Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ endif
# pthreads functions (possibly stub) for either thread model
LIBC_TOP_HALF_MUSL_SOURCES += \
$(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \
env/__init_tls.c \
thread/default_attr.c \
thread/pthread_attr_destroy.c \
thread/pthread_attr_get.c \
Expand All @@ -293,6 +294,7 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
thread/pthread_condattr_setclock.c \
thread/pthread_condattr_setpshared.c \
thread/pthread_equal.c \
thread/pthread_getattr_np.c \
thread/pthread_getspecific.c \
thread/pthread_key_create.c \
thread/pthread_mutex_destroy.c \
Expand Down Expand Up @@ -320,7 +322,6 @@ ifeq ($(THREAD_MODEL), posix)
# pthreads functions needed for actual thread support
LIBC_TOP_HALF_MUSL_SOURCES += \
$(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \
env/__init_tls.c \
stdio/__lockfile.c \
stdio/flockfile.c \
stdio/ftrylockfile.c \
Expand All @@ -339,7 +340,6 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
thread/pthread_cond_wait.c \
thread/pthread_create.c \
thread/pthread_detach.c \
thread/pthread_getattr_np.c \
thread/pthread_join.c \
thread/pthread_mutex_consistent.c \
thread/pthread_mutex_getprioceiling.c \
Expand Down Expand Up @@ -384,7 +384,6 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
pthread_cond_wait.c \
pthread_create.c \
pthread_detach.c \
pthread_getattr_np.c \
pthread_join.c \
pthread_mutex_consistent.c \
pthread_mutex_getprioceiling.c \
Expand Down
2 changes: 2 additions & 0 deletions expected/wasm32-wasip1/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ __gmtime_r
__hwcap
__inet_aton
__init_ssp
__init_tp
__intscan
__invtrigl_R
__isalnum_l
Expand Down Expand Up @@ -311,6 +312,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
Expand Down
2 changes: 2 additions & 0 deletions expected/wasm32-wasip1/undefined-symbols.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__addtf3
__data_end
__divtf3
__eqtf2
__extenddftf2
Expand All @@ -9,6 +10,7 @@ __fixunstfsi
__floatsitf
__floatunsitf
__getf2
__global_base
__gttf2
__heap_base
__heap_end
Expand Down
2 changes: 2 additions & 0 deletions expected/wasm32-wasip2/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ __gmtime_r
__hwcap
__inet_aton
__init_ssp
__init_tp
__intscan
__invtrigl_R
__isalnum_l
Expand Down Expand Up @@ -314,6 +315,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
Expand Down
2 changes: 2 additions & 0 deletions expected/wasm32-wasip2/undefined-symbols.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__addtf3
__data_end
__divtf3
__eqtf2
__extenddftf2
Expand All @@ -9,6 +10,7 @@ __fixunstfsi
__floatsitf
__floatunsitf
__getf2
__global_base
__gttf2
__heap_base
__heap_end
Expand Down
4 changes: 1 addition & 3 deletions libc-bottom-half/crt/crt1-command.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifdef _REENTRANT
#include <stdatomic.h>
extern void __wasi_init_tp(void);
#endif
extern void __wasi_init_tp(void);
#ifdef __wasilibc_use_wasip2
#include <wasi/wasip2.h>
#else
Expand Down Expand Up @@ -34,9 +34,7 @@ void _start(void) {
started = 1;
#endif

#ifdef _REENTRANT
__wasi_init_tp();
#endif

// The linker synthesizes this to call constructors.
__wasm_call_ctors();
Expand Down
5 changes: 2 additions & 3 deletions libc-bottom-half/crt/crt1-reactor.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if defined(_REENTRANT)
#include <stdatomic.h>
extern void __wasi_init_tp(void);
#endif
extern void __wasi_init_tp(void);
extern void __wasm_call_ctors(void);

__attribute__((export_name("_initialize")))
Expand All @@ -12,15 +12,14 @@ void _initialize(void) {
if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) {
__builtin_trap();
}

__wasi_init_tp();
#else
static volatile int initialized = 0;
if (initialized != 0) {
__builtin_trap();
}
initialized = 1;
#endif
__wasi_init_tp();

// The linker synthesizes this to call constructors.
__wasm_call_ctors();
Expand Down
20 changes: 19 additions & 1 deletion libc-top-half/musl/src/env/__init_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include "atomic.h"
#include "syscall.h"

#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
volatile int __thread_list_lock;
#endif

#ifndef __wasilibc_unmodified_upstream

Expand All @@ -25,9 +27,11 @@ volatile int __thread_list_lock;
* TODO: remove usage of __heap_base/__data_end for stack size calculation
* once we drop support for LLVM v15 and older.
*/
#if !defined(__pic__)
extern unsigned char __heap_base;
extern unsigned char __data_end;
extern unsigned char __global_base;
#endif
extern weak unsigned char __stack_high;
extern weak unsigned char __stack_low;

Expand All @@ -44,6 +48,10 @@ static inline struct stack_bounds get_stack_bounds()
bounds.base = &__stack_high;
bounds.size = &__stack_high - &__stack_low;
} else {
/* For non-pic, make a guess using the knowledge about
* how wasm-ld lays out things. For pic, just give up.
*/
#if !defined(__pic__)
unsigned char *sp;
__asm__(
".globaltype __stack_pointer, i32\n"
Expand All @@ -57,6 +65,10 @@ static inline struct stack_bounds get_stack_bounds()
bounds.base = &__global_base;
bounds.size = (size_t)&__global_base;
}
#else
bounds.base = 0;
bounds.size = 0;
#endif
}

return bounds;
Expand All @@ -82,10 +94,11 @@ int __init_tp(void *p)
__default_stacksize =
bounds.size < DEFAULT_STACK_MAX ?
bounds.size : DEFAULT_STACK_MAX;
td->detach_state = DT_JOINABLE;
td->stack = bounds.base;
td->stack_size = bounds.size;
td->guard_size = 0;
#ifdef _REENTRANT
td->detach_state = DT_JOINABLE;
/*
* Initialize the TID to a value which doesn't conflict with
* host-allocated TIDs, so that TID-based locks can work.
Expand All @@ -98,8 +111,11 @@ int __init_tp(void *p)
*/
td->tid = 0x3fffffff;
#endif
#endif
#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
td->locale = &libc.global_locale;
td->robust_list.head = &td->robust_list.head;
#endif
td->sysinfo = __sysinfo;
td->next = td->prev = td;
return 0;
Expand All @@ -121,6 +137,7 @@ static struct tls_module main_tls;
extern void __wasm_init_tls(void*);
#endif

#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
void *__copy_tls(unsigned char *mem)
{
#ifdef __wasilibc_unmodified_upstream
Expand Down Expand Up @@ -167,6 +184,7 @@ void *__copy_tls(unsigned char *mem)
return mem;
#endif
}
#endif /* defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) */

#ifdef __wasilibc_unmodified_upstream
#if ULONG_MAX == 0xffffffff
Expand Down
11 changes: 0 additions & 11 deletions thread-stub/pthread_getattr_np.c

This file was deleted.