Skip to content

Compiling with --emit-tsd, sMEMORY64=1, -sUSE_PTHREADS=1 and -sMAXIMUM_MEMORY over 4GB fails #26311

@sorenbg

Description

@sorenbg

Compiling with -sMEMORY=64 and linking with -lembind -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=16GB -sMEMORY64=1 "-sENVIRONMENT=web,worker" -sUSE_PTHREADS=1 triggers an error when generating types with --emit-tsd as far as I can tell.

The error goes away if:

  • the memory limit is set to 4 GB or less
  • the --emit-tsd flag is resmoved

Folllow up bug after testing fix to #26154 which might be related since the other was also triggered by --emit-tsd.

Attached self-contained example using CMake.

bug.zip

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 5.0.1 (8c5f43157a3f069ade75876e23061330521eabde)
clang version 23.0.0git (https:/github.com/llvm/llvm-project b447f5d9763010f8c6806c578533291aef2bd484)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/bin

Failing command line in full:
Full link command and output with -v appended:

: && /Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/emscripten/em++ -O3 -DNDEBUG -L/opt/homebrew/opt/llvm/lib/c++ -L/opt/homebrew/opt/llvm/lib/unwind    -lembind -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=16GB -sMEMORY64=1 -sENVIRONMENT=web,worker -sUSE_PTHREADS=1 --emit-tsd main.d.ts -v CMakeFiles/main.dir/main.o -o main.js   && :
 /Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/bin/clang --version
em++: warning: -pthread + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
 /Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/bin/wasm-ld -o main.wasm /var/folders/rx/cml17gjj1yn5zzpf_7sl1l9w0000gn/T/tmpsir871lslibemscripten_js_symbols.so --import-memory --shared-memory --strip-debug --export=_emscripten_stack_alloc --export=__getTypeName --export=_embind_initialize_bindings --export=_emscripten_thread_free_data --export=_emscripten_thread_crashed --export=__wasm_call_ctors --export=_emscripten_tls_init --export=_emscripten_thread_init --export=emscripten_stack_get_current --export=_emscripten_stack_restore --export=emscripten_stack_set_limits --export=_emscripten_thread_exit --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-table -z stack-size=65536 --max-memory=17179869184 --initial-memory=16777216 --no-entry --no-stack-first --table-base=1 --global-base=1024 -L/opt/homebrew/opt/llvm/lib/c++ -L/opt/homebrew/opt/llvm/lib/unwind -lembind-mt-rtti CMakeFiles/main.dir/main.o -L/Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/emscripten/cache/sysroot/lib/wasm64-emscripten -L/Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/emscripten/src/lib /Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/emscripten/cache/sysroot/lib/wasm64-emscripten/crtbegin.o -lGL-mt-getprocaddr -lal -lhtml5 -lstubs -lnoexit -lc-mt -ldlmalloc-mt -lcompiler_rt-mt -lc++-mt-noexcept -lc++abi-mt-noexcept -lsockets-mt -mwasm64 -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr
 /Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/bin/llvm-objcopy main.wasm main.wasm '--remove-section=llvm.func_attr.annotate.*' --remove-section=producers --remove-section=name '--remove-section=.debug*'
 /Users/soren/.local/share/mise/installs/emsdk/5.0.1/node/22.16.0_64bit/bin/node /Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/emscripten/tools/compiler.mjs -
 /Users/soren/.local/share/mise/installs/emsdk/5.0.1/node/22.16.0_64bit/bin/node /Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/emscripten/tools/compiler.mjs -
 /Users/soren/.local/share/mise/installs/emsdk/5.0.1/upstream/bin/wasm-opt --memory64-lowering --table64-lowering /var/folders/rx/cml17gjj1yn5zzpf_7sl1l9w0000gn/T/emscripten_temp_i5iq8ubp/tsgen.wasm -o /var/folders/rx/cml17gjj1yn5zzpf_7sl1l9w0000gn/T/emscripten_temp_i5iq8ubp/tsgen.wasm --mvp-features --enable-threads --enable-bulk-memory --enable-bulk-memory-opt --enable-call-indirect-overlong --enable-memory64 --enable-multivalue --enable-mutable-globals --enable-nontrapping-float-to-int --enable-reference-types --enable-sign-ext
 /Users/soren/.local/share/mise/installs/emsdk/5.0.1/node/22.16.0_64bit/bin/node /var/folders/rx/cml17gjj1yn5zzpf_7sl1l9w0000gn/T/emscripten_temp_i5iq8ubp/tsgen.js /var/folders/rx/cml17gjj1yn5zzpf_7sl1l9w0000gn/T/emscripten_temp_i5iq8ubp/embind_generated_output.js
/private/var/folders/rx/cml17gjj1yn5zzpf_7sl1l9w0000gn/T/emscripten_temp_i5iq8ubp/tsgen.js:516
    wasmMemory = new WebAssembly.Memory({
                 ^

RangeError: WebAssembly.Memory(): Property 'maximum': value 262144 is above the upper bound 65536
    at initMemory (/private/var/folders/rx/cml17gjj1yn5zzpf_7sl1l9w0000gn/T/emscripten_temp_i5iq8ubp/tsgen.js:516:18)
    at Object.<anonymous> (/private/var/folders/rx/cml17gjj1yn5zzpf_7sl1l9w0000gn/T/emscripten_temp_i5iq8ubp/tsgen.js:2064:3)
    at Module._compile (node:internal/modules/cjs/loader:1730:14)
    at Object..js (node:internal/modules/cjs/loader:1895:10)
    at Module.load (node:internal/modules/cjs/loader:1465:32)
    at Function._load (node:internal/modules/cjs/loader:1282:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
    at node:internal/main/run_main_module:36:49

Node.js v22.16.0
em++: error: '/Users/soren/.local/share/mise/installs/emsdk/5.0.1/node/22.16.0_64bit/bin/node /var/folders/rx/cml17gjj1yn5zzpf_7sl1l9w0000gn/T/emscripten_temp_i5iq8ubp/tsgen.js /var/folders/rx/cml17gjj1yn5zzpf_7sl1l9w0000gn/T/emscripten_temp_i5iq8ubp/embind_generated_output.js' failed (returned 1)
ninja: build stopped: subcommand failed.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions