diff --git a/src/struct_info_generated.json b/src/struct_info_generated.json index 437412628139a..163a1cf69779c 100644 --- a/src/struct_info_generated.json +++ b/src/struct_info_generated.json @@ -1036,11 +1036,11 @@ "p_proto": 8 }, "pthread": { - "__size__": 132, - "profilerBlock": 112, - "stack": 52, - "stack_size": 56, - "waiting_async": 128 + "__size__": 124, + "profilerBlock": 104, + "stack": 48, + "stack_size": 52, + "waiting_async": 120 }, "pthread_attr_t": { "__size__": 44, diff --git a/src/struct_info_generated_wasm64.json b/src/struct_info_generated_wasm64.json index 21abbd913404a..8b857fef5dbcb 100644 --- a/src/struct_info_generated_wasm64.json +++ b/src/struct_info_generated_wasm64.json @@ -1036,11 +1036,11 @@ "p_proto": 16 }, "pthread": { - "__size__": 232, - "profilerBlock": 200, - "stack": 88, - "stack_size": 96, - "waiting_async": 228 + "__size__": 216, + "profilerBlock": 184, + "stack": 80, + "stack_size": 88, + "waiting_async": 212 }, "pthread_attr_t": { "__size__": 88, diff --git a/system/lib/libc/musl/src/internal/locale_impl.h b/system/lib/libc/musl/src/internal/locale_impl.h index ed60d16000589..9a7b07c4aac0e 100644 --- a/system/lib/libc/musl/src/internal/locale_impl.h +++ b/system/lib/libc/musl/src/internal/locale_impl.h @@ -45,9 +45,17 @@ hidden char *__gettextdomain(void); #define C_LOCALE ((locale_t)&__c_locale) #define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale) +#ifdef __EMSCRIPTEN__ +extern _Thread_local locale_t __tls_locale; + +#define CURRENT_LOCALE (__tls_locale) + +#define CURRENT_UTF8 (!!__tls_locale->cat[LC_CTYPE]) +#else #define CURRENT_LOCALE (__pthread_self()->locale) #define CURRENT_UTF8 (!!__pthread_self()->locale->cat[LC_CTYPE]) +#endif #undef MB_CUR_MAX #define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1) diff --git a/system/lib/libc/musl/src/internal/pthread_impl.h b/system/lib/libc/musl/src/internal/pthread_impl.h index 7f3a5483c802f..7cff31e1108d6 100644 --- a/system/lib/libc/musl/src/internal/pthread_impl.h +++ b/system/lib/libc/musl/src/internal/pthread_impl.h @@ -39,7 +39,10 @@ struct pthread { /* Part 2 -- implementation details, non-ABI. */ int tid; +#ifndef __EMSCRIPTEN__ + // Emscripten uses C11 _Thread_local instead for errno int errno_val; +#endif volatile int detach_state; volatile int cancel; volatile unsigned char canceldisable, cancelasync; @@ -60,7 +63,10 @@ struct pthread { } robust_list; int h_errno_val; volatile int timer_id; +#ifndef __EMSCRIPTEN__ + // Emscripten uses C11 _Thread_local instead for locale locale_t locale; +#endif volatile int killlock[1]; char *dlerror_buf; void *stdio_locks; diff --git a/system/lib/libc/musl/src/locale/uselocale.c b/system/lib/libc/musl/src/locale/uselocale.c index 0fc5ecbc07f29..c7b68b5a0d14e 100644 --- a/system/lib/libc/musl/src/locale/uselocale.c +++ b/system/lib/libc/musl/src/locale/uselocale.c @@ -2,13 +2,24 @@ #include "pthread_impl.h" #include "libc.h" +#ifdef __EMSCRIPTEN__ +_Thread_local locale_t __tls_locale = &libc.global_locale; +#endif + locale_t __uselocale(locale_t new) { +#ifdef __EMSCRIPTEN__ + locale_t old = __tls_locale; + locale_t global = &libc.global_locale; + + if (new) __tls_locale = new == LC_GLOBAL_LOCALE ? global : new; +#else pthread_t self = __pthread_self(); locale_t old = self->locale; locale_t global = &libc.global_locale; if (new) self->locale = new == LC_GLOBAL_LOCALE ? global : new; +#endif return old == global ? LC_GLOBAL_LOCALE : old; } diff --git a/system/lib/pthread/library_pthread.c b/system/lib/pthread/library_pthread.c index cd0c0ba1a71ad..35d3fd4fd8d0c 100644 --- a/system/lib/pthread/library_pthread.c +++ b/system/lib/pthread/library_pthread.c @@ -147,7 +147,6 @@ void _emscripten_init_main_thread(void) { // Main thread ID is always 1. It can't be 0 because musl assumes // tid is always non-zero. __main_pthread.tid = getpid(); - __main_pthread.locale = &libc.global_locale; // pthread struct prev and next should initially point to itself (see __init_tp), // this is used by pthread_key_delete for deleting thread-specific data. __main_pthread.next = __main_pthread.prev = &__main_pthread; diff --git a/system/lib/pthread/pthread_create.c b/system/lib/pthread/pthread_create.c index f467131bbac2a..a553e7e40ecf7 100644 --- a/system/lib/pthread/pthread_create.c +++ b/system/lib/pthread/pthread_create.c @@ -182,7 +182,6 @@ int __pthread_create(pthread_t* restrict res, // pthread struct robust_list head should point to itself. new->robust_list.head = &new->robust_list.head; - new->locale = &libc.global_locale; if (attr._a_detach) { new->detach_state = DT_DETACHED; } else { diff --git a/system/lib/pthread/pthread_self_stub.c b/system/lib/pthread/pthread_self_stub.c index a233f8863c626..8a484c7cb82ac 100644 --- a/system/lib/pthread/pthread_self_stub.c +++ b/system/lib/pthread/pthread_self_stub.c @@ -30,7 +30,6 @@ extern int __stack_low; __attribute__((constructor)) static void init_pthread_self(void) { - __main_pthread.locale = &libc.global_locale; __main_pthread.tid = getpid(); __main_pthread.stack = &__stack_high; __main_pthread.stack_size = ((size_t)&__stack_high) - ((size_t)&__stack_low); diff --git a/test/codesize/test_codesize_cxx_ctors1.json b/test/codesize/test_codesize_cxx_ctors1.json index 7e4b11a094326..c5af8dc17687c 100644 --- a/test/codesize/test_codesize_cxx_ctors1.json +++ b/test/codesize/test_codesize_cxx_ctors1.json @@ -1,10 +1,10 @@ { "a.out.js": 19214, "a.out.js.gz": 7981, - "a.out.nodebug.wasm": 132658, - "a.out.nodebug.wasm.gz": 49938, - "total": 151872, - "total_gz": 57919, + "a.out.nodebug.wasm": 132638, + "a.out.nodebug.wasm.gz": 49927, + "total": 151852, + "total_gz": 57908, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_ctors2.json b/test/codesize/test_codesize_cxx_ctors2.json index 968bd78351899..92f730bae4918 100644 --- a/test/codesize/test_codesize_cxx_ctors2.json +++ b/test/codesize/test_codesize_cxx_ctors2.json @@ -1,10 +1,10 @@ { "a.out.js": 19191, "a.out.js.gz": 7966, - "a.out.nodebug.wasm": 132082, - "a.out.nodebug.wasm.gz": 49598, - "total": 151273, - "total_gz": 57564, + "a.out.nodebug.wasm": 132064, + "a.out.nodebug.wasm.gz": 49586, + "total": 151255, + "total_gz": 57552, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_except.json b/test/codesize/test_codesize_cxx_except.json index 6e5c7ca39b323..d6715219961dd 100644 --- a/test/codesize/test_codesize_cxx_except.json +++ b/test/codesize/test_codesize_cxx_except.json @@ -1,10 +1,10 @@ { "a.out.js": 22875, "a.out.js.gz": 8956, - "a.out.nodebug.wasm": 172547, - "a.out.nodebug.wasm.gz": 57453, - "total": 195422, - "total_gz": 66409, + "a.out.nodebug.wasm": 172540, + "a.out.nodebug.wasm.gz": 57452, + "total": 195415, + "total_gz": 66408, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_except_wasm.json b/test/codesize/test_codesize_cxx_except_wasm.json index a248c570c0fe7..5fc2a31081154 100644 --- a/test/codesize/test_codesize_cxx_except_wasm.json +++ b/test/codesize/test_codesize_cxx_except_wasm.json @@ -1,10 +1,10 @@ { "a.out.js": 19025, "a.out.js.gz": 7908, - "a.out.nodebug.wasm": 147940, - "a.out.nodebug.wasm.gz": 55311, - "total": 166965, - "total_gz": 63219, + "a.out.nodebug.wasm": 147922, + "a.out.nodebug.wasm.gz": 55312, + "total": 166947, + "total_gz": 63220, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/codesize/test_codesize_cxx_except_wasm_legacy.json b/test/codesize/test_codesize_cxx_except_wasm_legacy.json index 584cdccab107b..0b8f59eaf5ca2 100644 --- a/test/codesize/test_codesize_cxx_except_wasm_legacy.json +++ b/test/codesize/test_codesize_cxx_except_wasm_legacy.json @@ -1,10 +1,10 @@ { "a.out.js": 19099, "a.out.js.gz": 7930, - "a.out.nodebug.wasm": 145746, - "a.out.nodebug.wasm.gz": 54944, - "total": 164845, - "total_gz": 62874, + "a.out.nodebug.wasm": 145729, + "a.out.nodebug.wasm.gz": 54945, + "total": 164828, + "total_gz": 62875, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/codesize/test_codesize_cxx_lto.json b/test/codesize/test_codesize_cxx_lto.json index 42a606cabbadd..2ebca12e429b1 100644 --- a/test/codesize/test_codesize_cxx_lto.json +++ b/test/codesize/test_codesize_cxx_lto.json @@ -1,10 +1,10 @@ { "a.out.js": 18562, "a.out.js.gz": 7668, - "a.out.nodebug.wasm": 101965, - "a.out.nodebug.wasm.gz": 39470, - "total": 120527, - "total_gz": 47138, + "a.out.nodebug.wasm": 101956, + "a.out.nodebug.wasm.gz": 39461, + "total": 120518, + "total_gz": 47129, "sent": [ "a (emscripten_resize_heap)", "b (_setitimer_js)", diff --git a/test/codesize/test_codesize_cxx_mangle.json b/test/codesize/test_codesize_cxx_mangle.json index 9f448342438bf..da11e811b6e23 100644 --- a/test/codesize/test_codesize_cxx_mangle.json +++ b/test/codesize/test_codesize_cxx_mangle.json @@ -1,10 +1,10 @@ { "a.out.js": 22925, "a.out.js.gz": 8978, - "a.out.nodebug.wasm": 238988, - "a.out.nodebug.wasm.gz": 79856, - "total": 261913, - "total_gz": 88834, + "a.out.nodebug.wasm": 238981, + "a.out.nodebug.wasm.gz": 79855, + "total": 261906, + "total_gz": 88833, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_noexcept.json b/test/codesize/test_codesize_cxx_noexcept.json index 64d5ff2ce357c..f4d5c0e3e1bf0 100644 --- a/test/codesize/test_codesize_cxx_noexcept.json +++ b/test/codesize/test_codesize_cxx_noexcept.json @@ -1,10 +1,10 @@ { "a.out.js": 19214, "a.out.js.gz": 7981, - "a.out.nodebug.wasm": 134678, - "a.out.nodebug.wasm.gz": 50780, - "total": 153892, - "total_gz": 58761, + "a.out.nodebug.wasm": 134661, + "a.out.nodebug.wasm.gz": 50777, + "total": 153875, + "total_gz": 58758, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index a97b08ff8d09a..28af35c267494 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -1,10 +1,10 @@ { "a.out.js": 7053, "a.out.js.gz": 3325, - "a.out.nodebug.wasm": 172754, - "a.out.nodebug.wasm.gz": 63338, - "total": 179807, - "total_gz": 66663, + "a.out.nodebug.wasm": 172736, + "a.out.nodebug.wasm.gz": 63329, + "total": 179789, + "total_gz": 66654, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_hello_O0.json b/test/codesize/test_codesize_hello_O0.json index aeb65d7d15e86..5928ffbd66323 100644 --- a/test/codesize/test_codesize_hello_O0.json +++ b/test/codesize/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { "a.out.js": 24271, - "a.out.js.gz": 8729, - "a.out.nodebug.wasm": 14973, - "a.out.nodebug.wasm.gz": 7397, - "total": 39244, - "total_gz": 16126, + "a.out.js.gz": 8724, + "a.out.nodebug.wasm": 14850, + "a.out.nodebug.wasm.gz": 7311, + "total": 39121, + "total_gz": 16035, "sent": [ "fd_write" ], @@ -33,7 +33,6 @@ "$__emscripten_stdout_seek", "$__errno_location", "$__fwritex", - "$__get_tp", "$__lock", "$__lshrti3", "$__memcpy", @@ -43,7 +42,6 @@ "$__original_main", "$__stdio_write", "$__strerror_l", - "$__syscall_getpid", "$__towrite", "$__trunctfdf2", "$__unlock", @@ -65,8 +63,6 @@ "$fmt_x", "$frexp", "$getint", - "$getpid", - "$init_pthread_self", "$main", "$memchr", "$out", diff --git a/test/codesize/test_codesize_hello_dylink.json b/test/codesize/test_codesize_hello_dylink.json index 4176742b126c0..fe8f26d896058 100644 --- a/test/codesize/test_codesize_hello_dylink.json +++ b/test/codesize/test_codesize_hello_dylink.json @@ -1,10 +1,10 @@ { "a.out.js": 26256, "a.out.js.gz": 11230, - "a.out.nodebug.wasm": 17675, - "a.out.nodebug.wasm.gz": 8932, - "total": 43931, - "total_gz": 20162, + "a.out.nodebug.wasm": 17670, + "a.out.nodebug.wasm.gz": 8926, + "total": 43926, + "total_gz": 20156, "sent": [ "__syscall_stat64", "emscripten_resize_heap", diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index 79e5115487695..a761e5ca7e669 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { "a.out.js": 244367, - "a.out.nodebug.wasm": 577300, - "total": 821667, + "a.out.nodebug.wasm": 577323, + "total": 821690, "sent": [ "IMG_Init", "IMG_Load", @@ -1908,6 +1908,7 @@ "__sysv_signal", "__threwValue", "__timezone", + "__tls_locale", "__tolower_l", "__toupper_l", "__towctrans_l", diff --git a/test/codesize/test_codesize_minimal_pthreads.json b/test/codesize/test_codesize_minimal_pthreads.json index 09e2242e2bb4c..ecb62597f5166 100644 --- a/test/codesize/test_codesize_minimal_pthreads.json +++ b/test/codesize/test_codesize_minimal_pthreads.json @@ -1,10 +1,10 @@ { "a.out.js": 7884, - "a.out.js.gz": 3854, - "a.out.nodebug.wasm": 19726, - "a.out.nodebug.wasm.gz": 9135, - "total": 27610, - "total_gz": 12989, + "a.out.js.gz": 3855, + "a.out.nodebug.wasm": 19707, + "a.out.nodebug.wasm.gz": 9122, + "total": 27591, + "total_gz": 12977, "sent": [ "a (memory)", "b (emscripten_get_now)", diff --git a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json index 2f11f38175b3b..0ce7b8d3b0d77 100644 --- a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json @@ -1,10 +1,10 @@ { "a.out.js": 8306, - "a.out.js.gz": 4059, - "a.out.nodebug.wasm": 19727, - "a.out.nodebug.wasm.gz": 9137, - "total": 28033, - "total_gz": 13196, + "a.out.js.gz": 4060, + "a.out.nodebug.wasm": 19708, + "a.out.nodebug.wasm.gz": 9123, + "total": 28014, + "total_gz": 13183, "sent": [ "a (memory)", "b (emscripten_get_now)", diff --git a/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json b/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json index 51536f7323ad0..3ad29f76b66b9 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json @@ -3,8 +3,8 @@ "a.html.gz": 371, "a.js": 5353, "a.js.gz": 2524, - "a.wasm": 5806, - "a.wasm.gz": 2737, - "total": 11707, - "total_gz": 5632 + "a.wasm": 5797, + "a.wasm.gz": 2732, + "total": 11698, + "total_gz": 5627 } diff --git a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json index 6cc9977898cf7..2d6f52c4ad1e9 100644 --- a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json +++ b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json @@ -1,4 +1,4 @@ { - "a.html": 10873, - "a.html.gz": 5681 + "a.html": 10815, + "a.html.gz": 5649 } diff --git a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json index cc90fe549c325..abb290e68d76b 100644 --- a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json +++ b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json @@ -1,4 +1,4 @@ { - "a.html": 17175, - "a.html.gz": 7509 + "a.html": 17114, + "a.html.gz": 7478 } diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index 831a68833f3d6..ecc52999be8a2 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { "hello_world.js": 56949, - "hello_world.js.gz": 17710, - "hello_world.wasm": 14973, - "hello_world.wasm.gz": 7397, + "hello_world.js.gz": 17708, + "hello_world.wasm": 14850, + "hello_world.wasm.gz": 7311, "no_asserts.js": 26520, "no_asserts.js.gz": 8849, - "no_asserts.wasm": 12133, - "no_asserts.wasm.gz": 5955, + "no_asserts.wasm": 12010, + "no_asserts.wasm.gz": 5880, "strict.js": 54767, "strict.js.gz": 17016, - "strict.wasm": 14973, - "strict.wasm.gz": 7392, - "total": 180315, - "total_gz": 64319 + "strict.wasm": 14850, + "strict.wasm.gz": 7311, + "total": 179946, + "total_gz": 64075 } diff --git a/test/core/test_dlfcn_self.exports b/test/core/test_dlfcn_self.exports index 0bb3488384e51..d55e1b67d41fa 100644 --- a/test/core/test_dlfcn_self.exports +++ b/test/core/test_dlfcn_self.exports @@ -14,6 +14,7 @@ __stack_chk_guard __stack_pointer __threwValue __timezone +__tls_locale __tzname _environ _ns_flagdata