Skip to content

Fix omitexports0.test_wasm_global - #28480

Open
juj wants to merge 1 commit into
emscripten-core:mainfrom
juj:fix_omitexports_mutable_globals
Open

juj wants to merge 1 commit into
emscripten-core:mainfrom
juj:fix_omitexports_mutable_globals

Conversation

@juj

@juj juj commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Since #25530, mutable Wasm globals are exported to JS as WebAssembly.Global objects rather than plain numbers. This regressed DECLARE_ASM_MODULE_EXPORTS=0 path.

Rather than embedding the names of all exported mutable globals in the JS, probe each exported global by writing back its current value: this throws for immutable WebAssembly.Global objects, which are then unwrapped to plain numbers as before. The probe is only emitted when the module exports at least one mutable global (new internal setting HAS_MUTABLE_GLOBAL_EXPORTS), so code size is unchanged in the common case.

Under wasm2js, immutable globals are also exported with a setter, so when any mutable global is exported, all exported globals stay as objects.

Fixes the omitexports0 part of #25550.

…LE_EXPORTS=0

Since emscripten-core#25530, mutable Wasm globals are exported to JS as WebAssembly.Global
objects rather than plain numbers.  This was only done in the static
create_receiving path in emscripten.py; the dynamic $assignWasmExports
used with DECLARE_ASM_MODULE_EXPORTS=0 still unwrapped every global into a
number.

Rather than embedding the names of all exported mutable globals in the JS,
probe each exported global by writing back its current value: this throws
for immutable WebAssembly.Global objects, which are then unwrapped to
plain numbers as before.  The probe is only emitted when the module
exports at least one mutable global (new internal setting
HAS_MUTABLE_GLOBAL_EXPORTS), so code size is unchanged in the common case.

Under wasm2js, immutable globals are also exported with a setter, so when
any mutable global is exported, all exported globals stay as objects.

Fixes the omitexports0 part of emscripten-core#25550.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sbc100 sbc100 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I ask, are you using DECLARE_ASM_MODULE_EXPORT=0 in production?

It seems like a pretty limited settings since it depends on using globalThis to store all the exported symbols meaning that only one emscripten-generated program can live in a given context. This seems like a pretty big limitation.

@juj

juj commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

only one emscripten-generated program can live in a given context. This seems like a pretty big limitation.

This is 99% of Unity generated pages.

If multiple apps are needed, they are almost always wrapped in iframes, because browsers have bugs in garbage collecting full pages away. (this is what itch, poki, crazygames, youtube and all those other Unity content serving gaming portals do)

Tiny Unity used to ship with this flag. Current Unity doesn't though (which has been a TODO to investigate if it can help)

@sbc100

sbc100 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

only one emscripten-generated program can live in a given context. This seems like a pretty big limitation.

This is 99% of Unity generated pages.

If multiple apps are needed, they are almost always wrapped in iframes, because browsers have bugs in garbage collecting full pages away. (this is what itch, poki, crazygames, youtube and all those other Unity content serving gaming portals do)

Tiny Unity used to ship with this flag. Current Unity doesn't though (which has been a TODO to investigate if it can help)

I get that there is likely only one unity app on a given page.. but what about other wasm content that might live on the same page. Folks use wasm content for all kinds of things right? I guess you right that a lot of wasm content might be in iframes.

I will be curious to see if/when you revisit this. I'd love to remove this strange hacky path if possible!

@juj

juj commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

but what about other wasm content that might live on the same page

Hmm.. we haven't gotten reports that users would have had other wasm compiled content on the same page/iframe context. They could theoretically have other wasm compiled content on the site, but the globalThis would point to the local iframe still for the unity content part.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants