emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

Enabling Asyncify breaks module: Module.dynCall_i is not a function

Open pixelomer opened this issue 3 months ago • 4 comments

Uncaught (in promise) TypeError: Module.dynCall_i is not a function
    invoke_i http://localhost:8000/build/MyProject.js:1
    wrapper http://localhost:8000/build/MyProject.js:1
    callMain http://localhost:8000/build/MyProject.js:1
    doRun http://localhost:8000/build/MyProject.js:1
    run http://localhost:8000/build/MyProject.js:1
    createModule http://localhost:8000/build/MyProject.js:1
    load http://localhost:8000/wrapper.js:71
    <anonymous> http://localhost:8000/main.js:1
MyProject.js:1:129537

The link flags are as follows:

set_target_properties(MyProject PROPERTIES LINK_FLAGS "-s WASM=1 -s MAIN_MODULE=1 \
    -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s EXPORT_NAME=createModule -s MODULARIZE=1 \
    -s FORCE_FILESYSTEM -s EXPORTED_RUNTIME_METHODS=[\"FS\"] -s WASMFS=1 -fPIC -fexceptions --no-entry \
    -z muldefs -s ALLOW_MEMORY_GROWTH -s ASYNCIFY -s DYNCALLS -s ASYNCIFY_DEBUG -lasync.js \
    -s ASYNCIFY_ONLY=[\"extractFile(std::__2::basic_string<char?.std::__2::char_traits<char>?.std::__2::allocator<char>>)\"] ")

Adding/removing -s DYNCALLS and/or -lasync.js seems to have no effect. The project works fine when Asyncify is not enabled.

pixelomer avatar Oct 13 '25 08:10 pixelomer

Does removing ASYNCIFY_ONLY help?

kripken avatar Oct 13 '25 23:10 kripken

Does removing ASYNCIFY_ONLY help?

The issue remains even if I remove ASYNCIFY_ONLY.

I prepared a small example that reproduces the issue. It is available at https://github.com/pixelomer/emscripten-asyncify-25551

I also included my emcc version below:

$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.16 (09534bba7f0ee767bf6f6f8cb5b7bf9519b8d63a)
clang version 22.0.0git (https:/github.com/llvm/llvm-project c4e1bca407f4cca7644937c117890fad157fec4b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/me/emsdk/upstream/bin

pixelomer avatar Oct 14 '25 06:10 pixelomer

I can confirm the problem with that small testcase. Something is wrong in that the wasm calls invoke_i, and the JS has that, which calls dynCall_i back into the wasm, but the wasm does not have that particular signature.

This is not strictly an Asyncify issue as disabling MAIN_MODULE=1 fixes it. I wonder if in that mode we generate dynCalls differently..? cc @sbc100

kripken avatar Oct 14 '25 23:10 kripken

~~I tested the example with a few more versions. It seems like this issue may have been introduced in version 4.0.10. The example works as expected on earlier versions.~~

EDIT: ...or maybe not? The actual project I'm working on does not seem to work with -s ASYNCIFY even in earlier versions.

pixelomer avatar Oct 15 '25 07:10 pixelomer