Skip to content

Commit 1808912

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 a4a8121 commit 1808912

19 files changed

+123
-188
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": 2590,
3+
"a.out.js.gz": 1241,
4+
"a.out.nodebug.wasm": 75,
5+
"a.out.nodebug.wasm.gz": 88,
6+
"total": 2665,
7+
"total_gz": 1329,
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
@@ -1315,6 +1315,7 @@ var __emscripten_stack_restore = makeInvalidEarlyAccess('__emscripten_stack_rest
13151315
var __emscripten_stack_alloc = makeInvalidEarlyAccess('__emscripten_stack_alloc');
13161316
var _emscripten_stack_get_current = makeInvalidEarlyAccess('_emscripten_stack_get_current');
13171317
var memory = makeInvalidEarlyAccess('memory');
1318+
var _global_val = Module['_global_val'] = makeInvalidEarlyAccess('_global_val');
13181319
var __indirect_function_table = makeInvalidEarlyAccess('__indirect_function_table');
13191320
var wasmMemory = makeInvalidEarlyAccess('wasmMemory');
13201321

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

1346-
var _global_val = Module['_global_val'] = 65536;
1347-
13481349
var wasmImports = {
13491350

13501351
};

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": 19359,
3+
"a.out.js.gz": 6978,
44
"a.out.nodebug.wasm": 1136,
55
"a.out.nodebug.wasm.gz": 659,
6-
"total": 20398,
7-
"total_gz": 7625,
6+
"total": 20495,
7+
"total_gz": 7637,
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": 3055,
3+
"a.out.js.gz": 1296,
44
"a.out.nodebug.wasm": 449,
55
"a.out.nodebug.wasm.gz": 337,
6-
"total": 3498,
7-
"total_gz": 1638,
6+
"total": 3504,
7+
"total_gz": 1633,
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": 2346,
3+
"a.out.js.gz": 1168,
44
"a.out.nodebug.wasm": 280,
55
"a.out.nodebug.wasm.gz": 226,
6-
"total": 2622,
7-
"total_gz": 1397,
6+
"total": 2626,
7+
"total_gz": 1394,
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": 2287,
3+
"a.out.js.gz": 1133,
4+
"a.out.nodebug.wasm": 75,
5+
"a.out.nodebug.wasm.gz": 87,
6+
"total": 2362,
7+
"total_gz": 1220,
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": 2287,
3+
"a.out.js.gz": 1133,
4+
"a.out.nodebug.wasm": 75,
5+
"a.out.nodebug.wasm.gz": 87,
6+
"total": 2362,
7+
"total_gz": 1220,
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)