Skip to content

Commit b8c4812

Browse files
committed
Fix __errno_location under wasm workers. NFC
Previously the wasm workers build of `__errno_location` was using the single threaded code path which doesn't use a thead local location. In addition this change avoids the use of `__EMSCRIPTEN_PTHREADS__` in `__errno_location.c` which is helpful for unifying the shared memory libc build. See emscripten-core#22735.
1 parent daf541c commit b8c4812

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
#include <errno.h>
22
#include "pthread_impl.h"
33

4-
#if __EMSCRIPTEN_PTHREADS__
5-
// for pthreads, use the proper location on the thread info, so each
6-
// thread has its own errno
7-
int *__errno_location(void)
8-
{
9-
return &__pthread_self()->errno_val;
10-
}
11-
#else
12-
// for single-threaded mode, avoid linking in pthreads support code
13-
// just for this
14-
static int __errno_storage = 0;
4+
#if __EMSCRIPTEN__
5+
// For emscripten we use TLS here instead of `__pthread_self`, so that in single
6+
// threaded builds this gets lowered away to normal global variable.
7+
static _Thread_local int __errno_storage = 0;
8+
#endif
159

1610
int *__errno_location(void)
1711
{
12+
#if __EMSCRIPTEN__
1813
return &__errno_storage;
19-
}
14+
#else
15+
return &__pthread_self()->errno_val;
2016
#endif
17+
}
2118

2219
weak_alias(__errno_location, ___errno_location);

test/code_size/hello_wasm_worker_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"a.js.gz": 455,
66
"a.ww.js": 115,
77
"a.ww.js.gz": 127,
8-
"a.wasm": 1850,
9-
"a.wasm.gz": 1050,
10-
"total": 3248,
11-
"total_gz": 2016
8+
"a.wasm": 1894,
9+
"a.wasm.gz": 1077,
10+
"total": 3292,
11+
"total_gz": 2043
1212
}

tools/system_libs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ def vary_on(cls):
742742

743743
@classmethod
744744
def get_default_variation(cls, **kwargs):
745-
return super().get_default_variation(is_mt=settings.PTHREADS, is_ww=settings.WASM_WORKERS and not settings.PTHREADS, **kwargs)
745+
return super().get_default_variation(is_mt=settings.PTHREADS, is_ww=settings.SHARED_MEMORY and not settings.PTHREADS, **kwargs)
746746

747747
@classmethod
748748
def variations(cls):

0 commit comments

Comments
 (0)