Skip to content

Commit 6c1b746

Browse files
committed
Export data addresses from the Wasm module just like other symbols.
This removes the special handling of exported immutable globals which simplifies the code in a few different ways. For programs that export data addresses (this is relatively rare) this means codesize reduction for the generated JS (since it no longer contains the constant values) and the codesize increase for the Wasm binary (since it now contains extra exports). The main reason for this is consistency with dynamic linking (where data exports are always needed) and a reduction in complexity. The following (14) test expectation files were updated by running the tests with `--rebaseline`: ``` codesize/test_codesize_minimal_64.json: 2657 => 2665 [+8 bytes / +0.30%] test/codesize/test_codesize_minimal_O0.expected.js updated codesize/test_codesize_minimal_O0.json: 20398 => 20495 [+97 bytes / +0.48%] codesize/test_codesize_minimal_O1.json: 3498 => 3504 [+6 bytes / +0.17%] codesize/test_codesize_minimal_O2.json: 2622 => 2626 [+4 bytes / +0.15%] codesize/test_codesize_minimal_O3.json: 2354 => 2362 [+8 bytes / +0.34%] codesize/test_codesize_minimal_Os.json: 2354 => 2362 [+8 bytes / +0.34%] codesize/test_codesize_minimal_Os_mr.json: 559 => 572 [+13 bytes / +2.33%] codesize/test_codesize_minimal_Oz-ctors.json: 2322 => 2330 [+8 bytes / +0.34%] codesize/test_codesize_minimal_Oz.json: 2354 => 2362 [+8 bytes / +0.34%] codesize/test_codesize_minimal_esm.json: 2489 => 2498 [+9 bytes / +0.36%] codesize/test_codesize_minimal_pthreads.json: 27208 => 27214 [+6 bytes / +0.02%] codesize/test_codesize_minimal_pthreads_memgrowth.json: 27636 => 27642 [+6 bytes / +0.02%] codesize/test_codesize_minimal_wasmfs.json: 2354 => 2362 [+8 bytes / +0.34%] Average change: +0.43% (+0.02% - +2.33%) ```
1 parent f285b98 commit 6c1b746

19 files changed

+137
-195
lines changed

src/lib/libcore.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,16 +1630,11 @@ addToLibrary({
16301630
dynCalls[name.substr(8)] = exportedSymbol;
16311631
}
16321632
#endif
1633-
// Globals are currently statically enumerated into the output JS.
1634-
// TODO: If the number of Globals grows large, consider giving them a
1635-
// similar DECLARE_ASM_MODULE_EXPORTS = 0 treatment.
1636-
if (typeof exportedSymbol.value === 'undefined') {
16371633
#if MINIMAL_RUNTIME
1638-
globalThis[name] = exportedSymbol;
1634+
globalThis[name] = exportedSymbol;
16391635
#else
1640-
globalThis[name] = Module[name] = exportedSymbol;
1636+
globalThis[name] = Module[name] = exportedSymbol;
16411637
#endif
1642-
}
16431638
}
16441639
exportAliases(wasmExports);
16451640
},

src/settings_internal.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
// underscore.
1717
var WASM_EXPORTS = [];
1818

19-
// Similar to above but only includes the data symbols (address exports).
20-
var DATA_EXPORTS = [];
21-
2219
// An array of all symbols exported from all the side modules specified on the
2320
// command line.
2421
// These are raw symbol names and are not mangled to include the leading

test/codesize/test_codesize_minimal_64.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
2-
"a.out.js": 2595,
3-
"a.out.js.gz": 1243,
4-
"a.out.nodebug.wasm": 62,
5-
"a.out.nodebug.wasm.gz": 76,
6-
"total": 2657,
7-
"total_gz": 1319,
2+
"a.out.js": 2598,
3+
"a.out.js.gz": 1244,
4+
"a.out.nodebug.wasm": 75,
5+
"a.out.nodebug.wasm.gz": 88,
6+
"total": 2673,
7+
"total_gz": 1332,
88
"sent": [],
99
"imports": [],
1010
"exports": [
1111
"a (memory)",
1212
"b (__wasm_call_ctors)",
13-
"c (add)"
13+
"c (add)",
14+
"d (global_val)"
1415
],
1516
"funcs": [
1617
"$__wasm_call_ctors",

test/codesize/test_codesize_minimal_O0.expected.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,7 @@ var __emscripten_stack_restore = makeInvalidEarlyAccess('__emscripten_stack_rest
13161316
var __emscripten_stack_alloc = makeInvalidEarlyAccess('__emscripten_stack_alloc');
13171317
var _emscripten_stack_get_current = makeInvalidEarlyAccess('_emscripten_stack_get_current');
13181318
var memory = makeInvalidEarlyAccess('memory');
1319+
var _global_val = Module['_global_val'] = makeInvalidEarlyAccess('_global_val');
13191320
var __indirect_function_table = makeInvalidEarlyAccess('__indirect_function_table');
13201321
var wasmMemory = makeInvalidEarlyAccess('wasmMemory');
13211322

@@ -1340,12 +1341,12 @@ function assignWasmExports(wasmExports) {
13401341
_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'];
13411342
assert(wasmExports['memory'], 'missing Wasm export: memory');
13421343
memory = wasmMemory = wasmExports['memory'];
1344+
assert(wasmExports['global_val'], 'missing Wasm export: global_val');
1345+
_global_val = Module['_global_val'] = Number(wasmExports['global_val']);
13431346
assert(wasmExports['__indirect_function_table'], 'missing Wasm export: __indirect_function_table');
13441347
__indirect_function_table = wasmExports['__indirect_function_table'];
13451348
}
13461349

1347-
var _global_val = Module['_global_val'] = 65536;
1348-
13491350
var wasmImports = {
13501351

13511352
};

test/codesize/test_codesize_minimal_O0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19262,
3-
"a.out.js.gz": 6966,
2+
"a.out.js": 19367,
3+
"a.out.js.gz": 6982,
44
"a.out.nodebug.wasm": 1136,
55
"a.out.nodebug.wasm.gz": 659,
6-
"total": 20398,
7-
"total_gz": 7625,
6+
"total": 20503,
7+
"total_gz": 7641,
88
"sent": [],
99
"imports": [],
1010
"exports": [

test/codesize/test_codesize_minimal_O1.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 3049,
3-
"a.out.js.gz": 1301,
2+
"a.out.js": 3063,
3+
"a.out.js.gz": 1304,
44
"a.out.nodebug.wasm": 449,
55
"a.out.nodebug.wasm.gz": 337,
6-
"total": 3498,
7-
"total_gz": 1638,
6+
"total": 3512,
7+
"total_gz": 1641,
88
"sent": [],
99
"imports": [],
1010
"exports": [

test/codesize/test_codesize_minimal_O2.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 2342,
3-
"a.out.js.gz": 1171,
2+
"a.out.js": 2354,
3+
"a.out.js.gz": 1175,
44
"a.out.nodebug.wasm": 280,
55
"a.out.nodebug.wasm.gz": 226,
6-
"total": 2622,
7-
"total_gz": 1397,
6+
"total": 2634,
7+
"total_gz": 1401,
88
"sent": [],
99
"imports": [],
1010
"exports": [

test/codesize/test_codesize_minimal_O3.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
2-
"a.out.js": 2292,
3-
"a.out.js.gz": 1137,
4-
"a.out.nodebug.wasm": 62,
5-
"a.out.nodebug.wasm.gz": 76,
6-
"total": 2354,
7-
"total_gz": 1213,
2+
"a.out.js": 2295,
3+
"a.out.js.gz": 1140,
4+
"a.out.nodebug.wasm": 75,
5+
"a.out.nodebug.wasm.gz": 87,
6+
"total": 2370,
7+
"total_gz": 1227,
88
"sent": [],
99
"imports": [],
1010
"exports": [
1111
"a (memory)",
1212
"b (__wasm_call_ctors)",
13-
"c (add)"
13+
"c (add)",
14+
"d (global_val)"
1415
],
1516
"funcs": [
1617
"$__wasm_call_ctors",

test/codesize/test_codesize_minimal_Os.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
2-
"a.out.js": 2292,
3-
"a.out.js.gz": 1137,
4-
"a.out.nodebug.wasm": 62,
5-
"a.out.nodebug.wasm.gz": 76,
6-
"total": 2354,
7-
"total_gz": 1213,
2+
"a.out.js": 2295,
3+
"a.out.js.gz": 1140,
4+
"a.out.nodebug.wasm": 75,
5+
"a.out.nodebug.wasm.gz": 87,
6+
"total": 2370,
7+
"total_gz": 1227,
88
"sent": [],
99
"imports": [],
1010
"exports": [
1111
"a (memory)",
1212
"b (__wasm_call_ctors)",
13-
"c (add)"
13+
"c (add)",
14+
"d (global_val)"
1415
],
1516
"funcs": [
1617
"$__wasm_call_ctors",

test/codesize/test_codesize_minimal_Os_mr.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
22
"a.out.js": 497,
33
"a.out.js.gz": 297,
4-
"a.out.nodebug.wasm": 62,
5-
"a.out.nodebug.wasm.gz": 76,
6-
"total": 559,
7-
"total_gz": 373,
4+
"a.out.nodebug.wasm": 75,
5+
"a.out.nodebug.wasm.gz": 87,
6+
"total": 572,
7+
"total_gz": 384,
88
"sent": [],
99
"imports": [],
1010
"exports": [
1111
"a (memory)",
1212
"b (__wasm_call_ctors)",
13-
"c (add)"
13+
"c (add)",
14+
"d (global_val)"
1415
],
1516
"funcs": [
1617
"$__wasm_call_ctors",

0 commit comments

Comments
 (0)