Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e326df7

Browse filesBrowse files
zengdagekxxt
authored andcommitted
deps: V8: backport 209d2db9e24a
Original commit message: [riscv] Fix compilation error and disassembling error when enabling the RISC-V C extension Change-Id: I34a930f7bcda514698ce64d132cbe05fa32b323c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6934163 Reviewed-by: Yahan Lu (LuYahan) <yahan@iscas.ac.cn> Reviewed-by: Kasper Lund <kasperl@rivosinc.com> Commit-Queue: Yahan Lu (LuYahan) <yahan@iscas.ac.cn> Cr-Commit-Position: refs/heads/main@{#102431} Refs: v8/v8@209d2db Co-authored-by: kxxt <rsworktech@outlook.com> PR-URL: #61322 Reviewed-By: Stewart X Addison <sxa@redhat.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 571c5b8 commit e326df7
Copy full SHA for e326df7

3 files changed

+39-13Lines changed: 39 additions & 13 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎common.gypi‎

Copy file name to clipboardExpand all lines: common.gypi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.15',
41+
'v8_embedder_string': '-node.16',
4242

4343
##### V8 defaults for Node.js #####
4444

Collapse file

‎deps/v8/src/codegen/constant-pool.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/codegen/constant-pool.cc
+28-4Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,22 @@ void ConstantPool::EmitAndClear(Jump require_jump) {
554554
EmitPrologue(require_alignment);
555555
if (require_alignment == Alignment::kRequired) assm_->DataAlign(kInt64Size);
556556
EmitEntries();
557+
// Emit padding data to ensure the constant pool size matches the expected
558+
// constant count during disassembly.
559+
if (v8_flags.riscv_c_extension) {
560+
int code_size = assm_->SizeOfCodeGeneratedSince(&size_check);
561+
DCHECK_LE(code_size, size);
562+
563+
while (code_size < size) {
564+
assm_->db(0xcc);
565+
code_size++;
566+
}
567+
}
557568
assm_->RecordComment("]");
558569
assm_->bind(&after_pool);
559570
DEBUG_PRINTF("\tConstant Pool end\n")
560571

561-
DCHECK_LE(assm_->SizeOfCodeGeneratedSince(&size_check) - size, 3);
572+
DCHECK_EQ(size, assm_->SizeOfCodeGeneratedSince(&size_check));
562573
Clear();
563574
}
564575

@@ -666,17 +677,30 @@ bool ConstantPool::ShouldEmitNow(Jump require_jump, size_t margin) const {
666677
int ConstantPool::ComputeSize(Jump require_jump,
667678
Alignment require_alignment) const {
668679
int size_up_to_marker = PrologueSize(require_jump);
669-
int alignment = require_alignment == Alignment::kRequired ? kInstrSize : 0;
680+
// With RVC enabled, constant pool alignment must use kInt64Size to ensure
681+
// sufficient padding space for 8-byte alignment; otherwise, alignment may
682+
// fail.
683+
//
684+
// Example:
685+
// pc_offset = 0x22
686+
// Aligned(0x22, kInt64Size) = 0x28 → 6 bytes of padding needed.
687+
int alignment = require_alignment == Alignment::kRequired
688+
? (v8_flags.riscv_c_extension ? kInt64Size : kInstrSize)
689+
: 0;
670690
size_t size_after_marker =
671691
Entry32Count() * kInt32Size + alignment + Entry64Count() * kInt64Size;
672692
return size_up_to_marker + static_cast<int>(size_after_marker);
673693
}
674694

675695
Alignment ConstantPool::IsAlignmentRequiredIfEmittedAt(Jump require_jump,
676696
int pc_offset) const {
697+
// When the RVC extension is enabled, constant pool entries must be aligned to
698+
// kInstrSize to prevent unaligned 32-bit memory accesses.
677699
int size_up_to_marker = PrologueSize(require_jump);
678-
if (Entry64Count() != 0 &&
679-
!IsAligned(pc_offset + size_up_to_marker, kInt64Size)) {
700+
if ((Entry64Count() != 0 &&
701+
!IsAligned(pc_offset + size_up_to_marker, kInt64Size)) ||
702+
(Entry32Count() != 0 && v8_flags.riscv_c_extension &&
703+
!IsAligned(pc_offset + size_up_to_marker, kInstrSize))) {
680704
return Alignment::kRequired;
681705
}
682706
return Alignment::kOmitted;
Collapse file

‎deps/v8/src/codegen/riscv/macro-assembler-riscv.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/codegen/riscv/macro-assembler-riscv.cc
+10-8Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5370,24 +5370,22 @@ void MacroAssembler::StoreReturnAddressAndCall(Register target) {
53705370
// trigger GC, since the callee function will return to it.
53715371

53725372
Assembler::BlockTrampolinePoolScope block_trampoline_pool(this);
5373-
int kNumInstructions = v8_flags.riscv_c_extension ? 5 : 6;
5374-
Label start;
5373+
Label start, end;
53755374

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

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

5388-
// Make sure the stored 'ra' points to this position. This way, the 'ra'
5389-
// value we stored on the stack matches the value of 'ra' during the call.
5390-
DCHECK_EQ(kNumInstructions, InstructionsGeneratedSince(&start));
5386+
// The 'ra' value we stored on the stack matches the value of 'ra' during the
5387+
// call.
5388+
bind(&end);
53915389
}
53925390

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.