-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
When compiling an application using the Fetch API for >2GB max memory, the parameters to _emscripten_start_fetch
: successcb
, errorcb
, progresscb
, readystatechangecb
are somehow dropped or optimized out. When the app does not pass a corresponding callback for these callbacks in the C/C++ side, this will result in the JS code trying to call these non-existent parameters, resulting in an error.
index.web.js:4028 Uncaught ReferenceError: readystatechangecb is not defined
at index.web.js:4028:74
at callUserCallback (index.web.js:3870:1)
at doCallback (index.web.js:4008:1)
at reportReadyStateChange (index.web.js:4027:1)
at xhr.onreadystatechange (index.web.js:3819:1)
The produced signature for _emscripten_start_fetch
with max memory > 2GB:
function _emscripten_start_fetch(fetch) {
// ...
}
The expected signature, produced with max memory <= 2GB:
function _emscripten_start_fetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
// ...
}
This can be reproduced using the test: https://github.com/emscripten-core/emscripten/blob/main/test/fetch/example_xhr_progress.c and compiling it with max memory > 2GB or <= 2GB and comparing the resulting signature for _emscripten_start_fetch
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.48-git
clang version 18.0.0 (https://github.com/llvm/llvm-project.git a54545ba6514802178cf7cf1c1dd9f7efbf3cde7)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/emscripten/3.1.48/libexec/llvm/bin
Failing command line in full:
emcc -sFETCH=1 -sWASM=1 -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=4GB ./test.c
Full link command and output with -v
appended:
/opt/homebrew/Cellar/emscripten/3.1.48/libexec/llvm/bin/clang --version
/opt/homebrew/Cellar/emscripten/3.1.48/libexec/llvm/bin/clang -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN -Werror=implicit-function-declaration --sysroot=/opt/homebrew/Cellar/emscripten/3.1.48/libexec/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v ./test.c -c -o /var/folders/hv/hn2qx8vx6mzg5yy_m3cj16b00000gn/T/emscripten_temp_uo9nvc67/test_0.o
clang version 18.0.0 (https://github.com/llvm/llvm-project.git a54545ba6514802178cf7cf1c1dd9f7efbf3cde7)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/emscripten/3.1.48/libexec/llvm/bin
(in-process)
"/opt/homebrew/Cellar/emscripten/3.1.48/libexec/llvm/bin/clang-18" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/Users/will/Downloads -target-linker-version 1015.7 -v -fcoverage-compilation-dir=/Users/will/Downloads -resource-dir /opt/homebrew/Cellar/emscripten/3.1.48/libexec/llvm/lib/clang/18 -D EMSCRIPTEN -isysroot /opt/homebrew/Cellar/emscripten/3.1.48/libexec/cache/sysroot -internal-isystem /opt/homebrew/Cellar/emscripten/3.1.48/libexec/llvm/lib/clang/18/include -internal-isystem /opt/homebrew/Cellar/emscripten/3.1.48/libexec/cache/sysroot/include/wasm32-emscripten -internal-isystem /opt/homebrew/Cellar/emscripten/3.1.48/libexec/cache/sysroot/include -Werror=implicit-function-declaration -ferror-limit 19 -fvisibility=default -fgnuc-version=4.2.1 -fignore-exceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /var/folders/hv/hn2qx8vx6mzg5yy_m3cj16b00000gn/T/emscripten_temp_uo9nvc67/test_0.o -x c ./test.c
clang -cc1 version 18.0.0 based upon LLVM 18.0.0git default target arm64-apple-darwin23.1.0
ignoring nonexistent directory "/opt/homebrew/Cellar/emscripten/3.1.48/libexec/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
/opt/homebrew/Cellar/emscripten/3.1.48/libexec/cache/sysroot/include/fakesdl
/opt/homebrew/Cellar/emscripten/3.1.48/libexec/cache/sysroot/include/compat
/opt/homebrew/Cellar/emscripten/3.1.48/libexec/llvm/lib/clang/18/include
/opt/homebrew/Cellar/emscripten/3.1.48/libexec/cache/sysroot/include
End of search list.
/opt/homebrew/Cellar/emscripten/3.1.48/libexec/llvm/bin/wasm-ld -o a.out.wasm /var/folders/hv/hn2qx8vx6mzg5yy_m3cj16b00000gn/T/emscripten_temp_uo9nvc67/test_0.o -L/opt/homebrew/Cellar/emscripten/3.1.48/libexec/cache/sysroot/lib/wasm32-emscripten --whole-archive -lfetch --no-whole-archive -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /var/folders/hv/hn2qx8vx6mzg5yy_m3cj16b00000gn/T/tmphprdxmmulibemscripten_js_symbols.so --strip-debug --export-if-defined=main --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_argc_argv --export-if-defined=fflush --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=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export-table -z stack-size=65536 --initial-memory=16777216 --max-memory=4294967296 --no-entry --stack-first --table-base=1
/opt/homebrew/Cellar/emscripten/3.1.48/libexec/llvm/bin/llvm-objcopy a.out.wasm a.out.wasm --remove-section=.debug* --remove-section=producers
/opt/homebrew/Cellar/emscripten/3.1.48/libexec/binaryen/bin/wasm-emscripten-finalize --dyncalls-i64 --pass-arg=legalize-js-interface-exported-helpers a.out.wasm -o a.out.wasm --detect-features
/opt/homebrew/opt/node/bin/node /opt/homebrew/Cellar/emscripten/3.1.48/libexec/src/compiler.js /var/folders/hv/hn2qx8vx6mzg5yy_m3cj16b00000gn/T/tmp0x3wihay.json
/opt/homebrew/opt/node/bin/node /opt/homebrew/Cellar/emscripten/3.1.48/libexec/tools/acorn-optimizer.js /var/folders/hv/hn2qx8vx6mzg5yy_m3cj16b00000gn/T/emscripten_temp_uo9nvc67/a.out.js unsignPointers --closureFriendly -o /var/folders/hv/hn2qx8vx6mzg5yy_m3cj16b00000gn/T/emscripten_temp_uo9nvc67/a.out.jso1.js