diff options
author | Bill Wendling <isanbard@gmail.com> | 2012-08-07 20:59:05 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2012-08-07 20:59:05 +0000 |
commit | 1299422ee1e7834a8a697b2c915a8bfdada77246 (patch) | |
tree | fd60e60441b2801ef85c730b7537b5d42c2afa9f /lib | |
parent | 0b40d09ff6b1facd0fe81e50ee0271e035488520 (diff) | |
download | external_llvm-1299422ee1e7834a8a697b2c915a8bfdada77246.zip external_llvm-1299422ee1e7834a8a697b2c915a8bfdada77246.tar.gz external_llvm-1299422ee1e7834a8a697b2c915a8bfdada77246.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>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161446 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/StackProtector.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp index 43a6ad8..1a12303 100644 --- a/lib/CodeGen/StackProtector.cpp +++ b/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; + } } } |