Skip to content
Open
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
2 changes: 2 additions & 0 deletions test/other/test_pthread_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ void test_pthreads() {
int rtn;
int res;

printf("__builtin_thread_pointer non-null: %d\n", __builtin_thread_pointer() != NULL);

// pthread_atfork should silently succeed.
CHECK_SUCCESS(pthread_atfork(NULL, NULL, NULL));

Expand Down
1 change: 1 addition & 0 deletions test/other/test_pthread_stub.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test_c11_threads
test_pthreads
__builtin_thread_pointer non-null: 1
cleanup: 42
test_pthread_getattr_np
stack_addr: 0, stack_size: 65536, guard_size: 8192
9 changes: 2 additions & 7 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,8 @@ class libmimalloc(MTLibrary):
'-DNDEBUG',
# Emscripten uses musl libc internally
'-DMI_LIBC_MUSL',
# enable use of `__builtin_thread_pointer()`
'-DMI_USE_BUILTIN_THREAD_POINTER',
]

# malloc/free/calloc are runtime functions and can be generated during LTO
Expand All @@ -1911,13 +1913,6 @@ class libmimalloc(MTLibrary):
# Include sbrk.c in libc, it uses tracing and libc itself doesn't have a tracing variant.
src_files += [utils.path_from_root('system/lib/libc/sbrk.c')]

def get_cflags(self):
cflags = super().get_cflags()
if self.is_mt:
# enable use of `__builtin_thread_pointer()` in multithreaded builds
cflags += ['-DMI_USE_BUILTIN_THREAD_POINTER']
return cflags

def can_use(self):
return super().can_use() and settings.MALLOC == 'mimalloc'

Expand Down
Loading