Skip to content
Merged
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
18 changes: 11 additions & 7 deletions src/lib/libcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -1632,16 +1632,20 @@ addToLibrary({
dynCalls[name.substr(8)] = exportedSymbol;
}
#endif
// Globals are currently statically enumerated into the output JS.
// TODO: If the number of Globals grows large, consider giving them a
// similar DECLARE_ASM_MODULE_EXPORTS = 0 treatment.
if (typeof exportedSymbol.value === 'undefined') {
#if MINIMAL_RUNTIME
globalThis[name] = exportedSymbol;
// Special handling for Wasm globals. See `create_receiving` for the
// static version of this code.
if (typeof exportedSymbol.value != 'undefined') {
#if MEMORY64
exportedSymbol = Number(exportedSymbol.value);
#else
globalThis[name] = Module[name] = exportedSymbol;
exportedSymbol = exportedSymbol.value
#endif
}
#if MINIMAL_RUNTIME
globalThis[name] = exportedSymbol;
#else
globalThis[name] = Module[name] = exportedSymbol;
#endif
}
exportAliases(wasmExports);
},
Expand Down
21 changes: 13 additions & 8 deletions src/lib/libdylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ var LibraryDylink = {
var newValue;
if (typeof value == 'function') {
newValue = {{{ to64('addFunction(value)') }}};
} else if (typeof value == {{{ POINTER_JS_TYPE }}}) {
} else if (typeof value.value == {{{ POINTER_JS_TYPE }}}) {
newValue = value;
} else {
// The GOT can only contain addresses (i.e data addresses or function
Expand Down Expand Up @@ -306,7 +306,7 @@ var LibraryDylink = {
// Detect immuable wasm global exports. These represent data addresses
// which are relative to `memoryBase`
if (isImmutableGlobal(value)) {
return value.value + {{{ to64('memoryBase') }}};
return new WebAssembly.Global({'value': '{{{ POINTER_WASM_TYPE }}}'}, value.value + {{{ to64('memoryBase') }}});
}

// Return unmodified value (no relocation required).
Expand Down Expand Up @@ -354,10 +354,8 @@ var LibraryDylink = {
#endif
} else if (typeof value == 'number') {
entry.value = {{{ to64('value') }}};
#if MEMORY64
} else if (typeof value == 'bigint') {
} else if (typeof value.value == {{{ POINTER_JS_TYPE }}}) {
entry.value = value;
#endif
} else {
throw new Error(`bad export type for '${symName}': ${typeof value} (${value})`);
}
Expand Down Expand Up @@ -422,6 +420,8 @@ var LibraryDylink = {
// Keep __heap_base stack aligned.
var end = ret + alignMemory(size, {{{ STACK_ALIGN }}});
#if ASSERTIONS
//dbg(ret);
//dbg(HEAP8.length);
assert(end <= HEAP8.length, 'failure to getMemory - memory growth etc. is not supported there, call malloc/sbrk directly or increase INITIAL_MEMORY');
#endif
___heap_base = end;
Expand Down Expand Up @@ -859,10 +859,15 @@ var LibraryDylink = {

// Add any EM_ASM function that exist in the side module
if ('__start_em_asm' in moduleExports) {
var start = moduleExports['__start_em_asm'];
var stop = moduleExports['__stop_em_asm'];
var start = moduleExports['__start_em_asm'].value;
var stop = moduleExports['__stop_em_asm'].value;
#if CAN_ADDRESS_2GB
start >>>= 0;
stop >>>= 0;
#else
{{{ from64('start') }}}
{{{ from64('stop') }}}
#endif
while (start < stop) {
var jsString = UTF8ToString(start);
addEmAsm(start, jsString);
Expand Down Expand Up @@ -892,7 +897,7 @@ var LibraryDylink = {

for (var name in moduleExports) {
if (name.startsWith('__em_js__')) {
var start = moduleExports[name]
var start = moduleExports[name].value
var jsString = UTF8ToString({{{ from64Expr('start') }}});
// EM_JS strings are stored in the data section in the form
// SIG<::>BODY.
Expand Down
7 changes: 2 additions & 5 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,13 +719,10 @@ function getWasmImports() {
wasmExports = instance.exports;

#if MAIN_MODULE
// No relocation needed here.. but calling this just so that updateGOT is
// called.
#if RELOCATABLE
var origExports = wasmExports = relocateExports(wasmExports, {{{ GLOBAL_BASE }}});
#else
var origExports = wasmExports = relocateExports(wasmExports);
wasmExports = relocateExports(wasmExports, {{{ GLOBAL_BASE }}});
#endif
var origExports = wasmExports;
#endif

#if ASYNCIFY
Expand Down
3 changes: 0 additions & 3 deletions src/settings_internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
// underscore.
var WASM_EXPORTS = [];

// Similar to above but only includes the data symbols (address exports).
var DATA_EXPORTS = [];

// An array of all symbols exported from all the side modules specified on the
// command line.
// These are raw symbol names and are not mangled to include the leading
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_hello_dylink.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 26549,
"a.out.js.gz": 11353,
"a.out.js": 26672,
"a.out.js.gz": 11377,
"a.out.nodebug.wasm": 17761,
"a.out.nodebug.wasm.gz": 8991,
"total": 44310,
"total_gz": 20344,
"total": 44433,
"total_gz": 20368,
"sent": [
"__syscall_stat64",
"emscripten_resize_heap",
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 245302,
"a.out.js": 245421,
"a.out.nodebug.wasm": 574167,
"total": 819469,
"total": 819588,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
15 changes: 8 additions & 7 deletions test/codesize/test_codesize_minimal_64.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"a.out.js": 2595,
"a.out.js.gz": 1243,
"a.out.nodebug.wasm": 62,
"a.out.nodebug.wasm.gz": 76,
"total": 2657,
"total_gz": 1319,
"a.out.js": 2604,
"a.out.js.gz": 1247,
"a.out.nodebug.wasm": 75,
"a.out.nodebug.wasm.gz": 88,
"total": 2679,
"total_gz": 1335,
"sent": [],
"imports": [],
"exports": [
"a (memory)",
"b (__wasm_call_ctors)",
"c (add)"
"c (add)",
"d (global_val)"
],
"funcs": [
"$__wasm_call_ctors",
Expand Down
5 changes: 3 additions & 2 deletions test/codesize/test_codesize_minimal_O0.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,7 @@ var __emscripten_stack_restore = makeInvalidEarlyAccess('__emscripten_stack_rest
var __emscripten_stack_alloc = makeInvalidEarlyAccess('__emscripten_stack_alloc');
var _emscripten_stack_get_current = makeInvalidEarlyAccess('_emscripten_stack_get_current');
var memory = makeInvalidEarlyAccess('memory');
var _global_val = Module['_global_val'] = makeInvalidEarlyAccess('_global_val');
var __indirect_function_table = makeInvalidEarlyAccess('__indirect_function_table');
var wasmMemory = makeInvalidEarlyAccess('wasmMemory');

Expand All @@ -1347,12 +1348,12 @@ function assignWasmExports(wasmExports) {
_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'];
assert(typeof wasmExports['memory'] != 'undefined', 'missing Wasm export: memory');
memory = wasmMemory = wasmExports['memory'];
assert(typeof wasmExports['global_val'] != 'undefined', 'missing Wasm export: global_val');
_global_val = Module['_global_val'] = wasmExports['global_val'].value;
assert(typeof wasmExports['__indirect_function_table'] != 'undefined', 'missing Wasm export: __indirect_function_table');
__indirect_function_table = wasmExports['__indirect_function_table'];
}

var _global_val = Module['_global_val'] = 65536;

var wasmImports = {

};
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_minimal_O0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19364,
"a.out.js.gz": 6998,
"a.out.js": 19489,
"a.out.js.gz": 7016,
"a.out.nodebug.wasm": 1136,
"a.out.nodebug.wasm.gz": 659,
"total": 20500,
"total_gz": 7657,
"total": 20625,
"total_gz": 7675,
"sent": [],
"imports": [],
"exports": [
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_minimal_O1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 3049,
"a.out.js.gz": 1301,
"a.out.js": 3061,
"a.out.js.gz": 1300,
"a.out.nodebug.wasm": 449,
"a.out.nodebug.wasm.gz": 337,
"total": 3498,
"total_gz": 1638,
"total": 3510,
"total_gz": 1637,
"sent": [],
"imports": [],
"exports": [
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_minimal_O2.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"a.out.js": 2342,
"a.out.js": 2352,
"a.out.js.gz": 1171,
"a.out.nodebug.wasm": 280,
"a.out.nodebug.wasm.gz": 226,
"total": 2622,
"total": 2632,
"total_gz": 1397,
"sent": [],
"imports": [],
Expand Down
13 changes: 7 additions & 6 deletions test/codesize/test_codesize_minimal_O3.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"a.out.js": 2292,
"a.out.js": 2293,
"a.out.js.gz": 1137,
"a.out.nodebug.wasm": 62,
"a.out.nodebug.wasm.gz": 76,
"total": 2354,
"total_gz": 1213,
"a.out.nodebug.wasm": 75,
"a.out.nodebug.wasm.gz": 87,
"total": 2368,
"total_gz": 1224,
"sent": [],
"imports": [],
"exports": [
"a (memory)",
"b (__wasm_call_ctors)",
"c (add)"
"c (add)",
"d (global_val)"
],
"funcs": [
"$__wasm_call_ctors",
Expand Down
13 changes: 7 additions & 6 deletions test/codesize/test_codesize_minimal_Os.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"a.out.js": 2292,
"a.out.js": 2293,
"a.out.js.gz": 1137,
"a.out.nodebug.wasm": 62,
"a.out.nodebug.wasm.gz": 76,
"total": 2354,
"total_gz": 1213,
"a.out.nodebug.wasm": 75,
"a.out.nodebug.wasm.gz": 87,
"total": 2368,
"total_gz": 1224,
"sent": [],
"imports": [],
"exports": [
"a (memory)",
"b (__wasm_call_ctors)",
"c (add)"
"c (add)",
"d (global_val)"
],
"funcs": [
"$__wasm_call_ctors",
Expand Down
11 changes: 6 additions & 5 deletions test/codesize/test_codesize_minimal_Os_mr.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"a.out.js": 497,
"a.out.js.gz": 297,
"a.out.nodebug.wasm": 62,
"a.out.nodebug.wasm.gz": 76,
"total": 559,
"total_gz": 373,
"a.out.nodebug.wasm": 75,
"a.out.nodebug.wasm.gz": 87,
"total": 572,
"total_gz": 384,
"sent": [],
"imports": [],
"exports": [
"a (memory)",
"b (__wasm_call_ctors)",
"c (add)"
"c (add)",
"d (global_val)"
],
"funcs": [
"$__wasm_call_ctors",
Expand Down
13 changes: 7 additions & 6 deletions test/codesize/test_codesize_minimal_Oz-ctors.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"a.out.js": 2271,
"a.out.js": 2272,
"a.out.js.gz": 1122,
"a.out.nodebug.wasm": 51,
"a.out.nodebug.wasm.gz": 68,
"total": 2322,
"total_gz": 1190,
"a.out.nodebug.wasm": 64,
"a.out.nodebug.wasm.gz": 80,
"total": 2336,
"total_gz": 1202,
"sent": [],
"imports": [],
"exports": [
"a (memory)",
"b (add)"
"b (add)",
"c (global_val)"
],
"funcs": [
"$add"
Expand Down
13 changes: 7 additions & 6 deletions test/codesize/test_codesize_minimal_Oz.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"a.out.js": 2292,
"a.out.js": 2293,
"a.out.js.gz": 1137,
"a.out.nodebug.wasm": 62,
"a.out.nodebug.wasm.gz": 76,
"total": 2354,
"total_gz": 1213,
"a.out.nodebug.wasm": 75,
"a.out.nodebug.wasm.gz": 87,
"total": 2368,
"total_gz": 1224,
"sent": [],
"imports": [],
"exports": [
"a (memory)",
"b (__wasm_call_ctors)",
"c (add)"
"c (add)",
"d (global_val)"
],
"funcs": [
"$__wasm_call_ctors",
Expand Down
15 changes: 8 additions & 7 deletions test/codesize/test_codesize_minimal_esm.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"a.out.js": 2427,
"a.out.js.gz": 1169,
"a.out.nodebug.wasm": 62,
"a.out.nodebug.wasm.gz": 76,
"total": 2489,
"total_gz": 1245,
"a.out.js": 2429,
"a.out.js.gz": 1168,
"a.out.nodebug.wasm": 75,
"a.out.nodebug.wasm.gz": 87,
"total": 2504,
"total_gz": 1255,
"sent": [],
"imports": [],
"exports": [
"a (memory)",
"b (__wasm_call_ctors)",
"c (add)"
"c (add)",
"d (global_val)"
],
"funcs": [
"$__wasm_call_ctors",
Expand Down
Loading