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
This commit is contained in:
Chandler Carruth 2013-07-13 01:00:17 +00:00
parent 1dedabdfad
commit 12c74dc2c2
6 changed files with 25 additions and 20 deletions

View File

@ -220,4 +220,8 @@ cl::opt<std::string> StartAfter("start-after",
cl::value_desc("pass-name"), cl::value_desc("pass-name"),
cl::init("")); cl::init(""));
cl::opt<unsigned>
SSPBufferSize("stack-protector-buffer-size", cl::init(8),
cl::desc("Lower bound for a buffer to be considered for "
"stack protection"));
#endif #endif

View File

@ -48,7 +48,7 @@ namespace llvm {
UseSoftFloat(false), NoZerosInBSS(false), UseSoftFloat(false), NoZerosInBSS(false),
JITEmitDebugInfo(false), JITEmitDebugInfoToDisk(false), JITEmitDebugInfo(false), JITEmitDebugInfoToDisk(false),
GuaranteedTailCallOpt(false), DisableTailCalls(false), GuaranteedTailCallOpt(false), DisableTailCalls(false),
StackAlignmentOverride(0), RealignStack(true), StackAlignmentOverride(0), RealignStack(true), SSPBufferSize(0),
EnableFastISel(false), PositionIndependentExecutable(false), EnableFastISel(false), PositionIndependentExecutable(false),
EnableSegmentedStacks(false), UseInitArray(false), TrapFuncName(""), EnableSegmentedStacks(false), UseInitArray(false), TrapFuncName(""),
FloatABIType(FloatABI::Default), AllowFPOpFusion(FPOpFusion::Standard) FloatABIType(FloatABI::Default), AllowFPOpFusion(FPOpFusion::Standard)
@ -151,6 +151,10 @@ namespace llvm {
/// automatically realigned, if needed. /// automatically realigned, if needed.
unsigned RealignStack : 1; unsigned RealignStack : 1;
/// SSPBufferSize - The minimum size of buffers that will receive stack
/// smashing protection when -fstack-protection is used.
unsigned SSPBufferSize;
/// EnableFastISel - This flag enables fast-path instruction selection /// EnableFastISel - This flag enables fast-path instruction selection
/// which trades away generated code quality in favor of reducing /// which trades away generated code quality in favor of reducing
/// compile time. /// compile time.
@ -220,6 +224,7 @@ inline bool operator==(const TargetOptions &LHS,
ARE_EQUAL(DisableTailCalls) && ARE_EQUAL(DisableTailCalls) &&
ARE_EQUAL(StackAlignmentOverride) && ARE_EQUAL(StackAlignmentOverride) &&
ARE_EQUAL(RealignStack) && ARE_EQUAL(RealignStack) &&
ARE_EQUAL(SSPBufferSize) &&
ARE_EQUAL(EnableFastISel) && ARE_EQUAL(EnableFastISel) &&
ARE_EQUAL(PositionIndependentExecutable) && ARE_EQUAL(PositionIndependentExecutable) &&
ARE_EQUAL(EnableSegmentedStacks) && ARE_EQUAL(EnableSegmentedStacks) &&

View File

@ -33,7 +33,6 @@
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetLowering.h"
#include <cstdlib>
using namespace llvm; using namespace llvm;
STATISTIC(NumFunProtected, "Number of functions protected"); STATISTIC(NumFunProtected, "Number of functions protected");
@ -54,10 +53,6 @@ namespace {
DominatorTree *DT; 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 /// VisitedPHIs - The set of PHI nodes visited when determining
/// if a variable's reference has been taken. This set /// if a variable's reference has been taken. This set
/// is maintained to ensure we don't visit the same PHI node multiple /// is maintained to ensure we don't visit the same PHI node multiple
@ -90,12 +85,11 @@ namespace {
bool RequiresStackProtector(); bool RequiresStackProtector();
public: public:
static char ID; // Pass identification, replacement for typeid. 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()); initializeStackProtectorPass(*PassRegistry::getPassRegistry());
} }
StackProtector(const TargetMachine *TM) StackProtector(const TargetMachine *TM)
: FunctionPass(ID), TM(TM), TLI(0), Trip(TM->getTargetTriple()), : FunctionPass(ID), TM(TM), TLI(0), Trip(TM->getTargetTriple()) {
SSPBufferSize(8) {
initializeStackProtectorPass(*PassRegistry::getPassRegistry()); initializeStackProtectorPass(*PassRegistry::getPassRegistry());
} }
@ -123,12 +117,6 @@ bool StackProtector::runOnFunction(Function &Fn) {
if (!RequiresStackProtector()) return false; if (!RequiresStackProtector()) return false;
Attribute Attr =
Fn.getAttributes().getAttribute(AttributeSet::FunctionIndex,
"ssp-buffer-size");
if (Attr.isStringAttribute())
SSPBufferSize = atoi(Attr.getValueAsString().data());
++NumFunProtected; ++NumFunProtected;
return InsertStackProtectors(); return InsertStackProtectors();
} }
@ -144,6 +132,7 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool Strong,
// protector // protector
if (Strong) if (Strong)
return true; return true;
const TargetMachine &TM = TLI->getTargetMachine();
if (!AT->getElementType()->isIntegerTy(8)) { if (!AT->getElementType()->isIntegerTy(8)) {
// If we're on a non-Darwin platform or we're inside of a structure, don't // 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. // 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 // If an array has more than SSPBufferSize bytes of allocated space, then we
// emit stack protectors. // emit stack protectors.
if (SSPBufferSize <= TLI->getDataLayout()->getTypeAllocSize(AT)) if (TM.Options.SSPBufferSize <= TLI->getDataLayout()->getTypeAllocSize(AT))
return true; return true;
} }
@ -241,14 +230,13 @@ bool StackProtector::RequiresStackProtector() {
if (const ConstantInt *CI = if (const ConstantInt *CI =
dyn_cast<ConstantInt>(AI->getArraySize())) { 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 // A call to alloca with size >= SSPBufferSize requires
// stack protectors. // stack protectors.
return true; return true;
} else { } else // A call to alloca with a variable size requires protectors.
// A call to alloca with a variable size requires protectors.
return true; return true;
}
} }
if (ContainsProtectableArray(AI->getAllocatedType(), Strong)) if (ContainsProtectableArray(AI->getAllocatedType(), Strong))

View File

@ -280,6 +280,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
Options.PositionIndependentExecutable = EnablePIE; Options.PositionIndependentExecutable = EnablePIE;
Options.EnableSegmentedStacks = SegmentedStacks; Options.EnableSegmentedStacks = SegmentedStacks;
Options.UseInitArray = UseInitArray; Options.UseInitArray = UseInitArray;
Options.SSPBufferSize = SSPBufferSize;
OwningPtr<TargetMachine> OwningPtr<TargetMachine>
target(TheTarget->createTargetMachine(TheTriple.getTriple(), target(TheTarget->createTargetMachine(TheTriple.getTriple(),

View File

@ -151,6 +151,11 @@ UseInitArray("use-init-array",
cl::desc("Use .init_array instead of .ctors."), cl::desc("Use .init_array instead of .ctors."),
cl::init(false)); cl::init(false));
static cl::opt<unsigned>
SSPBufferSize("stack-protector-buffer-size", cl::init(8),
cl::desc("Lower bound for a buffer to be considered for "
"stack protection"));
LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t) LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
: _module(m), _target(t), : _module(m), _target(t),
_context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL), _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL),
@ -256,6 +261,7 @@ void LTOModule::getTargetOptions(TargetOptions &Options) {
Options.PositionIndependentExecutable = EnablePIE; Options.PositionIndependentExecutable = EnablePIE;
Options.EnableSegmentedStacks = SegmentedStacks; Options.EnableSegmentedStacks = SegmentedStacks;
Options.UseInitArray = UseInitArray; Options.UseInitArray = UseInitArray;
Options.SSPBufferSize = SSPBufferSize;
} }
LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,

View File

@ -510,6 +510,7 @@ static TargetOptions GetTargetOptions() {
Options.PositionIndependentExecutable = EnablePIE; Options.PositionIndependentExecutable = EnablePIE;
Options.EnableSegmentedStacks = SegmentedStacks; Options.EnableSegmentedStacks = SegmentedStacks;
Options.UseInitArray = UseInitArray; Options.UseInitArray = UseInitArray;
Options.SSPBufferSize = SSPBufferSize;
return Options; return Options;
} }