diff --git a/src/preamble.js b/src/preamble.js index e0bb2f3c57470..77cc7d8a2da97 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -44,18 +44,6 @@ if (typeof WebAssembly != 'object') { } #endif -#if SAFE_HEAP -#include "runtime_safe_heap.js" -#endif - -#if SHARED_MEMORY && ALLOW_MEMORY_GROWTH -#include "growableHeap.js" -#endif - -#if USE_ASAN -#include "runtime_asan.js" -#endif - #if SUPPORT_BASE64_EMBEDDING || FORCE_FILESYSTEM #include "base64Utils.js" #endif @@ -150,12 +138,16 @@ var HEAP, var HEAP_DATA_VIEW; #endif -#include "runtime_shared.js" +var runtimeInitialized = false; -#if PTHREADS -#include "runtime_pthread.js" +#if EXIT_RUNTIME +var runtimeExited = false; #endif +#include "URIUtils.js" + +#include "runtime_shared.js" + #if ASSERTIONS assert(!Module['STACK_SIZE'], 'STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time') #endif @@ -174,8 +166,6 @@ assert(!Module['wasmMemory'], 'Use of `wasmMemory` detected. Use -sIMPORTED_MEM assert(!Module['INITIAL_MEMORY'], 'Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically'); #endif // !IMPORTED_MEMORY && ASSERTIONS -#include "runtime_stack_check.js" - var __ATPRERUN__ = []; // functions called before the runtime is initialized var __ATINIT__ = []; // functions called during startup #if HAS_MAIN @@ -188,12 +178,6 @@ var __ATPOSTRUN__ = []; // functions called after the main() is called var __RELOC_FUNCS__ = []; #endif -var runtimeInitialized = false; - -#if EXIT_RUNTIME -var runtimeExited = false; -#endif - function preRun() { #if ASSERTIONS && PTHREADS assert(!ENVIRONMENT_IS_PTHREAD); // PThreads reuse the runtime from the main thread. @@ -483,8 +467,6 @@ function abort(what) { throw e; } -#include "memoryprofiler.js" - #if ASSERTIONS && !('$FS' in addedLibraryItems) // show errors on likely calls to FS when it was not included var FS = { @@ -506,8 +488,6 @@ Module['FS_createDataFile'] = FS.createDataFile; Module['FS_createPreloadedFile'] = FS.createPreloadedFile; #endif -#include "URIUtils.js" - #if ASSERTIONS function createExportWrapper(name, nargs) { return (...args) => { @@ -524,8 +504,6 @@ function createExportWrapper(name, nargs) { } #endif -#include "runtime_exceptions.js" - #if ABORT_ON_WASM_EXCEPTIONS // `abortWrapperDepth` counts the recursion level of the wrapper function so // that we only handle exceptions at the top level letting the exception @@ -675,16 +653,6 @@ async function getWasmBinary(binaryFile) { return getBinarySync(binaryFile); } -#if LOAD_SOURCE_MAP -var wasmSourceMap; -#include "source_map_support.js" -#endif - -#if USE_OFFSET_CONVERTER -var wasmOffsetConverter; -#include "wasm_offset_converter.js" -#endif - #if SPLIT_MODULE {{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync', true) }}} var splitModuleProxyHandler = { @@ -1127,8 +1095,6 @@ var tempDouble; var tempI64; #endif -#include "runtime_debug.js" - #if RETAIN_COMPILER_SETTINGS var compilerSettings = {{{ JSON.stringify(makeRetainedCompilerSettings()) }}} ; diff --git a/src/preamble_minimal.js b/src/preamble_minimal.js index 5f0a7594bda22..4cd2066c90e36 100644 --- a/src/preamble_minimal.js +++ b/src/preamble_minimal.js @@ -4,18 +4,6 @@ * SPDX-License-Identifier: MIT */ -#if SAFE_HEAP -#include "runtime_safe_heap.js" -#endif - -#if SHARED_MEMORY && ALLOW_MEMORY_GROWTH -#include "growableHeap.js" -#endif - -#if USE_ASAN -#include "runtime_asan.js" -#endif - #if ASSERTIONS /** @type {function(*, string=)} */ function assert(condition, text) { @@ -58,26 +46,8 @@ var HEAP8, HEAP16, HEAP32, HEAPU8, HEAPU16, HEAPU32, HEAPF32, HEAPF64, #endif wasmMemory; -#include "runtime_shared.js" - -#if PTHREADS -#include "runtime_pthread.js" -#endif - -#if IMPORTED_MEMORY -#include "runtime_init_memory.js" -#endif // IMPORTED_MEMORY - -#include "runtime_stack_check.js" - -#if LOAD_SOURCE_MAP -var wasmSourceMap; -#include "source_map_support.js" -#endif - -#if USE_OFFSET_CONVERTER -var wasmOffsetConverter; -#include "wasm_offset_converter.js" +#if ASSERTIONS || SAFE_HEAP || USE_ASAN +var runtimeInitialized = false; #endif #if EXIT_RUNTIME @@ -85,12 +55,10 @@ var __ATEXIT__ = []; // functions called during shutdown var runtimeExited = false; #endif -#if ASSERTIONS || SAFE_HEAP || USE_ASAN -var runtimeInitialized = false; -#endif +#include "runtime_shared.js" -#include "memoryprofiler.js" -#include "runtime_exceptions.js" -#include "runtime_debug.js" +#if IMPORTED_MEMORY +#include "runtime_init_memory.js" +#endif // IMPORTED_MEMORY // === Body === diff --git a/src/runtime_shared.js b/src/runtime_shared.js index 22ef5e881c426..850e0859ae051 100644 --- a/src/runtime_shared.js +++ b/src/runtime_shared.js @@ -4,6 +4,37 @@ * SPDX-License-Identifier: MIT */ +#include "runtime_stack_check.js" +#include "runtime_exceptions.js" +#include "runtime_debug.js" +#include "memoryprofiler.js" + +#if SAFE_HEAP +#include "runtime_safe_heap.js" +#endif + +#if SHARED_MEMORY && ALLOW_MEMORY_GROWTH +#include "growableHeap.js" +#endif + +#if USE_ASAN +#include "runtime_asan.js" +#endif + +#if PTHREADS +#include "runtime_pthread.js" +#endif + +#if LOAD_SOURCE_MAP +var wasmSourceMap; +#include "source_map_support.js" +#endif + +#if USE_OFFSET_CONVERTER +var wasmOffsetConverter; +#include "wasm_offset_converter.js" +#endif + {{{ // Helper function to export a heap symbol on the module object, // if requested. diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize index 9604c9f1829be..6b663b45b81f6 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize @@ -1 +1 @@ -8329 +8328 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.jssize b/test/other/codesize/test_codesize_cxx_except_wasm.jssize index 83a6ddde84fa6..21ce7fe7a474d 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.jssize @@ -1 +1 @@ -20266 +20267 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 9604c9f1829be..6b663b45b81f6 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 @@ -8329 +8328 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 83a6ddde84fa6..21ce7fe7a474d 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 @@ -20266 +20267 diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize index 3e9a7cd57a3f9..8d7a41cfdf9a7 100644 --- a/test/other/codesize/test_codesize_cxx_lto.gzsize +++ b/test/other/codesize/test_codesize_cxx_lto.gzsize @@ -1 +1 @@ -8363 +8360 diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize index edd50e57805be..f4514b3a9fef8 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.gzsize +++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize @@ -1 +1 @@ -9375 +9374 diff --git a/test/other/codesize/test_codesize_cxx_wasmfs.gzsize b/test/other/codesize/test_codesize_cxx_wasmfs.gzsize index 4dc663e66f8ed..2fb87dfdb1514 100644 --- a/test/other/codesize/test_codesize_cxx_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_cxx_wasmfs.gzsize @@ -1 +1 @@ -3600 +3599 diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize index a6589474f60cb..6dbf5aca4f890 100644 --- a/test/other/codesize/test_codesize_files_js_fs.gzsize +++ b/test/other/codesize/test_codesize_files_js_fs.gzsize @@ -1 +1 @@ -7656 +7655 diff --git a/test/other/codesize/test_codesize_files_wasmfs.gzsize b/test/other/codesize/test_codesize_files_wasmfs.gzsize index f1293228d187e..295764c17da68 100644 --- a/test/other/codesize/test_codesize_files_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_files_wasmfs.gzsize @@ -1 +1 @@ -2837 +2836 diff --git a/test/other/codesize/test_codesize_hello_O0.gzsize b/test/other/codesize/test_codesize_hello_O0.gzsize index 631cfb1647488..eb1d570cd3486 100644 --- a/test/other/codesize/test_codesize_hello_O0.gzsize +++ b/test/other/codesize/test_codesize_hello_O0.gzsize @@ -1 +1 @@ -7891 +7905 diff --git a/test/other/codesize/test_codesize_hello_O0.jssize b/test/other/codesize/test_codesize_hello_O0.jssize index 70f81fd011114..ca24f1eeac3f6 100644 --- a/test/other/codesize/test_codesize_hello_O0.jssize +++ b/test/other/codesize/test_codesize_hello_O0.jssize @@ -1 +1 @@ -21016 +21012 diff --git a/test/other/codesize/test_codesize_hello_O2.gzsize b/test/other/codesize/test_codesize_hello_O2.gzsize index da797840923f0..773f46ded04e7 100644 --- a/test/other/codesize/test_codesize_hello_O2.gzsize +++ b/test/other/codesize/test_codesize_hello_O2.gzsize @@ -1 +1 @@ -2357 +2356 diff --git a/test/other/codesize/test_codesize_hello_O3.gzsize b/test/other/codesize/test_codesize_hello_O3.gzsize index 616e2787a51d3..19697800ce696 100644 --- a/test/other/codesize/test_codesize_hello_O3.gzsize +++ b/test/other/codesize/test_codesize_hello_O3.gzsize @@ -1 +1 @@ -2296 +2297 diff --git a/test/other/codesize/test_codesize_hello_Os.gzsize b/test/other/codesize/test_codesize_hello_Os.gzsize index 616e2787a51d3..19697800ce696 100644 --- a/test/other/codesize/test_codesize_hello_Os.gzsize +++ b/test/other/codesize/test_codesize_hello_Os.gzsize @@ -1 +1 @@ -2296 +2297 diff --git a/test/other/codesize/test_codesize_hello_Oz.gzsize b/test/other/codesize/test_codesize_hello_Oz.gzsize index 20c65f21df41d..24ff55f1588d7 100644 --- a/test/other/codesize/test_codesize_hello_Oz.gzsize +++ b/test/other/codesize/test_codesize_hello_Oz.gzsize @@ -1 +1 @@ -2279 +2278 diff --git a/test/other/codesize/test_codesize_hello_dylink.gzsize b/test/other/codesize/test_codesize_hello_dylink.gzsize index 45a2573f0aa4b..20b75178d80e5 100644 --- a/test/other/codesize/test_codesize_hello_dylink.gzsize +++ b/test/other/codesize/test_codesize_hello_dylink.gzsize @@ -1 +1 @@ -6028 +6026 diff --git a/test/other/codesize/test_codesize_hello_dylink.jssize b/test/other/codesize/test_codesize_hello_dylink.jssize index c7ce89ced910f..0d9eaaec75df0 100644 --- a/test/other/codesize/test_codesize_hello_dylink.jssize +++ b/test/other/codesize/test_codesize_hello_dylink.jssize @@ -1 +1 @@ -13317 +13316 diff --git a/test/other/codesize/test_codesize_hello_export_nothing.gzsize b/test/other/codesize/test_codesize_hello_export_nothing.gzsize index 357a340dae7ae..5a9a9ee2f13eb 100644 --- a/test/other/codesize/test_codesize_hello_export_nothing.gzsize +++ b/test/other/codesize/test_codesize_hello_export_nothing.gzsize @@ -1 +1 @@ -1681 +1678 diff --git a/test/other/codesize/test_codesize_hello_wasmfs.gzsize b/test/other/codesize/test_codesize_hello_wasmfs.gzsize index 616e2787a51d3..19697800ce696 100644 --- a/test/other/codesize/test_codesize_hello_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_hello_wasmfs.gzsize @@ -1 +1 @@ -2296 +2297 diff --git a/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize b/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize index 988fde4112c52..98102958a72c9 100644 --- a/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize +++ b/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize @@ -1 +1 @@ -1873 +1874 diff --git a/test/other/codesize/test_codesize_mem_O3.gzsize b/test/other/codesize/test_codesize_mem_O3.gzsize index a4e114468e7e2..da898df886b32 100644 --- a/test/other/codesize/test_codesize_mem_O3.gzsize +++ b/test/other/codesize/test_codesize_mem_O3.gzsize @@ -1 +1 @@ -2327 +2326 diff --git a/test/other/codesize/test_codesize_mem_O3_grow.gzsize b/test/other/codesize/test_codesize_mem_O3_grow.gzsize index 9c251745dda72..fdf0f56cd467c 100644 --- a/test/other/codesize/test_codesize_mem_O3_grow.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_grow.gzsize @@ -1 +1 @@ -2476 +2474 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 d1fc75efc83f6..491c450e95ca7 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 @@ -2177 +2175 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone.gzsize b/test/other/codesize/test_codesize_mem_O3_standalone.gzsize index 1ed292725657e..6a4fd21351996 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_standalone.gzsize @@ -1 +1 @@ -2140 +2141 diff --git a/test/other/codesize/test_codesize_minimal_O0.gzsize b/test/other/codesize/test_codesize_minimal_O0.gzsize index 186aada4a792c..8ce186d95f541 100644 --- a/test/other/codesize/test_codesize_minimal_O0.gzsize +++ b/test/other/codesize/test_codesize_minimal_O0.gzsize @@ -1 +1 @@ -6435 +6443 diff --git a/test/other/codesize/test_codesize_minimal_O2.gzsize b/test/other/codesize/test_codesize_minimal_O2.gzsize index 1eea322546e5a..a3d3785badfdf 100644 --- a/test/other/codesize/test_codesize_minimal_O2.gzsize +++ b/test/other/codesize/test_codesize_minimal_O2.gzsize @@ -1 +1 @@ -1381 +1380 diff --git a/test/other/codesize/test_codesize_minimal_O3.gzsize b/test/other/codesize/test_codesize_minimal_O3.gzsize index 79abba8435fb0..e714efcd7f726 100644 --- a/test/other/codesize/test_codesize_minimal_O3.gzsize +++ b/test/other/codesize/test_codesize_minimal_O3.gzsize @@ -1 +1 @@ -1348 +1347 diff --git a/test/other/codesize/test_codesize_minimal_Os.gzsize b/test/other/codesize/test_codesize_minimal_Os.gzsize index 79abba8435fb0..e714efcd7f726 100644 --- a/test/other/codesize/test_codesize_minimal_Os.gzsize +++ b/test/other/codesize/test_codesize_minimal_Os.gzsize @@ -1 +1 @@ -1348 +1347 diff --git a/test/other/codesize/test_codesize_minimal_Oz.gzsize b/test/other/codesize/test_codesize_minimal_Oz.gzsize index 79abba8435fb0..e714efcd7f726 100644 --- a/test/other/codesize/test_codesize_minimal_Oz.gzsize +++ b/test/other/codesize/test_codesize_minimal_Oz.gzsize @@ -1 +1 @@ -1348 +1347 diff --git a/test/other/codesize/test_codesize_minimal_esm.gzsize b/test/other/codesize/test_codesize_minimal_esm.gzsize index 27600766db2b7..57c7c05238e16 100644 --- a/test/other/codesize/test_codesize_minimal_esm.gzsize +++ b/test/other/codesize/test_codesize_minimal_esm.gzsize @@ -1 +1 @@ -1541 +1542 diff --git a/test/other/codesize/test_codesize_minimal_pthreads.gzsize b/test/other/codesize/test_codesize_minimal_pthreads.gzsize index 025479c9c2a8b..b52fc8a6e1cae 100644 --- a/test/other/codesize/test_codesize_minimal_pthreads.gzsize +++ b/test/other/codesize/test_codesize_minimal_pthreads.gzsize @@ -1 +1 @@ -4190 +4186 diff --git a/test/other/codesize/test_codesize_minimal_wasmfs.gzsize b/test/other/codesize/test_codesize_minimal_wasmfs.gzsize index 79abba8435fb0..e714efcd7f726 100644 --- a/test/other/codesize/test_codesize_minimal_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_minimal_wasmfs.gzsize @@ -1 +1 @@ -1348 +1347 diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size index b588cb625d766..43d94fe09cb52 100644 --- a/test/other/test_unoptimized_code_size.js.size +++ b/test/other/test_unoptimized_code_size.js.size @@ -1 +1 @@ -52853 +52855 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 05aade25bbaae..eaeedc1a5532b 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 @@ -28644 +28646 diff --git a/test/other/test_unoptimized_code_size_strict.js.size b/test/other/test_unoptimized_code_size_strict.js.size index 33c30ad18274c..fd424a6af5731 100644 --- a/test/other/test_unoptimized_code_size_strict.js.size +++ b/test/other/test_unoptimized_code_size_strict.js.size @@ -1 +1 @@ -51636 +51638