openbsd-ports/devel/llvm/patches/patch-lib_CodeGen_StackProtector_cpp
brad cc75b05c01 Update to LLVM 3.2 and switces to __guard_local for stack protector support.
Initial work from landry@ with some fixes and further tweaking from pascal@ and brad@

ok sthen@ landry@
2012-12-23 20:49:29 +00:00

49 lines
2.3 KiB
Plaintext

$OpenBSD: patch-lib_CodeGen_StackProtector_cpp,v 1.2 2012/12/23 20:49:29 brad Exp $
--- lib/CodeGen/StackProtector.cpp.orig Tue Oct 9 09:45:08 2012
+++ lib/CodeGen/StackProtector.cpp Mon Dec 10 21:36:28 2012
@@ -196,6 +196,9 @@ bool StackProtector::InsertStackProtectors() {
StackGuardVar = ConstantExpr::getIntToPtr(OffsetVal,
PointerType::get(PtrTy, AddressSpace));
+ } else if (Triple(TLI->getTargetMachine().getTargetTriple()).getOS() ==
+ llvm::Triple::OpenBSD) {
+ StackGuardVar = M->getOrInsertGlobal("__guard_local", PtrTy);
} else {
StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy);
}
@@ -272,12 +275,28 @@ bool StackProtector::InsertStackProtectors() {
/// CreateFailBB - Create a basic block to jump to when the stack protector
/// check fails.
BasicBlock *StackProtector::CreateFailBB() {
- BasicBlock *FailBB = BasicBlock::Create(F->getContext(),
+ LLVMContext &Context = F->getContext();
+ BasicBlock *FailBB = BasicBlock::Create(Context,
"CallStackCheckFailBlk", F);
- Constant *StackChkFail =
- M->getOrInsertFunction("__stack_chk_fail",
- Type::getVoidTy(F->getContext()), NULL);
- CallInst::Create(StackChkFail, "", FailBB);
- new UnreachableInst(F->getContext(), FailBB);
+ if (Triple(TLI->getTargetMachine().getTargetTriple()).getOS() ==
+ llvm::Triple::OpenBSD) {
+ Constant *StackChkFail =
+ M->getOrInsertFunction("__stack_smash_handler",
+ Type::getVoidTy(Context), Type::getInt8PtrTy(Context), NULL);
+ Constant *G = new GlobalVariable(*M,
+ ArrayType::get(Type::getInt8Ty(Context),
+ F->getName().size() + 1),
+ true, GlobalVariable::PrivateLinkage,
+ ConstantDataArray::getString(Context,
+ F->getName(), true),
+ "SSH");
+ CallInst::Create(StackChkFail, G, "", FailBB);
+ } else {
+ Constant *StackChkFail =
+ M->getOrInsertFunction("__stack_chk_fail",
+ Type::getVoidTy(Context), NULL);
+ CallInst::Create(StackChkFail, "", FailBB);
+ }
+ new UnreachableInst(Context, FailBB);
return FailBB;
}