From: Haibo Huang Date: Wed, 12 Dec 2018 22:04:12 +0000 (+0000) Subject: Declares __cpu_model as dso local X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3279c3642e5fe23624de5e6e5ef0481cbd6ac7a1;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348978 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index e587d04d83..a0a5c2800c 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -9465,6 +9465,7 @@ Value *CodeGenFunction::EmitX86CpuIs(StringRef CPUStr) { // Grab the global __cpu_model. llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model"); + cast(CpuModel)->setDSOLocal(true); // Calculate the index needed to access the correct field based on the // range. Also adjust the expected value. @@ -9537,6 +9538,7 @@ llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) { // Grab the global __cpu_model. llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model"); + cast(CpuModel)->setDSOLocal(true); // Grab the first (0th) element from the field __cpu_features off of the // global in the struct STy. @@ -9556,6 +9558,8 @@ llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) { if (Features2 != 0) { llvm::Constant *CpuFeatures2 = CGM.CreateRuntimeVariable(Int32Ty, "__cpu_features2"); + cast(CpuFeatures2)->setDSOLocal(true); + Value *Features = Builder.CreateAlignedLoad(CpuFeatures2, CharUnits::fromQuantity(4)); @@ -9573,6 +9577,7 @@ Value *CodeGenFunction::EmitX86CpuInit() { llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, /*Variadic*/ false); llvm::Constant *Func = CGM.CreateRuntimeFunction(FTy, "__cpu_indicator_init"); + cast(Func)->setDSOLocal(true); return Builder.CreateCall(Func); } diff --git a/test/CodeGen/builtin-cpu-is.c b/test/CodeGen/builtin-cpu-is.c index f2a5f54a0c..bff3544c13 100644 --- a/test/CodeGen/builtin-cpu-is.c +++ b/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/test/CodeGen/builtin-cpu-supports.c b/test/CodeGen/builtin-cpu-supports.c index d384efbc20..761f00cf95 100644 --- a/test/CodeGen/builtin-cpu-supports.c +++ b/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()