diff options
author | Bill Wendling <isanbard@gmail.com> | 2008-11-06 02:38:58 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2008-11-06 02:38:58 +0000 |
commit | 43de293d7523b2664394a331629877fe4a0b28aa (patch) | |
tree | 1ad92b7967eebc83ab7fd9a5a412829fa638306b /llvm/lib/CodeGen/StackProtector.cpp | |
parent | d970ea3eac465d36b925b3b173d51d77681f32d2 (diff) | |
download | bcm5719-llvm-43de293d7523b2664394a331629877fe4a0b28aa.tar.gz bcm5719-llvm-43de293d7523b2664394a331629877fe4a0b28aa.zip |
Adjust the stack protector heuristic to care about only arrays or calls to
"alloca".
llvm-svn: 58792
Diffstat (limited to 'llvm/lib/CodeGen/StackProtector.cpp')
-rw-r--r-- | llvm/lib/CodeGen/StackProtector.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp index 659f8a01ab7..eaf52f691c6 100644 --- a/llvm/lib/CodeGen/StackProtector.cpp +++ b/llvm/lib/CodeGen/StackProtector.cpp @@ -184,7 +184,9 @@ BasicBlock *StackProtector::CreateFailBB() { } /// RequiresStackProtector - Check whether or not this function needs a stack -/// protector based upon the stack protector level. +/// protector based upon the stack protector level. The heuristic we use is to +/// add a guard variable to functions that call alloca, and functions with +/// buffers larger than 8 bytes. bool StackProtector::RequiresStackProtector() const { switch (Level) { default: return false; @@ -201,6 +203,8 @@ bool StackProtector::RequiresStackProtector() const { for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE; ++II) if (AllocaInst *AI = dyn_cast<AllocaInst>(II)) { + if (!AI->isArrayAllocation()) continue; // Only care about arrays. + if (ConstantInt *CI = dyn_cast<ConstantInt>(AI->getArraySize())) { const Type *Ty = AI->getAllocatedType(); uint64_t TySize = TD->getABITypeSize(Ty); @@ -208,6 +212,10 @@ bool StackProtector::RequiresStackProtector() const { if (SSPBufferSize <= StackSize) return true; + } else { + // This is a call to alloca with a variable size. Default to adding + // stack protectors. + return true; } } } |