Skip to content

Commit 408b816

Browse files
jgravelle-googlesbc100
authored andcommitted
Always incorporate the table segment offset when calculating jsCallStartIndex (#1579)
1 parent 1b99c75 commit 408b816

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/wasm/wasm-emscripten.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,16 @@ struct JSCallWalker : public PostWalker<JSCallWalker> {
207207
}
208208
const auto& tableSegmentData = wasm.table.segments[0].data;
209209

210+
jsCallStartIndex =
211+
wasm.table.segments[0].offset->cast<Const>()->value.getInteger();
210212
// Check if jsCalls have already been created
211213
for (Index i = 0; i < tableSegmentData.size(); ++i) {
212214
if (tableSegmentData[i].startsWith("jsCall_")) {
213-
jsCallStartIndex = i;
215+
jsCallStartIndex += i;
214216
return;
215217
}
216218
}
217-
jsCallStartIndex =
218-
wasm.table.segments[0].offset->cast<Const>()->value.getInteger() +
219-
tableSegmentData.size();
219+
jsCallStartIndex += tableSegmentData.size();
220220
}
221221

222222
// Gather all function signatures used in call_indirect, because any of them

test/lld/reserved_func_ptr.wast.jscall.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,4 @@
294294
)
295295
)
296296
)
297-
;; METADATA: { "asmConsts": {},"staticBump": 0, "initializers": ["__wasm_call_ctors"], "jsCallStartIndex": 2, "jsCallFuncType": ["ddi","fffi","iii","v","vi","viii"], "declares": ["_Z4atoiPKc"], "externs": [], "implementedFunctions": ["___wasm_call_ctors","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory","_dynCall_viii"], "exports": ["memory","__wasm_call_ctors","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory","dynCall_viii"], "invokeFuncs": [] }
297+
;; METADATA: { "asmConsts": {},"staticBump": 0, "initializers": ["__wasm_call_ctors"], "jsCallStartIndex": 3, "jsCallFuncType": ["ddi","fffi","iii","v","vi","viii"], "declares": ["_Z4atoiPKc"], "externs": [], "implementedFunctions": ["___wasm_call_ctors","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory","_dynCall_viii"], "exports": ["memory","__wasm_call_ctors","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory","dynCall_viii"], "invokeFuncs": [] }

0 commit comments

Comments
 (0)