diff --git a/test/other/test_pthread_stub.c b/test/other/test_pthread_stub.c index 7a01191c7a587..96e6537c4e7ac 100644 --- a/test/other/test_pthread_stub.c +++ b/test/other/test_pthread_stub.c @@ -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)); diff --git a/test/other/test_pthread_stub.out b/test/other/test_pthread_stub.out index 28eab1f1310c4..c5294d194f80a 100644 --- a/test/other/test_pthread_stub.out +++ b/test/other/test_pthread_stub.out @@ -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 diff --git a/tools/system_libs.py b/tools/system_libs.py index 3d3f14df7ae2c..b3e784b4aa0c3 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -1931,6 +1931,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 @@ -1953,13 +1955,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'