summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/StackProtector.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-11-06 02:29:10 +0000
committerBill Wendling <isanbard@gmail.com>2008-11-06 02:29:10 +0000
commitd970ea3eac465d36b925b3b173d51d77681f32d2 (patch)
tree3d22f836cf195ec60e901144d8d981847ef8d793 /llvm/lib/CodeGen/StackProtector.cpp
parentb870fd887437c8cd94905b275595af6378017e19 (diff)
downloadbcm5719-llvm-d970ea3eac465d36b925b3b173d51d77681f32d2.tar.gz
bcm5719-llvm-d970ea3eac465d36b925b3b173d51d77681f32d2.zip
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. llvm-svn: 58791
Diffstat (limited to 'llvm/lib/CodeGen/StackProtector.cpp')
-rw-r--r--llvm/lib/CodeGen/StackProtector.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp
index 5cd4c67b5f6..659f8a01ab7 100644
--- a/llvm/lib/CodeGen/StackProtector.cpp
+++ b/llvm/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);
}
OpenPOWER on IntegriCloud