Skip to content

Commit 8a79a40

Browse files
authored
[dylink] Share dynamicLibraries array across workers (emscripten-core#19496)
To ensure that the same dynamic libraries are loaded among all workers, it remains necessary to share the `dynamicLibraries` array, especially when it is defined outside the module (e.g. in `MODULARIZE` mode). Fixes a regression introduced in commit ceb2e28.
1 parent 0086fa3 commit 8a79a40

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/library_pthread.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ var LibraryPThread = {
379379
'wasmOffsetConverter': wasmOffsetConverter,
380380
#endif
381381
#if MAIN_MODULE
382+
'dynamicLibraries': dynamicLibraries,
382383
// Share all modules that have been loaded so far. New workers
383384
// won't start running threads until these are all loaded.
384385
'sharedModules': sharedModules,

src/runtime_pthread.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ if (ENVIRONMENT_IS_PTHREAD) {
129129
};
130130

131131
#if MAIN_MODULE
132+
dynamicLibraries = msgData['dynamicLibraries'];
132133
sharedModules = msgData['sharedModules'];
133134
#if RUNTIME_DEBUG
134135
dbg(`worker: received ${Object.keys(msgData['sharedModules']).length} shared modules: ${Object.keys(msgData.sharedModules)}`);

test/test_core.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9412,13 +9412,17 @@ def test_Module_dynamicLibraries(self, args):
94129412
self.emcc_args += args
94139413
self.emcc_args += ['--pre-js', 'pre.js']
94149414
self.emcc_args += ['--js-library', 'lib.js']
9415-
# This test is for setting dynamicLibraries at runtime so we don't
9415+
# This test is for setting dynamicLibraries at runtime, so we don't
94169416
# want emscripten loading `liblib.so` automatically (which it would
9417-
# do without this setting.
9417+
# do without this setting)
94189418
self.set_setting('NO_AUTOLOAD_DYLIBS')
94199419

94209420
create_file('pre.js', '''
9421-
Module['dynamicLibraries'] = ['liblib.so'];
9421+
if (typeof ENVIRONMENT_IS_PTHREAD == 'undefined' || !ENVIRONMENT_IS_PTHREAD) {
9422+
// Load liblib.so on the main thread, this would be equivalent to
9423+
// defining it outside the module (e.g. in MODULARIZE mode).
9424+
Module['dynamicLibraries'] = ['liblib.so'];
9425+
}
94229426
''')
94239427

94249428
create_file('lib.js', '''

0 commit comments

Comments
 (0)