Skip to content

Commit bbaae8e

Browse files
luyahanV8 LUCI CQ
authored andcommitted
Reland "[riscv] Fix Check failed in bind_to"
This is a reland of commit fdb5de2 Original change's description: > [riscv] Fix Check failed in bind_to > > The trampoline should be emitted before the constant pool. > > Bug: 420232092 > > Change-Id: I3a909b122607e37aca9d8765f28810ec74d5dc0b > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6578135 > Auto-Submit: Yahan Lu (LuYahan) <[email protected]> > Reviewed-by: Ji Qiu <[email protected]> > Commit-Queue: Ji Qiu <[email protected]> > Cr-Commit-Position: refs/heads/main@{#100480} Bug: 420232092 Change-Id: I1fac1ed8c349383ef4510abea338b3d695ed57ab Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6595668 Commit-Queue: Ji Qiu <[email protected]> Reviewed-by: Ji Qiu <[email protected]> Cr-Commit-Position: refs/heads/main@{#100745}
1 parent b4cc1a8 commit bbaae8e

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/codegen/riscv/assembler-riscv.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,8 @@ void Assembler::bind_to(Label* L, int pos) {
720720
trampoline_pos = get_trampoline_entry(fixup_pos);
721721
CHECK_NE(trampoline_pos, kInvalidSlotPos);
722722
}
723-
CHECK((trampoline_pos - fixup_pos) <= kMaxBranchOffset);
724723
DEBUG_PRINTF("\t\ttrampolining: %d\n", trampoline_pos);
724+
CHECK((trampoline_pos - fixup_pos) <= kMaxBranchOffset);
725725
target_at_put(fixup_pos, trampoline_pos, false);
726726
fixup_pos = trampoline_pos;
727727
}
@@ -1498,6 +1498,7 @@ void Assembler::BlockTrampolinePoolFor(int instructions) {
14981498
}
14991499

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

1522-
DCHECK(!trampoline_emitted_);
15231523
DCHECK_GE(unbound_labels_count_, 0);
15241524
if (unbound_labels_count_ > 0) {
15251525
// First we emit jump, then we emit trampoline pool.

src/codegen/riscv/assembler-riscv.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase,
305305
// See Assembler::CheckConstPool for more info.
306306
void EmitPoolGuard();
307307

308+
void FinishCode() { ForceConstantPoolEmissionWithoutJump(); }
309+
308310
#if defined(V8_TARGET_ARCH_RISCV64)
309311
static void set_target_value_at(
310312
Address pc, uint64_t target,
@@ -620,6 +622,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase,
620622
}
621623
}
622624

625+
inline int next_buffer_check() { return next_buffer_check_; }
626+
623627
friend class VectorUnit;
624628
class VectorUnit {
625629
public:
@@ -731,16 +735,19 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase,
731735

732736
// Block the emission of the trampoline pool before pc_offset.
733737
void BlockTrampolinePoolBefore(int pc_offset) {
734-
if (no_trampoline_pool_before_ < pc_offset)
738+
if (no_trampoline_pool_before_ < pc_offset) {
739+
DEBUG_PRINTF("\tBlockTrampolinePoolBefore %d\n", pc_offset);
735740
no_trampoline_pool_before_ = pc_offset;
741+
}
736742
}
737743

738744
void StartBlockTrampolinePool() {
739-
DEBUG_PRINTF("\tStartBlockTrampolinePool\n");
745+
DEBUG_PRINTF("\tStartBlockTrampolinePool %d\n", pc_offset());
740746
trampoline_pool_blocked_nesting_++;
741747
}
742748

743749
void EndBlockTrampolinePool() {
750+
DEBUG_PRINTF("\tEndBlockTrampolinePool\n");
744751
trampoline_pool_blocked_nesting_--;
745752
DEBUG_PRINTF("\ttrampoline_pool_blocked_nesting:%d\n",
746753
trampoline_pool_blocked_nesting_);
@@ -770,6 +777,10 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase,
770777

771778
bool is_buffer_growth_blocked() const { return block_buffer_growth_; }
772779

780+
inline int ConstpoolComputesize() {
781+
return constpool_.ComputeSize(Jump::kOmitted, Alignment::kOmitted);
782+
}
783+
773784
private:
774785
// Avoid overflows for displacements etc.
775786
static const int kMaximalBufferSize = 512 * MB;

src/codegen/riscv/macro-assembler-riscv.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4974,12 +4974,22 @@ void MacroAssembler::Jump(Register target, Condition cond, Register rs,
49744974
const Operand& rt) {
49754975
DCHECK_WITH_MSG(t0 != target,
49764976
"don't use x5 as target for jumps to avoid RAS pollution");
4977-
4978-
BlockTrampolinePoolScope block_trampoline_pool(this);
49794977
if (cond == cc_always) {
49804978
jr(target);
4979+
DEBUG_PRINTF("\tCheckTrampolinePool pc_offset:%d %d\n", pc_offset(),
4980+
next_buffer_check() - ConstpoolComputesize());
4981+
if (!is_trampoline_emitted() && v8_flags.debug_code &&
4982+
pc_offset() >= (next_buffer_check() - ConstpoolComputesize())) {
4983+
// Debug mode will emit more instrs than Release mode.
4984+
// so we need to check trampoline pool before Constant pool.
4985+
// Here need to emit trampoline first.
4986+
// Jump(ra, al) will block trampoline pool for 1 instr.
4987+
nop();
4988+
CheckTrampolinePool();
4989+
}
49814990
ForceConstantPoolEmissionWithoutJump();
49824991
} else {
4992+
BlockTrampolinePoolScope block_trampoline_pool(this);
49834993
BRANCH_ARGS_CHECK(cond, rs, rt);
49844994
Branch(kInstrSize * 2, NegateCondition(cond), rs, rt);
49854995
jr(target);
@@ -5393,9 +5403,6 @@ void MacroAssembler::StoreReturnAddressAndCall(Register target) {
53935403

53945404
void MacroAssembler::Ret(Condition cond, Register rs, const Operand& rt) {
53955405
Jump(ra, cond, rs, rt);
5396-
if (cond == al) {
5397-
ForceConstantPoolEmissionWithoutJump();
5398-
}
53995406
}
54005407

54015408
void MacroAssembler::BranchLong(Label* L) {

0 commit comments

Comments
 (0)