Skip to content

[riscv] Fix check failed in bind_to #58746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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.13',
'v8_embedder_string': '-node.15',

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

Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/codegen/riscv/assembler-riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,8 @@ void Assembler::bind_to(Label* L, int pos) {
trampoline_pos = get_trampoline_entry(fixup_pos);
CHECK_NE(trampoline_pos, kInvalidSlotPos);
}
CHECK((trampoline_pos - fixup_pos) <= kMaxBranchOffset);
DEBUG_PRINTF("\t\ttrampolining: %d\n", trampoline_pos);
CHECK((trampoline_pos - fixup_pos) <= kMaxBranchOffset);
target_at_put(fixup_pos, trampoline_pos, false);
fixup_pos = trampoline_pos;
}
Expand Down Expand Up @@ -1498,6 +1498,7 @@ void Assembler::BlockTrampolinePoolFor(int instructions) {
}

void Assembler::CheckTrampolinePool() {
if (trampoline_emitted_) return;
// Some small sequences of instructions must not be broken up by the
// insertion of a trampoline pool; such sequences are protected by setting
// either trampoline_pool_blocked_nesting_ or no_trampoline_pool_before_,
Expand All @@ -1519,7 +1520,6 @@ void Assembler::CheckTrampolinePool() {
return;
}

DCHECK(!trampoline_emitted_);
DCHECK_GE(unbound_labels_count_, 0);
if (unbound_labels_count_ > 0) {
// First we emit jump, then we emit trampoline pool.
Expand Down
15 changes: 13 additions & 2 deletions deps/v8/src/codegen/riscv/assembler-riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase,
// See Assembler::CheckConstPool for more info.
void EmitPoolGuard();

void FinishCode() { ForceConstantPoolEmissionWithoutJump(); }

#if defined(V8_TARGET_ARCH_RISCV64)
static void set_target_value_at(
Address pc, uint64_t target,
Expand Down Expand Up @@ -618,6 +620,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase,
}
}

inline int next_buffer_check() { return next_buffer_check_; }

friend class VectorUnit;
class VectorUnit {
public:
Expand Down Expand Up @@ -729,16 +733,19 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase,

// Block the emission of the trampoline pool before pc_offset.
void BlockTrampolinePoolBefore(int pc_offset) {
if (no_trampoline_pool_before_ < pc_offset)
if (no_trampoline_pool_before_ < pc_offset) {
DEBUG_PRINTF("\tBlockTrampolinePoolBefore %d\n", pc_offset);
no_trampoline_pool_before_ = pc_offset;
}
}

void StartBlockTrampolinePool() {
DEBUG_PRINTF("\tStartBlockTrampolinePool\n");
DEBUG_PRINTF("\tStartBlockTrampolinePool %d\n", pc_offset());
trampoline_pool_blocked_nesting_++;
}

void EndBlockTrampolinePool() {
DEBUG_PRINTF("\tEndBlockTrampolinePool\n");
trampoline_pool_blocked_nesting_--;
DEBUG_PRINTF("\ttrampoline_pool_blocked_nesting:%d\n",
trampoline_pool_blocked_nesting_);
Expand Down Expand Up @@ -768,6 +775,10 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase,

bool is_buffer_growth_blocked() const { return block_buffer_growth_; }

inline int ConstpoolComputesize() {
return constpool_.ComputeSize(Jump::kOmitted, Alignment::kOmitted);
}

private:
// Avoid overflows for displacements etc.
static const int kMaximalBufferSize = 512 * MB;
Expand Down
15 changes: 11 additions & 4 deletions deps/v8/src/codegen/riscv/macro-assembler-riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4937,11 +4937,21 @@ void MacroAssembler::LoadRootRegisterOffset(Register destination,

void MacroAssembler::Jump(Register target, Condition cond, Register rs,
const Operand& rt) {
BlockTrampolinePoolScope block_trampoline_pool(this);
if (cond == cc_always) {
jr(target);
DEBUG_PRINTF("\tCheckTrampolinePool pc_offset:%d %d\n", pc_offset(),
next_buffer_check() - ConstpoolComputesize());
if (!is_trampoline_emitted() &&
pc_offset() >= (next_buffer_check() - ConstpoolComputesize())) {
// We need to check trampoline pool before Constant pool.
// Here need to emit trampoline first.
// Jump(ra, al) will block trampoline pool for 1 instr.
nop();
CheckTrampolinePool();
}
ForceConstantPoolEmissionWithoutJump();
} else {
BlockTrampolinePoolScope block_trampoline_pool(this);
BRANCH_ARGS_CHECK(cond, rs, rt);
Branch(kInstrSize * 2, NegateCondition(cond), rs, rt);
jr(target);
Expand Down Expand Up @@ -5353,9 +5363,6 @@ void MacroAssembler::StoreReturnAddressAndCall(Register target) {

void MacroAssembler::Ret(Condition cond, Register rs, const Operand& rt) {
Jump(ra, cond, rs, rt);
if (cond == al) {
ForceConstantPoolEmissionWithoutJump();
}
}

void MacroAssembler::BranchLong(Label* L) {
Expand Down
Loading