Skip to content

Commit 6ab4f3a

Browse files
authored
Fix bug in wasm preload plugin (#19342)
Because we were not passing `byteArray` to the onload handle, no data was actually getting written to the fileystem in FS_createPreloadedFile -> processData -> finish and these preloaded files were being written as empty files. This matches the behavior of the other two plugins we have for images and audio. Fixing this bug allows us to fix one of the issues with `test_preload_module`, which is that it was falling back to loading from the a URL if the file was not found. By preloading the file under a different name we prevent the URL fallback from working. The URL fallback had been silently masking the `FS_createPreloadedFile` issue.
1 parent 347262a commit 6ab4f3a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/library_dylink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var LibraryDylink = {
2727
() => loadWebAssemblyModule(byteArray, {loadAsync: true, nodelete: true})).then(
2828
(module) => {
2929
preloadedWasm[name] = module;
30-
onload();
30+
onload(byteArray);
3131
},
3232
(error) => {
3333
err('failed to instantiate wasm: ' + name + ': ' + error);

test/test_other.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13425,14 +13425,21 @@ def test_preload_module(self, args):
1342513425
return 42;
1342613426
}
1342713427
''')
13428-
self.run_process([EMCC, 'library.c', '-sSIDE_MODULE', '-o', 'library.so'] + args)
13428+
self.run_process([EMCC, 'library.c', '-sSIDE_MODULE', '-o', 'tmp.so'] + args)
1342913429
create_file('main.c', r'''
1343013430
#include <assert.h>
1343113431
#include <dlfcn.h>
1343213432
#include <stdio.h>
13433+
#include <sys/stat.h>
1343313434
#include <emscripten.h>
1343413435
#include <emscripten/threading.h>
13436+
1343513437
int main() {
13438+
// Check the file exists in the VFS
13439+
struct stat statbuf;
13440+
assert(stat("/library.so", &statbuf) == 0);
13441+
13442+
// Check that it was preloaded
1343613443
if (emscripten_is_main_runtime_thread()) {
1343713444
int found = EM_ASM_INT(
1343813445
return preloadedWasm['/library.so'] !== undefined;
@@ -13449,4 +13456,4 @@ def test_preload_module(self, args):
1344913456
return 0;
1345013457
}
1345113458
''')
13452-
self.do_runf('main.c', 'done\n', emcc_args=['-sMAIN_MODULE=2', '--preload-file', '.@/', '--use-preload-plugins'] + args)
13459+
self.do_runf('main.c', 'done\n', emcc_args=['-sMAIN_MODULE=2', '--preload-file', '[email protected]', '--use-preload-plugins'] + args)

0 commit comments

Comments
 (0)