Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow EXPORTED_RUNTIME_METHODS for HEAPXX globals #21407

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,18 @@ function exportRuntime() {
'abort',
'wasmMemory',
'wasmExports',
'HEAP',
'HEAP_DATA_VIEW',
'HEAP8',
'HEAP16',
'HEAPU8',
'HEAPU16',
'HEAP32',
'HEAPU32',
'HEAPF32',
'HEAPF64',
'HEAP64',
'HEAPU64',
];

// These are actually native wasm functions these days but we allow exporting
Expand Down
24 changes: 12 additions & 12 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,19 @@ var HEAP_DATA_VIEW;
function updateMemoryViews() {
var b = wasmMemory.buffer;
#if SUPPORT_BIG_ENDIAN
Module['HEAP_DATA_VIEW'] = HEAP_DATA_VIEW = new DataView(b);
#endif
Module['HEAP8'] = HEAP8 = new Int8Array(b);
Module['HEAP16'] = HEAP16 = new Int16Array(b);
Module['HEAPU8'] = HEAPU8 = new Uint8Array(b);
Module['HEAPU16'] = HEAPU16 = new Uint16Array(b);
Module['HEAP32'] = HEAP32 = new Int32Array(b);
Module['HEAPU32'] = HEAPU32 = new Uint32Array(b);
Module['HEAPF32'] = HEAPF32 = new Float32Array(b);
Module['HEAPF64'] = HEAPF64 = new Float64Array(b);
HEAP_DATA_VIEW = HEAP_DATA_VIEW = new DataView(b);
#endif
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);
#if WASM_BIGINT
Module['HEAP64'] = HEAP64 = new BigInt64Array(b);
Module['HEAPU64'] = HEAPU64 = new BigUint64Array(b);
HEAP64 = new BigInt64Array(b);
HEAPU64 = new BigUint64Array(b);
#endif
}

Expand Down
35 changes: 12 additions & 23 deletions src/preamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
* SPDX-License-Identifier: MIT
*/

{{{
// Helper function to export a symbol on the module object
// if requested.
globalThis.maybeExport = (x) => MODULARIZE && EXPORT_ALL ? `Module['${x}'] = ` : '';
// Export to the AudioWorkletGlobalScope the needed variables to access
// the heap. AudioWorkletGlobalScope is unable to access global JS vars
// in the compiled main JS file.
globalThis.maybeExportIfAudioWorklet = (x) => (MODULARIZE && EXPORT_ALL) || AUDIO_WORKLET ? `Module['${x}'] = ` : '';
null;
}}}

#if SAFE_HEAP
#include "runtime_safe_heap.js"
#endif
Expand Down Expand Up @@ -71,19 +60,19 @@ function updateMemoryViews() {
assert(b instanceof SharedArrayBuffer, 'requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag');
#endif
#if SUPPORT_BIG_ENDIAN
{{{ maybeExport('HEAP_DATA_VIEW') }}} HEAP_DATA_VIEW = new DataView(b);
#endif
{{{ maybeExport('HEAP8') }}} HEAP8 = new Int8Array(b);
{{{ maybeExport('HEAP16') }}} HEAP16 = new Int16Array(b);
{{{ maybeExport('HEAPU8') }}} HEAPU8 = new Uint8Array(b);
{{{ maybeExport('HEAPU16') }}} HEAPU16 = new Uint16Array(b);
{{{ maybeExport('HEAP32') }}} HEAP32 = new Int32Array(b);
{{{ maybeExportIfAudioWorklet('HEAPU32') }}} HEAPU32 = new Uint32Array(b);
{{{ maybeExportIfAudioWorklet('HEAPF32') }}} HEAPF32 = new Float32Array(b);
{{{ maybeExport('HEAPF64') }}} HEAPF64 = new Float64Array(b);
HEAP_DATA_VIEW = new DataView(b);
#endif
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);
#if WASM_BIGINT
{{{ maybeExport('HEAP64') }}} HEAP64 = new BigInt64Array(b);
{{{ maybeExport('HEAPU64') }}} HEAPU64 = new BigUint64Array(b);
HEAP64 = new BigInt64Array(b);
HEAPU64 = new BigUint64Array(b);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors1.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9953
9998
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24510
24554
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9939
9981
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24478
24522
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11034
11063
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
28382
28426
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except_wasm.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9921
9959
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except_wasm.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24403
24447
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_mangle.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11041
11068
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_mangle.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
28383
28427
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_noexcept.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9953
9998
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_noexcept.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24510
24554
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_wasmfs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5245
5282
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12122
12166
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_files_js_fs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7899
7936
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_files_js_fs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19538
19588
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_files_wasmfs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3165
3212
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_files_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6875
6945
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O0.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8356
8421
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O0.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22913
23032
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O1.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3016
3064
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7769
7853
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2661
2702
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5530
5588
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O3.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2577
2620
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O3.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5376
5439
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_Os.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2577
2620
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_Os.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5376
5439
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_Oz.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2558
2601
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_Oz.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5343
5406
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_dylink.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6459
6510
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_dylink.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14303
14362
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1931
1979
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4162
4218
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_wasmfs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2577
2620
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5376
5439
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2141
2189
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4596
4665
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2173
2228
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4647
4718
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2595
2637
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5496
5558
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3_grow.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2754
2792
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3_grow.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5818
5880
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2445
2486
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5206
5268
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3_standalone.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2411
2452
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3_standalone.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5136
5198
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2163
2209
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4647
4716
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2173
2228
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4647
4718
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2173
2228
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4647
4718
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_64.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1725
1781
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_64.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3635
3698
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O0.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7177
7245
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O0.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19537
19666
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O1.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1827
1884
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4419
4499
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1660
1704
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3362
3410
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O3.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1618
1668
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O3.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3312
3360
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_Os.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1618
1668
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_Os.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3312
3360
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_Oz-ctors.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1610
1657
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_Oz-ctors.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3297
3345
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_Oz.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1618
1668
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_Oz.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3312
3360
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_pthreads.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4921
4950
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_pthreads.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13569
13613
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_wasmfs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1618
1668
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3312
3360
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
58086
58208
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_no_asserts.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
31565
31631
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56997
56996
8 changes: 8 additions & 0 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,14 @@ def phase_linker_setup(options, state, newargs):
# in global scope that is not suitable for MINIMAL_RUNTIME loader.
settings.EXPORTED_RUNTIME_METHODS += ['stackSave', 'stackAlloc', 'stackRestore', 'wasmTable']

if not settings.MINIMAL_RUNTIME and not settings.STRICT:
settings.EXPORTED_RUNTIME_METHODS += ['HEAP8', 'HEAPU8',
'HEAP16', 'HEAPU16',
'HEAP32', 'HEAPU32',
'HEAPF32', 'HEAPF64']
if settings.MEMORY64:
settings.EXPORTED_RUNTIME_METHODS += ['HEAP64', 'HEAPU64']

if settings.FORCE_FILESYSTEM and not settings.MINIMAL_RUNTIME:
# when the filesystem is forced, we export by default methods that filesystem usage
# may need, including filesystem usage from standalone file packager output (i.e.
Expand Down
Loading