[llvm-branch-commits] [llvm] 2518433 - Make __stack_chk_guard dso_local if Reloc::Static

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Dec 4 17:01:51 PST 2020


Author: Fangrui Song
Date: 2020-12-04T16:57:45-08:00
New Revision: 2518433f861fcb877d0a7bdd9aec1aec1f77505a

URL: https://github.com/llvm/llvm-project/commit/2518433f861fcb877d0a7bdd9aec1aec1f77505a
DIFF: https://github.com/llvm/llvm-project/commit/2518433f861fcb877d0a7bdd9aec1aec1f77505a.diff

LOG: Make __stack_chk_guard dso_local if Reloc::Static

This is currently implied by TargetMachine::shouldAssumeDSOLocal
but will be changed in the future.

Added: 
    

Modified: 
    llvm/lib/CodeGen/TargetLoweringBase.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 23b62456e2c3..61a2de711af8 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -1969,10 +1969,13 @@ Value *TargetLoweringBase::getIRStackGuard(IRBuilder<> &IRB) const {
 // Currently only support "standard" __stack_chk_guard.
 // TODO: add LOAD_STACK_GUARD support.
 void TargetLoweringBase::insertSSPDeclarations(Module &M) const {
-  if (!M.getNamedValue("__stack_chk_guard"))
-    new GlobalVariable(M, Type::getInt8PtrTy(M.getContext()), false,
-                       GlobalVariable::ExternalLinkage,
-                       nullptr, "__stack_chk_guard");
+  if (!M.getNamedValue("__stack_chk_guard")) {
+    auto *GV = new GlobalVariable(M, Type::getInt8PtrTy(M.getContext()), false,
+                                  GlobalVariable::ExternalLinkage, nullptr,
+                                  "__stack_chk_guard");
+    if (getTargetMachine().getRelocationModel() == Reloc::Static)
+      GV->setDSOLocal(true);
+  }
 }
 
 // Currently only support "standard" __stack_chk_guard.


        


More information about the llvm-branch-commits mailing list