Skip to content

Commit 6b22f59

Browse files
committedDec 12, 2018
Declares __cpu_model as dso local
__builtin_cpu_supports and __builtin_cpu_is use information in __cpu_model to decide cpu features. Before this change, __cpu_model was not declared as dso local. The generated code looks up the address in GOT when reading __cpu_model. This makes it impossible to use these functions in ifunc, because at that time GOT entries have not been relocated. This change makes it dso local. Differential Revision: https://reviews.llvm.org/D53850 llvm-svn: 348978
1 parent 5cdc2cd commit 6b22f59

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed
 

‎clang/lib/CodeGen/CGBuiltin.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -9465,6 +9465,7 @@ Value *CodeGenFunction::EmitX86CpuIs(StringRef CPUStr) {
94659465

94669466
// Grab the global __cpu_model.
94679467
llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model");
9468+
cast<llvm::GlobalValue>(CpuModel)->setDSOLocal(true);
94689469

94699470
// Calculate the index needed to access the correct field based on the
94709471
// range. Also adjust the expected value.
@@ -9537,6 +9538,7 @@ llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) {
95379538

95389539
// Grab the global __cpu_model.
95399540
llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model");
9541+
cast<llvm::GlobalValue>(CpuModel)->setDSOLocal(true);
95409542

95419543
// Grab the first (0th) element from the field __cpu_features off of the
95429544
// global in the struct STy.
@@ -9556,6 +9558,8 @@ llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) {
95569558
if (Features2 != 0) {
95579559
llvm::Constant *CpuFeatures2 = CGM.CreateRuntimeVariable(Int32Ty,
95589560
"__cpu_features2");
9561+
cast<llvm::GlobalValue>(CpuFeatures2)->setDSOLocal(true);
9562+
95599563
Value *Features =
95609564
Builder.CreateAlignedLoad(CpuFeatures2, CharUnits::fromQuantity(4));
95619565

@@ -9573,6 +9577,7 @@ Value *CodeGenFunction::EmitX86CpuInit() {
95739577
llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy,
95749578
/*Variadic*/ false);
95759579
llvm::Constant *Func = CGM.CreateRuntimeFunction(FTy, "__cpu_indicator_init");
9580+
cast<llvm::GlobalValue>(Func)->setDSOLocal(true);
95769581
return Builder.CreateCall(Func);
95779582
}
95789583

‎clang/test/CodeGen/builtin-cpu-is.c

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// global, the bit grab, and the icmp correct.
55
extern void a(const char *);
66

7+
// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] }
8+
79
void intel() {
810
if (__builtin_cpu_is("intel"))
911
a("intel");

‎clang/test/CodeGen/builtin-cpu-supports.c

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
// global, the bit grab, and the icmp correct.
55
extern void a(const char *);
66

7+
// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] }
8+
// CHECK: @__cpu_features2 = external dso_local global i32
9+
710
int main() {
811
__builtin_cpu_init();
912

@@ -25,3 +28,5 @@ int main() {
2528

2629
return 0;
2730
}
31+
32+
// CHECK: declare dso_local void @__cpu_indicator_init()

0 commit comments

Comments
 (0)
Please sign in to comment.