From 078ea971e02fde8d2398cb2f5ce28a2901a5790e Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 8 Jan 2025 15:09:53 -0800 Subject: [PATCH] Avoid creating wrapper thunks or wasm exports In debug builds nothing really changes here since we exported functions still get statically assigned to debug wrappers/thunks. However, after this change, in release builds, if you attempt to access `_foo` (internally) or `Module['_foo']` externally before the module is loaded you will now get `undefined`. Since it was always the case that calling these function would crash anyway, the only effected folks would be folks that take the reference early and then call later. e.g. ``` var myfunc = Module['_foo']; // Run before module is loaded // wait until loaded myfunc(); // This will no longer work. ``` Fixes: #23339 --- ChangeLog.md | 2 + src/postamble_minimal.js | 6 +- src/preamble.js | 4 +- .../codesize/test_codesize_cxx_ctors1.gzsize | 2 +- .../codesize/test_codesize_cxx_ctors1.jssize | 2 +- .../codesize/test_codesize_cxx_ctors2.gzsize | 2 +- .../codesize/test_codesize_cxx_ctors2.jssize | 2 +- .../codesize/test_codesize_cxx_except.gzsize | 2 +- .../codesize/test_codesize_cxx_except.jssize | 2 +- .../test_codesize_cxx_except_wasm.gzsize | 2 +- .../test_codesize_cxx_except_wasm.jssize | 2 +- ...est_codesize_cxx_except_wasm_exnref.gzsize | 2 +- ...est_codesize_cxx_except_wasm_exnref.jssize | 2 +- .../codesize/test_codesize_cxx_lto.gzsize | 2 +- .../codesize/test_codesize_cxx_lto.jssize | 2 +- .../codesize/test_codesize_cxx_mangle.gzsize | 2 +- .../codesize/test_codesize_cxx_mangle.jssize | 2 +- .../test_codesize_cxx_noexcept.gzsize | 2 +- .../test_codesize_cxx_noexcept.jssize | 2 +- .../codesize/test_codesize_cxx_wasmfs.gzsize | 2 +- .../codesize/test_codesize_cxx_wasmfs.jssize | 2 +- .../codesize/test_codesize_files_js_fs.gzsize | 2 +- .../codesize/test_codesize_files_js_fs.jssize | 2 +- .../test_codesize_files_wasmfs.gzsize | 2 +- .../test_codesize_files_wasmfs.jssize | 2 +- .../codesize/test_codesize_hello_O0.gzsize | 2 +- .../codesize/test_codesize_hello_O0.jssize | 2 +- .../codesize/test_codesize_hello_O1.gzsize | 2 +- .../codesize/test_codesize_hello_O1.jssize | 2 +- .../codesize/test_codesize_hello_O2.gzsize | 2 +- .../codesize/test_codesize_hello_O2.jssize | 2 +- .../codesize/test_codesize_hello_O3.gzsize | 2 +- .../codesize/test_codesize_hello_O3.jssize | 2 +- .../codesize/test_codesize_hello_Os.gzsize | 2 +- .../codesize/test_codesize_hello_Os.jssize | 2 +- .../codesize/test_codesize_hello_Oz.gzsize | 2 +- .../codesize/test_codesize_hello_Oz.jssize | 2 +- .../test_codesize_hello_dylink.gzsize | 2 +- .../test_codesize_hello_dylink.jssize | 2 +- .../test_codesize_hello_wasmfs.gzsize | 2 +- .../test_codesize_hello_wasmfs.jssize | 2 +- .../test_codesize_libcxxabi_message_O3.gzsize | 2 +- .../test_codesize_libcxxabi_message_O3.jssize | 2 +- ...ize_libcxxabi_message_O3_standalone.gzsize | 2 +- ...ize_libcxxabi_message_O3_standalone.jssize | 2 +- .../codesize/test_codesize_mem_O3.gzsize | 2 +- .../codesize/test_codesize_mem_O3.jssize | 2 +- .../codesize/test_codesize_mem_O3_grow.gzsize | 2 +- .../codesize/test_codesize_mem_O3_grow.jssize | 2 +- ...est_codesize_mem_O3_grow_standalone.gzsize | 2 +- ...est_codesize_mem_O3_grow_standalone.jssize | 2 +- .../test_codesize_mem_O3_standalone.gzsize | 2 +- .../test_codesize_mem_O3_standalone.jssize | 2 +- ...test_codesize_mem_O3_standalone_lib.gzsize | 2 +- ...test_codesize_mem_O3_standalone_lib.jssize | 2 +- ...est_codesize_mem_O3_standalone_narg.gzsize | 2 +- ...est_codesize_mem_O3_standalone_narg.jssize | 2 +- ...odesize_mem_O3_standalone_narg_flto.gzsize | 2 +- ...odesize_mem_O3_standalone_narg_flto.jssize | 2 +- .../codesize/test_codesize_minimal_64.gzsize | 2 +- .../codesize/test_codesize_minimal_64.jssize | 2 +- .../codesize/test_codesize_minimal_O0.gzsize | 2 +- .../codesize/test_codesize_minimal_O0.jssize | 2 +- .../codesize/test_codesize_minimal_O1.gzsize | 2 +- .../codesize/test_codesize_minimal_O1.jssize | 2 +- .../codesize/test_codesize_minimal_O2.gzsize | 2 +- .../codesize/test_codesize_minimal_O2.jssize | 2 +- .../codesize/test_codesize_minimal_O3.gzsize | 2 +- .../codesize/test_codesize_minimal_O3.jssize | 2 +- .../codesize/test_codesize_minimal_Os.gzsize | 2 +- .../codesize/test_codesize_minimal_Os.jssize | 2 +- .../test_codesize_minimal_Oz-ctors.gzsize | 2 +- .../test_codesize_minimal_Oz-ctors.jssize | 2 +- .../codesize/test_codesize_minimal_Oz.gzsize | 2 +- .../codesize/test_codesize_minimal_Oz.jssize | 2 +- .../codesize/test_codesize_minimal_esm.gzsize | 2 +- .../codesize/test_codesize_minimal_esm.jssize | 2 +- .../test_codesize_minimal_pthreads.gzsize | 2 +- .../test_codesize_minimal_pthreads.jssize | 2 +- .../test_codesize_minimal_wasmfs.gzsize | 2 +- .../test_codesize_minimal_wasmfs.jssize | 2 +- test/other/test_unoptimized_code_size.js.size | 2 +- ...t_unoptimized_code_size_no_asserts.js.size | 2 +- .../test_unoptimized_code_size_strict.js.size | 2 +- tools/emscripten.py | 95 ++++++++++++------- 85 files changed, 148 insertions(+), 121 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index bd1cc78513d09..8d81105831d63 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -23,6 +23,8 @@ See docs/process.md for more on how version tagging works. - The minimum version of node required to run emscripten was bumped from v16.20 to v18. Version 4.0 was mistakenly shipped with a change that required v20, but that was reverted. (#23410) +- Taking a refernce to an exported function before the Wasm module is loaded, + and then calling its later, is no longer supported. (#23411) 4.0.0 - 01/14/25 ---------------- diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 1f573cd229858..03747cfce83f5 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -180,10 +180,10 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => { wasmOffsetConverter = new WasmOffsetConverter(Module['wasm'], output.module); #endif -#if !DECLARE_ASM_MODULE_EXPORTS - exportWasmSymbols(wasmExports); -#else +#if DECLARE_ASM_MODULE_EXPORTS assignWasmExports(wasmExports); +#else + exportWasmSymbols(wasmExports); #endif #if '$wasmTable' in addedLibraryItems wasmTable = wasmExports['__indirect_function_table']; diff --git a/src/preamble.js b/src/preamble.js index 2a422c49008ea..0d06c428336d6 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -966,7 +966,9 @@ function getWasmImports() { instrumentWasmTableWithAbort(); #endif -#if !DECLARE_ASM_MODULE_EXPORTS +#if DECLARE_ASM_MODULE_EXPORTS + assignWasmExports(wasmExports); +#else // If we didn't declare the asm exports as top level enties this function // is in charge of programmatically exporting them on the global object. exportWasmSymbols(wasmExports); diff --git a/test/other/codesize/test_codesize_cxx_ctors1.gzsize b/test/other/codesize/test_codesize_cxx_ctors1.gzsize index cbcd6490a2762..1d7bdf0051254 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors1.gzsize @@ -1 +1 @@ -8343 +8337 diff --git a/test/other/codesize/test_codesize_cxx_ctors1.jssize b/test/other/codesize/test_codesize_cxx_ctors1.jssize index cfadcdff8168b..a081ddb2cf858 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.jssize +++ b/test/other/codesize/test_codesize_cxx_ctors1.jssize @@ -1 +1 @@ -20273 +20247 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.gzsize b/test/other/codesize/test_codesize_cxx_ctors2.gzsize index 09ccded12e2c4..f14ddc132870a 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors2.gzsize @@ -1 +1 @@ -8327 +8321 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.jssize b/test/other/codesize/test_codesize_cxx_ctors2.jssize index 27ff70803812b..1288971ac5fc2 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.jssize +++ b/test/other/codesize/test_codesize_cxx_ctors2.jssize @@ -1 +1 @@ -20241 +20215 diff --git a/test/other/codesize/test_codesize_cxx_except.gzsize b/test/other/codesize/test_codesize_cxx_except.gzsize index a14be756fbbb7..dfdc5b2794ac4 100644 --- a/test/other/codesize/test_codesize_cxx_except.gzsize +++ b/test/other/codesize/test_codesize_cxx_except.gzsize @@ -1 +1 @@ -9343 +9316 diff --git a/test/other/codesize/test_codesize_cxx_except.jssize b/test/other/codesize/test_codesize_cxx_except.jssize index 37b5c20b7dff5..9014cf53ab6e1 100644 --- a/test/other/codesize/test_codesize_cxx_except.jssize +++ b/test/other/codesize/test_codesize_cxx_except.jssize @@ -1 +1 @@ -24041 +23938 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize index 116ecc04e8d72..0f39737f7a041 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize @@ -1 +1 @@ -8294 +8286 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.jssize b/test/other/codesize/test_codesize_cxx_except_wasm.jssize index e2819c5beac21..83aea2fe30baf 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.jssize @@ -1 +1 @@ -20166 +20136 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize index 116ecc04e8d72..0f39737f7a041 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize @@ -1 +1 @@ -8294 +8286 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize index e2819c5beac21..83aea2fe30baf 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize @@ -1 +1 @@ -20166 +20136 diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize index b57252391c66a..7947190fcc750 100644 --- a/test/other/codesize/test_codesize_cxx_lto.gzsize +++ b/test/other/codesize/test_codesize_cxx_lto.gzsize @@ -1 +1 @@ -8357 +8348 diff --git a/test/other/codesize/test_codesize_cxx_lto.jssize b/test/other/codesize/test_codesize_cxx_lto.jssize index e5351bb2b3ec6..e292ea4e694a4 100644 --- a/test/other/codesize/test_codesize_cxx_lto.jssize +++ b/test/other/codesize/test_codesize_cxx_lto.jssize @@ -1 +1 @@ -20348 +20312 diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize index 217ff0cc7646e..6f4e1ed6d392e 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.gzsize +++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize @@ -1 +1 @@ -9349 +9320 diff --git a/test/other/codesize/test_codesize_cxx_mangle.jssize b/test/other/codesize/test_codesize_cxx_mangle.jssize index 37b5c20b7dff5..9014cf53ab6e1 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.jssize +++ b/test/other/codesize/test_codesize_cxx_mangle.jssize @@ -1 +1 @@ -24041 +23938 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.gzsize b/test/other/codesize/test_codesize_cxx_noexcept.gzsize index cbcd6490a2762..1d7bdf0051254 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.gzsize +++ b/test/other/codesize/test_codesize_cxx_noexcept.gzsize @@ -1 +1 @@ -8343 +8337 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.jssize b/test/other/codesize/test_codesize_cxx_noexcept.jssize index cfadcdff8168b..a081ddb2cf858 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.jssize +++ b/test/other/codesize/test_codesize_cxx_noexcept.jssize @@ -1 +1 @@ -20273 +20247 diff --git a/test/other/codesize/test_codesize_cxx_wasmfs.gzsize b/test/other/codesize/test_codesize_cxx_wasmfs.gzsize index 61c5a7e888399..3b094a526db87 100644 --- a/test/other/codesize/test_codesize_cxx_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_cxx_wasmfs.gzsize @@ -1 +1 @@ -3564 +3558 diff --git a/test/other/codesize/test_codesize_cxx_wasmfs.jssize b/test/other/codesize/test_codesize_cxx_wasmfs.jssize index bcc05aee525c4..322e1c5d47e09 100644 --- a/test/other/codesize/test_codesize_cxx_wasmfs.jssize +++ b/test/other/codesize/test_codesize_cxx_wasmfs.jssize @@ -1 +1 @@ -7676 +7650 diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize index c9ebb127902ab..8916bf3e32817 100644 --- a/test/other/codesize/test_codesize_files_js_fs.gzsize +++ b/test/other/codesize/test_codesize_files_js_fs.gzsize @@ -1 +1 @@ -7647 +7639 diff --git a/test/other/codesize/test_codesize_files_js_fs.jssize b/test/other/codesize/test_codesize_files_js_fs.jssize index 1862f08cb9bd4..2cd92e688af5d 100644 --- a/test/other/codesize/test_codesize_files_js_fs.jssize +++ b/test/other/codesize/test_codesize_files_js_fs.jssize @@ -1 +1 @@ -18820 +18794 diff --git a/test/other/codesize/test_codesize_files_wasmfs.gzsize b/test/other/codesize/test_codesize_files_wasmfs.gzsize index 9fe34ed6cff3e..9ddd587ee7d83 100644 --- a/test/other/codesize/test_codesize_files_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_files_wasmfs.gzsize @@ -1 +1 @@ -2804 +2797 diff --git a/test/other/codesize/test_codesize_files_wasmfs.jssize b/test/other/codesize/test_codesize_files_wasmfs.jssize index d628a8d498f0a..71e2238de50a8 100644 --- a/test/other/codesize/test_codesize_files_wasmfs.jssize +++ b/test/other/codesize/test_codesize_files_wasmfs.jssize @@ -1 +1 @@ -5984 +5958 diff --git a/test/other/codesize/test_codesize_hello_O0.gzsize b/test/other/codesize/test_codesize_hello_O0.gzsize index ffd7b3d6e32c8..3e8e9adc89f47 100644 --- a/test/other/codesize/test_codesize_hello_O0.gzsize +++ b/test/other/codesize/test_codesize_hello_O0.gzsize @@ -1 +1 @@ -7883 +7881 diff --git a/test/other/codesize/test_codesize_hello_O0.jssize b/test/other/codesize/test_codesize_hello_O0.jssize index be8a9dce3d78c..f0d741b18ae22 100644 --- a/test/other/codesize/test_codesize_hello_O0.jssize +++ b/test/other/codesize/test_codesize_hello_O0.jssize @@ -1 +1 @@ -20983 +20969 diff --git a/test/other/codesize/test_codesize_hello_O1.gzsize b/test/other/codesize/test_codesize_hello_O1.gzsize index 9e4687c072b66..b3c16aa14390a 100644 --- a/test/other/codesize/test_codesize_hello_O1.gzsize +++ b/test/other/codesize/test_codesize_hello_O1.gzsize @@ -1 +1 @@ -2658 +2649 diff --git a/test/other/codesize/test_codesize_hello_O1.jssize b/test/other/codesize/test_codesize_hello_O1.jssize index 1be5e3f4c2ddc..6a3fff47e3652 100644 --- a/test/other/codesize/test_codesize_hello_O1.jssize +++ b/test/other/codesize/test_codesize_hello_O1.jssize @@ -1 +1 @@ -6837 +6808 diff --git a/test/other/codesize/test_codesize_hello_O2.gzsize b/test/other/codesize/test_codesize_hello_O2.gzsize index ed5edbf7f250d..86be9d1591b64 100644 --- a/test/other/codesize/test_codesize_hello_O2.gzsize +++ b/test/other/codesize/test_codesize_hello_O2.gzsize @@ -1 +1 @@ -2320 +2314 diff --git a/test/other/codesize/test_codesize_hello_O2.jssize b/test/other/codesize/test_codesize_hello_O2.jssize index 7f776c653b31c..8013a68846f95 100644 --- a/test/other/codesize/test_codesize_hello_O2.jssize +++ b/test/other/codesize/test_codesize_hello_O2.jssize @@ -1 +1 @@ -4778 +4752 diff --git a/test/other/codesize/test_codesize_hello_O3.gzsize b/test/other/codesize/test_codesize_hello_O3.gzsize index 24ff55f1588d7..f33eeca5c0db2 100644 --- a/test/other/codesize/test_codesize_hello_O3.gzsize +++ b/test/other/codesize/test_codesize_hello_O3.gzsize @@ -1 +1 @@ -2278 +2271 diff --git a/test/other/codesize/test_codesize_hello_O3.jssize b/test/other/codesize/test_codesize_hello_O3.jssize index 4f652d136a346..a8db9bd71ab78 100644 --- a/test/other/codesize/test_codesize_hello_O3.jssize +++ b/test/other/codesize/test_codesize_hello_O3.jssize @@ -1 +1 @@ -4720 +4694 diff --git a/test/other/codesize/test_codesize_hello_Os.gzsize b/test/other/codesize/test_codesize_hello_Os.gzsize index 24ff55f1588d7..f33eeca5c0db2 100644 --- a/test/other/codesize/test_codesize_hello_Os.gzsize +++ b/test/other/codesize/test_codesize_hello_Os.gzsize @@ -1 +1 @@ -2278 +2271 diff --git a/test/other/codesize/test_codesize_hello_Os.jssize b/test/other/codesize/test_codesize_hello_Os.jssize index 4f652d136a346..a8db9bd71ab78 100644 --- a/test/other/codesize/test_codesize_hello_Os.jssize +++ b/test/other/codesize/test_codesize_hello_Os.jssize @@ -1 +1 @@ -4720 +4694 diff --git a/test/other/codesize/test_codesize_hello_Oz.gzsize b/test/other/codesize/test_codesize_hello_Oz.gzsize index 24ff55f1588d7..f33eeca5c0db2 100644 --- a/test/other/codesize/test_codesize_hello_Oz.gzsize +++ b/test/other/codesize/test_codesize_hello_Oz.gzsize @@ -1 +1 @@ -2278 +2271 diff --git a/test/other/codesize/test_codesize_hello_Oz.jssize b/test/other/codesize/test_codesize_hello_Oz.jssize index 4f652d136a346..a8db9bd71ab78 100644 --- a/test/other/codesize/test_codesize_hello_Oz.jssize +++ b/test/other/codesize/test_codesize_hello_Oz.jssize @@ -1 +1 @@ -4720 +4694 diff --git a/test/other/codesize/test_codesize_hello_dylink.gzsize b/test/other/codesize/test_codesize_hello_dylink.gzsize index 06d0b728023d8..06ec466f32a4a 100644 --- a/test/other/codesize/test_codesize_hello_dylink.gzsize +++ b/test/other/codesize/test_codesize_hello_dylink.gzsize @@ -1 +1 @@ -5992 +5973 diff --git a/test/other/codesize/test_codesize_hello_dylink.jssize b/test/other/codesize/test_codesize_hello_dylink.jssize index c19262676f100..3a83c78b94577 100644 --- a/test/other/codesize/test_codesize_hello_dylink.jssize +++ b/test/other/codesize/test_codesize_hello_dylink.jssize @@ -1 +1 @@ -13241 +13167 diff --git a/test/other/codesize/test_codesize_hello_wasmfs.gzsize b/test/other/codesize/test_codesize_hello_wasmfs.gzsize index 24ff55f1588d7..f33eeca5c0db2 100644 --- a/test/other/codesize/test_codesize_hello_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_hello_wasmfs.gzsize @@ -1 +1 @@ -2278 +2271 diff --git a/test/other/codesize/test_codesize_hello_wasmfs.jssize b/test/other/codesize/test_codesize_hello_wasmfs.jssize index 4f652d136a346..a8db9bd71ab78 100644 --- a/test/other/codesize/test_codesize_hello_wasmfs.jssize +++ b/test/other/codesize/test_codesize_hello_wasmfs.jssize @@ -1 +1 @@ -4720 +4694 diff --git a/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize b/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize index 98102958a72c9..1902baead2626 100644 --- a/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize +++ b/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize @@ -1 +1 @@ -1874 +1865 diff --git a/test/other/codesize/test_codesize_libcxxabi_message_O3.jssize b/test/other/codesize/test_codesize_libcxxabi_message_O3.jssize index 1263586a20af3..04d0e6f305b32 100644 --- a/test/other/codesize/test_codesize_libcxxabi_message_O3.jssize +++ b/test/other/codesize/test_codesize_libcxxabi_message_O3.jssize @@ -1 +1 @@ -3996 +3970 diff --git a/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.gzsize b/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.gzsize index 23e07fb71b3f9..b0effbb3f7fc5 100644 --- a/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.gzsize +++ b/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.gzsize @@ -1 +1 @@ -1912 +1906 diff --git a/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.jssize b/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.jssize index 24b2d1ddd384c..cdfa59eaeb4dc 100644 --- a/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.jssize +++ b/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.jssize @@ -1 +1 @@ -4044 +4022 diff --git a/test/other/codesize/test_codesize_mem_O3.gzsize b/test/other/codesize/test_codesize_mem_O3.gzsize index da898df886b32..be54986fa6767 100644 --- a/test/other/codesize/test_codesize_mem_O3.gzsize +++ b/test/other/codesize/test_codesize_mem_O3.gzsize @@ -1 +1 @@ -2326 +2319 diff --git a/test/other/codesize/test_codesize_mem_O3.jssize b/test/other/codesize/test_codesize_mem_O3.jssize index a155f5afbd071..056e7f563b429 100644 --- a/test/other/codesize/test_codesize_mem_O3.jssize +++ b/test/other/codesize/test_codesize_mem_O3.jssize @@ -1 +1 @@ -4888 +4858 diff --git a/test/other/codesize/test_codesize_mem_O3_grow.gzsize b/test/other/codesize/test_codesize_mem_O3_grow.gzsize index fdf0f56cd467c..8da928e69d5e8 100644 --- a/test/other/codesize/test_codesize_mem_O3_grow.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_grow.gzsize @@ -1 +1 @@ -2474 +2466 diff --git a/test/other/codesize/test_codesize_mem_O3_grow.jssize b/test/other/codesize/test_codesize_mem_O3_grow.jssize index cd147334a1386..ad0eeb465f5dd 100644 --- a/test/other/codesize/test_codesize_mem_O3_grow.jssize +++ b/test/other/codesize/test_codesize_mem_O3_grow.jssize @@ -1 +1 @@ -5172 +5142 diff --git a/test/other/codesize/test_codesize_mem_O3_grow_standalone.gzsize b/test/other/codesize/test_codesize_mem_O3_grow_standalone.gzsize index 491c450e95ca7..d03b13697b271 100644 --- a/test/other/codesize/test_codesize_mem_O3_grow_standalone.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_grow_standalone.gzsize @@ -1 +1 @@ -2175 +2170 diff --git a/test/other/codesize/test_codesize_mem_O3_grow_standalone.jssize b/test/other/codesize/test_codesize_mem_O3_grow_standalone.jssize index 5b9e54fbbe923..eedf96b1fab25 100644 --- a/test/other/codesize/test_codesize_mem_O3_grow_standalone.jssize +++ b/test/other/codesize/test_codesize_mem_O3_grow_standalone.jssize @@ -1 +1 @@ -4581 +4563 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone.gzsize b/test/other/codesize/test_codesize_mem_O3_standalone.gzsize index 6a4fd21351996..2ce51091e4726 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_standalone.gzsize @@ -1 +1 @@ -2141 +2136 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone.jssize b/test/other/codesize/test_codesize_mem_O3_standalone.jssize index 570a753145afa..a5bb21c73e78e 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone.jssize +++ b/test/other/codesize/test_codesize_mem_O3_standalone.jssize @@ -1 +1 @@ -4513 +4495 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_lib.gzsize b/test/other/codesize/test_codesize_mem_O3_standalone_lib.gzsize index 3964950a079db..719c962dfb7ce 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_lib.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_lib.gzsize @@ -1 +1 @@ -1898 +1890 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_lib.jssize b/test/other/codesize/test_codesize_mem_O3_standalone_lib.jssize index 4a3a63211e267..2fab692d620a4 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_lib.jssize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_lib.jssize @@ -1 +1 @@ -4043 +4005 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_narg.gzsize b/test/other/codesize/test_codesize_mem_O3_standalone_narg.gzsize index 23e07fb71b3f9..b0effbb3f7fc5 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_narg.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_narg.gzsize @@ -1 +1 @@ -1912 +1906 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_narg.jssize b/test/other/codesize/test_codesize_mem_O3_standalone_narg.jssize index 24b2d1ddd384c..cdfa59eaeb4dc 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_narg.jssize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_narg.jssize @@ -1 +1 @@ -4044 +4022 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.gzsize b/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.gzsize index 23e07fb71b3f9..b0effbb3f7fc5 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.gzsize @@ -1 +1 @@ -1912 +1906 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.jssize b/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.jssize index 24b2d1ddd384c..cdfa59eaeb4dc 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.jssize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.jssize @@ -1 +1 @@ -4044 +4022 diff --git a/test/other/codesize/test_codesize_minimal_64.gzsize b/test/other/codesize/test_codesize_minimal_64.gzsize index 4d851a7800ac5..74103fb62ac3e 100644 --- a/test/other/codesize/test_codesize_minimal_64.gzsize +++ b/test/other/codesize/test_codesize_minimal_64.gzsize @@ -1 +1 @@ -1441 +1431 diff --git a/test/other/codesize/test_codesize_minimal_64.jssize b/test/other/codesize/test_codesize_minimal_64.jssize index 9bcc9f43c3d2c..ba868b5e1b72a 100644 --- a/test/other/codesize/test_codesize_minimal_64.jssize +++ b/test/other/codesize/test_codesize_minimal_64.jssize @@ -1 +1 @@ -3058 +3041 diff --git a/test/other/codesize/test_codesize_minimal_O0.gzsize b/test/other/codesize/test_codesize_minimal_O0.gzsize index 536a5fa692079..09887900c93e3 100644 --- a/test/other/codesize/test_codesize_minimal_O0.gzsize +++ b/test/other/codesize/test_codesize_minimal_O0.gzsize @@ -1 +1 @@ -6449 +6446 diff --git a/test/other/codesize/test_codesize_minimal_O0.jssize b/test/other/codesize/test_codesize_minimal_O0.jssize index d925085b05f33..5f5431430c0b5 100644 --- a/test/other/codesize/test_codesize_minimal_O0.jssize +++ b/test/other/codesize/test_codesize_minimal_O0.jssize @@ -1 +1 @@ -17094 +17089 diff --git a/test/other/codesize/test_codesize_minimal_O1.gzsize b/test/other/codesize/test_codesize_minimal_O1.gzsize index effd6e7865f0d..641d5f59ecacf 100644 --- a/test/other/codesize/test_codesize_minimal_O1.gzsize +++ b/test/other/codesize/test_codesize_minimal_O1.gzsize @@ -1 +1 @@ -1534 +1524 diff --git a/test/other/codesize/test_codesize_minimal_O1.jssize b/test/other/codesize/test_codesize_minimal_O1.jssize index 496991636dc10..f246e47d1581b 100644 --- a/test/other/codesize/test_codesize_minimal_O1.jssize +++ b/test/other/codesize/test_codesize_minimal_O1.jssize @@ -1 +1 @@ -3702 +3681 diff --git a/test/other/codesize/test_codesize_minimal_O2.gzsize b/test/other/codesize/test_codesize_minimal_O2.gzsize index a3d3785badfdf..5ae289b43f8d7 100644 --- a/test/other/codesize/test_codesize_minimal_O2.gzsize +++ b/test/other/codesize/test_codesize_minimal_O2.gzsize @@ -1 +1 @@ -1380 +1371 diff --git a/test/other/codesize/test_codesize_minimal_O2.jssize b/test/other/codesize/test_codesize_minimal_O2.jssize index f06c1c5aa9471..0be71814d36cf 100644 --- a/test/other/codesize/test_codesize_minimal_O2.jssize +++ b/test/other/codesize/test_codesize_minimal_O2.jssize @@ -1 +1 @@ -2806 +2789 diff --git a/test/other/codesize/test_codesize_minimal_O3.gzsize b/test/other/codesize/test_codesize_minimal_O3.gzsize index e714efcd7f726..a369ea6071bfc 100644 --- a/test/other/codesize/test_codesize_minimal_O3.gzsize +++ b/test/other/codesize/test_codesize_minimal_O3.gzsize @@ -1 +1 @@ -1347 +1337 diff --git a/test/other/codesize/test_codesize_minimal_O3.jssize b/test/other/codesize/test_codesize_minimal_O3.jssize index 0ece43ab5c071..344446a8c3b46 100644 --- a/test/other/codesize/test_codesize_minimal_O3.jssize +++ b/test/other/codesize/test_codesize_minimal_O3.jssize @@ -1 +1 @@ -2756 +2739 diff --git a/test/other/codesize/test_codesize_minimal_Os.gzsize b/test/other/codesize/test_codesize_minimal_Os.gzsize index e714efcd7f726..a369ea6071bfc 100644 --- a/test/other/codesize/test_codesize_minimal_Os.gzsize +++ b/test/other/codesize/test_codesize_minimal_Os.gzsize @@ -1 +1 @@ -1347 +1337 diff --git a/test/other/codesize/test_codesize_minimal_Os.jssize b/test/other/codesize/test_codesize_minimal_Os.jssize index 0ece43ab5c071..344446a8c3b46 100644 --- a/test/other/codesize/test_codesize_minimal_Os.jssize +++ b/test/other/codesize/test_codesize_minimal_Os.jssize @@ -1 +1 @@ -2756 +2739 diff --git a/test/other/codesize/test_codesize_minimal_Oz-ctors.gzsize b/test/other/codesize/test_codesize_minimal_Oz-ctors.gzsize index a9449958c6a77..7ae5be655b033 100644 --- a/test/other/codesize/test_codesize_minimal_Oz-ctors.gzsize +++ b/test/other/codesize/test_codesize_minimal_Oz-ctors.gzsize @@ -1 +1 @@ -1338 +1329 diff --git a/test/other/codesize/test_codesize_minimal_Oz-ctors.jssize b/test/other/codesize/test_codesize_minimal_Oz-ctors.jssize index 32dec52aa5d71..be4762f6ddc12 100644 --- a/test/other/codesize/test_codesize_minimal_Oz-ctors.jssize +++ b/test/other/codesize/test_codesize_minimal_Oz-ctors.jssize @@ -1 +1 @@ -2741 +2724 diff --git a/test/other/codesize/test_codesize_minimal_Oz.gzsize b/test/other/codesize/test_codesize_minimal_Oz.gzsize index e714efcd7f726..a369ea6071bfc 100644 --- a/test/other/codesize/test_codesize_minimal_Oz.gzsize +++ b/test/other/codesize/test_codesize_minimal_Oz.gzsize @@ -1 +1 @@ -1347 +1337 diff --git a/test/other/codesize/test_codesize_minimal_Oz.jssize b/test/other/codesize/test_codesize_minimal_Oz.jssize index 0ece43ab5c071..344446a8c3b46 100644 --- a/test/other/codesize/test_codesize_minimal_Oz.jssize +++ b/test/other/codesize/test_codesize_minimal_Oz.jssize @@ -1 +1 @@ -2756 +2739 diff --git a/test/other/codesize/test_codesize_minimal_esm.gzsize b/test/other/codesize/test_codesize_minimal_esm.gzsize index 57c7c05238e16..fa94e88e60f14 100644 --- a/test/other/codesize/test_codesize_minimal_esm.gzsize +++ b/test/other/codesize/test_codesize_minimal_esm.gzsize @@ -1 +1 @@ -1542 +1536 diff --git a/test/other/codesize/test_codesize_minimal_esm.jssize b/test/other/codesize/test_codesize_minimal_esm.jssize index 465a35cfc4a0f..bed5801ace9ad 100644 --- a/test/other/codesize/test_codesize_minimal_esm.jssize +++ b/test/other/codesize/test_codesize_minimal_esm.jssize @@ -1 +1 @@ -3210 +3193 diff --git a/test/other/codesize/test_codesize_minimal_pthreads.gzsize b/test/other/codesize/test_codesize_minimal_pthreads.gzsize index b52fc8a6e1cae..e9afe54fe38c8 100644 --- a/test/other/codesize/test_codesize_minimal_pthreads.gzsize +++ b/test/other/codesize/test_codesize_minimal_pthreads.gzsize @@ -1 +1 @@ -4186 +4140 diff --git a/test/other/codesize/test_codesize_minimal_pthreads.jssize b/test/other/codesize/test_codesize_minimal_pthreads.jssize index 7a53a34d4eeef..b40b6a0fd0a30 100644 --- a/test/other/codesize/test_codesize_minimal_pthreads.jssize +++ b/test/other/codesize/test_codesize_minimal_pthreads.jssize @@ -1 +1 @@ -8728 +8514 diff --git a/test/other/codesize/test_codesize_minimal_wasmfs.gzsize b/test/other/codesize/test_codesize_minimal_wasmfs.gzsize index e714efcd7f726..a369ea6071bfc 100644 --- a/test/other/codesize/test_codesize_minimal_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_minimal_wasmfs.gzsize @@ -1 +1 @@ -1347 +1337 diff --git a/test/other/codesize/test_codesize_minimal_wasmfs.jssize b/test/other/codesize/test_codesize_minimal_wasmfs.jssize index 0ece43ab5c071..344446a8c3b46 100644 --- a/test/other/codesize/test_codesize_minimal_wasmfs.jssize +++ b/test/other/codesize/test_codesize_minimal_wasmfs.jssize @@ -1 +1 @@ -2756 +2739 diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size index a9abb660fbe9c..03923be36cd46 100644 --- a/test/other/test_unoptimized_code_size.js.size +++ b/test/other/test_unoptimized_code_size.js.size @@ -1 +1 @@ -52739 +52879 diff --git a/test/other/test_unoptimized_code_size_no_asserts.js.size b/test/other/test_unoptimized_code_size_no_asserts.js.size index 918c9c91947b0..cafa1cb40ef77 100644 --- a/test/other/test_unoptimized_code_size_no_asserts.js.size +++ b/test/other/test_unoptimized_code_size_no_asserts.js.size @@ -1 +1 @@ -28487 +28607 diff --git a/test/other/test_unoptimized_code_size_strict.js.size b/test/other/test_unoptimized_code_size_strict.js.size index 8a03cbf8f27f0..81495d2c67c31 100644 --- a/test/other/test_unoptimized_code_size_strict.js.size +++ b/test/other/test_unoptimized_code_size_strict.js.size @@ -1 +1 @@ -51522 +51662 diff --git a/tools/emscripten.py b/tools/emscripten.py index c412c77250d1b..155da37160ef0 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -886,9 +886,14 @@ def can_use_await(): def make_export_wrappers(function_exports): assert not settings.MINIMAL_RUNTIME - wrappers = [] + # When exports are only available asyncronously we generate an extran assignWasmExports + # function. When they are syncronously available we inline the assignment along + # with the declaration. + async_exports = (settings.WASM_ASYNC_COMPILATION and not can_use_await()) or settings.PTHREADS - def install_wrapper(sym): + def install_debug_wrapper(sym): + if not settings.ASSERTIONS: + return False # The emscripten stack functions are called very early (by writeStackCookie) before # the runtime is initialized so we can't create these wrappers that check for # runtimeInitialized. @@ -901,38 +906,58 @@ def install_wrapper(sym): # TODO: Look into removing these, and improving our robustness around thread termination. return sym not in {'__trap', 'pthread_self', '_emscripten_proxy_execute_task_queue'} - for name, types in function_exports.items(): - nargs = len(types.params) - mangled = asmjs_mangle(name) - wrapper = 'var %s = ' % mangled - - # TODO(sbc): Can we avoid exporting the dynCall_ functions on the module. + def outside_export(mangled): should_export = settings.EXPORT_KEEPALIVE and mangled in settings.EXPORTED_FUNCTIONS + # TODO(sbc): Can we avoid exporting the dynCall_ functions on the module. if (name.startswith('dynCall_') and settings.MODULARIZE != 'instance') or should_export: if settings.MODULARIZE == 'instance': # Update the export declared at the top level. - wrapper += f" __exp_{mangled} = " + return f" __exp_{mangled}" else: - exported = "Module['%s'] = " % mangled - else: - exported = '' - wrapper += exported - - if settings.ASSERTIONS and install_wrapper(name): - # With assertions enabled we create a wrapper that are calls get routed through, for - # the lifetime of the program. - wrapper += f"createExportWrapper('{name}', {nargs});" - elif (settings.WASM_ASYNC_COMPILATION and not can_use_await()) or settings.PTHREADS: - # With WASM_ASYNC_COMPILATION wrapper will replace the global var and Module var on - # first use. - args = [f'a{i}' for i in range(nargs)] - args = ', '.join(args) - wrapper += f"({args}) => ({mangled} = {exported}wasmExports['{name}'])({args});" - else: - wrapper += f"wasmExports['{name}']" + return "Module['%s']" % mangled + + rtn = [] + rtn.append('function assignWasmExports(wasmExports) {') + for name in function_exports: + # If a debug wrapper was used then we don't need to update anything, we want to + # always use the wrapper, and never the direct export. + if install_debug_wrapper(name): + continue + mangled = asmjs_mangle(name) + wrapper = f' {mangled} = ' + additional_export = outside_export(mangled) + if additional_export: + wrapper += additional_export + ' = ' + wrapper += f"wasmExports['{name}'];" + rtn.append(wrapper) - wrappers.append(wrapper) - return wrappers + rtn.append('}') + + rtn.append('') + rtn.append('// Exported wasm functions.') + if async_exports: + rtn.append('// These are declared here but will be remain undefined until async wasm instanatiation is complete.') + + if settings.ASSERTIONS: + for name, types in function_exports.items(): + mangled = asmjs_mangle(name) + if install_debug_wrapper(name): + # With assertions enabled we create a wrapper that are calls get routed through, for + # the lifetime of the program. + nargs = len(types.params) + additional_export = outside_export(mangled) + if additional_export: + rtn.append(f"var {mangled} = {additional_export} = createExportWrapper('{name}', {nargs});") + else: + rtn.append(f"var {mangled} = createExportWrapper('{name}', {nargs});") + else: + rtn.append(f'var {mangled};') + else: + mangled = [asmjs_mangle(name) for name in function_exports] + sep = ',\n ' + rtn.append(f'var {sep.join(mangled)};') + + return rtn def create_receiving(function_exports): @@ -986,17 +1011,15 @@ def create_module(receiving, metadata, global_exports, library_symbols): else: module.append('var wasmImports = %s;\n' % sending) + module.append(receiving) + if not settings.MINIMAL_RUNTIME: - if settings.WASM_ASYNC_COMPILATION: - if can_use_await(): - # In modularize mode the generated code is within a factory function. - module.append("var wasmExports = await createWasm();\n") - else: - module.append("var wasmExports;\ncreateWasm();\n") + if settings.WASM_ASYNC_COMPILATION and can_use_await(): + # In modularize mode the generated code is within a factory function. + module.append("var wasmExports = await createWasm();\n") else: - module.append("var wasmExports = createWasm();\n") + module.append("var wasmExports;\ncreateWasm();\n") - module.append(receiving) if settings.SUPPORT_LONGJMP == 'emscripten' or not settings.DISABLE_EXCEPTION_CATCHING: module.append(create_invoke_wrappers(metadata)) else: