[llvm-commits] [PATCH] Make use of OpenBSD's libc routines for stack protector

Brad Smith brad at comstyle.com
Thu Aug 9 00:52:29 PDT 2012


This makes LLVM use OpenBSD's libc routines for stack protector.

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-------------- next part --------------
Index: lib/CodeGen/StackProtector.cpp
===================================================================
--- lib/CodeGen/StackProtector.cpp	(revision 161304)
+++ lib/CodeGen/StackProtector.cpp	(working copy)
@@ -169,7 +169,11 @@
         StackGuardVar = ConstantExpr::getIntToPtr(OffsetVal,
                                       PointerType::get(PtrTy, AddressSpace));
       } else {
+#if defined(__OpenBSD__)
+        StackGuardVar = M->getOrInsertGlobal("__guard", PtrTy); 
+#else
         StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy); 
+#endif
       }
 
       BasicBlock &Entry = F->getEntryBlock();
@@ -246,10 +250,24 @@
 BasicBlock *StackProtector::CreateFailBB() {
   BasicBlock *FailBB = BasicBlock::Create(F->getContext(),
                                           "CallStackCheckFailBlk", F);
+#if defined(__OpenBSD__)
   Constant *StackChkFail =
+    M->getOrInsertFunction("__stack_smash_handler",
+                           Type::getVoidTy(F->getContext()), NULL);
+  Constant *G = new GlobalVariable(*M,
+                        ArrayType::get(Type::getInt1Ty(F->getContext()),
+                        F->getName().size() + 1),
+                        true, GlobalVariable::PrivateLinkage, 
+                        ConstantDataArray::getString(F->getContext(),
+                                F->getName(), true),
+                         "SSH", false, 0);
+  CallInst::Create(StackChkFail, G, "", FailBB);
+#else
+  Constant *StackChkFail =
     M->getOrInsertFunction("__stack_chk_fail",
                            Type::getVoidTy(F->getContext()), NULL);
   CallInst::Create(StackChkFail, "", FailBB);
+#endif
   new UnreachableInst(F->getContext(), FailBB);
   return FailBB;
 }


More information about the llvm-commits mailing list