emscripten-core / emscripten-core/emscripten

Fetch.js calls addRunDependency/removeRunDependency but helpers are stripped in MODULARIZE builds

Open
#26,008 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Hi. Thank you to all the emscripten contributors, you're doing great work!

We've encountered this issue after upgrading from 4.0.4 to the latest 4.0.22 without changing any build flags so it might be a regression.

---

**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.22 (0f3d2e62bccf8e14497ff19e05a1202c51eb0c65)
clang version 22.0.0git (https:/github.com/llvm/llvm-project c7706d9472fe880ba1d3418919ad4185710c9559)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/emsdk/upstream/bin
```

**Failing command line in full:**
```
emcc main.c -s FETCH=1 -s MODULARIZE=1 -o out.mjs
```

Output:
```
(no output; build succeeds)
```

**Full link command and output with `-v` appended:**
```
emcc main.c -s FETCH=1 -s MODULARIZE=1 -o out.mjs -v
```

Output:
```
/usr/local/emsdk/upstream/bin/clang -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=/tmp/emscripten_fetch_run_deps_issue/cache/sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v -c main.c -o /tmp/emscripten_temp_9hmnahe0/main.o
clang version 22.0.0git (https:/github.com/llvm/llvm-project c7706d9472fe880ba1d3418919ad4185710c9559)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/emsdk/upstream/bin
(in-process)
"/usr/local/emsdk/upstream/bin/clang-22" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility=hidden -debugger-tuning=gdb -fdebug-compilation-dir=/tmp/emscripten_fetch_run_deps_issue -v -fcoverage-compilation-dir=/tmp/emscripten_fetch_run_deps_issue -resource-dir /usr/local/emsdk/upstream/lib/clang/22 -D EMSCRIPTEN -isysroot /tmp/emscripten_fetch_run_deps_issue/cache/sysroot -internal-isystem /usr/local/emsdk/upstream/lib/clang/22/include -internal-isystem /tmp/emscripten_fetch_run_deps_issue/cache/sysroot/include/wasm32-emscripten -internal-isystem /tmp/emscripten_fetch_run_deps_issue/cache/sysroot/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fignore-exceptions -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /tmp/emscripten_temp_9hmnahe0/main.o -x c main.c
clang -cc1 version 22.0.0git based upon LLVM 22.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/tmp/emscripten_fetch_run_deps_issue/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
/tmp/emscripten_fetch_run_deps_issue/cache/sysroot/include/fakesdl
/tmp/emscripten_fetch_run_deps_issue/cache/sysroot/include/compat
/usr/local/emsdk/upstream/lib/clang/22/include
/tmp/emscripten_fetch_run_deps_issue/cache/sysroot/include
End of search list.
/usr/local/emsdk/upstream/bin/clang --version
/usr/local/emsdk/upstream/bin/wasm-ld -o out.wasm -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmpzp1g29hllibemscripten_js_symbols.so --strip-debug --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=_emscripten_stack_alloc --export=__wasm_call_ctors --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --stack-first --table-base=1 /tmp/emscripten_temp_9hmnahe0/main.o -L/tmp/emscripten_fetch_run_deps_issue/cache/sysroot/lib/wasm32-emscripten -L/usr/local/emsdk/upstream/emscripten/src/lib -lfetch -lGL-getprocaddr -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc-debug -lcompiler_rt -lc++-debug-noexcept -lc++abi-debug-noexcept -lsockets
/usr/local/emsdk/upstream/bin/llvm-objcopy out.wasm out.wasm '--remove-section=.debug*' --remove-section=producers --remove-section=name
/usr/local/emsdk/node/22.16.0_64bit/bin/node /usr/local/emsdk/upstream/emscripten/tools/compiler.mjs -
/usr/local/emsdk/node/22.16.0_64bit/bin/node /usr/local/emsdk/upstream/emscripten/tools/preprocessor.mjs - modularize.js --expand-macros
```

---

### Minimal repro
**main.c**
```c
#include
#include

static void fetch_success(emscripten_fetch_t* fetch) { emscripten_fetch_close(fetch); }
static void fetch_error(emscripten_fetch_t* fetch) { emscripten_fetch_close(fetch); }

int main() {
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
strcpy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
attr.onsuccess = fetch_success;
attr.onerror = fetch_error;
emscripten_fetch(&attr, "data:application/octet-stream;base64,AA==");
return 0;
}
```

**index.html**
```html

const wasm = await fetch("./out.wasm").then((r) => r.arrayBuffer());
const { default: Module } = await import("./out.mjs");
Module({ wasm });

```

**Steps**
1) Build: `emcc main.c -s FETCH=1 -s MODULARIZE=1 -o out.mjs`
2) Serve the directory and open `index.html` in a browser.

**Actual**
```
ReferenceError: addRunDependency is not defined
at Fetch.init (...)
```

**Expected**
No ReferenceError. Fetch.init should run without requiring manual inclusion of run dependency helpers.

**Notes / workaround**
This repro was built against a clean emsdk 4.0.22. A workaround is:
```
-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=['$addRunDependency','$removeRunDependency']
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.