deps: V8: backport 0b94a9fd23ba

Original commit message:

    [leaptiering] Fix BaselineOutOfLinePrologue builtin

    ... which tried to preserve kJavaScriptCallDispatchHandleRegister even
    on configurations where it's not used which resulted in a random value
    on the stack discoverable by GC.
    This issue triggered only on non-sandbox configuration with enabled
    leaptiering.

    Drive-by: fix MacroAssembler::GenerateTailCallToReturnedCode() on riscv
    port which wasn't preserving dispatch handle as all the other ports do.

    Bug: 42204201
    Fixed: 413769394

    Change-Id: If146b0b7a6cf972ed5a881142f40980774f19cba
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6587010
    Commit-Queue: Igor Sheludko <ishell@chromium.org>
    Reviewed-by: Olivier Flückiger <olivf@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#100512}

Node.js 24 builds V8 with leaptiering enabled and the sandbox disabled,
so V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE is not defined and the JS
calling convention does not carry the dispatch handle register (x4 on
arm64). BaselineOutOfLinePrologue and GenerateTailCallToReturnedCode
still pushed that register as a tagged slot of an INTERNAL frame, so
whatever value the caller left there is dereferenced by
ClearStaleLeftTrimmedPointerVisitor during mark-compact root scanning
and crashes the process with SIGSEGV (seen as jest workers dying).

Refs: https://github.com/v8/v8/commit/0b94a9fd23ba5f59b3f675fb04d60a9b0102e27d
Fixes: https://github.com/nodejs/node/issues/62393
PR-URL: https://github.com/nodejs/node/pull/65753
Reviewed-By: Richard Lau <richard.lau@ibm.com>
This commit is contained in:
Ruan Gustavo authored and Richard Lau committed 2026-09-29 12:01:52 +00:00
1 parent 13987f4418
commit fb0d0ca289
11 files changed
+47 -24

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@
# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.53',
'v8_embedder_string': '-node.54',
##### V8 defaults for Node.js #####
+2 -1
View File
@@ -1293,11 +1293,12 @@ void Builtins::Generate_BaselineOutOfLinePrologue(MacroAssembler* masm) {
FrameScope frame_scope(masm, StackFrame::INTERNAL);
// Save incoming new target or generator
Register maybe_dispatch_handle = V8_ENABLE_LEAPTIERING_BOOL
Register maybe_dispatch_handle = V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE_BOOL
? kJavaScriptCallDispatchHandleRegister
: padreg;
// No need to SmiTag as dispatch handles always look like Smis.
static_assert(kJSDispatchHandleShift > 0);
__ AssertSmi(maybe_dispatch_handle);
__ Push(maybe_dispatch_handle, new_target);
__ SmiTag(frame_size);
__ PushArgument(frame_size);
+3 -2
View File
@@ -1103,15 +1103,16 @@ void Builtins::Generate_BaselineOutOfLinePrologue(MacroAssembler* masm) {
FrameScope frame_scope(masm, StackFrame::INTERNAL);
// Save incoming new target or generator
__ Push(kJavaScriptCallNewTargetRegister);
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
// No need to SmiTag as dispatch handles always look like Smis.
static_assert(kJSDispatchHandleShift > 0);
__ AssertSmi(kJavaScriptCallDispatchHandleRegister);
__ Push(kJavaScriptCallDispatchHandleRegister);
#endif
__ SmiTag(frame_size);
__ Push(frame_size);
__ CallRuntime(Runtime::kStackGuardWithGap);
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
__ Pop(kJavaScriptCallDispatchHandleRegister);
#endif
__ Pop(kJavaScriptCallNewTargetRegister);
+3 -2
View File
@@ -1065,15 +1065,16 @@ void Builtins::Generate_BaselineOutOfLinePrologue(MacroAssembler* masm) {
FrameScope frame_scope(masm, StackFrame::INTERNAL);
// Save incoming new target or generator
__ Push(kJavaScriptCallNewTargetRegister);
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
// No need to SmiTag as dispatch handles always look like Smis.
static_assert(kJSDispatchHandleShift > 0);
__ AssertSmi(kJavaScriptCallDispatchHandleRegister);
__ Push(kJavaScriptCallDispatchHandleRegister);
#endif
__ SmiTag(frame_size);
__ Push(frame_size);
__ CallRuntime(Runtime::kStackGuardWithGap);
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
__ Pop(kJavaScriptCallDispatchHandleRegister);
#endif
__ Pop(kJavaScriptCallNewTargetRegister);
+5 -2
View File
@@ -1099,15 +1099,18 @@ void Builtins::Generate_BaselineOutOfLinePrologue(MacroAssembler* masm) {
FrameScope frame_scope(masm, StackFrame::INTERNAL);
// Save incoming new target or generator
__ Push(kJavaScriptCallNewTargetRegister);
#if defined(V8_ENABLE_LEAPTIERING) && defined(V8_TARGET_ARCH_RISCV64)
#if defined(V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE) && \
defined(V8_TARGET_ARCH_RISCV64)
// No need to SmiTag as dispatch handles always look like Smis.
static_assert(kJSDispatchHandleShift > 0);
__ AssertSmi(kJavaScriptCallDispatchHandleRegister);
__ Push(kJavaScriptCallDispatchHandleRegister);
#endif
__ SmiTag(frame_size);
__ Push(frame_size);
__ CallRuntime(Runtime::kStackGuardWithGap);
#if defined(V8_ENABLE_LEAPTIERING) && defined(V8_TARGET_ARCH_RISCV64)
#if defined(V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE) && \
defined(V8_TARGET_ARCH_RISCV64)
__ Pop(kJavaScriptCallDispatchHandleRegister);
#endif
__ Pop(kJavaScriptCallNewTargetRegister);
+3 -2
View File
@@ -2018,15 +2018,16 @@ void Builtins::Generate_BaselineOutOfLinePrologue(MacroAssembler* masm) {
FrameScope inner_frame_scope(masm, StackFrame::INTERNAL);
// Save incoming new target or generator
__ Push(new_target);
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
// No need to SmiTag as dispatch handles always look like Smis.
static_assert(kJSDispatchHandleShift > 0);
__ AssertSmi(kJavaScriptCallDispatchHandleRegister);
__ Push(kJavaScriptCallDispatchHandleRegister);
#endif
__ SmiTag(frame_size);
__ Push(frame_size);
__ CallRuntime(Runtime::kStackGuardWithGap, 1);
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
__ Pop(kJavaScriptCallDispatchHandleRegister);
#endif
__ Pop(new_target);
+6 -5
View File
@@ -1518,14 +1518,15 @@ void MacroAssembler::GenerateTailCallToReturnedCode(
FrameScope scope(this, StackFrame::INTERNAL);
// Push a copy of the target function, the new target, the actual
// argument count, and the dispatch handle.
Register lastreg = V8_ENABLE_LEAPTIERING_BOOL
? kJavaScriptCallDispatchHandleRegister
: padreg;
Register maybe_dispatch_handle = V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE_BOOL
? kJavaScriptCallDispatchHandleRegister
: padreg;
SmiTag(kJavaScriptCallArgCountRegister);
// No need to SmiTag the dispatch handle as it always looks like a Smi.
static_assert(kJSDispatchHandleShift > 0);
AssertSmi(maybe_dispatch_handle);
Push(kJavaScriptCallTargetRegister, kJavaScriptCallNewTargetRegister,
kJavaScriptCallArgCountRegister, lastreg);
kJavaScriptCallArgCountRegister, maybe_dispatch_handle);
// Push another copy as a parameter to the runtime call.
PushArgument(kJavaScriptCallTargetRegister);
@@ -1534,7 +1535,7 @@ void MacroAssembler::GenerateTailCallToReturnedCode(
// Restore target function, new target, actual argument count, and dispatch
// handle.
Pop(lastreg, kJavaScriptCallArgCountRegister,
Pop(maybe_dispatch_handle, kJavaScriptCallArgCountRegister,
kJavaScriptCallNewTargetRegister, kJavaScriptCallTargetRegister);
SmiUntag(kJavaScriptCallArgCountRegister);
}
+3 -2
View File
@@ -5113,9 +5113,10 @@ void MacroAssembler::GenerateTailCallToReturnedCode(
SmiTag(kJavaScriptCallArgCountRegister);
Push(kJavaScriptCallTargetRegister, kJavaScriptCallNewTargetRegister,
kJavaScriptCallArgCountRegister);
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
// No need to SmiTag since dispatch handles always look like Smis.
static_assert(kJSDispatchHandleShift > 0);
AssertSmi(kJavaScriptCallDispatchHandleRegister);
Push(kJavaScriptCallDispatchHandleRegister);
#endif
// Function is also the parameter to the runtime call.
@@ -5126,7 +5127,7 @@ void MacroAssembler::GenerateTailCallToReturnedCode(
// Restore target function, new target, actual argument count and dispatch
// handle.
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
Pop(kJavaScriptCallDispatchHandleRegister);
#endif
Pop(kJavaScriptCallTargetRegister, kJavaScriptCallNewTargetRegister,
+3 -2
View File
@@ -6578,16 +6578,17 @@ void MacroAssembler::GenerateTailCallToReturnedCode(
SmiTag(kJavaScriptCallArgCountRegister);
Push(kJavaScriptCallTargetRegister, kJavaScriptCallNewTargetRegister,
kJavaScriptCallArgCountRegister);
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
// No need to SmiTag since dispatch handles always look like Smis.
static_assert(kJSDispatchHandleShift > 0);
AssertSmi(kJavaScriptCallDispatchHandleRegister);
Push(kJavaScriptCallDispatchHandleRegister);
#endif
// Function is also the parameter to the runtime call.
Push(kJavaScriptCallTargetRegister);
CallRuntime(function_id, 1);
// Restore target function, new target and actual argument count.
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
Pop(kJavaScriptCallDispatchHandleRegister);
#endif
Pop(kJavaScriptCallTargetRegister, kJavaScriptCallNewTargetRegister,
+15 -3
View File
@@ -186,15 +186,23 @@ void MacroAssembler::GenerateTailCallToReturnedCode(
// -- a0 : actual argument count
// -- a1 : target function (preserved for callee)
// -- a3 : new target (preserved for callee)
// -- a4 : dispatch handle (preserved for callee)
// -----------------------------------
{
FrameScope scope(this, StackFrame::INTERNAL);
// Push a copy of the target function, the new target and the actual
// argument count.
// Push a copy of the target function, the new target, the actual
// argument count, and the dispatch handle.
// Push function as parameter to the runtime call.
SmiTag(kJavaScriptCallArgCountRegister);
#if defined(V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE) && \
defined(V8_TARGET_ARCH_RISCV64)
// No need to SmiTag as dispatch handles always look like Smis.
static_assert(kJSDispatchHandleShift > 0);
AssertSmi(kJavaScriptCallDispatchHandleRegister);
Push(kJavaScriptCallDispatchHandleRegister);
#endif
Push(kJavaScriptCallTargetRegister, kJavaScriptCallNewTargetRegister,
kJavaScriptCallArgCountRegister, kJavaScriptCallTargetRegister);
kJavaScriptCallArgCountRegister);
CallRuntime(function_id, 1);
// Use the return value before restoring a0
@@ -202,6 +210,10 @@ void MacroAssembler::GenerateTailCallToReturnedCode(
// Restore target function, new target and actual argument count.
Pop(kJavaScriptCallTargetRegister, kJavaScriptCallNewTargetRegister,
kJavaScriptCallArgCountRegister);
#if defined(V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE) && \
defined(V8_TARGET_ARCH_RISCV64)
Pop(kJavaScriptCallDispatchHandleRegister);
#endif
SmiUntag(kJavaScriptCallArgCountRegister);
}
+3 -2
View File
@@ -1247,9 +1247,10 @@ void MacroAssembler::GenerateTailCallToReturnedCode(
Push(kJavaScriptCallNewTargetRegister);
SmiTag(kJavaScriptCallArgCountRegister);
Push(kJavaScriptCallArgCountRegister);
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
// No need to SmiTag since dispatch handles always look like Smis.
static_assert(kJSDispatchHandleShift > 0);
AssertSmi(kJavaScriptCallDispatchHandleRegister);
Push(kJavaScriptCallDispatchHandleRegister);
#endif
// Function is also the parameter to the runtime call.
@@ -1260,7 +1261,7 @@ void MacroAssembler::GenerateTailCallToReturnedCode(
// Restore target function, new target, actual argument count, and dispatch
// handle.
#ifdef V8_ENABLE_LEAPTIERING
#ifdef V8_JS_LINKAGE_INCLUDES_DISPATCH_HANDLE
Pop(kJavaScriptCallDispatchHandleRegister);
#endif
Pop(kJavaScriptCallArgCountRegister);