diff options
author | Eric Christopher <echristo@apple.com> | 2010-07-06 05:18:56 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2010-07-06 05:18:56 +0000 |
commit | f7a0c7bf8bc8318ed28d889c9a56437ab3e91385 (patch) | |
tree | 939c6983e75200e8aa262597fd4787d8b12007e9 /lib/CodeGen/StackProtector.cpp | |
parent | 10d2f4d01bb1732611d0647df321164bc0b6c98b (diff) |
Fix up -fstack-protector on linux to use the segment
registers. Split out testcases per architecture and os
now.
Patch from Nelson Elhage.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107640 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/StackProtector.cpp')
-rw-r--r-- | lib/CodeGen/StackProtector.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp index 8a6a727a1f..e318afe2b5 100644 --- a/lib/CodeGen/StackProtector.cpp +++ b/lib/CodeGen/StackProtector.cpp @@ -136,7 +136,7 @@ bool StackProtector::RequiresStackProtector() const { bool StackProtector::InsertStackProtectors() { BasicBlock *FailBB = 0; // The basic block to jump to if check fails. AllocaInst *AI = 0; // Place on stack that stores the stack guard. - Constant *StackGuardVar = 0; // The stack guard variable. + Value *StackGuardVar = 0; // The stack guard variable. for (Function::iterator I = F->begin(), E = F->end(); I != E; ) { BasicBlock *BB = I++; @@ -155,7 +155,20 @@ bool StackProtector::InsertStackProtectors() { // PointerType *PtrTy = PointerType::getUnqual( Type::getInt8Ty(RI->getContext())); - StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy); + + unsigned AddressSpace, Offset; + if (TLI->getStackCookieLocation(AddressSpace, Offset)) { + Constant *ASPtr = Constant::getNullValue( + PointerType::get(Type::getInt8Ty(RI->getContext()), AddressSpace)); + APInt OffsetInt(32, Offset); + Constant *OffsetVal = Constant::getIntegerValue( + Type::getInt32Ty(RI->getContext()), OffsetInt); + StackGuardVar = ConstantExpr::getPointerCast( + ConstantExpr::getGetElementPtr(ASPtr, &OffsetVal, 1), + PointerType::get(PtrTy, AddressSpace)); + } else { + StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy); + } BasicBlock &Entry = F->getEntryBlock(); Instruction *InsPt = &Entry.front(); |