Skip to content

Commit b29d85c

Browse files
kxxtfelixonmars
authored andcommitted
updpatch: nodejs 24.2.0-1
Backport two V8 CL to fix riscv-forks/electron#9, upstreamed: nodejs/node#58746
1 parent 891e2f4 commit b29d85c

File tree

3 files changed

+240
-4
lines changed

3 files changed

+240
-4
lines changed

nodejs/riscv64.patch

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- PKGBUILD
22
+++ PKGBUILD
3-
@@ -51,6 +51,15 @@ _set_flags() {
3+
@@ -51,6 +51,17 @@ _set_flags() {
44
# /usr/lib/libnode.so uses malloc_usable_size, which is incompatible with fortification level 3
55
CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
66
CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
@@ -13,17 +13,23 @@
1313
+ cd node
1414
+ patch -Np1 -i ../fix-trap-handler.patch
1515
+ patch -Np1 -i ../hwy-broken-rvv.diff
16+
+ patch -Np1 -i ../v8-riscv-fix-trampoline.patch
17+
+ patch -Np1 -i ../v8-riscv-fix-trampoline-release.patch
1618
}
1719

1820
build() {
19-
@@ -95,4 +104,10 @@ package() {
21+
@@ -95,4 +106,14 @@ package() {
2022
install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/nodejs/
2123
}
2224

2325
+
2426
+makedepends+=(clang)
2527
+source+=("fix-trap-handler.patch"
26-
+ "hwy-broken-rvv.diff")
28+
+ "hwy-broken-rvv.diff"
29+
+ "v8-riscv-fix-trampoline.patch"
30+
+ "v8-riscv-fix-trampoline-release.patch")
2731
+sha512sums+=('f2ff6da8cf5dcc994a7a20342e2928dc1821fbbf42891009a6234b6051277e0200d7e3fbba63b9a2773887591d0ad5ceb1bb3d25e5efeb557f6d00109a80253c'
28-
+ 'de07b0d9c3481036ee97a22941ff444fee86c78abbc26afef36f17508bb479ce3ab83ca160109fbf4f0b9b3266dcce30860873dc8ffbcac1a70e98d17638ca55')
32+
+ 'de07b0d9c3481036ee97a22941ff444fee86c78abbc26afef36f17508bb479ce3ab83ca160109fbf4f0b9b3266dcce30860873dc8ffbcac1a70e98d17638ca55'
33+
+ '625507d38eb6c14e9a502aa85d6a265bf14444987b6a62da40cf63cdbb027ef530adafbae55e89266f2077715a3c94f77f32037c793340dd2b192c99ebd5abed'
34+
+ 'fcb6226fae37958d3b0566a6e30e1ef6d8a434baa1d0850133c4c2aedf98108c6033de6a81858a5e84b04d8524c7d09080a965b00a9f6f9e13fc7825cb348ea5')
2935
# vim:set ts=2 sw=2 et:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
From 35e479a4ea840e72a286bf0519c76151b42c539e Mon Sep 17 00:00:00 2001
2+
From: Lu Yahan <[email protected]>
3+
Date: Wed, 18 Jun 2025 09:02:36 +0800
4+
Subject: [PATCH] deps: V8: cherry-pick 7f436a0b44a1
5+
6+
Original commit message:
7+
8+
[riscv] Check trampoline before Constant pool in Release mode
9+
10+
Change-Id: I9645cded9328dabb2c11c7859b998c838b95f97b
11+
12+
Refs: https://github.com/v8/v8/commit/7f436a0b44a15f2f8536e3d208d1e2f99592f803
13+
---
14+
common.gypi | 2 +-
15+
deps/v8/src/codegen/riscv/macro-assembler-riscv.cc | 5 ++---
16+
2 files changed, 3 insertions(+), 4 deletions(-)
17+
18+
diff --git a/common.gypi b/common.gypi
19+
index 90f48604f3..f9fe11388d 100644
20+
--- a/common.gypi
21+
+++ b/common.gypi
22+
@@ -38,7 +38,7 @@
23+
24+
# Reset this number to 0 on major V8 upgrades.
25+
# Increment by one for each non-official patch applied to deps/v8.
26+
- 'v8_embedder_string': '-node.18',
27+
+ 'v8_embedder_string': '-node.19',
28+
29+
##### V8 defaults for Node.js #####
30+
31+
diff --git a/deps/v8/src/codegen/riscv/macro-assembler-riscv.cc b/deps/v8/src/codegen/riscv/macro-assembler-riscv.cc
32+
index 71a1866246..04ffd05c0b 100644
33+
--- a/deps/v8/src/codegen/riscv/macro-assembler-riscv.cc
34+
+++ b/deps/v8/src/codegen/riscv/macro-assembler-riscv.cc
35+
@@ -4941,10 +4941,9 @@ void MacroAssembler::Jump(Register target, Condition cond, Register rs,
36+
jr(target);
37+
DEBUG_PRINTF("\tCheckTrampolinePool pc_offset:%d %d\n", pc_offset(),
38+
next_buffer_check() - ConstpoolComputesize());
39+
- if (!is_trampoline_emitted() && v8_flags.debug_code &&
40+
+ if (!is_trampoline_emitted() &&
41+
pc_offset() >= (next_buffer_check() - ConstpoolComputesize())) {
42+
- // Debug mode will emit more instrs than Release mode.
43+
- // so we need to check trampoline pool before Constant pool.
44+
+ // We need to check trampoline pool before Constant pool.
45+
// Here need to emit trampoline first.
46+
// Jump(ra, al) will block trampoline pool for 1 instr.
47+
nop();
48+
--
49+
2.47.2
50+
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
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

Comments
 (0)