emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

Wasm ESM integration does not seem to work with import/exporting wasm mutable globals

Open sbc100 opened this issue 2 months ago • 3 comments

It seems to coerce the Wasm globals in the numbers (i.e. snapshots them), which seems to make exporting mutable globals and manipulating them from JS impossible.

sbc100 avatar Oct 10 '25 19:10 sbc100

@sbc100 I've implemented a fix for issue #25543 The issue occurs in two places:

  1. tools/extract_metadata.py - get_global_exports() only stores the numeric value of globals, losing mutability information
  2. tools/emscripten.py - create_global_exports() and create_receiving() don't handle mutable globals specially in ESM integration mode

I modified get_global_exports() to store both value and mutability in tools/extract_metadata.py:

Image

tools/emscripten.py - Updated create_global_exports() to skip declaring mutable globals locally in ESM mode (they'll be imported from WASM instead)

Image

Modified create_receiving() to import mutable globals from the WASM module in ESM integration mode

Image

Before raising the PR, I'd like to understand your preferred testing approach

devalgupta404 avatar Oct 11 '25 05:10 devalgupta404

We do now support exporting mutable globals to JS since I landed #25530.

The issue described in this bug is that there is no way to export mutable globals from Wasm to JS under the ESM integration proposal. I don't think this something that emscripten can solve because its more of spec issue. See https://github.com/WebAssembly/esm-integration/pull/104

sbc100 avatar Oct 11 '25 16:10 sbc100

According to https://github.com/emscripten-core/emscripten/issues/25543 it seems like this issue is not something that is possible with the current ESM integration spec.

sbc100 avatar Oct 14 '25 18:10 sbc100