diff options
author | Bill Wendling <isanbard@gmail.com> | 2008-11-06 02:29:10 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2008-11-06 02:29:10 +0000 |
commit | b2a4298ce41e7ef80cd75a3c1dfa6433f0759a1a (patch) | |
tree | 90348b042f4b796ea7643d4966ccb2207a5bfdfa /lib/CodeGen/StackProtector.cpp | |
parent | 9092213a5e50d4991f900d2df009d27bddfd9941 (diff) |
Implement the stack protector stack accesses via intrinsics:
- stackprotector_prologue creates a stack object and stores the guard there.
- stackprotector_epilogue reads the stack guard from the stack position created
by stackprotector_prologue.
- The PrologEpilogInserter was changed to make sure that the stack guard is
first on the stack frame.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58791 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/StackProtector.cpp')
-rw-r--r-- | lib/CodeGen/StackProtector.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp index 5cd4c67b5f..659f8a01ab 100644 --- a/lib/CodeGen/StackProtector.cpp +++ b/lib/CodeGen/StackProtector.cpp @@ -20,6 +20,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Function.h" #include "llvm/Instructions.h" +#include "llvm/Intrinsics.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/ADT/APInt.h" @@ -110,16 +111,15 @@ bool StackProtector::InsertStackProtectors() { // onto the stack. BasicBlock &Entry = F->getEntryBlock(); Instruction *InsertPt = &Entry.front(); + const PointerType *GuardTy = PointerType::getUnqual(Type::Int8Ty); // The global variable for the stack guard. Constant *StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", GuardTy); - - // The place on the stack that the stack protector guard is kept. - AllocaInst *StackProtFrameSlot = - new AllocaInst(GuardTy, "StackProt_Frame", InsertPt); LoadInst *LI = new LoadInst(StackGuardVar, "StackGuard", false, InsertPt); - new StoreInst(LI, StackProtFrameSlot, false, InsertPt); + CallInst:: + Create(Intrinsic::getDeclaration(M, Intrinsic::stackprotector_prologue), + LI, "", InsertPt); // Create the basic block to jump to when the guard check fails. BasicBlock *FailBB = CreateFailBB(); @@ -137,7 +137,7 @@ bool StackProtector::InsertStackProtectors() { // %1 = load __stack_chk_guard // %2 = load <stored stack guard> // %3 = cmp i1 %1, %2 - // br i1 %3, label %SPRet, label %CallStackCheckFailBlk + // br i1 %3, label %SP_return, label %CallStackCheckFailBlk // // SP_return: // ret ... @@ -161,9 +161,11 @@ bool StackProtector::InsertStackProtectors() { F->getBasicBlockList().insert(InsPt, NewBB); // Generate the stack protector instructions in the old basic block. - LoadInst *LI2 = new LoadInst(StackGuardVar, "", false, BB); - LoadInst *LI1 = new LoadInst(StackProtFrameSlot, "", true, BB); - ICmpInst *Cmp = new ICmpInst(CmpInst::ICMP_EQ, LI1, LI2, "", BB); + LoadInst *LI1 = new LoadInst(StackGuardVar, "", false, BB); + CallInst *CI = CallInst:: + Create(Intrinsic::getDeclaration(M, Intrinsic::stackprotector_epilogue), + "", BB); + ICmpInst *Cmp = new ICmpInst(CmpInst::ICMP_EQ, CI, LI1, "", BB); BranchInst::Create(NewBB, FailBB, Cmp, BB); } |