summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2018-12-20 21:33:59 +0000
committerHaibo Huang <hhb@google.com>2018-12-20 21:33:59 +0000
commit303b2333e40318adf22f721297c42902466fa3b8 (patch)
tree9102d2d7aaef102201f9dd88a8b616c79212ab00
parentd001380a69cdc546b2724d3305b167644f6151f4 (diff)
downloadbcm5719-llvm-303b2333e40318adf22f721297c42902466fa3b8.tar.gz
bcm5719-llvm-303b2333e40318adf22f721297c42902466fa3b8.zip
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: 349825
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp7
-rw-r--r--clang/test/CodeGen/builtin-cpu-is.c2
-rw-r--r--clang/test/CodeGen/builtin-cpu-supports.c5
3 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 8f53a83abe7..93484f82c30 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9537,6 +9537,7 @@ Value *CodeGenFunction::EmitX86CpuIs(StringRef CPUStr) {
// Grab the global __cpu_model.
llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model");
+ cast<llvm::GlobalValue>(CpuModel)->setDSOLocal(true);
// Calculate the index needed to access the correct field based on the
// range. Also adjust the expected value.
@@ -9609,6 +9610,7 @@ llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) {
// Grab the global __cpu_model.
llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model");
+ cast<llvm::GlobalValue>(CpuModel)->setDSOLocal(true);
// Grab the first (0th) element from the field __cpu_features off of the
// global in the struct STy.
@@ -9628,6 +9630,8 @@ llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) {
if (Features2 != 0) {
llvm::Constant *CpuFeatures2 = CGM.CreateRuntimeVariable(Int32Ty,
"__cpu_features2");
+ cast<llvm::GlobalValue>(CpuFeatures2)->setDSOLocal(true);
+
Value *Features =
Builder.CreateAlignedLoad(CpuFeatures2, CharUnits::fromQuantity(4));
@@ -9645,6 +9649,9 @@ Value *CodeGenFunction::EmitX86CpuInit() {
llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy,
/*Variadic*/ false);
llvm::Constant *Func = CGM.CreateRuntimeFunction(FTy, "__cpu_indicator_init");
+ cast<llvm::GlobalValue>(Func)->setDSOLocal(true);
+ cast<llvm::GlobalValue>(Func)->setDLLStorageClass(
+ llvm::GlobalValue::DefaultStorageClass);
return Builder.CreateCall(Func);
}
diff --git a/clang/test/CodeGen/builtin-cpu-is.c b/clang/test/CodeGen/builtin-cpu-is.c
index f2a5f54a0c8..bff3544c136 100644
--- a/clang/test/CodeGen/builtin-cpu-is.c
+++ b/clang/test/CodeGen/builtin-cpu-is.c
@@ -4,6 +4,8 @@
// global, the bit grab, and the icmp correct.
extern void a(const char *);
+// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] }
+
void intel() {
if (__builtin_cpu_is("intel"))
a("intel");
diff --git a/clang/test/CodeGen/builtin-cpu-supports.c b/clang/test/CodeGen/builtin-cpu-supports.c
index d384efbc208..761f00cf957 100644
--- a/clang/test/CodeGen/builtin-cpu-supports.c
+++ b/clang/test/CodeGen/builtin-cpu-supports.c
@@ -4,6 +4,9 @@
// global, the bit grab, and the icmp correct.
extern void a(const char *);
+// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] }
+// CHECK: @__cpu_features2 = external dso_local global i32
+
int main() {
__builtin_cpu_init();
@@ -25,3 +28,5 @@ int main() {
return 0;
}
+
+// CHECK: declare dso_local void @__cpu_indicator_init()
OpenPOWER on IntegriCloud