SafeStack: Create the unsafe stack pointer on demand.
authorPeter Collingbourne <peter@pcc.me.uk>
Mon, 22 Jun 2015 20:26:54 +0000 (20:26 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Mon, 22 Jun 2015 20:26:54 +0000 (20:26 +0000)
This avoids creating an unnecessary undefined reference on targets such as
NVPTX that require such references to be declared in asm output.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240321 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/SafeStack.cpp
test/Transforms/SafeStack/no-attr.ll

index 13c5412183133fd578d4c66dc27704dbff9d72dc..6b185a2b127b92f700a6e6ee65e2628bd269a876 100644 (file)
@@ -165,7 +165,7 @@ class SafeStack : public FunctionPass {
   Type *Int32Ty;
   Type *Int8Ty;
 
   Type *Int32Ty;
   Type *Int8Ty;
 
-  Constant *UnsafeStackPtr;
+  Constant *UnsafeStackPtr = nullptr;
 
   /// Unsafe stack alignment. Each stack frame must ensure that the stack is
   /// aligned to this value. We need to re-align the unsafe stack if the
 
   /// Unsafe stack alignment. Each stack frame must ensure that the stack is
   /// aligned to this value. We need to re-align the unsafe stack if the
@@ -232,8 +232,6 @@ public:
     Int32Ty = Type::getInt32Ty(M.getContext());
     Int8Ty = Type::getInt8Ty(M.getContext());
 
     Int32Ty = Type::getInt32Ty(M.getContext());
     Int8Ty = Type::getInt8Ty(M.getContext());
 
-    UnsafeStackPtr = getOrCreateUnsafeStackPtr(M);
-
     return false;
   }
 
     return false;
   }
 
@@ -576,6 +574,9 @@ bool SafeStack::runOnFunction(Function &F) {
   if (!StackRestorePoints.empty())
     ++NumUnsafeStackRestorePointsFunctions;
 
   if (!StackRestorePoints.empty())
     ++NumUnsafeStackRestorePointsFunctions;
 
+  if (!UnsafeStackPtr)
+    UnsafeStackPtr = getOrCreateUnsafeStackPtr(*F.getParent());
+
   // The top of the unsafe stack after all unsafe static allocas are allocated.
   Value *StaticTop = moveStaticAllocasToUnsafeStack(F, StaticAllocas, Returns);
 
   // The top of the unsafe stack after all unsafe static allocas are allocated.
   Value *StaticTop = moveStaticAllocasToUnsafeStack(F, StaticAllocas, Returns);
 
index ca3c21ab01bb5fa955f83c90eb66db73eb3b3e18..d9bcefd3c8492ce621846b935b6ed7acf53b3eaf 100644 (file)
@@ -6,6 +6,8 @@
 ; no safestack attribute
 ; Requires no protector.
 
 ; no safestack attribute
 ; Requires no protector.
 
+; CHECK-NOT: __safestack_unsafe_stack_ptr
+
 ; CHECK: @foo
 define void @foo(i8* %a) nounwind uwtable {
 entry:
 ; CHECK: @foo
 define void @foo(i8* %a) nounwind uwtable {
 entry: