Skip to content

Commit 3a84c35

Browse files
authored
Use await for loadDylibs (#27079)
This avoids the need for addRunDependency/removeRunDependency.
1 parent cb6d2eb commit 3a84c35

5 files changed

Lines changed: 17 additions & 19 deletions

File tree

src/lib/libdylink.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ var LibraryDylink = {
12351235
},
12361236

12371237
$loadDylibs__internal: true,
1238-
$loadDylibs__deps: ['$loadDynamicLibrary', '$reportUndefinedSymbols', '$addRunDependency', '$removeRunDependency'],
1238+
$loadDylibs__deps: ['$loadDynamicLibrary', '$reportUndefinedSymbols'],
12391239
$loadDylibs: async () => {
12401240
if (!dynamicLibraries.length) {
12411241
#if DYLINK_DEBUG
@@ -1248,7 +1248,6 @@ var LibraryDylink = {
12481248
#if DYLINK_DEBUG
12491249
dbg('loadDylibs:', dynamicLibraries);
12501250
#endif
1251-
addRunDependency('loadDylibs');
12521251

12531252
// Load binaries asynchronously
12541253
for (var lib of dynamicLibraries) {
@@ -1260,7 +1259,6 @@ var LibraryDylink = {
12601259
#if DYLINK_DEBUG
12611260
dbg('loadDylibs done!');
12621261
#endif
1263-
removeRunDependency('loadDylibs');
12641262
},
12651263

12661264
// void* dlopen(const char* filename, int flags);

src/preamble.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ function getWasmImports() {
716716
// handle a generated wasm instance, receiving its exports and
717717
// performing other necessary setup
718718
/** @param {WebAssembly.Module=} module*/
719-
function receiveInstance(instance, module) {
719+
{{{ asyncIf(MAIN_MODULE) }}}function receiveInstance(instance, module) {
720720
#if RUNTIME_DEBUG
721721
dbg('receiveInstance')
722722
#endif
@@ -776,21 +776,21 @@ function getWasmImports() {
776776
Module['wasmExports'] = wasmExports;
777777
#endif
778778

779+
#if !IMPORTED_MEMORY
780+
updateMemoryViews();
781+
#endif
782+
779783
#if MAIN_MODULE
780784
#if '$LDSO' in addedLibraryItems
781785
LDSO.init();
782786
#endif
783-
loadDylibs();
787+
await loadDylibs();
784788
#endif
785789

786790
#if ABORT_ON_WASM_EXCEPTIONS
787791
instrumentWasmTableWithAbort();
788792
#endif
789793

790-
#if !IMPORTED_MEMORY
791-
updateMemoryViews();
792-
#endif
793-
794794
#if PTHREADS || WASM_WORKERS
795795
// We now have the Wasm module loaded up, keep a reference to the compiled module so we can post it to the workers.
796796
wasmModule = module;
@@ -864,7 +864,7 @@ function getWasmImports() {
864864

865865
#if SOURCE_PHASE_IMPORTS
866866
var instance = await WebAssembly.instantiate(wasmModule, info);
867-
var exports = receiveInstantiationResult({instance, 'module':wasmModule});
867+
var exports = {{{ awaitIf(MAIN_MODULE) }}}receiveInstantiationResult({instance, 'module':wasmModule});
868868
return exports;
869869
#else
870870
wasmBinaryFile ??= findWasmBinary();
@@ -873,7 +873,7 @@ function getWasmImports() {
873873
dbg('asynchronously preparing wasm');
874874
#endif
875875
var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
876-
var exports = receiveInstantiationResult(result);
876+
var exports = {{{ awaitIf(MAIN_MODULE) }}}receiveInstantiationResult(result);
877877
return exports;
878878
#else // WASM_ASYNC_COMPILATION
879879
var result = instantiateSync(wasmBinaryFile, info);

src/runtime_pthread.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if (ENVIRONMENT_IS_PTHREAD) {
4242
// notified about them.
4343
self.onunhandledrejection = (e) => { throw e.reason || e; };
4444

45-
{{{ asyncIf(ASYNCIFY == 2) }}}function handleMessage(e) {
45+
{{{ asyncIf(ASYNCIFY == 2 || MAIN_MODULE) }}}function handleMessage(e) {
4646
try {
4747
var msgData = e.data;
4848
//dbg('msgData: ' + Object.keys(msgData));
@@ -123,7 +123,7 @@ if (ENVIRONMENT_IS_PTHREAD) {
123123
#if MODULARIZE == 'instance'
124124
init();
125125
#else
126-
createWasm();
126+
{{{ awaitIf(MAIN_MODULE) }}}createWasm();
127127
run();
128128
#endif
129129
#endif // MINIMAL_RUNTIME

test/codesize/test_codesize_hello_dylink.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 26397,
3-
"a.out.js.gz": 11245,
2+
"a.out.js": 26265,
3+
"a.out.js.gz": 11182,
44
"a.out.nodebug.wasm": 17861,
55
"a.out.nodebug.wasm.gz": 9019,
6-
"total": 44258,
7-
"total_gz": 20264,
6+
"total": 44126,
7+
"total_gz": 20201,
88
"sent": [
99
"__syscall_stat64",
1010
"emscripten_resize_heap",

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 268126,
2+
"a.out.js": 268089,
33
"a.out.nodebug.wasm": 587575,
4-
"total": 855701,
4+
"total": 855664,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

0 commit comments

Comments
 (0)