From 5805b7b4176444143813147c117979f66628c840 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 7 Jul 2026 21:44:48 +0000 Subject: [PATCH 1/7] Include heap views only when needed Previously, all standard heap views (HEAP8 through HEAPF64) were always included in the JS bundle and initialized, even when unused. This increased bundle size and memory overhead. Remove heap view symbols from default library inclusions. Only include and initialize heap views that are required by runtime features, exported, or referenced in user code and snippets. --- src/jsifier.mjs | 67 +++++++++++++++++++++++++++++++++++++++++++ src/runtime_common.js | 41 +++++++++++++++----------- src/settings.js | 4 +++ tools/emscripten.py | 1 + tools/link.py | 7 ----- 5 files changed, 97 insertions(+), 23 deletions(-) diff --git a/src/jsifier.mjs b/src/jsifier.mjs index 84dc251827b75..5afef3b32fcda 100644 --- a/src/jsifier.mjs +++ b/src/jsifier.mjs @@ -247,12 +247,70 @@ function addImplicitDeps(snippet, deps) { 'runtimeKeepalivePush', 'runtimeKeepalivePop', 'UTF8ToString', + 'getValue', + 'setValue', ]; for (const dep of autoDeps) { if (snippet.includes(dep + '(')) { deps.push('$' + dep); } } + if (snippet.includes('eval(')) { + deps.push('$HEAP8', '$HEAPU8', '$HEAP16', '$HEAPU16', '$HEAP32', '$HEAPU32', '$HEAPF32', '$HEAPF64'); + if (WASM_BIGINT || MEMORY64) { + deps.push('$HEAP64', '$HEAPU64'); + } + } + const heapDeps = [ + 'HEAP8', 'HEAP16', 'HEAPU8', 'HEAPU16', + 'HEAP32', 'HEAPU32', 'HEAPF32', 'HEAPF64', + 'HEAP64', 'HEAPU64', + ]; + for (const heap of heapDeps) { + if (snippet.includes(heap)) { + deps.push('$' + heap); + } + } +} + +// Auto-include heap views and helper symbols required by certain build modes or runtime +// scaffolding files (e.g., postamble.js, runtime_stack_check.js, memoryprofiler.js). +// Because addImplicitDeps only scans library functions and user code (pre-js/post-js/EM_JS), +// runtime scaffolding files that access linear memory directly must have their heap views +// explicitly declared here so they are emitted in the final JS bundle. +function getRequiredHeapSymbols() { + const heaps = new Set(); + if (MAIN_MODULE || EXPORT_ALL || SAFE_HEAP) { + // Dynamic linking side modules, full symbol exports, or safe heap instrumentation + // require all standard heap views and value helpers to be available. + heaps.add('$getValue').add('$setValue'); + heaps.add('$HEAP8').add('$HEAPU8').add('$HEAP16').add('$HEAPU16') + .add('$HEAP32').add('$HEAPU32').add('$HEAPF32').add('$HEAPF64'); + if (WASM_BIGINT || MEMORY64) { + heaps.add('$HEAP64').add('$HEAPU64'); + } + } else { + // STACK_OVERFLOW_CHECK accesses HEAP32/HEAPU32 in runtime_stack_check.js. + // MAIN_READS_PARAMS populates argv pointers in linear memory in postamble.js (callMain). + if (STACK_OVERFLOW_CHECK || (HAS_MAIN && MAIN_READS_PARAMS)) { + heaps.add('$HEAP32').add('$HEAPU32'); + if ((HAS_MAIN && MAIN_READS_PARAMS) && (WASM_BIGINT || MEMORY64)) { + heaps.add('$HEAP64').add('$HEAPU64'); + } + } + // MEMORYPROFILER accesses HEAP8 in memoryprofiler.js. + if (MEMORYPROFILER) { + heaps.add('$HEAP8'); + } + // AUDIO_WORKLET accesses HEAP32, HEAPU32, and HEAPF32 in audio_worklet.js. + if (AUDIO_WORKLET) { + heaps.add('$HEAP32').add('$HEAPU32').add('$HEAPF32'); + if (WASM_BIGINT || MEMORY64) { + heaps.add('$HEAP64').add('$HEAPU64'); + } + } + } + return Array.from(heaps); } function sigToArgs(sig) { @@ -408,6 +466,15 @@ export async function runJSify(outputFile, symbolsOnly) { const symbolsNeeded = DEFAULT_LIBRARY_FUNCS_TO_INCLUDE; symbolsNeeded.push(...extraLibraryFuncs); + symbolsNeeded.push(...getRequiredHeapSymbols()); + + for (const fileName of [...PRE_JS_FILES, ...POST_JS_FILES]) { + const content = readFile(fileName); + addImplicitDeps(content, symbolsNeeded); + } + for (const snippet of EM_JS_SNIPPETS) { + addImplicitDeps(snippet, symbolsNeeded); + } for (const sym of EXPORTED_RUNTIME_METHODS) { if ('$' + sym in LibraryManager.library) { symbolsNeeded.push('$' + sym); diff --git a/src/runtime_common.js b/src/runtime_common.js index f060b54a1bf76..e412a8fe0982d 100644 --- a/src/runtime_common.js +++ b/src/runtime_common.js @@ -28,7 +28,7 @@ // must be updated. function growMemViews() { // `updateMemoryViews` updates all the views simultaneously, so it's enough to check any of them. - if (wasmMemory.buffer != HEAP8.buffer) { + if (typeof HEAP8 != 'undefined' && wasmMemory.buffer != HEAP8.buffer) { updateMemoryViews(); } } @@ -102,13 +102,22 @@ var runtimeExited = false; shouldExport = true; } return shouldExport; - } + }; const maybeExportHeap = (x) => { if (shouldExportHeap(x) && MODULARIZE != 'instance') { return `Module['${x}'] = `; } return ''; }; + const isHeapNeeded = (x) => { + return shouldExportHeap(x) || addedLibraryItems['$' + x]; + }; + const updateHeap = (x, type) => { + if (isHeapNeeded(x)) { + return `${maybeExportHeap(x)}${x} = new ${type}(b);`; + } + return ''; + }; }}} @@ -146,35 +155,35 @@ function getMemoryBuffer() { function updateMemoryViews() { #if RUNTIME_DEBUG - dbg(`updateMemoryViews: first=${!HEAP8} size=${wasmMemory.buffer.byteLength}`); + dbg(`updateMemoryViews: first=${typeof HEAP8 == 'undefined' || !HEAP8} size=${wasmMemory.buffer.byteLength}`); #endif #if ALLOW_MEMORY_GROWTH // If we already have a heap that is resizeable/growable buffer we don't // need to do anything in updateMemoryViews. #if SHARED_MEMORY - if (HEAP8?.buffer?.growable) return; + if (typeof HEAP8 != 'undefined' && HEAP8?.buffer?.growable) return; #else - if (HEAP8?.buffer?.resizable) return; + if (typeof HEAP8 != 'undefined' && HEAP8?.buffer?.resizable) return; #endif var b = getMemoryBuffer(); #else #if ASSERTIONS // When memory growth is disabled this function should be called exactly once. - assert(!HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); + assert(typeof HEAP8 == 'undefined' || !HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); #endif var b = wasmMemory.buffer; #endif - {{{ maybeExportHeap('HEAP8') }}}HEAP8 = new Int8Array(b); - {{{ maybeExportHeap('HEAP16') }}}HEAP16 = new Int16Array(b); - {{{ maybeExportHeap('HEAPU8') }}}HEAPU8 = new Uint8Array(b); - {{{ maybeExportHeap('HEAPU16') }}}HEAPU16 = new Uint16Array(b); - {{{ maybeExportHeap('HEAP32') }}}HEAP32 = new Int32Array(b); - {{{ maybeExportHeap('HEAPU32') }}}HEAPU32 = new Uint32Array(b); - {{{ maybeExportHeap('HEAPF32') }}}HEAPF32 = new Float32Array(b); - {{{ maybeExportHeap('HEAPF64') }}}HEAPF64 = new Float64Array(b); + {{{ updateHeap('HEAP8', 'Int8Array') }}} + {{{ updateHeap('HEAP16', 'Int16Array') }}} + {{{ updateHeap('HEAPU8', 'Uint8Array') }}} + {{{ updateHeap('HEAPU16', 'Uint16Array') }}} + {{{ updateHeap('HEAP32', 'Int32Array') }}} + {{{ updateHeap('HEAPU32', 'Uint32Array') }}} + {{{ updateHeap('HEAPF32', 'Float32Array') }}} + {{{ updateHeap('HEAPF64', 'Float64Array') }}} #if WASM_BIGINT - {{{ maybeExportHeap('HEAP64') }}}HEAP64 = new BigInt64Array(b); - {{{ maybeExportHeap('HEAPU64') }}}HEAPU64 = new BigUint64Array(b); + {{{ updateHeap('HEAP64', 'BigInt64Array') }}} + {{{ updateHeap('HEAPU64', 'BigUint64Array') }}} #endif #if SUPPORT_BIG_ENDIAN {{{ maybeExportHeap('HEAP_DATA_VIEW') }}} HEAP_DATA_VIEW = new DataView(b); diff --git a/src/settings.js b/src/settings.js index 24c88a7be4749..063bbe353a417 100644 --- a/src/settings.js +++ b/src/settings.js @@ -2335,3 +2335,7 @@ var FAKE_DYLIBS = false; // This setting can also be set to a string value, in which case that string // will be used as the #! command to embed in the generated file. var EXECUTABLE = false; + +// Internal setting for passing EM_JS and EM_ASM function code snippets to JSifier. +// [internal] +var EM_JS_SNIPPETS = []; diff --git a/tools/emscripten.py b/tools/emscripten.py index 07be8938baeb3..2d39e0627466a 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -390,6 +390,7 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat asm_consts = create_asm_consts(metadata) em_js_funcs = create_em_js(metadata) + settings.EM_JS_SNIPPETS = em_js_funcs + [f for _, f in asm_consts] if settings.SIDE_MODULE: # When building side modules, validate the EM_ASM and EM_JS string by running diff --git a/tools/link.py b/tools/link.py index db52cd9ced9ba..d336c4d82eae2 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1196,8 +1196,6 @@ def limit_incoming_module_api(): settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += [ '$wasmMemory', - '$HEAP8', '$HEAPU8', '$HEAP16', '$HEAPU16', - '$HEAP32', '$HEAPU32', '$HEAPF32', '$HEAPF64', ] if 'noExitRuntime' in settings.INCOMING_MODULE_JS_API: @@ -1273,8 +1271,6 @@ def limit_incoming_module_api(): # "checkUnflushedContent()" and "missingLibrarySymbol()" depend on warnOnce settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$warnOnce'] - settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$getValue', '$setValue'] - settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$ExitStatus'] if settings.LOAD_SOURCE_MAP: @@ -1573,9 +1569,6 @@ def limit_incoming_module_api(): feature_matrix.auto_enable_features() - if settings.WASM_BIGINT: - settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$HEAP64', '$HEAPU64'] - if settings.AUDIO_WORKLET: add_system_js_lib('libwebaudio.js') settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append('$getWasmTableEntry') From 795396efd94af399d727f721c6798c9a1c7598b2 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 7 Jul 2026 23:21:41 +0000 Subject: [PATCH 2/7] docs --- src/settings.js | 4 ---- src/settings_internal.js | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/settings.js b/src/settings.js index 063bbe353a417..24c88a7be4749 100644 --- a/src/settings.js +++ b/src/settings.js @@ -2335,7 +2335,3 @@ var FAKE_DYLIBS = false; // This setting can also be set to a string value, in which case that string // will be used as the #! command to embed in the generated file. var EXECUTABLE = false; - -// Internal setting for passing EM_JS and EM_ASM function code snippets to JSifier. -// [internal] -var EM_JS_SNIPPETS = []; diff --git a/src/settings_internal.js b/src/settings_internal.js index 3b425fccba8bf..9d5da03a64fc1 100644 --- a/src/settings_internal.js +++ b/src/settings_internal.js @@ -295,5 +295,8 @@ var LOAD_SOURCE_MAP = false; var ALIASES = []; +// Internal setting for passing EM_JS and EM_ASM function code snippets to JSifier. +var EM_JS_SNIPPETS = []; + // List of public setting names (Used by RETAIN_COMPILER_SETTINGS) var PUBLIC_SETTINGS = []; From a96102827c6369fb645915ef416cb1b078f9747e Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Thu, 9 Jul 2026 23:41:33 +0000 Subject: [PATCH 3/7] review comments --- src/jsifier.mjs | 11 ++++++++++- src/runtime_common.js | 10 +++++----- src/settings_internal.js | 5 ++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/jsifier.mjs b/src/jsifier.mjs index 5afef3b32fcda..657d41b1c3e63 100644 --- a/src/jsifier.mjs +++ b/src/jsifier.mjs @@ -255,6 +255,9 @@ function addImplicitDeps(snippet, deps) { deps.push('$' + dep); } } + // If the snippet contains eval(), it may dynamically evaluate strings that reference any + // heap view (e.g., eval('HEAP8[0]')). Since static string matching cannot detect which + // heap views are used inside dynamically evaluated code, we must include all of them. if (snippet.includes('eval(')) { deps.push('$HEAP8', '$HEAPU8', '$HEAP16', '$HEAPU16', '$HEAP32', '$HEAPU32', '$HEAPF32', '$HEAPF64'); if (WASM_BIGINT || MEMORY64) { @@ -309,8 +312,14 @@ function getRequiredHeapSymbols() { heaps.add('$HEAP64').add('$HEAPU64'); } } + // runtime_common.js accesses HEAP8 under ALLOW_MEMORY_GROWTH (to check buffer resizability), + // RUNTIME_DEBUG (to log initial setup), and ASSERTIONS (to guard against re-entrancy when + // ALLOW_MEMORY_GROWTH is 0). + if (ALLOW_MEMORY_GROWTH || RUNTIME_DEBUG || ASSERTIONS) { + heaps.add('$HEAP8'); + } } - return Array.from(heaps); + return heaps; } function sigToArgs(sig) { diff --git a/src/runtime_common.js b/src/runtime_common.js index e412a8fe0982d..91d43dcfae69c 100644 --- a/src/runtime_common.js +++ b/src/runtime_common.js @@ -28,7 +28,7 @@ // must be updated. function growMemViews() { // `updateMemoryViews` updates all the views simultaneously, so it's enough to check any of them. - if (typeof HEAP8 != 'undefined' && wasmMemory.buffer != HEAP8.buffer) { + if (wasmMemory.buffer != HEAP8.buffer) { updateMemoryViews(); } } @@ -155,21 +155,21 @@ function getMemoryBuffer() { function updateMemoryViews() { #if RUNTIME_DEBUG - dbg(`updateMemoryViews: first=${typeof HEAP8 == 'undefined' || !HEAP8} size=${wasmMemory.buffer.byteLength}`); + dbg(`updateMemoryViews: first=${!HEAP8} size=${wasmMemory.buffer.byteLength}`); #endif #if ALLOW_MEMORY_GROWTH // If we already have a heap that is resizeable/growable buffer we don't // need to do anything in updateMemoryViews. #if SHARED_MEMORY - if (typeof HEAP8 != 'undefined' && HEAP8?.buffer?.growable) return; + if (HEAP8?.buffer?.growable) return; #else - if (typeof HEAP8 != 'undefined' && HEAP8?.buffer?.resizable) return; + if (HEAP8?.buffer?.resizable) return; #endif var b = getMemoryBuffer(); #else #if ASSERTIONS // When memory growth is disabled this function should be called exactly once. - assert(typeof HEAP8 == 'undefined' || !HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); + assert(!HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); #endif var b = wasmMemory.buffer; #endif diff --git a/src/settings_internal.js b/src/settings_internal.js index 9d5da03a64fc1..7405b50118136 100644 --- a/src/settings_internal.js +++ b/src/settings_internal.js @@ -295,7 +295,10 @@ var LOAD_SOURCE_MAP = false; var ALIASES = []; -// Internal setting for passing EM_JS and EM_ASM function code snippets to JSifier. +// Internal setting for passing EM_JS and EM_ASM function code snippets to JSifier so that +// implicit heap dependencies (e.g. HEAP8, HEAP32) can be scanned and included automatically +// without needing to search for them in Python. +// This could be removed if/when we require explicit heap dependencies (via EM_JS_DEPS). var EM_JS_SNIPPETS = []; // List of public setting names (Used by RETAIN_COMPILER_SETTINGS) From c95fa7fd159daa3ba61a1ea0f1b343df73c830cc Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Fri, 10 Jul 2026 00:01:23 +0000 Subject: [PATCH 4/7] review comments --- src/jsifier.mjs | 8 +++++--- tools/emscripten.py | 2 +- tools/link.py | 4 +--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/jsifier.mjs b/src/jsifier.mjs index 657d41b1c3e63..ca9b1564ab517 100644 --- a/src/jsifier.mjs +++ b/src/jsifier.mjs @@ -247,6 +247,7 @@ function addImplicitDeps(snippet, deps) { 'runtimeKeepalivePush', 'runtimeKeepalivePop', 'UTF8ToString', + // TODO: Consider removing getValue and setValue if they are rarely used implicitly. 'getValue', 'setValue', ]; @@ -255,9 +256,10 @@ function addImplicitDeps(snippet, deps) { deps.push('$' + dep); } } - // If the snippet contains eval(), it may dynamically evaluate strings that reference any - // heap view (e.g., eval('HEAP8[0]')). Since static string matching cannot detect which - // heap views are used inside dynamically evaluated code, we must include all of them. + // If the snippet contains eval(), it may dynamically evaluate code loaded from memory at runtime + // (for example, in emscripten_run_script where the snippet is eval(UTF8ToString(ptr))). + // Because static string matching cannot inspect what strings are stored in memory or evaluated + // at runtime, we must conservatively include all heap views whenever a snippet uses eval(). if (snippet.includes('eval(')) { deps.push('$HEAP8', '$HEAPU8', '$HEAP16', '$HEAPU16', '$HEAP32', '$HEAPU32', '$HEAPF32', '$HEAPF64'); if (WASM_BIGINT || MEMORY64) { diff --git a/tools/emscripten.py b/tools/emscripten.py index 2d39e0627466a..3b0e9c553249c 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -390,7 +390,7 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat asm_consts = create_asm_consts(metadata) em_js_funcs = create_em_js(metadata) - settings.EM_JS_SNIPPETS = em_js_funcs + [f for _, f in asm_consts] + settings.EM_JS_SNIPPETS = em_js_funcs + [f[1] for f in asm_consts] if settings.SIDE_MODULE: # When building side modules, validate the EM_ASM and EM_JS string by running diff --git a/tools/link.py b/tools/link.py index d336c4d82eae2..5101814e68950 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1194,9 +1194,7 @@ def limit_incoming_module_api(): if prop not in settings.ALL_INCOMING_MODULE_JS_API: diagnostics.warning('unused-command-line-argument', f'invalid entry in INCOMING_MODULE_JS_API: {prop}') - settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += [ - '$wasmMemory', - ] + settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$wasmMemory'] if 'noExitRuntime' in settings.INCOMING_MODULE_JS_API: settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append('$noExitRuntime') From 8132ad003dbc94a6c67c7625ea0e2eec3cd9f068 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Fri, 10 Jul 2026 19:55:09 +0000 Subject: [PATCH 5/7] move to python --- src/jsifier.mjs | 47 --------------------------------------------- tools/emscripten.py | 3 +++ tools/link.py | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/jsifier.mjs b/src/jsifier.mjs index ca9b1564ab517..de51b0d6fd992 100644 --- a/src/jsifier.mjs +++ b/src/jsifier.mjs @@ -278,52 +278,6 @@ function addImplicitDeps(snippet, deps) { } } -// Auto-include heap views and helper symbols required by certain build modes or runtime -// scaffolding files (e.g., postamble.js, runtime_stack_check.js, memoryprofiler.js). -// Because addImplicitDeps only scans library functions and user code (pre-js/post-js/EM_JS), -// runtime scaffolding files that access linear memory directly must have their heap views -// explicitly declared here so they are emitted in the final JS bundle. -function getRequiredHeapSymbols() { - const heaps = new Set(); - if (MAIN_MODULE || EXPORT_ALL || SAFE_HEAP) { - // Dynamic linking side modules, full symbol exports, or safe heap instrumentation - // require all standard heap views and value helpers to be available. - heaps.add('$getValue').add('$setValue'); - heaps.add('$HEAP8').add('$HEAPU8').add('$HEAP16').add('$HEAPU16') - .add('$HEAP32').add('$HEAPU32').add('$HEAPF32').add('$HEAPF64'); - if (WASM_BIGINT || MEMORY64) { - heaps.add('$HEAP64').add('$HEAPU64'); - } - } else { - // STACK_OVERFLOW_CHECK accesses HEAP32/HEAPU32 in runtime_stack_check.js. - // MAIN_READS_PARAMS populates argv pointers in linear memory in postamble.js (callMain). - if (STACK_OVERFLOW_CHECK || (HAS_MAIN && MAIN_READS_PARAMS)) { - heaps.add('$HEAP32').add('$HEAPU32'); - if ((HAS_MAIN && MAIN_READS_PARAMS) && (WASM_BIGINT || MEMORY64)) { - heaps.add('$HEAP64').add('$HEAPU64'); - } - } - // MEMORYPROFILER accesses HEAP8 in memoryprofiler.js. - if (MEMORYPROFILER) { - heaps.add('$HEAP8'); - } - // AUDIO_WORKLET accesses HEAP32, HEAPU32, and HEAPF32 in audio_worklet.js. - if (AUDIO_WORKLET) { - heaps.add('$HEAP32').add('$HEAPU32').add('$HEAPF32'); - if (WASM_BIGINT || MEMORY64) { - heaps.add('$HEAP64').add('$HEAPU64'); - } - } - // runtime_common.js accesses HEAP8 under ALLOW_MEMORY_GROWTH (to check buffer resizability), - // RUNTIME_DEBUG (to log initial setup), and ASSERTIONS (to guard against re-entrancy when - // ALLOW_MEMORY_GROWTH is 0). - if (ALLOW_MEMORY_GROWTH || RUNTIME_DEBUG || ASSERTIONS) { - heaps.add('$HEAP8'); - } - } - return heaps; -} - function sigToArgs(sig) { const args = [] for (var i = 1; i < sig.length; i++) { @@ -477,7 +431,6 @@ export async function runJSify(outputFile, symbolsOnly) { const symbolsNeeded = DEFAULT_LIBRARY_FUNCS_TO_INCLUDE; symbolsNeeded.push(...extraLibraryFuncs); - symbolsNeeded.push(...getRequiredHeapSymbols()); for (const fileName of [...PRE_JS_FILES, ...POST_JS_FILES]) { const content = readFile(fileName); diff --git a/tools/emscripten.py b/tools/emscripten.py index 3b0e9c553249c..df7e1889ab77f 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -30,6 +30,7 @@ extract_metadata, filelock, js_manipulation, + link, shared, utils, webassembly, @@ -155,6 +156,8 @@ def update_settings_glue(wasm_file, metadata, base_metadata): for deps in metadata.js_deps: settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.extend(deps.split(',')) + link.add_required_heap_symbols() + def apply_static_code_hooks(forwarded_json, code): def inject_code_hooks(name): diff --git a/tools/link.py b/tools/link.py index 5101814e68950..4daf89a08b19b 100644 --- a/tools/link.py +++ b/tools/link.py @@ -806,6 +806,49 @@ def setup_cross_origin_storage(): exit_with_error(f"CROSS_ORIGIN_STORAGE_ORIGINS: {o!r} is not a valid HTTPS origin (expected 'https://host' or 'https://host:port')") +def add_required_heap_symbols(): + """Auto-include heap views and helper symbols required by certain build modes or runtime. + + Because addImplicitDeps only scans library functions and user code (pre-js/post-js/EM_JS), + runtime scaffolding files (e.g., postamble.js, runtime_stack_check.js, memoryprofiler.js) + that access linear memory directly must have their heap views explicitly declared here + so they are emitted in the final JS bundle. + """ + heaps = [] + if settings.MAIN_MODULE or settings.EXPORT_ALL or settings.SAFE_HEAP: + # Dynamic linking side modules, full symbol exports, or safe heap instrumentation + # require all standard heap views and value helpers to be available. + heaps += ['$getValue', '$setValue'] + heaps += ['$HEAP8', '$HEAPU8', '$HEAP16', '$HEAPU16', + '$HEAP32', '$HEAPU32', '$HEAPF32', '$HEAPF64'] + if settings.WASM_BIGINT or settings.MEMORY64: + heaps += ['$HEAP64', '$HEAPU64'] + else: + # STACK_OVERFLOW_CHECK accesses HEAP32/HEAPU32 in runtime_stack_check.js. + # MAIN_READS_PARAMS populates argv pointers in linear memory in postamble.js (callMain). + if settings.STACK_OVERFLOW_CHECK or (settings.HAS_MAIN and settings.MAIN_READS_PARAMS): + heaps += ['$HEAP32', '$HEAPU32'] + if (settings.HAS_MAIN and settings.MAIN_READS_PARAMS) and (settings.WASM_BIGINT or settings.MEMORY64): + heaps += ['$HEAP64', '$HEAPU64'] + # MEMORYPROFILER accesses HEAP8 in memoryprofiler.js. + if settings.MEMORYPROFILER: + heaps.append('$HEAP8') + # AUDIO_WORKLET accesses HEAP32, HEAPU32, and HEAPF32 in audio_worklet.js. + if settings.AUDIO_WORKLET: + heaps += ['$HEAP32', '$HEAPU32', '$HEAPF32'] + if settings.WASM_BIGINT or settings.MEMORY64: + heaps += ['$HEAP64', '$HEAPU64'] + # runtime_common.js accesses HEAP8 under ALLOW_MEMORY_GROWTH (to check buffer resizability), + # RUNTIME_DEBUG (to log initial setup), and ASSERTIONS (to guard against re-entrancy when + # ALLOW_MEMORY_GROWTH is 0). + if settings.ALLOW_MEMORY_GROWTH or settings.RUNTIME_DEBUG or settings.ASSERTIONS: + heaps.append('$HEAP8') + + for h in heaps: + if h not in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE: + settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append(h) + + @ToolchainProfiler.profile_block('linker_setup') def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915 """Future modifications should consider refactoring to reduce complexity. @@ -1848,6 +1891,7 @@ def get_full_import_name(name): if settings.USE_CLOSURE_COMPILER or not settings.MINIFY_WHITESPACE: settings.MAYBE_CLOSURE_COMPILER = 1 + add_required_heap_symbols() check_settings() return target, wasm_target From af17009590eb892c1c65f45b2d2ec4b23ee9aec1 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 14 Jul 2026 21:39:56 +0000 Subject: [PATCH 6/7] review comments --- tools/emscripten.py | 12 +++++++++--- tools/link.py | 5 +---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tools/emscripten.py b/tools/emscripten.py index df7e1889ab77f..f021800ba1995 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -30,7 +30,6 @@ extract_metadata, filelock, js_manipulation, - link, shared, utils, webassembly, @@ -148,6 +147,15 @@ def update_settings_glue(wasm_file, metadata, base_metadata): # callMain depends on this library function settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$stringToUTF8OnStack'] + # Add heap views required by callMain/MAIN_READS_PARAMS + if settings.HAS_MAIN and settings.MAIN_READS_PARAMS: + heaps = ['$HEAP32', '$HEAPU32'] + if settings.WASM_BIGINT or settings.MEMORY64: + heaps += ['$HEAP64', '$HEAPU64'] + for h in heaps: + if h not in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE: + settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append(h) + if settings.STACK_OVERFLOW_CHECK and not settings.SIDE_MODULE: # writeStackCookie and checkStackCookie both rely on emscripten_stack_get_end being # exported. In theory it should always be present since its defined in compiler-rt. @@ -156,8 +164,6 @@ def update_settings_glue(wasm_file, metadata, base_metadata): for deps in metadata.js_deps: settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.extend(deps.split(',')) - link.add_required_heap_symbols() - def apply_static_code_hooks(forwarded_json, code): def inject_code_hooks(name): diff --git a/tools/link.py b/tools/link.py index 4daf89a08b19b..2d409dd92a2bd 100644 --- a/tools/link.py +++ b/tools/link.py @@ -825,11 +825,8 @@ def add_required_heap_symbols(): heaps += ['$HEAP64', '$HEAPU64'] else: # STACK_OVERFLOW_CHECK accesses HEAP32/HEAPU32 in runtime_stack_check.js. - # MAIN_READS_PARAMS populates argv pointers in linear memory in postamble.js (callMain). - if settings.STACK_OVERFLOW_CHECK or (settings.HAS_MAIN and settings.MAIN_READS_PARAMS): + if settings.STACK_OVERFLOW_CHECK: heaps += ['$HEAP32', '$HEAPU32'] - if (settings.HAS_MAIN and settings.MAIN_READS_PARAMS) and (settings.WASM_BIGINT or settings.MEMORY64): - heaps += ['$HEAP64', '$HEAPU64'] # MEMORYPROFILER accesses HEAP8 in memoryprofiler.js. if settings.MEMORYPROFILER: heaps.append('$HEAP8') From a26ce32bdfa20a48fcb4b59b1d41d3cc6c33625c Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 14 Jul 2026 21:58:05 +0000 Subject: [PATCH 7/7] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (61) test expectation files were updated by running the tests with `--rebaseline`: ``` test/codesize/audio_worklet_wasm.expected.js updated test/codesize/hello_wasm_worker_wasm.expected.js updated test/codesize/hello_world_wasm.expected.js updated test/codesize/hello_world_wasm2js.expected.js updated codesize/test_codesize_cxx_ctors1.json: 151884 => 151784 [-100 bytes / -0.07%] codesize/test_codesize_cxx_ctors2.json: 151287 => 151187 [-100 bytes / -0.07%] codesize/test_codesize_cxx_except.json: 195773 => 195674 [-99 bytes / -0.05%] codesize/test_codesize_cxx_except_wasm.json: 167008 => 166908 [-100 bytes / -0.06%] codesize/test_codesize_cxx_except_wasm_legacy.json: 164892 => 164792 [-100 bytes / -0.06%] codesize/test_codesize_cxx_lto.json: 120735 => 120635 [-100 bytes / -0.08%] codesize/test_codesize_cxx_mangle.json: 262251 => 262152 [-99 bytes / -0.04%] codesize/test_codesize_cxx_noexcept.json: 153884 => 153784 [-100 bytes / -0.06%] codesize/test_codesize_cxx_wasmfs.json: 179507 => 179386 [-121 bytes / -0.07%] test/codesize/test_codesize_file_preload.expected.js updated codesize/test_codesize_file_preload.json: 23969 => 23870 [-99 bytes / -0.41%] codesize/test_codesize_files_js_fs.json: 18352 => 18253 [-99 bytes / -0.54%] codesize/test_codesize_files_wasmfs.json: 63764 => 63585 [-179 bytes / -0.28%] codesize/test_codesize_hello_O0.json: 38794 => 38644 [-150 bytes / -0.39%] codesize/test_codesize_hello_O1.json: 8261 => 8066 [-195 bytes / -2.36%] codesize/test_codesize_hello_O2.json: 5927 => 5771 [-156 bytes / -2.63%] codesize/test_codesize_hello_O3.json: 5622 => 5467 [-155 bytes / -2.76%] codesize/test_codesize_hello_Os.json: 5610 => 5455 [-155 bytes / -2.76%] codesize/test_codesize_hello_Oz.json: 4781 => 4626 [-155 bytes / -3.24%] codesize/test_codesize_hello_export_nothing.json: 2899 => 2685 [-214 bytes / -7.38%] codesize/test_codesize_hello_single_file.json: 5008 => 4853 [-155 bytes / -3.10%] codesize/test_codesize_hello_wasmfs.json: 5622 => 5467 [-155 bytes / -2.76%] codesize/test_codesize_libcxxabi_message_O3.json: 3312 => 3099 [-213 bytes / -6.43%] codesize/test_codesize_libcxxabi_message_O3_standalone.json: 3493 => 3380 [-113 bytes / -3.24%] codesize/test_codesize_mem_O3.json: 9290 => 9196 [-94 bytes / -1.01%] codesize/test_codesize_mem_O3_grow.json: 9608 => 9531 [-77 bytes / -0.80%] codesize/test_codesize_mem_O3_grow_standalone.json: 9454 => 9359 [-95 bytes / -1.00%] codesize/test_codesize_mem_O3_standalone.json: 9289 => 9193 [-96 bytes / -1.03%] codesize/test_codesize_mem_O3_standalone_lib.json: 8503 => 8390 [-113 bytes / -1.33%] codesize/test_codesize_mem_O3_standalone_narg.json: 8625 => 8512 [-113 bytes / -1.31%] codesize/test_codesize_mem_O3_standalone_narg_flto.json: 7556 => 7443 [-113 bytes / -1.50%] codesize/test_codesize_minimal_64.json: 2600 => 2388 [-212 bytes / -8.15%] test/codesize/test_codesize_minimal_O0.expected.js updated codesize/test_codesize_minimal_O0.json: 19872 => 19713 [-159 bytes / -0.80%] codesize/test_codesize_minimal_O1.json: 3376 => 3119 [-257 bytes / -7.61%] codesize/test_codesize_minimal_O2.json: 2549 => 2332 [-217 bytes / -8.51%] codesize/test_codesize_minimal_O3.json: 2285 => 2073 [-212 bytes / -9.28%] codesize/test_codesize_minimal_Os.json: 2285 => 2073 [-212 bytes / -9.28%] codesize/test_codesize_minimal_Os_mr.json: 577 => 353 [-224 bytes / -38.82%] codesize/test_codesize_minimal_Oz-ctors.json: 2256 => 2044 [-212 bytes / -9.40%] codesize/test_codesize_minimal_Oz.json: 2285 => 2073 [-212 bytes / -9.28%] codesize/test_codesize_minimal_esm.json: 2423 => 2212 [-211 bytes / -8.71%] codesize/test_codesize_minimal_pthreads.json: 26063 => 25967 [-96 bytes / -0.37%] codesize/test_codesize_minimal_pthreads_memgrowth.json: 26498 => 26419 [-79 bytes / -0.30%] codesize/test_codesize_minimal_wasmfs.json: 2285 => 2073 [-212 bytes / -9.28%] codesize/test_minimal_runtime_code_size_hello_embind.json: 14911 => 14911 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_hello_embind_val.json: 11638 => 11638 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_hello_wasm_worker.json: 4121 => 4099 [-22 bytes / -0.53%] codesize/test_minimal_runtime_code_size_hello_webgl2_wasm2js.json: 18559 => 18559 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json: 15040 => 15040 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_hello_webgl_wasm.json: 12724 => 12724 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_hello_world_wasm.json: 927 => 927 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_random_printf_wasm.json: 11054 => 11054 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json: 17417 => 17417 [+0 bytes / +0.00%] test/codesize/test_small_js_flags.expected.js updated codesize/test_small_js_flags.json: 3888 => 3732 [-156 bytes / -4.01%] codesize/test_unoptimized_code_size.json: 177802 => 172449 [-5353 bytes / -3.01%] Average change: -3.23% (-38.82% - +0.00%) ``` --- test/codesize/audio_worklet_wasm.expected.js | 2 +- .../hello_wasm_worker_wasm.expected.js | 75 +++++++++-------- test/codesize/hello_world_wasm.expected.js | 14 ++-- test/codesize/hello_world_wasm2js.expected.js | 8 +- test/codesize/test_codesize_cxx_ctors1.json | 8 +- test/codesize/test_codesize_cxx_ctors2.json | 8 +- test/codesize/test_codesize_cxx_except.json | 8 +- .../test_codesize_cxx_except_wasm.json | 8 +- .../test_codesize_cxx_except_wasm_legacy.json | 8 +- test/codesize/test_codesize_cxx_lto.json | 8 +- test/codesize/test_codesize_cxx_mangle.json | 8 +- test/codesize/test_codesize_cxx_noexcept.json | 8 +- test/codesize/test_codesize_cxx_wasmfs.json | 8 +- .../test_codesize_file_preload.expected.js | 35 +++----- test/codesize/test_codesize_file_preload.json | 8 +- test/codesize/test_codesize_files_js_fs.json | 8 +- test/codesize/test_codesize_files_wasmfs.json | 8 +- test/codesize/test_codesize_hello_O0.json | 8 +- test/codesize/test_codesize_hello_O1.json | 8 +- test/codesize/test_codesize_hello_O2.json | 8 +- test/codesize/test_codesize_hello_O3.json | 8 +- test/codesize/test_codesize_hello_Os.json | 8 +- test/codesize/test_codesize_hello_Oz.json | 8 +- .../test_codesize_hello_export_nothing.json | 8 +- .../test_codesize_hello_single_file.json | 4 +- test/codesize/test_codesize_hello_wasmfs.json | 8 +- .../test_codesize_libcxxabi_message_O3.json | 8 +- ...esize_libcxxabi_message_O3_standalone.json | 8 +- test/codesize/test_codesize_mem_O3.json | 8 +- test/codesize/test_codesize_mem_O3_grow.json | 8 +- .../test_codesize_mem_O3_grow_standalone.json | 8 +- .../test_codesize_mem_O3_standalone.json | 8 +- .../test_codesize_mem_O3_standalone_lib.json | 8 +- .../test_codesize_mem_O3_standalone_narg.json | 8 +- ..._codesize_mem_O3_standalone_narg_flto.json | 8 +- test/codesize/test_codesize_minimal_64.json | 8 +- .../test_codesize_minimal_O0.expected.js | 80 +++---------------- test/codesize/test_codesize_minimal_O0.json | 8 +- test/codesize/test_codesize_minimal_O1.json | 8 +- test/codesize/test_codesize_minimal_O2.json | 8 +- test/codesize/test_codesize_minimal_O3.json | 8 +- test/codesize/test_codesize_minimal_Os.json | 8 +- .../codesize/test_codesize_minimal_Os_mr.json | 8 +- .../test_codesize_minimal_Oz-ctors.json | 8 +- test/codesize/test_codesize_minimal_Oz.json | 8 +- test/codesize/test_codesize_minimal_esm.json | 8 +- .../test_codesize_minimal_pthreads.json | 8 +- ...t_codesize_minimal_pthreads_memgrowth.json | 8 +- .../test_codesize_minimal_wasmfs.json | 8 +- ...inimal_runtime_code_size_hello_embind.json | 4 +- ...al_runtime_code_size_hello_embind_val.json | 4 +- ...l_runtime_code_size_hello_wasm_worker.json | 8 +- ...untime_code_size_hello_webgl2_wasm2js.json | 4 +- ...ode_size_hello_webgl2_wasm_singlefile.json | 2 +- ...al_runtime_code_size_hello_webgl_wasm.json | 4 +- ...al_runtime_code_size_hello_world_wasm.json | 4 +- ..._runtime_code_size_random_printf_wasm.json | 2 +- ...ntime_code_size_random_printf_wasm2js.json | 2 +- test/codesize/test_small_js_flags.expected.js | 32 +------- test/codesize/test_small_js_flags.json | 8 +- test/codesize/test_unoptimized_code_size.json | 16 ++-- 61 files changed, 270 insertions(+), 374 deletions(-) diff --git a/test/codesize/audio_worklet_wasm.expected.js b/test/codesize/audio_worklet_wasm.expected.js index 9ed7b1108c88e..52cebda2389a7 100644 --- a/test/codesize/audio_worklet_wasm.expected.js +++ b/test/codesize/audio_worklet_wasm.expected.js @@ -1,4 +1,4 @@ -var m = globalThis.Module || typeof Module != "undefined" ? Module : {}, r = !!globalThis.WorkerGlobalScope, t = !!globalThis.AudioWorkletGlobalScope, u = globalThis.name == "em-ww" || t, v, K, E, G, J, x, W, P, F, D, C, X, A, Z, H; +var m = globalThis.Module || typeof Module != "undefined" ? Module : {}, r = !!globalThis.WorkerGlobalScope, t = !!globalThis.AudioWorkletGlobalScope, u = globalThis.name == "em-ww" || t, v, K, E, G, x, J, W, P, F, D, C, X, A, Z, H; function w(a) { v = a; diff --git a/test/codesize/hello_wasm_worker_wasm.expected.js b/test/codesize/hello_wasm_worker_wasm.expected.js index a212f66c66b87..5fc571366f86b 100644 --- a/test/codesize/hello_wasm_worker_wasm.expected.js +++ b/test/codesize/hello_wasm_worker_wasm.expected.js @@ -1,80 +1,77 @@ -var c = Module, d = !!globalThis.WorkerGlobalScope, e = globalThis.name == "em-ww", f, g, C, q, D, m, E, v; +var c = Module, d = !!globalThis.WorkerGlobalScope, e = globalThis.name == "em-ww", f, g, B, p, C, l, D, u; e && (onmessage = a => { onmessage = null; f = a = a.data; g = a.o; - h(); c ||= {}; c.wasm = a.m; - k(); + h(); a.m = a.o = 0; }); -function h() {} - e || (g = new WebAssembly.Memory({ initial: 256, maximum: 256, shared: !0 -}), h()); +})); -var l = [], n = a => { +var k = [], m = a => { a = a.data; var b = a._wsc; - b && m.get(b)(...a.x); -}, p = a => { - l.push(a); -}, r = () => { - q(0, !d, !e, d && 1); -}, u = {}, w = (a, b, z) => { - var t = u[a] = new Worker(c.js, { + b && l.get(b)(...a.x); +}, n = a => { + k.push(a); +}, q = () => { + p(0, !d, !e, d && 1); +}, t = {}, v = (a, b, y) => { + var r = t[a] = new Worker(c.js, { name: "em-ww" }); - t.postMessage({ + r.postMessage({ A: a, - m: v, + m: u, o: g, u: b, - v: z + v: y }); - t.onmessage = n; + r.onmessage = m; return !0; -}, x = () => performance.now(), y = () => !1, A = (a, b) => { - u[a].postMessage({ +}, w = () => performance.now(), x = () => !1, z = (a, b) => { + t[a].postMessage({ _wsc: b, x: [] }); }; -e && (u[0] = globalThis, addEventListener("message", p)); +e && (t[0] = globalThis, addEventListener("message", n)); -function B() { +function A() { console.log("Hello from wasm worker!"); } -function k() { - E = { - d: r, - c: w, - b: x, - e: y, - f: A, - g: B, +function h() { + D = { + d: q, + c: v, + b: w, + e: x, + f: z, + g: A, a: g }; WebAssembly.instantiate(c.wasm, { - a: E + a: D }).then((a => { var b = (a.instance || a).exports; - v = a.module || c.wasm; - C = b.i; - q = b.k; - D = b.l; - m = b.j; - e ? (D(f.A, f.u, f.v), removeEventListener("message", p), l = l.forEach(n), addEventListener("message", n)) : b.h(); - e || C(); + u = a.module || c.wasm; + B = b.i; + p = b.k; + C = b.l; + l = b.j; + e ? (C(f.A, f.u, f.v), removeEventListener("message", n), k = k.forEach(m), addEventListener("message", m)) : b.h(); + e || B(); })); } -e || k(); \ No newline at end of file +e || h(); \ No newline at end of file diff --git a/test/codesize/hello_world_wasm.expected.js b/test/codesize/hello_world_wasm.expected.js index cb72d2838de31..1cd54e114ae98 100644 --- a/test/codesize/hello_world_wasm.expected.js +++ b/test/codesize/hello_world_wasm.expected.js @@ -1,21 +1,21 @@ -var d = Module, e, f = new TextDecoder, g, h; +var c = Module, d = new TextDecoder, e, f, h; -WebAssembly.instantiate(d.wasm, { +WebAssembly.instantiate(c.wasm, { a: { a: a => { - var c = console, k = c.log; + var g = console, k = g.log; if (a) { for (var b = a, l = e, m = b + NaN; l[b] && !(b >= m); ) ++b; - a = f.decode(e.subarray(a, b)); + a = d.decode(e.subarray(a, b)); } else a = ""; - k.call(c, a); + k.call(g, a); } } }).then((a => { a = a.instance.exports; - g = a.d; + f = a.d; h = a.b; e = new Uint8Array(h.buffer); a.c(); - g(); + f(); })); \ No newline at end of file diff --git a/test/codesize/hello_world_wasm2js.expected.js b/test/codesize/hello_world_wasm2js.expected.js index d23d8bf32480c..5593170066940 100644 --- a/test/codesize/hello_world_wasm2js.expected.js +++ b/test/codesize/hello_world_wasm2js.expected.js @@ -1,4 +1,4 @@ -var d = Module, g, h = new TextDecoder, k, l; +var d = Module, g = new TextDecoder, h, k, l; function e(a) { this.exports = function(q) { @@ -48,8 +48,8 @@ function e(a) { a: a => { var q = console, u = q.log; if (a) { - for (var n = a, c = g, f = n + void 0; c[n] && !(n >= f); ) ++n; - a = h.decode(g.subarray(a, n)); + for (var n = a, c = h, f = n + void 0; c[n] && !(n >= f); ) ++n; + a = g.decode(h.subarray(a, n)); } else a = ""; u.call(q, a); } @@ -58,7 +58,7 @@ function e(a) { a = a.instance.exports; k = a.d; l = a.b; - g = new Uint8Array(l.buffer); + h = new Uint8Array(l.buffer); a.c(); k(); })); \ No newline at end of file diff --git a/test/codesize/test_codesize_cxx_ctors1.json b/test/codesize/test_codesize_cxx_ctors1.json index 76984e799dfe5..7f63cdd8e8727 100644 --- a/test/codesize/test_codesize_cxx_ctors1.json +++ b/test/codesize/test_codesize_cxx_ctors1.json @@ -1,10 +1,10 @@ { - "a.out.js": 19328, - "a.out.js.gz": 8148, + "a.out.js": 19228, + "a.out.js.gz": 8122, "a.out.nodebug.wasm": 132556, "a.out.nodebug.wasm.gz": 49942, - "total": 151884, - "total_gz": 58090, + "total": 151784, + "total_gz": 58064, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_ctors2.json b/test/codesize/test_codesize_cxx_ctors2.json index a881fb94ddbc6..f9e9a9c9e00e0 100644 --- a/test/codesize/test_codesize_cxx_ctors2.json +++ b/test/codesize/test_codesize_cxx_ctors2.json @@ -1,10 +1,10 @@ { - "a.out.js": 19305, - "a.out.js.gz": 8131, + "a.out.js": 19205, + "a.out.js.gz": 8105, "a.out.nodebug.wasm": 131982, "a.out.nodebug.wasm.gz": 49600, - "total": 151287, - "total_gz": 57731, + "total": 151187, + "total_gz": 57705, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_except.json b/test/codesize/test_codesize_cxx_except.json index 84ade4de60667..2d51fba18fdef 100644 --- a/test/codesize/test_codesize_cxx_except.json +++ b/test/codesize/test_codesize_cxx_except.json @@ -1,10 +1,10 @@ { - "a.out.js": 23307, - "a.out.js.gz": 9134, + "a.out.js": 23208, + "a.out.js.gz": 9114, "a.out.nodebug.wasm": 172466, "a.out.nodebug.wasm.gz": 57476, - "total": 195773, - "total_gz": 66610, + "total": 195674, + "total_gz": 66590, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_except_wasm.json b/test/codesize/test_codesize_cxx_except_wasm.json index e29fceeeec624..f2f32a3a38de4 100644 --- a/test/codesize/test_codesize_cxx_except_wasm.json +++ b/test/codesize/test_codesize_cxx_except_wasm.json @@ -1,10 +1,10 @@ { - "a.out.js": 19127, - "a.out.js.gz": 8063, + "a.out.js": 19027, + "a.out.js.gz": 8035, "a.out.nodebug.wasm": 147881, "a.out.nodebug.wasm.gz": 55368, - "total": 167008, - "total_gz": 63431, + "total": 166908, + "total_gz": 63403, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/codesize/test_codesize_cxx_except_wasm_legacy.json b/test/codesize/test_codesize_cxx_except_wasm_legacy.json index 86b4d2349bce9..253031eccb31a 100644 --- a/test/codesize/test_codesize_cxx_except_wasm_legacy.json +++ b/test/codesize/test_codesize_cxx_except_wasm_legacy.json @@ -1,10 +1,10 @@ { - "a.out.js": 19205, - "a.out.js.gz": 8089, + "a.out.js": 19105, + "a.out.js.gz": 8060, "a.out.nodebug.wasm": 145687, "a.out.nodebug.wasm.gz": 54986, - "total": 164892, - "total_gz": 63075, + "total": 164792, + "total_gz": 63046, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/codesize/test_codesize_cxx_lto.json b/test/codesize/test_codesize_cxx_lto.json index bc412d0722de8..0c866d71aa93d 100644 --- a/test/codesize/test_codesize_cxx_lto.json +++ b/test/codesize/test_codesize_cxx_lto.json @@ -1,10 +1,10 @@ { - "a.out.js": 18672, - "a.out.js.gz": 7841, + "a.out.js": 18572, + "a.out.js.gz": 7817, "a.out.nodebug.wasm": 102063, "a.out.nodebug.wasm.gz": 39527, - "total": 120735, - "total_gz": 47368, + "total": 120635, + "total_gz": 47344, "sent": [ "a (emscripten_resize_heap)", "b (_setitimer_js)", diff --git a/test/codesize/test_codesize_cxx_mangle.json b/test/codesize/test_codesize_cxx_mangle.json index 3232c30bb0e46..be9c992937f9c 100644 --- a/test/codesize/test_codesize_cxx_mangle.json +++ b/test/codesize/test_codesize_cxx_mangle.json @@ -1,10 +1,10 @@ { - "a.out.js": 23357, - "a.out.js.gz": 9153, + "a.out.js": 23258, + "a.out.js.gz": 9134, "a.out.nodebug.wasm": 238894, "a.out.nodebug.wasm.gz": 79813, - "total": 262251, - "total_gz": 88966, + "total": 262152, + "total_gz": 88947, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_noexcept.json b/test/codesize/test_codesize_cxx_noexcept.json index ce0a95b981a64..f87d475b5bbfc 100644 --- a/test/codesize/test_codesize_cxx_noexcept.json +++ b/test/codesize/test_codesize_cxx_noexcept.json @@ -1,10 +1,10 @@ { - "a.out.js": 19328, - "a.out.js.gz": 8148, + "a.out.js": 19228, + "a.out.js.gz": 8122, "a.out.nodebug.wasm": 134556, "a.out.nodebug.wasm.gz": 50786, - "total": 153884, - "total_gz": 58934, + "total": 153784, + "total_gz": 58908, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index 4a243a7b662fe..9d96b1b15c8f9 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 6725, - "a.out.js.gz": 3184, + "a.out.js": 6604, + "a.out.js.gz": 3154, "a.out.nodebug.wasm": 172782, "a.out.nodebug.wasm.gz": 63335, - "total": 179507, - "total_gz": 66519, + "total": 179386, + "total_gz": 66489, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_file_preload.expected.js b/test/codesize/test_codesize_file_preload.expected.js index d364a4d198491..04a321132d71e 100644 --- a/test/codesize/test_codesize_file_preload.expected.js +++ b/test/codesize/test_codesize_file_preload.expected.js @@ -315,15 +315,10 @@ var runtimeInitialized = false; function updateMemoryViews() { var b = wasmMemory.buffer; HEAP8 = new Int8Array(b); - HEAP16 = new Int16Array(b); HEAPU8 = new Uint8Array(b); - HEAPU16 = new Uint16Array(b); HEAP32 = new Int32Array(b); HEAPU32 = new Uint32Array(b); - HEAPF32 = new Float32Array(b); - HEAPF64 = new Float64Array(b); HEAP64 = new BigInt64Array(b); - HEAPU64 = new BigUint64Array(b); } // include: memoryprofiler.js @@ -482,26 +477,6 @@ class ExitStatus { } } -/** @type {!Int16Array} */ var HEAP16; - -/** @type {!Int32Array} */ var HEAP32; - -/** not-@type {!BigInt64Array} */ var HEAP64; - -/** @type {!Int8Array} */ var HEAP8; - -/** @type {!Float32Array} */ var HEAPF32; - -/** @type {!Float64Array} */ var HEAPF64; - -/** @type {!Uint16Array} */ var HEAPU16; - -/** @type {!Uint32Array} */ var HEAPU32; - -/** not-@type {!BigUint64Array} */ var HEAPU64; - -/** @type {!Uint8Array} */ var HEAPU8; - var callRuntimeCallbacks = callbacks => { while (callbacks.length > 0) { // Pass the module as the first argument. @@ -511,6 +486,12 @@ var callRuntimeCallbacks = callbacks => { var onPreRuns = []; +/** @type {!Int8Array} */ var HEAP8; + +/** @type {!Uint8Array} */ var HEAPU8; + +/** @type {!Uint32Array} */ var HEAPU32; + /** @param {number=} offset */ var doWritev = (stream, iov, iovcnt, offset) => { // Gather all iovecs into one contiguous buffer and issue a single // FS.write, matching POSIX writev's single gather-write semantics (as @@ -3068,6 +3049,10 @@ var FS = { * @return {string} */ var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : ""; +/** @type {!Int32Array} */ var HEAP32; + +/** not-@type {!BigInt64Array} */ var HEAP64; + var SYSCALLS = { currentUmask: 18, calculateAt(dirfd, path, allowEmpty) { diff --git a/test/codesize/test_codesize_file_preload.json b/test/codesize/test_codesize_file_preload.json index f81e231f27041..43aefe571dd8a 100644 --- a/test/codesize/test_codesize_file_preload.json +++ b/test/codesize/test_codesize_file_preload.json @@ -1,10 +1,10 @@ { - "a.out.js": 22303, - "a.out.js.gz": 9284, + "a.out.js": 22204, + "a.out.js.gz": 9264, "a.out.nodebug.wasm": 1666, "a.out.nodebug.wasm.gz": 945, - "total": 23969, - "total_gz": 10229, + "total": 23870, + "total_gz": 10209, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_files_js_fs.json b/test/codesize/test_codesize_files_js_fs.json index 83cc5418965f0..51305d3167d94 100644 --- a/test/codesize/test_codesize_files_js_fs.json +++ b/test/codesize/test_codesize_files_js_fs.json @@ -1,10 +1,10 @@ { - "a.out.js": 17971, - "a.out.js.gz": 7480, + "a.out.js": 17872, + "a.out.js.gz": 7464, "a.out.nodebug.wasm": 381, "a.out.nodebug.wasm.gz": 258, - "total": 18352, - "total_gz": 7738, + "total": 18253, + "total_gz": 7722, "sent": [ "a (fd_write)", "b (fd_read)", diff --git a/test/codesize/test_codesize_files_wasmfs.json b/test/codesize/test_codesize_files_wasmfs.json index bb886c6dc297a..b7442014fc01c 100644 --- a/test/codesize/test_codesize_files_wasmfs.json +++ b/test/codesize/test_codesize_files_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 5158, - "a.out.js.gz": 2458, + "a.out.js": 4979, + "a.out.js.gz": 2409, "a.out.nodebug.wasm": 58606, "a.out.nodebug.wasm.gz": 18406, - "total": 63764, - "total_gz": 20864, + "total": 63585, + "total_gz": 20815, "sent": [ "a (emscripten_date_now)", "b (emscripten_err)", diff --git a/test/codesize/test_codesize_hello_O0.json b/test/codesize/test_codesize_hello_O0.json index 7a6749f3c294e..99ff6931579e0 100644 --- a/test/codesize/test_codesize_hello_O0.json +++ b/test/codesize/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 23679, - "a.out.js.gz": 8604, + "a.out.js": 23529, + "a.out.js.gz": 8574, "a.out.nodebug.wasm": 15115, "a.out.nodebug.wasm.gz": 7464, - "total": 38794, - "total_gz": 16068, + "total": 38644, + "total_gz": 16038, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O1.json b/test/codesize/test_codesize_hello_O1.json index a1aad3d6c2fd1..be7c4fe9daa15 100644 --- a/test/codesize/test_codesize_hello_O1.json +++ b/test/codesize/test_codesize_hello_O1.json @@ -1,10 +1,10 @@ { - "a.out.js": 5717, - "a.out.js.gz": 2279, + "a.out.js": 5522, + "a.out.js.gz": 2239, "a.out.nodebug.wasm": 2544, "a.out.nodebug.wasm.gz": 1436, - "total": 8261, - "total_gz": 3715, + "total": 8066, + "total_gz": 3675, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O2.json b/test/codesize/test_codesize_hello_O2.json index b42281069ef1f..ba874758500df 100644 --- a/test/codesize/test_codesize_hello_O2.json +++ b/test/codesize/test_codesize_hello_O2.json @@ -1,10 +1,10 @@ { - "a.out.js": 4015, - "a.out.js.gz": 2014, + "a.out.js": 3859, + "a.out.js.gz": 1970, "a.out.nodebug.wasm": 1912, "a.out.nodebug.wasm.gz": 1129, - "total": 5927, - "total_gz": 3143, + "total": 5771, + "total_gz": 3099, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O3.json b/test/codesize/test_codesize_hello_O3.json index 4b0f47f84662e..be2ba272d7006 100644 --- a/test/codesize/test_codesize_hello_O3.json +++ b/test/codesize/test_codesize_hello_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 3956, - "a.out.js.gz": 1971, + "a.out.js": 3801, + "a.out.js.gz": 1928, "a.out.nodebug.wasm": 1666, "a.out.nodebug.wasm.gz": 945, - "total": 5622, - "total_gz": 2916, + "total": 5467, + "total_gz": 2873, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_Os.json b/test/codesize/test_codesize_hello_Os.json index f47b9a846859a..71749bb323745 100644 --- a/test/codesize/test_codesize_hello_Os.json +++ b/test/codesize/test_codesize_hello_Os.json @@ -1,10 +1,10 @@ { - "a.out.js": 3956, - "a.out.js.gz": 1971, + "a.out.js": 3801, + "a.out.js.gz": 1928, "a.out.nodebug.wasm": 1654, "a.out.nodebug.wasm.gz": 953, - "total": 5610, - "total_gz": 2924, + "total": 5455, + "total_gz": 2881, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_Oz.json b/test/codesize/test_codesize_hello_Oz.json index 3892ef01ed941..85d5d192a160a 100644 --- a/test/codesize/test_codesize_hello_Oz.json +++ b/test/codesize/test_codesize_hello_Oz.json @@ -1,10 +1,10 @@ { - "a.out.js": 3593, - "a.out.js.gz": 1776, + "a.out.js": 3438, + "a.out.js.gz": 1732, "a.out.nodebug.wasm": 1188, "a.out.nodebug.wasm.gz": 731, - "total": 4781, - "total_gz": 2507, + "total": 4626, + "total_gz": 2463, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_export_nothing.json b/test/codesize/test_codesize_hello_export_nothing.json index 92943bc741178..c4012b3373c4f 100644 --- a/test/codesize/test_codesize_hello_export_nothing.json +++ b/test/codesize/test_codesize_hello_export_nothing.json @@ -1,10 +1,10 @@ { - "a.out.js": 2856, - "a.out.js.gz": 1359, + "a.out.js": 2642, + "a.out.js.gz": 1290, "a.out.nodebug.wasm": 43, "a.out.nodebug.wasm.gz": 59, - "total": 2899, - "total_gz": 1418, + "total": 2685, + "total_gz": 1349, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_hello_single_file.json b/test/codesize/test_codesize_hello_single_file.json index c8a0a2a0ac36e..5903fc859d0f6 100644 --- a/test/codesize/test_codesize_hello_single_file.json +++ b/test/codesize/test_codesize_hello_single_file.json @@ -1,6 +1,6 @@ { - "a.out.js": 5008, - "a.out.js.gz": 2793, + "a.out.js": 4853, + "a.out.js.gz": 2750, "sent": [ "a (fd_write)" ] diff --git a/test/codesize/test_codesize_hello_wasmfs.json b/test/codesize/test_codesize_hello_wasmfs.json index 4b0f47f84662e..be2ba272d7006 100644 --- a/test/codesize/test_codesize_hello_wasmfs.json +++ b/test/codesize/test_codesize_hello_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 3956, - "a.out.js.gz": 1971, + "a.out.js": 3801, + "a.out.js.gz": 1928, "a.out.nodebug.wasm": 1666, "a.out.nodebug.wasm.gz": 945, - "total": 5622, - "total_gz": 2916, + "total": 5467, + "total_gz": 2873, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_libcxxabi_message_O3.json b/test/codesize/test_codesize_libcxxabi_message_O3.json index 767a0d4b776fe..a3d564f5f2563 100644 --- a/test/codesize/test_codesize_libcxxabi_message_O3.json +++ b/test/codesize/test_codesize_libcxxabi_message_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 3223, - "a.out.js.gz": 1545, + "a.out.js": 3010, + "a.out.js.gz": 1480, "a.out.nodebug.wasm": 89, "a.out.nodebug.wasm.gz": 98, - "total": 3312, - "total_gz": 1643, + "total": 3099, + "total_gz": 1578, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json b/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json index 2d66550fe7101..7582dfb485e0e 100644 --- a/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json +++ b/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 3271, - "a.out.js.gz": 1579, + "a.out.js": 3158, + "a.out.js.gz": 1555, "a.out.nodebug.wasm": 222, "a.out.nodebug.wasm.gz": 206, - "total": 3493, - "total_gz": 1785, + "total": 3380, + "total_gz": 1761, "sent": [ "proc_exit" ], diff --git a/test/codesize/test_codesize_mem_O3.json b/test/codesize/test_codesize_mem_O3.json index b8826edc16c2e..b88e76157cbb1 100644 --- a/test/codesize/test_codesize_mem_O3.json +++ b/test/codesize/test_codesize_mem_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 4030, - "a.out.js.gz": 1966, + "a.out.js": 3936, + "a.out.js.gz": 1945, "a.out.nodebug.wasm": 5260, "a.out.nodebug.wasm.gz": 2419, - "total": 9290, - "total_gz": 4385, + "total": 9196, + "total_gz": 4364, "sent": [ "a (emscripten_resize_heap)" ], diff --git a/test/codesize/test_codesize_mem_O3_grow.json b/test/codesize/test_codesize_mem_O3_grow.json index f6bd386c93d8a..3afbc6b9f756b 100644 --- a/test/codesize/test_codesize_mem_O3_grow.json +++ b/test/codesize/test_codesize_mem_O3_grow.json @@ -1,10 +1,10 @@ { - "a.out.js": 4347, - "a.out.js.gz": 2138, + "a.out.js": 4270, + "a.out.js.gz": 2119, "a.out.nodebug.wasm": 5261, "a.out.nodebug.wasm.gz": 2419, - "total": 9608, - "total_gz": 4557, + "total": 9531, + "total_gz": 4538, "sent": [ "a (emscripten_resize_heap)" ], diff --git a/test/codesize/test_codesize_mem_O3_grow_standalone.json b/test/codesize/test_codesize_mem_O3_grow_standalone.json index 3190458c7ceae..4a7d92d491fc1 100644 --- a/test/codesize/test_codesize_mem_O3_grow_standalone.json +++ b/test/codesize/test_codesize_mem_O3_grow_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 3813, - "a.out.js.gz": 1874, + "a.out.js": 3718, + "a.out.js.gz": 1853, "a.out.nodebug.wasm": 5641, "a.out.nodebug.wasm.gz": 2659, - "total": 9454, - "total_gz": 4533, + "total": 9359, + "total_gz": 4512, "sent": [ "args_get", "args_sizes_get", diff --git a/test/codesize/test_codesize_mem_O3_standalone.json b/test/codesize/test_codesize_mem_O3_standalone.json index bca2761225edb..c423ccbfaed0b 100644 --- a/test/codesize/test_codesize_mem_O3_standalone.json +++ b/test/codesize/test_codesize_mem_O3_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 3724, - "a.out.js.gz": 1822, + "a.out.js": 3628, + "a.out.js.gz": 1803, "a.out.nodebug.wasm": 5565, "a.out.nodebug.wasm.gz": 2598, - "total": 9289, - "total_gz": 4420, + "total": 9193, + "total_gz": 4401, "sent": [ "args_get", "args_sizes_get", diff --git a/test/codesize/test_codesize_mem_O3_standalone_lib.json b/test/codesize/test_codesize_mem_O3_standalone_lib.json index 874a6a5510cb9..b9429c483376d 100644 --- a/test/codesize/test_codesize_mem_O3_standalone_lib.json +++ b/test/codesize/test_codesize_mem_O3_standalone_lib.json @@ -1,10 +1,10 @@ { - "a.out.js": 3264, - "a.out.js.gz": 1571, + "a.out.js": 3151, + "a.out.js.gz": 1548, "a.out.nodebug.wasm": 5239, "a.out.nodebug.wasm.gz": 2359, - "total": 8503, - "total_gz": 3930, + "total": 8390, + "total_gz": 3907, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_mem_O3_standalone_narg.json b/test/codesize/test_codesize_mem_O3_standalone_narg.json index acb2104805bc2..9c32bec0d90ab 100644 --- a/test/codesize/test_codesize_mem_O3_standalone_narg.json +++ b/test/codesize/test_codesize_mem_O3_standalone_narg.json @@ -1,10 +1,10 @@ { - "a.out.js": 3271, - "a.out.js.gz": 1579, + "a.out.js": 3158, + "a.out.js.gz": 1555, "a.out.nodebug.wasm": 5354, "a.out.nodebug.wasm.gz": 2442, - "total": 8625, - "total_gz": 4021, + "total": 8512, + "total_gz": 3997, "sent": [ "proc_exit" ], diff --git a/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json b/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json index 4fd05e77f282b..7ca5726e90dc9 100644 --- a/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json +++ b/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json @@ -1,10 +1,10 @@ { - "a.out.js": 3271, - "a.out.js.gz": 1579, + "a.out.js": 3158, + "a.out.js.gz": 1555, "a.out.nodebug.wasm": 4285, "a.out.nodebug.wasm.gz": 2142, - "total": 7556, - "total_gz": 3721, + "total": 7443, + "total_gz": 3697, "sent": [ "proc_exit" ], diff --git a/test/codesize/test_codesize_minimal_64.json b/test/codesize/test_codesize_minimal_64.json index 73afa227590d6..337855a8c4b26 100644 --- a/test/codesize/test_codesize_minimal_64.json +++ b/test/codesize/test_codesize_minimal_64.json @@ -1,10 +1,10 @@ { - "a.out.js": 2525, - "a.out.js.gz": 1200, + "a.out.js": 2313, + "a.out.js.gz": 1138, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 88, - "total": 2600, - "total_gz": 1288, + "total": 2388, + "total_gz": 1226, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O0.expected.js b/test/codesize/test_codesize_minimal_O0.expected.js index e11b174c400ee..04d24a1fd168e 100644 --- a/test/codesize/test_codesize_minimal_O0.expected.js +++ b/test/codesize/test_codesize_minimal_O0.expected.js @@ -497,15 +497,15 @@ function updateMemoryViews() { assert(!HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); var b = wasmMemory.buffer; HEAP8 = new Int8Array(b); - HEAP16 = new Int16Array(b); - HEAPU8 = new Uint8Array(b); - HEAPU16 = new Uint16Array(b); + + + HEAP32 = new Int32Array(b); HEAPU32 = new Uint32Array(b); - HEAPF32 = new Float32Array(b); - HEAPF64 = new Float64Array(b); - HEAP64 = new BigInt64Array(b); - HEAPU64 = new BigUint64Array(b); + + + + } // include: memoryprofiler.js @@ -735,36 +735,15 @@ async function createWasm() { } } - /** @type {!Int16Array} */ - var HEAP16; - /** @type {!Int32Array} */ var HEAP32; - /** not-@type {!BigInt64Array} */ - var HEAP64; - /** @type {!Int8Array} */ var HEAP8; - /** @type {!Float32Array} */ - var HEAPF32; - - /** @type {!Float64Array} */ - var HEAPF64; - - /** @type {!Uint16Array} */ - var HEAPU16; - /** @type {!Uint32Array} */ var HEAPU32; - /** not-@type {!BigUint64Array} */ - var HEAPU64; - - /** @type {!Uint8Array} */ - var HEAPU8; - var callRuntimeCallbacks = (callbacks) => { while (callbacks.length > 0) { // Pass the module as the first argument. @@ -772,26 +751,6 @@ async function createWasm() { } }; - - /** - * @param {number} ptr - * @param {string} type - */ - function getValue(ptr, type = 'i8') { - if (type.endsWith('*')) type = '*'; - switch (type) { - case 'i1': return HEAP8[ptr]; - case 'i8': return HEAP8[ptr]; - case 'i16': return HEAP16[((ptr)>>1)]; - case 'i32': return HEAP32[((ptr)>>2)]; - case 'i64': return HEAP64[((ptr)>>3)]; - case 'float': return HEAPF32[((ptr)>>2)]; - case 'double': return HEAPF64[((ptr)>>3)]; - case '*': return HEAPU32[((ptr)>>2)]; - default: abort(`invalid type for getValue: ${type}`); - } - } - function ptrToString(ptr) { assert(typeof ptr === 'number', `ptrToString expects a number, got ${typeof ptr}`); // Convert to 32-bit unsigned value @@ -799,27 +758,6 @@ async function createWasm() { return '0x' + ptr.toString(16).padStart(8, '0'); } - - /** - * @param {number} ptr - * @param {number} value - * @param {string} type - */ - function setValue(ptr, value, type = 'i8') { - if (type.endsWith('*')) type = '*'; - switch (type) { - case 'i1': HEAP8[ptr] = value; break; - case 'i8': HEAP8[ptr] = value; break; - case 'i16': HEAP16[((ptr)>>1)] = value; break; - case 'i32': HEAP32[((ptr)>>2)] = value; break; - case 'i64': HEAP64[((ptr)>>3)] = BigInt(value); break; - case 'float': HEAPF32[((ptr)>>2)] = value; break; - case 'double': HEAPF64[((ptr)>>3)] = value; break; - case '*': HEAPU32[((ptr)>>2)] = value; break; - default: abort(`invalid type for setValue: ${type}`); - } - } - var stackRestore = (val) => __emscripten_stack_restore(val); var stackSave = () => _emscripten_stack_get_current(); @@ -940,6 +878,8 @@ Module['FS_createPreloadedFile'] = FS.createPreloadedFile; 'getFunctionAddress', 'addFunction', 'removeFunction', + 'setValue', + 'getValue', 'UTF8ArrayToString', 'UTF8ToString', 'stringToUTF8Array', @@ -1076,8 +1016,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol) 'noExitRuntime', 'freeTableIndexes', 'functionsInTableMap', - 'setValue', - 'getValue', 'PATH', 'PATH_FS', 'UTF8Decoder', diff --git a/test/codesize/test_codesize_minimal_O0.json b/test/codesize/test_codesize_minimal_O0.json index a48ad7acf9a1b..3871da8e19b04 100644 --- a/test/codesize/test_codesize_minimal_O0.json +++ b/test/codesize/test_codesize_minimal_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 18857, - "a.out.js.gz": 6768, + "a.out.js": 18698, + "a.out.js.gz": 6737, "a.out.nodebug.wasm": 1015, "a.out.nodebug.wasm.gz": 602, - "total": 19872, - "total_gz": 7370, + "total": 19713, + "total_gz": 7339, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O1.json b/test/codesize/test_codesize_minimal_O1.json index 7614d27da4188..ed105fff59191 100644 --- a/test/codesize/test_codesize_minimal_O1.json +++ b/test/codesize/test_codesize_minimal_O1.json @@ -1,10 +1,10 @@ { - "a.out.js": 2927, - "a.out.js.gz": 1237, + "a.out.js": 2670, + "a.out.js.gz": 1167, "a.out.nodebug.wasm": 449, "a.out.nodebug.wasm.gz": 337, - "total": 3376, - "total_gz": 1574, + "total": 3119, + "total_gz": 1504, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O2.json b/test/codesize/test_codesize_minimal_O2.json index 9bc333dc5260d..3436eb3b2d8eb 100644 --- a/test/codesize/test_codesize_minimal_O2.json +++ b/test/codesize/test_codesize_minimal_O2.json @@ -1,10 +1,10 @@ { - "a.out.js": 2269, - "a.out.js.gz": 1125, + "a.out.js": 2052, + "a.out.js.gz": 1058, "a.out.nodebug.wasm": 280, "a.out.nodebug.wasm.gz": 226, - "total": 2549, - "total_gz": 1351, + "total": 2332, + "total_gz": 1284, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O3.json b/test/codesize/test_codesize_minimal_O3.json index 08e058c9cd5ad..5fe4c0860fef6 100644 --- a/test/codesize/test_codesize_minimal_O3.json +++ b/test/codesize/test_codesize_minimal_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 2210, - "a.out.js.gz": 1089, + "a.out.js": 1998, + "a.out.js.gz": 1027, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2285, - "total_gz": 1176, + "total": 2073, + "total_gz": 1114, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Os.json b/test/codesize/test_codesize_minimal_Os.json index 08e058c9cd5ad..5fe4c0860fef6 100644 --- a/test/codesize/test_codesize_minimal_Os.json +++ b/test/codesize/test_codesize_minimal_Os.json @@ -1,10 +1,10 @@ { - "a.out.js": 2210, - "a.out.js.gz": 1089, + "a.out.js": 1998, + "a.out.js.gz": 1027, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2285, - "total_gz": 1176, + "total": 2073, + "total_gz": 1114, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Os_mr.json b/test/codesize/test_codesize_minimal_Os_mr.json index 2f947a492386e..f4b4c13a25bde 100644 --- a/test/codesize/test_codesize_minimal_Os_mr.json +++ b/test/codesize/test_codesize_minimal_Os_mr.json @@ -1,10 +1,10 @@ { - "a.out.js": 502, - "a.out.js.gz": 299, + "a.out.js": 278, + "a.out.js.gz": 225, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 577, - "total_gz": 386, + "total": 353, + "total_gz": 312, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Oz-ctors.json b/test/codesize/test_codesize_minimal_Oz-ctors.json index 1d23c0ca40143..01649ef200d36 100644 --- a/test/codesize/test_codesize_minimal_Oz-ctors.json +++ b/test/codesize/test_codesize_minimal_Oz-ctors.json @@ -1,10 +1,10 @@ { - "a.out.js": 2192, - "a.out.js.gz": 1077, + "a.out.js": 1980, + "a.out.js.gz": 1012, "a.out.nodebug.wasm": 64, "a.out.nodebug.wasm.gz": 80, - "total": 2256, - "total_gz": 1157, + "total": 2044, + "total_gz": 1092, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Oz.json b/test/codesize/test_codesize_minimal_Oz.json index 08e058c9cd5ad..5fe4c0860fef6 100644 --- a/test/codesize/test_codesize_minimal_Oz.json +++ b/test/codesize/test_codesize_minimal_Oz.json @@ -1,10 +1,10 @@ { - "a.out.js": 2210, - "a.out.js.gz": 1089, + "a.out.js": 1998, + "a.out.js.gz": 1027, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2285, - "total_gz": 1176, + "total": 2073, + "total_gz": 1114, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_esm.json b/test/codesize/test_codesize_minimal_esm.json index eceee257497fd..fe01e4510c897 100644 --- a/test/codesize/test_codesize_minimal_esm.json +++ b/test/codesize/test_codesize_minimal_esm.json @@ -1,10 +1,10 @@ { - "a.out.js": 2348, - "a.out.js.gz": 1111, + "a.out.js": 2137, + "a.out.js.gz": 1050, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2423, - "total_gz": 1198, + "total": 2212, + "total_gz": 1137, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_pthreads.json b/test/codesize/test_codesize_minimal_pthreads.json index ab8c2d4354a6e..2621f9754073e 100644 --- a/test/codesize/test_codesize_minimal_pthreads.json +++ b/test/codesize/test_codesize_minimal_pthreads.json @@ -1,10 +1,10 @@ { - "a.out.js": 6955, - "a.out.js.gz": 3431, + "a.out.js": 6859, + "a.out.js.gz": 3409, "a.out.nodebug.wasm": 19108, "a.out.nodebug.wasm.gz": 8824, - "total": 26063, - "total_gz": 12255, + "total": 25967, + "total_gz": 12233, "sent": [ "a (memory)", "b (exit)", diff --git a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json index 56a3d321836d4..f87b8f974fa98 100644 --- a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json @@ -1,10 +1,10 @@ { - "a.out.js": 7389, - "a.out.js.gz": 3647, + "a.out.js": 7310, + "a.out.js.gz": 3625, "a.out.nodebug.wasm": 19109, "a.out.nodebug.wasm.gz": 8826, - "total": 26498, - "total_gz": 12473, + "total": 26419, + "total_gz": 12451, "sent": [ "a (memory)", "b (exit)", diff --git a/test/codesize/test_codesize_minimal_wasmfs.json b/test/codesize/test_codesize_minimal_wasmfs.json index 08e058c9cd5ad..5fe4c0860fef6 100644 --- a/test/codesize/test_codesize_minimal_wasmfs.json +++ b/test/codesize/test_codesize_minimal_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 2210, - "a.out.js.gz": 1089, + "a.out.js": 1998, + "a.out.js.gz": 1027, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2285, - "total_gz": 1176, + "total": 2073, + "total_gz": 1114, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_minimal_runtime_code_size_hello_embind.json b/test/codesize/test_minimal_runtime_code_size_hello_embind.json index 758e36ffd878b..cf70e440a103b 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_embind.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_embind.json @@ -2,9 +2,9 @@ "a.html": 548, "a.html.gz": 371, "a.js": 7264, - "a.js.gz": 3333, + "a.js.gz": 3334, "a.wasm": 7099, "a.wasm.gz": 3246, "total": 14911, - "total_gz": 6950 + "total_gz": 6951 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json b/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json index cf60299af7164..258fed7df0ecb 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json @@ -2,9 +2,9 @@ "a.html": 548, "a.html.gz": 371, "a.js": 5349, - "a.js.gz": 2514, + "a.js.gz": 2515, "a.wasm": 5741, "a.wasm.gz": 2690, "total": 11638, - "total_gz": 5575 + "total_gz": 5576 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_wasm_worker.json b/test/codesize/test_minimal_runtime_code_size_hello_wasm_worker.json index b9e76134b7f12..9faf5f4e0f058 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_wasm_worker.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_wasm_worker.json @@ -1,10 +1,10 @@ { "a.html": 515, "a.html.gz": 355, - "a.js": 945, - "a.js.gz": 593, + "a.js": 923, + "a.js.gz": 582, "a.wasm": 2661, "a.wasm.gz": 1479, - "total": 4121, - "total_gz": 2427 + "total": 4099, + "total_gz": 2416 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm2js.json b/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm2js.json index 39c2e3644a679..9e0775c7bbb04 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm2js.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm2js.json @@ -2,7 +2,7 @@ "a.html": 342, "a.html.gz": 252, "a.js": 18217, - "a.js.gz": 9828, + "a.js.gz": 9827, "total": 18559, - "total_gz": 10080 + "total_gz": 10079 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json b/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json index b8bee5125d38e..1a8c46bd18e82 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json @@ -1,4 +1,4 @@ { "a.html": 15040, - "a.html.gz": 9004 + "a.html.gz": 9027 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_webgl_wasm.json b/test/codesize/test_minimal_runtime_code_size_hello_webgl_wasm.json index ecb88a72d5678..318bc1fae19d2 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_webgl_wasm.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_webgl_wasm.json @@ -2,9 +2,9 @@ "a.html": 450, "a.html.gz": 318, "a.js": 3961, - "a.js.gz": 2109, + "a.js.gz": 2108, "a.wasm": 8313, "a.wasm.gz": 5646, "total": 12724, - "total_gz": 8073 + "total_gz": 8072 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_world_wasm.json b/test/codesize/test_minimal_runtime_code_size_hello_world_wasm.json index 99c0d29ff9a53..d8132a0cf3154 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_world_wasm.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_world_wasm.json @@ -2,9 +2,9 @@ "a.html": 548, "a.html.gz": 371, "a.js": 284, - "a.js.gz": 240, + "a.js.gz": 239, "a.wasm": 95, "a.wasm.gz": 101, "total": 927, - "total_gz": 712 + "total_gz": 711 } diff --git a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json index 206b2029eedff..98f3f3999840a 100644 --- a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json +++ b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json @@ -1,4 +1,4 @@ { "a.html": 11054, - "a.html.gz": 5754 + "a.html.gz": 5752 } diff --git a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json index 5dc96cb01d779..269bfba988fe7 100644 --- a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json +++ b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json @@ -1,4 +1,4 @@ { "a.html": 17417, - "a.html.gz": 7658 + "a.html.gz": 7659 } diff --git a/test/codesize/test_small_js_flags.expected.js b/test/codesize/test_small_js_flags.expected.js index 43b883abf4d98..a97e03c35e819 100644 --- a/test/codesize/test_small_js_flags.expected.js +++ b/test/codesize/test_small_js_flags.expected.js @@ -105,16 +105,8 @@ var runtimeInitialized = false; function updateMemoryViews() { var b = wasmMemory.buffer; - HEAP8 = new Int8Array(b); - HEAP16 = new Int16Array(b); HEAPU8 = new Uint8Array(b); - HEAPU16 = new Uint16Array(b); - HEAP32 = new Int32Array(b); HEAPU32 = new Uint32Array(b); - HEAPF32 = new Float32Array(b); - HEAPF64 = new Float64Array(b); - HEAP64 = new BigInt64Array(b); - HEAPU64 = new BigUint64Array(b); } // include: memoryprofiler.js @@ -260,26 +252,6 @@ class ExitStatus { } } -/** @type {!Int16Array} */ var HEAP16; - -/** @type {!Int32Array} */ var HEAP32; - -/** not-@type {!BigInt64Array} */ var HEAP64; - -/** @type {!Int8Array} */ var HEAP8; - -/** @type {!Float32Array} */ var HEAPF32; - -/** @type {!Float64Array} */ var HEAPF64; - -/** @type {!Uint16Array} */ var HEAPU16; - -/** @type {!Uint32Array} */ var HEAPU32; - -/** not-@type {!BigUint64Array} */ var HEAPU64; - -/** @type {!Uint8Array} */ var HEAPU8; - var printCharBuffers = [ null, [], [] ]; var UTF8Decoder = globalThis.TextDecoder && new TextDecoder; @@ -358,6 +330,10 @@ var printChar = (stream, curr) => { } }; +/** @type {!Uint8Array} */ var HEAPU8; + +/** @type {!Uint32Array} */ var HEAPU32; + var _fd_write = (fd, iov, iovcnt, pnum) => { // hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0 var num = 0; diff --git a/test/codesize/test_small_js_flags.json b/test/codesize/test_small_js_flags.json index 7ca0c00f0cfbd..fca4a53fc1243 100644 --- a/test/codesize/test_small_js_flags.json +++ b/test/codesize/test_small_js_flags.json @@ -1,10 +1,10 @@ { - "a.out.js": 2222, - "a.out.js.gz": 1230, + "a.out.js": 2066, + "a.out.js.gz": 1187, "a.out.nodebug.wasm": 1666, "a.out.nodebug.wasm.gz": 945, - "total": 3888, - "total_gz": 2175, + "total": 3732, + "total_gz": 2132, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index 117fdc26c92d8..c022f2fb2806f 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { - "hello_world.js": 56365, - "hello_world.js.gz": 17729, + "hello_world.js": 54627, + "hello_world.js.gz": 17353, "hello_world.wasm": 15115, "hello_world.wasm.gz": 7464, - "no_asserts.js": 25511, - "no_asserts.js.gz": 8679, + "no_asserts.js": 23634, + "no_asserts.js.gz": 8288, "no_asserts.wasm": 12229, "no_asserts.wasm.gz": 6004, - "strict.js": 53467, - "strict.js.gz": 16713, + "strict.js": 51729, + "strict.js.gz": 16339, "strict.wasm": 15115, "strict.wasm.gz": 7461, - "total": 177802, - "total_gz": 64050 + "total": 172449, + "total_gz": 62909 }