Skip to content
Open
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
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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.15',
'v8_embedder_string': '-node.16',

##### V8 defaults for Node.js #####

Expand Down
32 changes: 28 additions & 4 deletions deps/v8/src/codegen/constant-pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,22 @@ void ConstantPool::EmitAndClear(Jump require_jump) {
EmitPrologue(require_alignment);
if (require_alignment == Alignment::kRequired) assm_->DataAlign(kInt64Size);
EmitEntries();
// Emit padding data to ensure the constant pool size matches the expected
// constant count during disassembly.
if (v8_flags.riscv_c_extension) {
int code_size = assm_->SizeOfCodeGeneratedSince(&size_check);
DCHECK_LE(code_size, size);

while (code_size < size) {
assm_->db(0xcc);
code_size++;
}
}
assm_->RecordComment("]");
assm_->bind(&after_pool);
DEBUG_PRINTF("\tConstant Pool end\n")

DCHECK_LE(assm_->SizeOfCodeGeneratedSince(&size_check) - size, 3);
DCHECK_EQ(size, assm_->SizeOfCodeGeneratedSince(&size_check));
Clear();
}

Expand Down Expand Up @@ -666,17 +677,30 @@ bool ConstantPool::ShouldEmitNow(Jump require_jump, size_t margin) const {
int ConstantPool::ComputeSize(Jump require_jump,
Alignment require_alignment) const {
int size_up_to_marker = PrologueSize(require_jump);
int alignment = require_alignment == Alignment::kRequired ? kInstrSize : 0;
// With RVC enabled, constant pool alignment must use kInt64Size to ensure
// sufficient padding space for 8-byte alignment; otherwise, alignment may
// fail.
//
// Example:
// pc_offset = 0x22
// Aligned(0x22, kInt64Size) = 0x28 → 6 bytes of padding needed.
int alignment = require_alignment == Alignment::kRequired
? (v8_flags.riscv_c_extension ? kInt64Size : kInstrSize)
: 0;
size_t size_after_marker =
Entry32Count() * kInt32Size + alignment + Entry64Count() * kInt64Size;
return size_up_to_marker + static_cast<int>(size_after_marker);
}

Alignment ConstantPool::IsAlignmentRequiredIfEmittedAt(Jump require_jump,
int pc_offset) const {
// When the RVC extension is enabled, constant pool entries must be aligned to
// kInstrSize to prevent unaligned 32-bit memory accesses.
int size_up_to_marker = PrologueSize(require_jump);
if (Entry64Count() != 0 &&
!IsAligned(pc_offset + size_up_to_marker, kInt64Size)) {
if ((Entry64Count() != 0 &&
!IsAligned(pc_offset + size_up_to_marker, kInt64Size)) ||
(Entry32Count() != 0 && v8_flags.riscv_c_extension &&
!IsAligned(pc_offset + size_up_to_marker, kInstrSize))) {
return Alignment::kRequired;
}
return Alignment::kOmitted;
Expand Down
18 changes: 10 additions & 8 deletions deps/v8/src/codegen/riscv/macro-assembler-riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5370,24 +5370,22 @@ void MacroAssembler::StoreReturnAddressAndCall(Register target) {
// trigger GC, since the callee function will return to it.

Assembler::BlockTrampolinePoolScope block_trampoline_pool(this);
int kNumInstructions = v8_flags.riscv_c_extension ? 5 : 6;
Label start;
Label start, end;

// Make 'ra' point to the correct return location, just after the 'jalr t6'
// instruction that does the call, and store 'ra' at the top of the stack.
bind(&start);
auipc(ra, 0); // Set 'ra' the current 'pc'.
AddWord(ra, ra, kNumInstructions * kInstrSize);
LoadAddress(ra, &end);
StoreWord(ra, MemOperand(sp)); // Reserved in EnterExitFrame.
AddWord(sp, sp, -kCArgsSlotsSize); // Preserves stack alignment.

// Call the C routine.
Mv(t6, target); // Function pointer in 't6' to conform to ABI for PIC.
jalr(t6);

// Make sure the stored 'ra' points to this position. This way, the 'ra'
// value we stored on the stack matches the value of 'ra' during the call.
DCHECK_EQ(kNumInstructions, InstructionsGeneratedSince(&start));
// The 'ra' value we stored on the stack matches the value of 'ra' during the
// call.
bind(&end);
}

void MacroAssembler::Ret(Condition cond, Register rs, const Operand& rt) {
Expand Down Expand Up @@ -7358,7 +7356,11 @@ int MacroAssembler::CallCFunctionHelper(
AddWord(sp, sp, Operand(stack_passed_arguments * kSystemPointerSize));
}
if (kMaxSizeOfMoveAfterFastCall > pc_offset() - before_offset) {
nop();
// If the RCV extension is enabled, we may have to emit multiple NOPs to
// have enough space for patching in the deopt trampoline.
do {
NOP();
} while (pc_offset() - before_offset != kMaxSizeOfMoveAfterFastCall);
}
// We assume that with the nop padding, the move instruction uses
// kMaxSizeOfMoveAfterFastCall bytes. When we patch in the deopt trampoline,
Expand Down
Loading