emscripten-core / emscripten-core/emscripten
WASM dynamicLibraries defined with --pre-js are loaded incorrectly when they have a prefix path
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Hey, when defining sidemodules to be loaded together with the .js file, by defining dynamicLibraries with --pre-js commandline option, and the paths have a prefix in the pre.js (eg: "dist/sidemodule.wasm"), the sidemodule is being tried first to be loaded from "/sidemodule.wasm", resulting in the asynchronous loading of the module to fail, as the file is not found.
I compile with the flag '--pre-js pre.js', and in my pre.js I have the following line:
```
Module['dynamicLibraries'] = ['dist/test_sidemodule.wasm'];
```
When loading the generated boilerplate js test_omg_core.js that is generated by emscripten, this line in the code tries to first load this path without the "dist" part, and after that with the dist one, but fails to continue because the first load fails to find the file on my static webserver:

Here I have added the console.dir lines to the generated .js file to see what part fails the loading, and looking at that output I can see that the "dist/" part is discarded from the library name:

Is this desired behaviour, or am I doing something wrong ?
Please include the following in your bug report:
**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.8-git
clang version 15.0.0 (https://github.com/llvm/llvm-project.git 80ec0ebfdc5692a58e0832125f2c6a991df9d63f)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/emscripten/3.1.8/libexec/llvm/bin
```
**Failing command line in full:**
If this is compile or link-time failure please include the full failing command
along with its entire output.
**Full link command and output with `-v` appended:**
```
opt/homebrew/Cellar/emscripten/3.1.8/libexec/em++ -g --bind -s LLD_REPORT_UNDEFINED -s WASM=1 -s MAIN_MODULE=2 -v --pre-js /Users/sakari/dvl/sumo/mandala/testing/test-omg-core/src/pre.js @CMakeFiles/test_omg_core.dir/objects1.rsp -o bin/test_omg_core.js @CMakeFiles/test_omg_core.dir/linklibs.rsp
"/opt/homebrew/bin/node" /opt/homebrew/Cellar/emscripten/3.1.8/libexec/src/compiler.js /var/folders/ql/lcdkc34x02z645rm54kwhfb40000gn/T/tmp_ynt6lld.json
"/opt/homebrew/Cellar/emscripten/3.1.8/libexec/llvm/bin/wasm-ld" -o bin/test_omg_core.wasm CMakeFiles/test_omg_core.dir/src/main.cpp.o /Users/sakari/dvl/omg/omg-core/omg//lib/emscripten_wasm/libomg.a ../sidemodule/lib/test_sidemodule.wasm -L/opt/homebrew/Cellar/emscripten/3.1.8/libexec/cache/sysroot/lib/wasm32-emscripten/pic --whole-archive -lembind-rtti --no-whole-archive -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=/var/folders/ql/lcdkc34x02z645rm54kwhfb40000gn/T/tmp0ozle9ew.undefined --import-memory --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__stdio_exit --export=setThrew --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_set_limits --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=malloc --export=free --experimental-pic -pie --no-export-dynamic -z stack-size=5242880 --initial-memory=16777216 --entry=main --max-memory=16777216
"/opt/homebrew/Cellar/emscripten/3.1.8/libexec/binaryen/bin/wasm-emscripten-finalize" -g --dyncalls-i64 --pass-arg=legalize-js-interface-export-originals --dwarf bin/test_omg_core.wasm -o bin/test_omg_core.wasm --detect-features
```
Contributor guide
Assessment
This issue has not been assessed yet.