Skip to content

Commit 68ae81b

Browse files
Milad FaV8 LUCI CQ
authored andcommitted
PPC/s390: [wasm] Fix return value of lazy compile runtime function
Port 22a16bd Original Commit Message: The Runtime_WasmCompileLazy function was returning a ptr-sized address, wrapped in an Object. This worked because no GC is triggered between the return from the runtime function and the point where we jump to the returned address. In a pointer-compressed world though, generated code assumes that all objects live in the same 4GB heap, so comparisons only compare the lower 32 bit. On a 64-bit system, this can lead to collisions where a comparison determines that the returned address equals a heap object, even though the upper 32-bit differ. This happens occasionally in the wild, where the returned function entry pointer has the same lower half than the exception sentinel value. This leads to triggering stack unwinding (by the CEntry stub), which then fails (with a CHECK) because there is no pending exception. This CL fixes that by returning a Smi instead which is the offset in the jump table where the kWasmCompileLazy builtin should jump to. The builtin then gets the jump table start address from the instance object, adds the offset that the runtime function returned, and performs the jump. We do not include a regression test because this failure is very spurious and hard to reproduce. [email protected], [email protected], [email protected], [email protected] BUG= LOG=N Change-Id: I92907b97a9d44d8cf42bb356ef350a22f7c5d5e1 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3666249 Commit-Queue: Milad Farazmand <[email protected]> Reviewed-by: Clemens Backes <[email protected]> Reviewed-by: Junliang Yan <[email protected]> Cr-Commit-Position: refs/heads/main@{#80752}
1 parent fe44d70 commit 68ae81b

2 files changed

Lines changed: 44 additions & 14 deletions

File tree

src/builtins/ppc/builtins-ppc.cc

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,8 +2904,8 @@ void Builtins::Generate_Construct(MacroAssembler* masm) {
29042904
void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
29052905
// The function index was put in a register by the jump table trampoline.
29062906
// Convert to Smi for the runtime call.
2907-
__ SmiTag(kWasmCompileLazyFuncIndexRegister,
2908-
kWasmCompileLazyFuncIndexRegister);
2907+
__ SmiTag(kWasmCompileLazyFuncIndexRegister);
2908+
29092909
{
29102910
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
29112911
FrameAndConstantPoolScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
@@ -2939,21 +2939,37 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
29392939
__ MultiPush(gp_regs);
29402940
__ MultiPushF64AndV128(fp_regs, simd_regs);
29412941

2942-
// Pass instance and function index as explicit arguments to the runtime
2942+
// Push the Wasm instance for loading the jump table address after the
2943+
// runtime call.
2944+
__ Push(kWasmInstanceRegister);
2945+
2946+
// Push the Wasm instance again as an explicit argument to the runtime
29432947
// function.
2944-
__ Push(kWasmInstanceRegister, kWasmCompileLazyFuncIndexRegister);
2948+
__ Push(kWasmInstanceRegister);
2949+
// Push the function index as second argument.
2950+
__ Push(kWasmCompileLazyFuncIndexRegister);
29452951
// Initialize the JavaScript context with 0. CEntry will use it to
29462952
// set the current context on the isolate.
29472953
__ LoadSmiLiteral(cp, Smi::zero());
29482954
__ CallRuntime(Runtime::kWasmCompileLazy, 2);
2949-
// The entrypoint address is the return value.
2950-
__ mr(r11, kReturnRegister0);
2955+
// The runtime function returns the jump table slot offset as a Smi. Use
2956+
// that to compute the jump target in r11.
2957+
__ Pop(kWasmInstanceRegister);
2958+
__ LoadU64(
2959+
r11,
2960+
MemOperand(kWasmInstanceRegister,
2961+
WasmInstanceObject::kJumpTableStartOffset - kHeapObjectTag),
2962+
r0);
2963+
__ SmiUntag(kReturnRegister0);
2964+
__ AddS64(r11, r11, kReturnRegister0);
2965+
// r11 now holds the jump table slot where we want to jump to in the end.
29512966

29522967
// Restore registers.
29532968
__ MultiPopF64AndV128(fp_regs, simd_regs);
29542969
__ MultiPop(gp_regs);
29552970
}
2956-
// Finally, jump to the entrypoint.
2971+
2972+
// Finally, jump to the jump table slot for the function.
29572973
__ Jump(r11);
29582974
}
29592975

src/builtins/s390/builtins-s390.cc

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,8 +2910,8 @@ void Builtins::Generate_Construct(MacroAssembler* masm) {
29102910
void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
29112911
// The function index was put in a register by the jump table trampoline.
29122912
// Convert to Smi for the runtime call.
2913-
__ SmiTag(kWasmCompileLazyFuncIndexRegister,
2914-
kWasmCompileLazyFuncIndexRegister);
2913+
__ SmiTag(kWasmCompileLazyFuncIndexRegister);
2914+
29152915
{
29162916
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
29172917
FrameAndConstantPoolScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
@@ -2939,21 +2939,35 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
29392939
__ MultiPush(gp_regs);
29402940
__ MultiPushF64OrV128(fp_regs, ip);
29412941

2942-
// Pass instance and function index as explicit arguments to the runtime
2942+
// Push the Wasm instance for loading the jump table address after the
2943+
// runtime call.
2944+
__ Push(kWasmInstanceRegister);
2945+
2946+
// Push the Wasm instance again as an explicit argument to the runtime
29432947
// function.
2944-
__ Push(kWasmInstanceRegister, r7);
2948+
__ Push(kWasmInstanceRegister);
2949+
// Push the function index as second argument.
2950+
__ Push(kWasmCompileLazyFuncIndexRegister);
29452951
// Initialize the JavaScript context with 0. CEntry will use it to
29462952
// set the current context on the isolate.
29472953
__ LoadSmiLiteral(cp, Smi::zero());
29482954
__ CallRuntime(Runtime::kWasmCompileLazy, 2);
2949-
// The entrypoint address is the return value.
2950-
__ mov(ip, r2);
2955+
// The runtime function returns the jump table slot offset as a Smi. Use
2956+
// that to compute the jump target in ip.
2957+
__ Pop(kWasmInstanceRegister);
2958+
__ LoadU64(ip, MemOperand(kWasmInstanceRegister,
2959+
WasmInstanceObject::kJumpTableStartOffset -
2960+
kHeapObjectTag));
2961+
__ SmiUntag(kReturnRegister0);
2962+
__ AddS64(ip, ip, kReturnRegister0);
2963+
// ip now holds the jump table slot where we want to jump to in the end.
29512964

29522965
// Restore registers.
29532966
__ MultiPopF64OrV128(fp_regs, ip);
29542967
__ MultiPop(gp_regs);
29552968
}
2956-
// Finally, jump to the entrypoint.
2969+
2970+
// Finally, jump to the jump table slot for the function.
29572971
__ Jump(ip);
29582972
}
29592973

0 commit comments

Comments
 (0)