Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/lib/libcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -1720,10 +1720,17 @@ addToLibrary({
// Special handling for Wasm globals. See `create_receiving` for the
// static version of this code.
if (typeof exportedSymbol.value !== 'undefined') {
#if MEMORY64
exportedSymbol = Number(exportedSymbol.value);
#else
exportedSymbol = exportedSymbol.value
#if HAS_MUTABLE_GLOBAL_EXPORTS
try {
// Throws for immutable globals, which are then unwrapped below.
// Mutable globals are left as WebAssembly.Global objects.
exportedSymbol.value = exportedSymbol.value;
} catch {
#endif
// Unwrap immutable global to a bare Number.
exportedSymbol = {{{ from64Expr('exportedSymbol.value') }}};
#if HAS_MUTABLE_GLOBAL_EXPORTS
}
#endif
}
#if MINIMAL_RUNTIME
Expand Down
4 changes: 4 additions & 0 deletions src/settings_internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// underscore.
var WASM_EXPORTS = [];

// Whether compiled code exports any mutable Wasm globals. These are exported
// to JS as WebAssembly.Global objects rather than as plain numbers.
var HAS_MUTABLE_GLOBAL_EXPORTS = false;

// An array of all symbols exported from all the side modules specified on the
// command line.
// These are raw symbol names and are not mangled to include the leading
Expand Down
1 change: 0 additions & 1 deletion test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9775,7 +9775,6 @@ def test_externref_emjs(self, dynlink):
'dylink': (True,),
})
@no_esm_integration('https://github.com/emscripten-core/emscripten/issues/25543')
@no_omit_asm_module_exports('https://github.com/emscripten-core/emscripten/issues/25550')
def test_wasm_global(self, dynlink):
if '-flto' in self.cflags or '-flto=thin' in self.cflags:
self.skipTest('https://github.com/emscripten-core/emscripten/issues/25555')
Expand Down
3 changes: 3 additions & 0 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,11 @@ def update_settings_glue(wasm_file, metadata, base_metadata):

if base_metadata:
settings.WASM_EXPORTS = base_metadata.all_exports
other_exports = base_metadata.other_exports
else:
settings.WASM_EXPORTS = metadata.all_exports
other_exports = metadata.other_exports
settings.HAS_MUTABLE_GLOBAL_EXPORTS = any(e.kind == webassembly.ExternType.GLOBAL and info.mutable for e, info in other_exports)
if metadata.empty_ctors and not settings.EVAL_CTORS:
# There are no static constructors to run, so there is no point in calling
# `__wasm_call_ctors` from JS. Unless the user asked for it to be exported,
Expand Down
Loading