llvm.org GIT mirror llvm / 12c74dc
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 Chandler Carruth 6 years ago
6 changed file(s) with 25 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
219219 cl::value_desc("pass-name"),
220220 cl::init(""));
221221
222 cl::opt
223 SSPBufferSize("stack-protector-buffer-size", cl::init(8),
224 cl::desc("Lower bound for a buffer to be considered for "
225 "stack protection"));
222226 #endif
4747 UseSoftFloat(false), NoZerosInBSS(false),
4848 JITEmitDebugInfo(false), JITEmitDebugInfoToDisk(false),
4949 GuaranteedTailCallOpt(false), DisableTailCalls(false),
50 StackAlignmentOverride(0), RealignStack(true),
50 StackAlignmentOverride(0), RealignStack(true), SSPBufferSize(0),
5151 EnableFastISel(false), PositionIndependentExecutable(false),
5252 EnableSegmentedStacks(false), UseInitArray(false), TrapFuncName(""),
5353 FloatABIType(FloatABI::Default), AllowFPOpFusion(FPOpFusion::Standard)
149149 /// RealignStack - This flag indicates whether the stack should be
150150 /// automatically realigned, if needed.
151151 unsigned RealignStack : 1;
152
153 /// SSPBufferSize - The minimum size of buffers that will receive stack
154 /// smashing protection when -fstack-protection is used.
155 unsigned SSPBufferSize;
152156
153157 /// EnableFastISel - This flag enables fast-path instruction selection
154158 /// which trades away generated code quality in favor of reducing
219223 ARE_EQUAL(DisableTailCalls) &&
220224 ARE_EQUAL(StackAlignmentOverride) &&
221225 ARE_EQUAL(RealignStack) &&
226 ARE_EQUAL(SSPBufferSize) &&
222227 ARE_EQUAL(EnableFastISel) &&
223228 ARE_EQUAL(PositionIndependentExecutable) &&
224229 ARE_EQUAL(EnableSegmentedStacks) &&
3232 #include "llvm/Pass.h"
3333 #include "llvm/Support/CommandLine.h"
3434 #include "llvm/Target/TargetLowering.h"
35 #include
3635 using namespace llvm;
3736
3837 STATISTIC(NumFunProtected, "Number of functions protected");
5251 Module *M;
5352
5453 DominatorTree *DT;
55
56 /// \brief The minimum size of buffers that will receive stack smashing
57 /// protection when -fstack-protection is used.
58 unsigned SSPBufferSize;
5954
6055 /// VisitedPHIs - The set of PHI nodes visited when determining
6156 /// if a variable's reference has been taken. This set
8984 bool RequiresStackProtector();
9085 public:
9186 static char ID; // Pass identification, replacement for typeid.
92 StackProtector() : FunctionPass(ID), TM(0), TLI(0), SSPBufferSize(0) {
87 StackProtector() : FunctionPass(ID), TM(0), TLI(0) {
9388 initializeStackProtectorPass(*PassRegistry::getPassRegistry());
9489 }
9590 StackProtector(const TargetMachine *TM)
96 : FunctionPass(ID), TM(TM), TLI(0), Trip(TM->getTargetTriple()),
97 SSPBufferSize(8) {
91 : FunctionPass(ID), TM(TM), TLI(0), Trip(TM->getTargetTriple()) {
9892 initializeStackProtectorPass(*PassRegistry::getPassRegistry());
9993 }
10094
121115 TLI = TM->getTargetLowering();
122116
123117 if (!RequiresStackProtector()) return false;
124
125 Attribute Attr =
126 Fn.getAttributes().getAttribute(AttributeSet::FunctionIndex,
127 "ssp-buffer-size");
128 if (Attr.isStringAttribute())
129 SSPBufferSize = atoi(Attr.getValueAsString().data());
130118
131119 ++NumFunProtected;
132120 return InsertStackProtectors();
143131 // protector
144132 if (Strong)
145133 return true;
134 const TargetMachine &TM = TLI->getTargetMachine();
146135 if (!AT->getElementType()->isIntegerTy(8)) {
147136 // If we're on a non-Darwin platform or we're inside of a structure, don't
148137 // add stack protectors unless the array is a character array.
152141
153142 // If an array has more than SSPBufferSize bytes of allocated space, then we
154143 // emit stack protectors.
155 if (SSPBufferSize <= TLI->getDataLayout()->getTypeAllocSize(AT))
144 if (TM.Options.SSPBufferSize <= TLI->getDataLayout()->getTypeAllocSize(AT))
156145 return true;
157146 }
158147
240229
241230 if (const ConstantInt *CI =
242231 dyn_cast(AI->getArraySize())) {
243 if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize)
232 unsigned BufferSize = TLI->getTargetMachine().Options.SSPBufferSize;
233 if (CI->getLimitedValue(BufferSize) >= BufferSize)
244234 // A call to alloca with size >= SSPBufferSize requires
245235 // stack protectors.
246236 return true;
247 } else {
248 // A call to alloca with a variable size requires protectors.
237 } else // A call to alloca with a variable size requires protectors.
249238 return true;
250 }
251239 }
252240
253241 if (ContainsProtectableArray(AI->getAllocatedType(), Strong))
279279 Options.PositionIndependentExecutable = EnablePIE;
280280 Options.EnableSegmentedStacks = SegmentedStacks;
281281 Options.UseInitArray = UseInitArray;
282 Options.SSPBufferSize = SSPBufferSize;
282283
283284 OwningPtr
284285 target(TheTarget->createTargetMachine(TheTriple.getTriple(),
150150 cl::desc("Use .init_array instead of .ctors."),
151151 cl::init(false));
152152
153 static cl::opt
154 SSPBufferSize("stack-protector-buffer-size", cl::init(8),
155 cl::desc("Lower bound for a buffer to be considered for "
156 "stack protection"));
157
153158 LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
154159 : _module(m), _target(t),
155160 _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL),
255260 Options.PositionIndependentExecutable = EnablePIE;
256261 Options.EnableSegmentedStacks = SegmentedStacks;
257262 Options.UseInitArray = UseInitArray;
263 Options.SSPBufferSize = SSPBufferSize;
258264 }
259265
260266 LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
509509 Options.PositionIndependentExecutable = EnablePIE;
510510 Options.EnableSegmentedStacks = SegmentedStacks;
511511 Options.UseInitArray = UseInitArray;
512 Options.SSPBufferSize = SSPBufferSize;
512513 return Options;
513514 }
514515