aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/StackProtector.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-08-07 20:59:05 +0000
committerBill Wendling <isanbard@gmail.com>2012-08-07 20:59:05 +0000
commit61396b81a4eb8b3a2d439be012bca6da783fa1dd (patch)
tree1265b89622513087377675dc8e69d0274a975c40 /llvm/lib/CodeGen/StackProtector.cpp
parent06228f273af1043bdab51f44e4a117ddd2d1c6eb (diff)
downloadllvm-61396b81a4eb8b3a2d439be012bca6da783fa1dd.zip
llvm-61396b81a4eb8b3a2d439be012bca6da783fa1dd.tar.gz
llvm-61396b81a4eb8b3a2d439be012bca6da783fa1dd.tar.bz2
For non-Darwin platforms, we want to generate stack protectors only for
character arrays. This is in line with what GCC does. <rdar://problem/10529227> llvm-svn: 161446
Diffstat (limited to 'llvm/lib/CodeGen/StackProtector.cpp')
-rw-r--r--llvm/lib/CodeGen/StackProtector.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp
index 43a6ad8..1a12303 100644
--- a/llvm/lib/CodeGen/StackProtector.cpp
+++ b/llvm/lib/CodeGen/StackProtector.cpp
@@ -28,6 +28,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetLowering.h"
+#include "llvm/ADT/Triple.h"
using namespace llvm;
// SSPBufferSize - The lower bound for a buffer to be considered for stack
@@ -111,6 +112,8 @@ bool StackProtector::RequiresStackProtector() const {
return false;
const TargetData *TD = TLI->getTargetData();
+ const TargetMachine &TM = TLI->getTargetMachine();
+ Triple Trip(TM.getTargetTriple());
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
BasicBlock *BB = I;
@@ -123,11 +126,17 @@ bool StackProtector::RequiresStackProtector() const {
// protectors.
return true;
- if (ArrayType *AT = dyn_cast<ArrayType>(AI->getAllocatedType()))
+ if (ArrayType *AT = dyn_cast<ArrayType>(AI->getAllocatedType())) {
+ // If we're on a non-Darwin platform, don't add stack protectors
+ // unless the array is a character array.
+ if (!Trip.isOSDarwin() && !AT->getElementType()->isIntegerTy(8))
+ continue;
+
// If an array has more than SSPBufferSize bytes of allocated space,
// then we emit stack protectors.
if (SSPBufferSize <= TD->getTypeAllocSize(AT))
return true;
+ }
}
}