Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 6.0.3 (283e2d130132859fde6a4e4c87fd254b38127651)
clang version 23.0.0git (https:/github.com/llvm/llvm-project 592953beff733a1e28f6c6e5e39f948fb035a329)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
Full link command and output with -v appended:
container run --rm -it -v .:/workdir -w /workdir docker.io/emscripten/emsdk:6.0.3 em++ -o out.mjs bind.cpp -sMODULARIZE=instance -sAUTO_INIT -lembind -sEMBIND_AOT -v
"/emsdk/upstream/bin/clang++" -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v -c bind.cpp -o /tmp/emscripten_temp_71jealkh/bind.o
clang version 23.0.0git (https:/github.com/llvm/llvm-project 592953beff733a1e28f6c6e5e39f948fb035a329)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
(in-process)
"/emsdk/upstream/bin/clang-23" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name bind.cpp -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=/workdir -v -fcoverage-compilation-dir=/workdir -resource-dir /emsdk/upstream/lib/clang/23 -isysroot /emsdk/upstream/emscripten/cache/sysroot-internal-isystem /emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/noeh/c++/v1 -internal-isystem /emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1 -internal-isystem /emsdk/upstream/emscripten/cache/sysroot/include/c++/v1 -internal-isystem /emsdk/upstream/lib/clang/23/include -internal-isystem /emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /emsdk/upstream/emscripten/cache/sysroot/include -fdeprecated-macro -ferror-limit 19 -fmessage-length=87 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fignore-exceptions -fexceptions -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /tmp/emscripten_temp_71jealkh/bind.o -x c++ bind.cpp
clang -cc1 version 23.0.0git based upon LLVM 23.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/noeh/c++/v1"
ignoring nonexistent directory "/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
/emsdk/upstream/emscripten/cache/sysroot/include/compat
/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1
/emsdk/upstream/lib/clang/23/include
/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
/emsdk/upstream/bin/clang --version
em++: warning: MODULARIZE=instance is still experimental. Many features may not work or will change. [-Wexperimental]
/emsdk/node/22.16.0_64bit/bin/node /emsdk/upstream/emscripten/tools/compiler.mjs - --symbols-only
/emsdk/upstream/bin/wasm-ld -o out.wasm /tmp/tmprh0093k0libemscripten_js_symbols.so -Bstatic --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=__getTypeName --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_71jealkh/bind.o -lembind-rtti -L/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -L/emsdk/upstream/emscripten/src/lib -lGL-getprocaddr -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc-debug -lclang_rt.builtins -lc++-debug-noexcept -lc++abi-debug-noexcept -lsockets-mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr
/emsdk/upstream/bin/llvm-objcopy out.wasm out.wasm '--remove-section=llvm.func_attr.annotate.*' --remove-section=producers --remove-section=name '--remove-section=.debug*'
/emsdk/node/22.16.0_64bit/bin/node /emsdk/upstream/emscripten/tools/compiler.mjs -
/emsdk/node/22.16.0_64bit/bin/node /emsdk/upstream/emscripten/tools/compiler.mjs -
/emsdk/node/22.16.0_64bit/bin/node /tmp/emscripten_temp_71jealkh/tsgen.js /tmp/emscripten_temp_71jealkh/embind_generated_output.js
Repro code:
https://github.com/yume-chan/emscripten_issues/tree/master/auto_init_embind
Description:
When using -sMODULARIZE=instance -sAUTO_INIT -sEMBIND_AOT, exports from embind are undefined when the module is imported, because addOnPostCtor is ran after init, which has already run onPostCtors.
out.mjs:
var wasmExports;
// In MODULARIZE=instance mode we delay most of the initialization work until
// the `init` function is called.
var initCalled = false;
// In AUTO_INIT mode `init` is not exported; we self-initialize below.
async function init() {
assert(!initCalled);
initCalled = true;
processModuleArgs();
wasmExports = await createWasm();
await run();
}
await init();
// end include: postamble.js
// start embind exports
function assignEmbindExports() { add = Module['add']; };
addOnPostCtor(assignEmbindExports);
export var add;
// end embind exports
Version of emscripten/emsdk:
Full link command and output with
-vappended:Repro code:
https://github.com/yume-chan/emscripten_issues/tree/master/auto_init_embind
Description:
When using
-sMODULARIZE=instance -sAUTO_INIT -sEMBIND_AOT, exports from embind areundefinedwhen the module is imported, becauseaddOnPostCtoris ran afterinit, which has already runonPostCtors.out.mjs: