[llvm-commits] [PATCH] Make use of OpenBSD's libc routines for stack protector
Brad Smith
brad at comstyle.com
Sat Aug 11 00:49:15 PDT 2012
On Thu, Aug 09, 2012 at 01:40:14AM -0700, Eli Friedman wrote:
> On Thu, Aug 9, 2012 at 12:52 AM, Brad Smith <brad at comstyle.com> wrote:
> > This makes LLVM use OpenBSD's libc routines for stack protector.
>
> +#if defined(__OpenBSD__)
>
> This is wrong; you want to check if the target is OpenBSD, not if the
> host is OpenBSD.
You're right. How about this?
Index: lib/CodeGen/StackProtector.cpp
===================================================================
--- lib/CodeGen/StackProtector.cpp (revision 161304)
+++ lib/CodeGen/StackProtector.cpp (working copy)
@@ -16,6 +16,7 @@
#define DEBUG_TYPE "stack-protector"
#include "llvm/CodeGen/Passes.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Attributes.h"
#include "llvm/Constants.h"
@@ -169,7 +170,10 @@
StackGuardVar = ConstantExpr::getIntToPtr(OffsetVal,
PointerType::get(PtrTy, AddressSpace));
} else {
- StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy);
+ if (Triple(TLI->getTargetMachine().getTargetTriple()).getOS() == llvm::Triple::OpenBSD)
+ StackGuardVar = M->getOrInsertGlobal("__guard", PtrTy);
+ else
+ StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy);
}
BasicBlock &Entry = F->getEntryBlock();
@@ -246,10 +250,24 @@
BasicBlock *StackProtector::CreateFailBB() {
BasicBlock *FailBB = BasicBlock::Create(F->getContext(),
"CallStackCheckFailBlk", F);
- Constant *StackChkFail =
- M->getOrInsertFunction("__stack_chk_fail",
- Type::getVoidTy(F->getContext()), NULL);
- CallInst::Create(StackChkFail, "", FailBB);
+ if (Triple(TLI->getTargetMachine().getTargetTriple()).getOS() == llvm::Triple::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);
+ }
new UnreachableInst(F->getContext(), FailBB);
return FailBB;
}
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the llvm-commits
mailing list