From 88120158ad895877cb81f90228aab5fbbf80a632 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 26 Nov 2025 14:45:52 -0800 Subject: [PATCH] Use asyncify-export-globals when building main modules. NFC Depends on https://github.com/WebAssembly/binaryen/pull/8074 --- src/lib/libcore.js | 5 ----- tools/emscripten.py | 7 ++++--- tools/link.py | 11 +++-------- tools/maint/gen_sig_info.py | 1 - 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/lib/libcore.js b/src/lib/libcore.js index f3b042033f3ca..d774ed139d044 100644 --- a/src/lib/libcore.js +++ b/src/lib/libcore.js @@ -2212,11 +2212,6 @@ addToLibrary({ __global_base: '{{{ GLOBAL_BASE }}}', #endif // RELOCATABLE -#if (MAIN_MODULE || RELOCATABLE) && ASYNCIFY == 1 - __asyncify_state: "new WebAssembly.Global({'value': 'i32', 'mutable': true}, 0)", - __asyncify_data: "new WebAssembly.Global({'value': '{{{ POINTER_WASM_TYPE }}}', 'mutable': true}, {{{ to64(0) }}})", -#endif - _emscripten_fs_load_embedded_files__deps: ['$FS', '$PATH'], _emscripten_fs_load_embedded_files: (ptr) => { #if RUNTIME_DEBUG diff --git a/tools/emscripten.py b/tools/emscripten.py index 97235d59f3e7f..efe0cc1150c59 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -114,6 +114,10 @@ def update_settings_glue(wasm_file, metadata, base_metadata): settings.WASM_EXPORTS = metadata.all_exports settings.HAVE_EM_ASM = bool(settings.MAIN_MODULE or len(metadata.em_asm_consts) != 0) + if settings.MAIN_MODULE: + # These will be exported from Wasm, but only once we run the asyncify pass. + settings.WASM_EXPORTS += ['__asyncify_state', '__asyncify_data'] + # start with the MVP features, and add any detected features. building.binaryen_features = ['--mvp-features'] + metadata.features if settings.ASYNCIFY == 2: @@ -351,9 +355,6 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat if settings.INITIAL_TABLE == -1: settings.INITIAL_TABLE = dylink_sec.table_size + 1 - if settings.MAIN_MODULE and settings.ASYNCIFY == 1: - metadata.imports += ['__asyncify_state', '__asyncify_data'] - if metadata.invoke_funcs: settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$getWasmTableEntry'] diff --git a/tools/link.py b/tools/link.py index 18f7d7cad912e..b649d90413ecf 100644 --- a/tools/link.py +++ b/tools/link.py @@ -431,7 +431,9 @@ def get_binaryen_passes(options): passes += ['--fpcast-emu'] if settings.ASYNCIFY == 1: passes += ['--asyncify'] - if settings.RELOCATABLE or settings.MAIN_MODULE: + if settings.MAIN_MODULE: + passes += ['--pass-arg=asyncify-export-globals'] + elif settings.RELOCATABLE: passes += ['--pass-arg=asyncify-relocatable'] if settings.ASSERTIONS: passes += ['--pass-arg=asyncify-asserts'] @@ -1331,13 +1333,6 @@ def limit_incoming_module_api(): '$relocateExports', '$GOTHandler', ] - - if settings.ASYNCIFY == 1: - settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += [ - '__asyncify_state', - '__asyncify_data', - ] - # shared modules need memory utilities to allocate their memory settings.ALLOW_TABLE_GROWTH = 1 diff --git a/tools/maint/gen_sig_info.py b/tools/maint/gen_sig_info.py index 534f6d2e9d9e7..b1ff53a95d3d3 100755 --- a/tools/maint/gen_sig_info.py +++ b/tools/maint/gen_sig_info.py @@ -179,7 +179,6 @@ def ignore_symbol(s, cxx): return True if s in {'__stack_base', '__memory_base', '__table_base', '__global_base', '__heap_base', '__stack_pointer', '__stack_high', '__stack_low', '_load_secondary_module', - '__asyncify_state', '__asyncify_data', # legacy aliases, not callable from native code. 'stackSave', 'stackRestore', 'stackAlloc', 'getTempRet0', 'setTempRet0', }: