|
| 1 | +From fcf3c056959c4fa5ad477d253db926796614225d Mon Sep 17 00:00:00 2001 |
| 2 | +From: Lu Yahan < [email protected]> |
| 3 | +Date: Tue, 10 Jun 2025 15:41:56 +0800 |
| 4 | +Subject: [PATCH] deps: V8: backport bbaae8e36164 |
| 5 | + |
| 6 | +Original commit message: |
| 7 | + |
| 8 | + Reland "[riscv] Fix Check failed in bind_to" |
| 9 | + |
| 10 | + This is a reland of commit fdb5de2c741658e94944f2ec1218530e98601c23 |
| 11 | + |
| 12 | + Original change's description: |
| 13 | + > [riscv] Fix Check failed in bind_to |
| 14 | + > |
| 15 | + > The trampoline should be emitted before the constant pool. |
| 16 | + > |
| 17 | + > Bug: 420232092 |
| 18 | + > |
| 19 | + > Change-Id: I3a909b122607e37aca9d8765f28810ec74d5dc0b |
| 20 | + > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6578135 |
| 21 | + > Auto-Submit: Yahan Lu (LuYahan) < [email protected]> |
| 22 | + > Reviewed-by: Ji Qiu < [email protected]> |
| 23 | + > Commit-Queue: Ji Qiu < [email protected]> |
| 24 | + > Cr-Commit-Position: refs/heads/main@{#100480} |
| 25 | + |
| 26 | + Bug: 420232092 |
| 27 | + Change-Id: I1fac1ed8c349383ef4510abea338b3d695ed57ab |
| 28 | + Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6595668 |
| 29 | + Commit-Queue: Ji Qiu < [email protected]> |
| 30 | + Reviewed-by: Ji Qiu < [email protected]> |
| 31 | + Cr-Commit-Position: refs/heads/main@{#100745} |
| 32 | + |
| 33 | +Refs: https://github.com/v8/v8/commit/bbaae8e36164b02b678966c7612bf3d23644b22c |
| 34 | +Co-authored-by: kxxt < [email protected]> |
| 35 | +--- |
| 36 | + common.gypi | 2 +- |
| 37 | + deps/v8/src/codegen/riscv/assembler-riscv.cc | 4 ++-- |
| 38 | + deps/v8/src/codegen/riscv/assembler-riscv.h | 15 +++++++++++++-- |
| 39 | + .../src/codegen/riscv/macro-assembler-riscv.cc | 16 ++++++++++++---- |
| 40 | + 4 files changed, 28 insertions(+), 9 deletions(-) |
| 41 | + |
| 42 | +diff --git a/common.gypi b/common.gypi |
| 43 | +index 96ec81cd81..9904ad4ce3 100644 |
| 44 | +--- a/common.gypi |
| 45 | ++++ b/common.gypi |
| 46 | +@@ -38,7 +38,7 @@ |
| 47 | + |
| 48 | + # Reset this number to 0 on major V8 upgrades. |
| 49 | + # Increment by one for each non-official patch applied to deps/v8. |
| 50 | +- 'v8_embedder_string': '-node.17', |
| 51 | ++ 'v8_embedder_string': '-node.18', |
| 52 | + |
| 53 | + ##### V8 defaults for Node.js ##### |
| 54 | + |
| 55 | +diff --git a/deps/v8/src/codegen/riscv/assembler-riscv.cc b/deps/v8/src/codegen/riscv/assembler-riscv.cc |
| 56 | +index a9093ed331..6cc3724b25 100644 |
| 57 | +--- a/deps/v8/src/codegen/riscv/assembler-riscv.cc |
| 58 | ++++ b/deps/v8/src/codegen/riscv/assembler-riscv.cc |
| 59 | +@@ -720,8 +720,8 @@ void Assembler::bind_to(Label* L, int pos) { |
| 60 | + trampoline_pos = get_trampoline_entry(fixup_pos); |
| 61 | + CHECK_NE(trampoline_pos, kInvalidSlotPos); |
| 62 | + } |
| 63 | +- CHECK((trampoline_pos - fixup_pos) <= kMaxBranchOffset); |
| 64 | + DEBUG_PRINTF("\t\ttrampolining: %d\n", trampoline_pos); |
| 65 | ++ CHECK((trampoline_pos - fixup_pos) <= kMaxBranchOffset); |
| 66 | + target_at_put(fixup_pos, trampoline_pos, false); |
| 67 | + fixup_pos = trampoline_pos; |
| 68 | + } |
| 69 | +@@ -1486,6 +1486,7 @@ void Assembler::BlockTrampolinePoolFor(int instructions) { |
| 70 | + } |
| 71 | + |
| 72 | + void Assembler::CheckTrampolinePool() { |
| 73 | ++ if (trampoline_emitted_) return; |
| 74 | + // Some small sequences of instructions must not be broken up by the |
| 75 | + // insertion of a trampoline pool; such sequences are protected by setting |
| 76 | + // either trampoline_pool_blocked_nesting_ or no_trampoline_pool_before_, |
| 77 | +@@ -1507,7 +1508,6 @@ void Assembler::CheckTrampolinePool() { |
| 78 | + return; |
| 79 | + } |
| 80 | + |
| 81 | +- DCHECK(!trampoline_emitted_); |
| 82 | + DCHECK_GE(unbound_labels_count_, 0); |
| 83 | + if (unbound_labels_count_ > 0) { |
| 84 | + // First we emit jump, then we emit trampoline pool. |
| 85 | +diff --git a/deps/v8/src/codegen/riscv/assembler-riscv.h b/deps/v8/src/codegen/riscv/assembler-riscv.h |
| 86 | +index 2577e12a5d..5c408bfd2e 100644 |
| 87 | +--- a/deps/v8/src/codegen/riscv/assembler-riscv.h |
| 88 | ++++ b/deps/v8/src/codegen/riscv/assembler-riscv.h |
| 89 | +@@ -303,6 +303,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase, |
| 90 | + // See Assembler::CheckConstPool for more info. |
| 91 | + void EmitPoolGuard(); |
| 92 | + |
| 93 | ++ void FinishCode() { ForceConstantPoolEmissionWithoutJump(); } |
| 94 | ++ |
| 95 | + #if defined(V8_TARGET_ARCH_RISCV64) |
| 96 | + static void set_target_value_at( |
| 97 | + Address pc, uint64_t target, |
| 98 | +@@ -617,6 +619,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase, |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | ++ inline int next_buffer_check() { return next_buffer_check_; } |
| 103 | ++ |
| 104 | + friend class VectorUnit; |
| 105 | + class VectorUnit { |
| 106 | + public: |
| 107 | +@@ -728,16 +732,19 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase, |
| 108 | + |
| 109 | + // Block the emission of the trampoline pool before pc_offset. |
| 110 | + void BlockTrampolinePoolBefore(int pc_offset) { |
| 111 | +- if (no_trampoline_pool_before_ < pc_offset) |
| 112 | ++ if (no_trampoline_pool_before_ < pc_offset) { |
| 113 | ++ DEBUG_PRINTF("\tBlockTrampolinePoolBefore %d\n", pc_offset); |
| 114 | + no_trampoline_pool_before_ = pc_offset; |
| 115 | ++ } |
| 116 | + } |
| 117 | + |
| 118 | + void StartBlockTrampolinePool() { |
| 119 | +- DEBUG_PRINTF("\tStartBlockTrampolinePool\n"); |
| 120 | ++ DEBUG_PRINTF("\tStartBlockTrampolinePool %d\n", pc_offset()); |
| 121 | + trampoline_pool_blocked_nesting_++; |
| 122 | + } |
| 123 | + |
| 124 | + void EndBlockTrampolinePool() { |
| 125 | ++ DEBUG_PRINTF("\tEndBlockTrampolinePool\n"); |
| 126 | + trampoline_pool_blocked_nesting_--; |
| 127 | + DEBUG_PRINTF("\ttrampoline_pool_blocked_nesting:%d\n", |
| 128 | + trampoline_pool_blocked_nesting_); |
| 129 | +@@ -767,6 +774,10 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase, |
| 130 | + |
| 131 | + bool is_buffer_growth_blocked() const { return block_buffer_growth_; } |
| 132 | + |
| 133 | ++ inline int ConstpoolComputesize() { |
| 134 | ++ return constpool_.ComputeSize(Jump::kOmitted, Alignment::kOmitted); |
| 135 | ++ } |
| 136 | ++ |
| 137 | + private: |
| 138 | + // Avoid overflows for displacements etc. |
| 139 | + static const int kMaximalBufferSize = 512 * MB; |
| 140 | +diff --git a/deps/v8/src/codegen/riscv/macro-assembler-riscv.cc b/deps/v8/src/codegen/riscv/macro-assembler-riscv.cc |
| 141 | +index 9ac7746ad1..28e648fb0c 100644 |
| 142 | +--- a/deps/v8/src/codegen/riscv/macro-assembler-riscv.cc |
| 143 | ++++ b/deps/v8/src/codegen/riscv/macro-assembler-riscv.cc |
| 144 | +@@ -4926,11 +4926,22 @@ void MacroAssembler::LoadRootRegisterOffset(Register destination, |
| 145 | + |
| 146 | + void MacroAssembler::Jump(Register target, Condition cond, Register rs, |
| 147 | + const Operand& rt) { |
| 148 | +- BlockTrampolinePoolScope block_trampoline_pool(this); |
| 149 | + if (cond == cc_always) { |
| 150 | + jr(target); |
| 151 | ++ DEBUG_PRINTF("\tCheckTrampolinePool pc_offset:%d %d\n", pc_offset(), |
| 152 | ++ next_buffer_check() - ConstpoolComputesize()); |
| 153 | ++ if (!is_trampoline_emitted() && v8_flags.debug_code && |
| 154 | ++ pc_offset() >= (next_buffer_check() - ConstpoolComputesize())) { |
| 155 | ++ // Debug mode will emit more instrs than Release mode. |
| 156 | ++ // so we need to check trampoline pool before Constant pool. |
| 157 | ++ // Here need to emit trampoline first. |
| 158 | ++ // Jump(ra, al) will block trampoline pool for 1 instr. |
| 159 | ++ nop(); |
| 160 | ++ CheckTrampolinePool(); |
| 161 | ++ } |
| 162 | + ForceConstantPoolEmissionWithoutJump(); |
| 163 | + } else { |
| 164 | ++ BlockTrampolinePoolScope block_trampoline_pool(this); |
| 165 | + BRANCH_ARGS_CHECK(cond, rs, rt); |
| 166 | + Branch(kInstrSize * 2, NegateCondition(cond), rs, rt); |
| 167 | + jr(target); |
| 168 | +@@ -5342,9 +5353,6 @@ void MacroAssembler::StoreReturnAddressAndCall(Register target) { |
| 169 | + |
| 170 | + void MacroAssembler::Ret(Condition cond, Register rs, const Operand& rt) { |
| 171 | + Jump(ra, cond, rs, rt); |
| 172 | +- if (cond == al) { |
| 173 | +- ForceConstantPoolEmissionWithoutJump(); |
| 174 | +- } |
| 175 | + } |
| 176 | + |
| 177 | + void MacroAssembler::BranchLong(Label* L) { |
| 178 | +-- |
| 179 | +2.47.2 |
| 180 | + |
0 commit comments