summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2010-07-06 05:18:56 +0000
committerEric Christopher <echristo@apple.com>2010-07-06 05:18:56 +0000
commit2ad0c779c3ea2104913a6d92d9d98f00b41c5adb (patch)
tree14fc7505379b40a74ae00291403566818f0f748c /llvm/lib/CodeGen
parent466e2210375026eacb9eb572341e170243bd2db2 (diff)
downloadbcm5719-llvm-2ad0c779c3ea2104913a6d92d9d98f00b41c5adb.tar.gz
bcm5719-llvm-2ad0c779c3ea2104913a6d92d9d98f00b41c5adb.zip
Fix up -fstack-protector on linux to use the segment
registers. Split out testcases per architecture and os now. Patch from Nelson Elhage. llvm-svn: 107640
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/StackProtector.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp
index 8a6a727a1f9..e318afe2b55 100644
--- a/llvm/lib/CodeGen/StackProtector.cpp
+++ b/llvm/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();
OpenPOWER on IntegriCloud