Skip to content

Commit 06ac87a

Browse files
spholzHendiadyoin1
authored andcommitted
Toolchain: Add GCC RISC-V function multi-versioning support
1 parent df4a46b commit 06ac87a

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?S=C3=B6nke=20Holz?= <[email protected]>
3+
Date: Thu, 8 May 2025 13:20:05 +0200
4+
Subject: [PATCH] RISC-V: Implement __init_riscv_feature_bits for SerenityOS
5+
6+
The SerenityOS dynamic linker provides a magic function
7+
"__get_riscv_feature_bits" that populates __riscv_feature_bits
8+
and __riscv_cpu_model.
9+
---
10+
libgcc/config/riscv/feature_bits.c | 27 +++++++++++++++++++++++++--
11+
1 file changed, 25 insertions(+), 2 deletions(-)
12+
13+
diff --git a/libgcc/config/riscv/feature_bits.c b/libgcc/config/riscv/feature_bits.c
14+
index 157bcdcad69a939037f6faca3a90c2598dd61f89..8b3f45ffda99f3931ca86b0623283cf029918489 100644
15+
--- a/libgcc/config/riscv/feature_bits.c
16+
+++ b/libgcc/config/riscv/feature_bits.c
17+
@@ -145,7 +145,7 @@ struct {
18+
19+
#define SET_EXT(EXT) features[EXT##_GROUPID] |= EXT##_BITMASK
20+
21+
-#ifdef __linux
22+
+#if defined(__linux)
23+
24+
#define __NR_riscv_hwprobe 258
25+
#define RISCV_HWPROBE_KEY_MVENDORID 0
26+
@@ -376,6 +376,27 @@ static void __init_riscv_features_bits_linux ()
27+
28+
__riscv_feature_bits.length = RISCV_FEATURE_BITS_LENGTH;
29+
}
30+
+
31+
+#elif defined(__serenity__)
32+
+
33+
+extern void __get_riscv_feature_bits(void*, void*) __attribute__((weak));
34+
+
35+
+static void __init_riscv_features_bits_serenity ()
36+
+{
37+
+ if (__get_riscv_feature_bits)
38+
+ {
39+
+ __riscv_feature_bits.length = RISCV_FEATURE_BITS_LENGTH;
40+
+ __get_riscv_feature_bits (&__riscv_feature_bits, &__riscv_cpu_model);
41+
+ }
42+
+ else
43+
+ {
44+
+ __riscv_feature_bits.length = 0;
45+
+ __riscv_cpu_model.mvendorid = 0;
46+
+ __riscv_cpu_model.marchid = 0;
47+
+ __riscv_cpu_model.mimpid = 0;
48+
+ }
49+
+}
50+
+
51+
#endif
52+
53+
54+
@@ -388,8 +409,10 @@ __init_riscv_feature_bits ()
55+
if (__init)
56+
return;
57+
58+
-#ifdef __linux
59+
+#if defined(__linux)
60+
__init_riscv_features_bits_linux ();
61+
+#elif defined(__serenity__)
62+
+ __init_riscv_features_bits_serenity ();
63+
#else
64+
/* Unsupported, just initialize that into all zeros. */
65+
__riscv_feature_bits.length = 0;

Toolchain/Patches/gcc/ReadMe.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,12 @@ it statically into LibC/our shared objects. However, the build system
6464
forces no-pic/pie instead.
6565

6666
This hack is from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58638
67+
68+
## `0008-RISC-V-Implement-__init_riscv_feature_bits-for-Seren.patch`
69+
70+
RISC-V: Implement __init_riscv_feature_bits for SerenityOS
71+
72+
The SerenityOS dynamic linker provides a magic function
73+
"__get_riscv_feature_bits" that populates __riscv_feature_bits
74+
and __riscv_cpu_model.
75+

0 commit comments

Comments
 (0)