From 005a033b0c39c103b8239209133d0b9d37276c40 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 1 Jun 2023 11:09:20 +0200 Subject: [PATCH] dylink: Share `dynamicLibraries` array across workers 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. --- src/library_pthread.js | 1 + src/runtime_pthread.js | 1 + test/test_core.py | 10 +++++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/library_pthread.js b/src/library_pthread.js index 21752e14e0b67..e572dc6252ad3 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js @@ -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, diff --git a/src/runtime_pthread.js b/src/runtime_pthread.js index ca2f6138e61ee..00cf3af11c898 100644 --- a/src/runtime_pthread.js +++ b/src/runtime_pthread.js @@ -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)}`); diff --git a/test/test_core.py b/test/test_core.py index 8d446615c8422..c010f9e5faa74 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -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', '''