diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-07-13 01:00:17 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-07-13 01:00:17 +0000 |
commit | 12c74dc2c2ee306f60fb39a9b2a43000e23addcc (patch) | |
tree | 1a4a03195d8312595fa1479be4618bafdffe86ab /lib/CodeGen/StackProtector.cpp | |
parent | 1dedabdfad8f3412256e706905b9b3b69aa2e17a (diff) | |
download | llvm-12c74dc2c2ee306f60fb39a9b2a43000e23addcc.tar.gz llvm-12c74dc2c2ee306f60fb39a9b2a43000e23addcc.tar.bz2 llvm-12c74dc2c2ee306f60fb39a9b2a43000e23addcc.tar.xz |
Revert commit r186217 -- this is breaking bots:
http://lab.llvm.org:8013/builders/clang-x86_64-darwin11-nobootstrap-RAincremental/builds/4328
Original commit log:
Use the function attributes to pass along the stack protector buffer
size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186234 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/StackProtector.cpp')
-rw-r--r-- | lib/CodeGen/StackProtector.cpp | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp index bf5d0c7d9e..1f673ab037 100644 --- a/lib/CodeGen/StackProtector.cpp +++ b/lib/CodeGen/StackProtector.cpp @@ -33,7 +33,6 @@ #include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" #include "llvm/Target/TargetLowering.h" -#include <cstdlib> using namespace llvm; STATISTIC(NumFunProtected, "Number of functions protected"); @@ -54,10 +53,6 @@ namespace { DominatorTree *DT; - /// \brief The minimum size of buffers that will receive stack smashing - /// protection when -fstack-protection is used. - unsigned SSPBufferSize; - /// VisitedPHIs - The set of PHI nodes visited when determining /// if a variable's reference has been taken. This set /// is maintained to ensure we don't visit the same PHI node multiple @@ -90,12 +85,11 @@ namespace { bool RequiresStackProtector(); public: static char ID; // Pass identification, replacement for typeid. - StackProtector() : FunctionPass(ID), TM(0), TLI(0), SSPBufferSize(0) { + StackProtector() : FunctionPass(ID), TM(0), TLI(0) { initializeStackProtectorPass(*PassRegistry::getPassRegistry()); } StackProtector(const TargetMachine *TM) - : FunctionPass(ID), TM(TM), TLI(0), Trip(TM->getTargetTriple()), - SSPBufferSize(8) { + : FunctionPass(ID), TM(TM), TLI(0), Trip(TM->getTargetTriple()) { initializeStackProtectorPass(*PassRegistry::getPassRegistry()); } @@ -123,12 +117,6 @@ bool StackProtector::runOnFunction(Function &Fn) { if (!RequiresStackProtector()) return false; - Attribute Attr = - Fn.getAttributes().getAttribute(AttributeSet::FunctionIndex, - "ssp-buffer-size"); - if (Attr.isStringAttribute()) - SSPBufferSize = atoi(Attr.getValueAsString().data()); - ++NumFunProtected; return InsertStackProtectors(); } @@ -144,6 +132,7 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool Strong, // protector if (Strong) return true; + const TargetMachine &TM = TLI->getTargetMachine(); if (!AT->getElementType()->isIntegerTy(8)) { // If we're on a non-Darwin platform or we're inside of a structure, don't // add stack protectors unless the array is a character array. @@ -153,7 +142,7 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool Strong, // If an array has more than SSPBufferSize bytes of allocated space, then we // emit stack protectors. - if (SSPBufferSize <= TLI->getDataLayout()->getTypeAllocSize(AT)) + if (TM.Options.SSPBufferSize <= TLI->getDataLayout()->getTypeAllocSize(AT)) return true; } @@ -241,14 +230,13 @@ bool StackProtector::RequiresStackProtector() { if (const ConstantInt *CI = dyn_cast<ConstantInt>(AI->getArraySize())) { - if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize) + unsigned BufferSize = TLI->getTargetMachine().Options.SSPBufferSize; + if (CI->getLimitedValue(BufferSize) >= BufferSize) // A call to alloca with size >= SSPBufferSize requires // stack protectors. return true; - } else { - // A call to alloca with a variable size requires protectors. + } else // A call to alloca with a variable size requires protectors. return true; - } } if (ContainsProtectableArray(AI->getAllocatedType(), Strong)) |