Skip to content

Commit dba1a61

Browse files
committed
Address review: test the parsed path, skip custom page size, tidy
1 parent 365bd82 commit dba1a61

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎src/lib/libdylink.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ var LibraryDylink = {
295295
// Detect immutable wasm global exports. These represent data addresses
296296
// which are relative to `memoryBase`. `mutableGlobals`, when known,
297297
// saves probing each global.
298-
if (mutableGlobals ? value instanceof WebAssembly.Global && !mutableGlobals.has(name) : isImmutableGlobal(value)) {
298+
var immutable = mutableGlobals
299+
? value instanceof WebAssembly.Global && !mutableGlobals.has(name)
300+
: isImmutableGlobal(value);
301+
if (immutable) {
299302
return new WebAssembly.Global({'value': '{{{ POINTER_WASM_TYPE }}}'}, value.value + {{{ to64('memoryBase') }}});
300303
}
301304

@@ -496,8 +499,9 @@ var LibraryDylink = {
496499

497500
function skipLimits() {
498501
var flags = getU8();
499-
getLEB();
500-
if (flags & 1) getLEB();
502+
getLEB(); // min
503+
if (flags & 1) getLEB(); // max
504+
if (flags & 8) getLEB(); // page size (custom-page-sizes)
501505
}
502506

503507
while (offset < binary.length) {
@@ -525,7 +529,7 @@ var LibraryDylink = {
525529
if (op === 0x43) offset += 4; // f32.const
526530
else if (op === 0x44) offset += 8; // f64.const
527531
// i32.const, i64.const, global.get, ref.null, ref.func
528-
else if ([0x41, 0x42, 0x23, 0xd0, 0xd2].includes(op)) getLEB();
532+
else if (op === 0x41 || op === 0x42 || op === 0x23 || op === 0xd0 || op === 0xd2) getLEB();
529533
// Anything but the extended-const add, sub and mul instructions
530534
else if (!(op >= 0x6a && op <= 0x6c || op >= 0x7c && op <= 0x7e)) return;
531535
}

‎test/test_other.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7340,6 +7340,12 @@ def test_dlopen_exported_globals(self):
73407340
assert(side_data && side_data == side_data_addr());
73417341
assert(*side_data == 42);
73427342
EM_ASM({
7343+
// The loader read the mutable globals from the binary, rather than
7344+
// falling back to probing each one.
7345+
var metadata = getDylinkMetadata(new Uint8Array(require('fs').readFileSync('libside.wasm')));
7346+
assert(metadata.mutableGlobals, 'mutableGlobals not parsed');
7347+
assert(metadata.mutableGlobals.size == 1 && metadata.mutableGlobals.has('side_global'));
7348+
73437349
var g = LDSO.loadedLibsByHandle[$0].exports['side_global'];
73447350
assert(g instanceof WebAssembly.Global);
73457351
g.value = 7;

0 commit comments

Comments
 (0)