Skip to content

Commit

Permalink
dylink: Share dynamicLibraries array across workers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kleisauke committed Jun 11, 2024
1 parent 59d2290 commit 005a033
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ var LibraryPThread = {
'wasmOffsetConverter': wasmOffsetConverter,
#endif
#if MAIN_MODULE
'dynamicLibraries': dynamicLibraries,
// Share all modules that have been loaded so far. New workers
// won't start running threads until these are all loaded.
'sharedModules': sharedModules,
Expand Down
1 change: 1 addition & 0 deletions src/runtime_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ if (ENVIRONMENT_IS_PTHREAD) {
};

#if MAIN_MODULE
dynamicLibraries = msgData['dynamicLibraries'];
sharedModules = msgData['sharedModules'];
#if RUNTIME_DEBUG
dbg(`worker: received ${Object.keys(msgData['sharedModules']).length} shared modules: ${Object.keys(msgData.sharedModules)}`);
Expand Down
10 changes: 7 additions & 3 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9412,13 +9412,17 @@ def test_Module_dynamicLibraries(self, args):
self.emcc_args += args
self.emcc_args += ['--pre-js', 'pre.js']
self.emcc_args += ['--js-library', 'lib.js']
# This test is for setting dynamicLibraries at runtime so we don't
# This test is for setting dynamicLibraries at runtime, so we don't
# want emscripten loading `liblib.so` automatically (which it would
# do without this setting.
# do without this setting)
self.set_setting('NO_AUTOLOAD_DYLIBS')

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

create_file('lib.js', '''
Expand Down

0 comments on commit 005a033

Please sign in to comment.