Skip to content

Commit 113e175

Browse files
committed
Patch OpenSSL 3.5 to hardcode the vlenb CSR address on RISC-V
Our GCC version doesn't know it, so replace the `vlenb` variable with `0xc22`. See openssl/openssl#23011.
1 parent cc6f971 commit 113e175

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

cpython-unix/build-openssl-3.5.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ tar -xf openssl-${OPENSSL_3_5_VERSION}.tar.gz
1313

1414
pushd openssl-${OPENSSL_3_5_VERSION}
1515

16+
# hardcode the vlenb CSR address (0xc22) as our GCC version doesn't know it
17+
# https://github.com/riscv/riscv-isa-manual/blob/c001fa237cdd8b6079384044462a89eb0e3fd9cf/src/v-st-ext.adoc?plain=1#L74
18+
if [[ "${TARGET_TRIPLE}" = "riscv64-unknown-linux-gnu" ]]; then
19+
patch -p1 -i "${ROOT}/patch-openssl-3.5-riscv-vlenb-register.patch"
20+
fi
21+
1622
# Otherwise it gets set to /tools/deps/ssl by default.
1723
case "${TARGET_TRIPLE}" in
1824
*apple*)

cpython-unix/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,11 @@ def simple_build(
274274

275275
add_target_env(env, host_platform, target_triple, build_env)
276276

277+
# for OpenSSL, set the OPENSSL_TARGET environment variable and copy in patches
277278
if entry.startswith("openssl-"):
278279
settings = get_targets(TARGETS_CONFIG)[target_triple]
279280
env["OPENSSL_TARGET"] = settings["openssl_target"]
281+
build_env.copy_file(SUPPORT / "patch-openssl-3.5-riscv-vlenb-register.patch")
280282

281283
build_env.run("build-%s.sh" % entry, environment=env)
282284

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/crypto/riscv64cpuid.pl b/crypto/riscv64cpuid.pl
2+
index 5dcdc5c584..7751ad50d9 100644
3+
--- a/crypto/riscv64cpuid.pl
4+
+++ b/crypto/riscv64cpuid.pl
5+
@@ -94,8 +94,8 @@ $code .= <<___;
6+
.globl riscv_vlen_asm
7+
.type riscv_vlen_asm,\@function
8+
riscv_vlen_asm:
9+
- csrr $ret, vlenb
10+
- slli $ret, $ret, 3
11+
+ csrr a0, 0xc22
12+
+ slli a0, a0, 3
13+
ret
14+
.size riscv_vlen_asm,.-riscv_vlen_asm
15+
___

0 commit comments

Comments
 (0)