[compiler-rt] 522880c - [compiler-rt][RISCV] Avoid using __init_riscv_feature_bits as a direc… (#115316)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 08:06:53 PST 2024
Author: Kito Cheng
Date: 2024-11-08T00:06:48+08:00
New Revision: 522880cb99b0573d8689eee083b28af18ff3f9c2
URL: https://github.com/llvm/llvm-project/commit/522880cb99b0573d8689eee083b28af18ff3f9c2
DIFF: https://github.com/llvm/llvm-project/commit/522880cb99b0573d8689eee083b28af18ff3f9c2.diff
LOG: [compiler-rt][RISCV] Avoid using __init_riscv_feature_bits as a direc… (#115316)
…t constructor
`__init_riscv_feature_bits` takes an argument that can be
platform-specific, potentially pointing to the VDSO address of the
hwprobe system call for Linux. However, marking it as a constructor does
not guarantee that 0/NULL will always be passed to this argument, which
may result in treating an uninitialized or garbage value as a pointer to
hwprobe, leading to a crash.
The simplest solution is to introduce a small constructor function to
ensure that the platform-specific argument is set to 0/NULL.
Added:
Modified:
compiler-rt/lib/builtins/cpu_model/riscv.c
Removed:
################################################################################
diff --git a/compiler-rt/lib/builtins/cpu_model/riscv.c b/compiler-rt/lib/builtins/cpu_model/riscv.c
index 052124fdde447e..74534896057ef5 100644
--- a/compiler-rt/lib/builtins/cpu_model/riscv.c
+++ b/compiler-rt/lib/builtins/cpu_model/riscv.c
@@ -335,7 +335,8 @@ static void initRISCVFeature(struct riscv_hwprobe Hwprobes[]) {
static int FeaturesBitCached = 0;
-void __init_riscv_feature_bits(void *) CONSTRUCTOR_ATTRIBUTE;
+void __init_riscv_feature_bits(void *);
+static void __init_riscv_feature_bits_ctor(void) CONSTRUCTOR_ATTRIBUTE;
// A constructor function that sets __riscv_feature_bits, and
// __riscv_vendor_feature_bits to the right values. This needs to run
@@ -343,10 +344,14 @@ void __init_riscv_feature_bits(void *) CONSTRUCTOR_ATTRIBUTE;
// run before constructors without the priority set. However, it still runs
// after ifunc initializers and needs to be called explicitly there.
+static void CONSTRUCTOR_ATTRIBUTE __init_riscv_feature_bits_ctor(void) {
+ __init_riscv_feature_bits(0);
+}
+
// PlatformArgs allows the platform to provide pre-computed data and access it
// without extra effort. For example, Linux could pass the vDSO object to avoid
// an extra system call.
-void CONSTRUCTOR_ATTRIBUTE __init_riscv_feature_bits(void *PlatformArgs) {
+void __init_riscv_feature_bits(void *PlatformArgs) {
if (FeaturesBitCached)
return;
More information about the llvm-commits
mailing list