Skip to content

Commit 94f4173

Browse files
authored
[WASM_WORKERS] Ensure TLS is initialized (#22856)
The main thread TLS region get initialized via a static constructor in `library_wasm_worker.c`. Without this change programs that don't otherwise reference `library_wasm_worker.c` will not have this static constructor run. Fixes: #22852
1 parent 5f0643b commit 94f4173

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

test/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def with_all_sjlj(f):
614614
assert callable(f)
615615

616616
@wraps(f)
617-
def metafunc(self, mode):
617+
def metafunc(self, mode, *args, **kwargs):
618618
if mode == 'wasm' or mode == 'wasm_exnref':
619619
if self.is_wasm2js():
620620
self.skipTest('wasm2js does not support wasm SjLj')
@@ -627,10 +627,10 @@ def metafunc(self, mode):
627627
if mode == 'wasm_exnref':
628628
self.require_wasm_exnref()
629629
self.set_setting('WASM_EXNREF')
630-
f(self)
630+
f(self, *args, **kwargs)
631631
else:
632632
self.set_setting('SUPPORT_LONGJMP', 'emscripten')
633-
f(self)
633+
f(self, *args, **kwargs)
634634

635635
parameterize(metafunc, {'emscripten': ('emscripten',),
636636
'wasm': ('wasm',),

test/test_core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@ def test_longjmp_standalone(self):
863863
def test_longjmp(self):
864864
self.do_core_test('test_longjmp.c')
865865

866+
def test_longjmp_wasm_workers(self):
867+
self.do_core_test('test_longjmp.c', emcc_args=['-sWASM_WORKERS'])
868+
866869
@with_all_sjlj
867870
def test_longjmp_zero(self):
868871
if '-fsanitize=undefined' in self.emcc_args and self.get_setting('SUPPORT_LONGJMP') == 'emscripten':

tools/system_libs.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,7 @@ def get_libs_to_link(args):
22762276
if force_include:
22772277
logger.debug(f'forcing stdlibs: {force_include}')
22782278

2279-
def add_library(libname):
2279+
def add_library(libname, whole_archive=False):
22802280
lib = system_libs_map[libname]
22812281
if lib.name in already_included:
22822282
return
@@ -2285,7 +2285,7 @@ def add_library(libname):
22852285
logger.debug('including %s (%s)' % (lib.name, lib.get_filename()))
22862286

22872287
need_whole_archive = lib.name in force_include and lib.get_ext() == '.a'
2288-
libs_to_link.append((lib.get_link_flag(), need_whole_archive))
2288+
libs_to_link.append((lib.get_link_flag(), whole_archive or need_whole_archive))
22892289

22902290
if '-nostartfiles' not in args:
22912291
if settings.SHARED_MEMORY:
@@ -2396,7 +2396,10 @@ def add_sanitizer_libs():
23962396
if settings.WASM_WORKERS and (not settings.SINGLE_FILE and
23972397
not settings.RELOCATABLE and
23982398
not settings.PROXY_TO_WORKER):
2399-
add_library('libwasm_workers')
2399+
# When we include libwasm_workers we use `--whole-archive` to ensure
2400+
# that the static constructor (`emscripten_wasm_worker_main_thread_initialize`)
2401+
# is run.
2402+
add_library('libwasm_workers', whole_archive=True)
24002403

24012404
if settings.WASMFS:
24022405
# Link in the no-fs version first, so that if it provides all the needed

0 commit comments

Comments
 (0)