LLVM  6.0.0svn
StackProtector.cpp
Go to the documentation of this file.
1 //===- StackProtector.cpp - Stack Protector Insertion ---------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass inserts stack protectors into functions which need them. A variable
11 // with a random value in it is stored onto the stack before the local variables
12 // are allocated. Upon exiting the block, the stored value is checked. If it's
13 // changed, then there was some sort of violation and the program aborts.
14 //
15 //===----------------------------------------------------------------------===//
16 
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/Statistic.h"
23 #include "llvm/CodeGen/Passes.h"
27 #include "llvm/IR/Attributes.h"
28 #include "llvm/IR/BasicBlock.h"
29 #include "llvm/IR/Constants.h"
30 #include "llvm/IR/DataLayout.h"
31 #include "llvm/IR/DebugInfo.h"
32 #include "llvm/IR/DebugLoc.h"
33 #include "llvm/IR/DerivedTypes.h"
34 #include "llvm/IR/Dominators.h"
35 #include "llvm/IR/Function.h"
36 #include "llvm/IR/IRBuilder.h"
37 #include "llvm/IR/Instruction.h"
38 #include "llvm/IR/Instructions.h"
39 #include "llvm/IR/Intrinsics.h"
40 #include "llvm/IR/MDBuilder.h"
41 #include "llvm/IR/Module.h"
42 #include "llvm/IR/Type.h"
43 #include "llvm/IR/User.h"
44 #include "llvm/Pass.h"
45 #include "llvm/Support/Casting.h"
49 #include <utility>
50 
51 using namespace llvm;
52 
53 #define DEBUG_TYPE "stack-protector"
54 
55 STATISTIC(NumFunProtected, "Number of functions protected");
56 STATISTIC(NumAddrTaken, "Number of local variables that have their address"
57  " taken.");
58 
59 static cl::opt<bool> EnableSelectionDAGSP("enable-selectiondag-sp",
60  cl::init(true), cl::Hidden);
61 
62 char StackProtector::ID = 0;
63 
65  "Insert stack protectors", false, true)
68  "Insert stack protectors", false, true)
69 
70 FunctionPass *llvm::createStackProtectorPass() { return new StackProtector(); }
71 
74  return AI ? Layout.lookup(AI) : SSPLK_None;
75 }
76 
78  const AllocaInst *To) {
79  // When coloring replaces one alloca with another, transfer the SSPLayoutKind
80  // tag from the remapped to the target alloca. The remapped alloca should
81  // have a size smaller than or equal to the replacement alloca.
82  SSPLayoutMap::iterator I = Layout.find(From);
83  if (I != Layout.end()) {
84  SSPLayoutKind Kind = I->second;
85  Layout.erase(I);
86 
87  // Transfer the tag, but make sure that SSPLK_AddrOf does not overwrite
88  // SSPLK_SmallArray or SSPLK_LargeArray, and make sure that
89  // SSPLK_SmallArray does not overwrite SSPLK_LargeArray.
90  I = Layout.find(To);
91  if (I == Layout.end())
92  Layout.insert(std::make_pair(To, Kind));
93  else if (I->second != SSPLK_LargeArray && Kind != SSPLK_AddrOf)
94  I->second = Kind;
95  }
96 }
97 
101 }
102 
104  F = &Fn;
105  M = F->getParent();
107  getAnalysisIfAvailable<DominatorTreeWrapperPass>();
108  DT = DTWP ? &DTWP->getDomTree() : nullptr;
109  TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
110  Trip = TM->getTargetTriple();
111  TLI = TM->getSubtargetImpl(Fn)->getTargetLowering();
112  HasPrologue = false;
113  HasIRCheck = false;
114 
115  Attribute Attr = Fn.getFnAttribute("stack-protector-buffer-size");
116  if (Attr.isStringAttribute() &&
117  Attr.getValueAsString().getAsInteger(10, SSPBufferSize))
118  return false; // Invalid integer string
119 
120  if (!RequiresStackProtector())
121  return false;
122 
123  // TODO(etienneb): Functions with funclets are not correctly supported now.
124  // Do nothing if this is funclet-based personality.
125  if (Fn.hasPersonalityFn()) {
127  if (isFuncletEHPersonality(Personality))
128  return false;
129  }
130 
131  ++NumFunProtected;
132  return InsertStackProtectors();
133 }
134 
135 /// \param [out] IsLarge is set to true if a protectable array is found and
136 /// it is "large" ( >= ssp-buffer-size). In the case of a structure with
137 /// multiple arrays, this gets set if any of them is large.
138 bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
139  bool Strong,
140  bool InStruct) const {
141  if (!Ty)
142  return false;
143  if (ArrayType *AT = dyn_cast<ArrayType>(Ty)) {
144  if (!AT->getElementType()->isIntegerTy(8)) {
145  // If we're on a non-Darwin platform or we're inside of a structure, don't
146  // add stack protectors unless the array is a character array.
147  // However, in strong mode any array, regardless of type and size,
148  // triggers a protector.
149  if (!Strong && (InStruct || !Trip.isOSDarwin()))
150  return false;
151  }
152 
153  // If an array has more than SSPBufferSize bytes of allocated space, then we
154  // emit stack protectors.
155  if (SSPBufferSize <= M->getDataLayout().getTypeAllocSize(AT)) {
156  IsLarge = true;
157  return true;
158  }
159 
160  if (Strong)
161  // Require a protector for all arrays in strong mode
162  return true;
163  }
164 
165  const StructType *ST = dyn_cast<StructType>(Ty);
166  if (!ST)
167  return false;
168 
169  bool NeedsProtector = false;
171  E = ST->element_end();
172  I != E; ++I)
173  if (ContainsProtectableArray(*I, IsLarge, Strong, true)) {
174  // If the element is a protectable array and is large (>= SSPBufferSize)
175  // then we are done. If the protectable array is not large, then
176  // keep looking in case a subsequent element is a large array.
177  if (IsLarge)
178  return true;
179  NeedsProtector = true;
180  }
181 
182  return NeedsProtector;
183 }
184 
185 bool StackProtector::HasAddressTaken(const Instruction *AI) {
186  for (const User *U : AI->users()) {
187  if (const StoreInst *SI = dyn_cast<StoreInst>(U)) {
188  if (AI == SI->getValueOperand())
189  return true;
190  } else if (const PtrToIntInst *SI = dyn_cast<PtrToIntInst>(U)) {
191  if (AI == SI->getOperand(0))
192  return true;
193  } else if (isa<CallInst>(U)) {
194  return true;
195  } else if (isa<InvokeInst>(U)) {
196  return true;
197  } else if (const SelectInst *SI = dyn_cast<SelectInst>(U)) {
198  if (HasAddressTaken(SI))
199  return true;
200  } else if (const PHINode *PN = dyn_cast<PHINode>(U)) {
201  // Keep track of what PHI nodes we have already visited to ensure
202  // they are only visited once.
203  if (VisitedPHIs.insert(PN).second)
204  if (HasAddressTaken(PN))
205  return true;
206  } else if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
207  if (HasAddressTaken(GEP))
208  return true;
209  } else if (const BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
210  if (HasAddressTaken(BI))
211  return true;
212  }
213  }
214  return false;
215 }
216 
217 /// \brief Check whether or not this function needs a stack protector based
218 /// upon the stack protector level.
219 ///
220 /// We use two heuristics: a standard (ssp) and strong (sspstrong).
221 /// The standard heuristic which will add a guard variable to functions that
222 /// call alloca with a either a variable size or a size >= SSPBufferSize,
223 /// functions with character buffers larger than SSPBufferSize, and functions
224 /// with aggregates containing character buffers larger than SSPBufferSize. The
225 /// strong heuristic will add a guard variables to functions that call alloca
226 /// regardless of size, functions with any buffer regardless of type and size,
227 /// functions with aggregates that contain any buffer regardless of type and
228 /// size, and functions that contain stack-based variables that have had their
229 /// address taken.
230 bool StackProtector::RequiresStackProtector() {
231  bool Strong = false;
232  bool NeedsProtector = false;
233  for (const BasicBlock &BB : *F)
234  for (const Instruction &I : BB)
235  if (const CallInst *CI = dyn_cast<CallInst>(&I))
236  if (CI->getCalledFunction() ==
237  Intrinsic::getDeclaration(F->getParent(),
238  Intrinsic::stackprotector))
239  HasPrologue = true;
240 
241  if (F->hasFnAttribute(Attribute::SafeStack))
242  return false;
243 
244  // We are constructing the OptimizationRemarkEmitter on the fly rather than
245  // using the analysis pass to avoid building DominatorTree and LoopInfo which
246  // are not available this late in the IR pipeline.
248 
249  if (F->hasFnAttribute(Attribute::StackProtectReq)) {
250  ORE.emit([&]() {
251  return OptimizationRemark(DEBUG_TYPE, "StackProtectorRequested", F)
252  << "Stack protection applied to function "
253  << ore::NV("Function", F)
254  << " due to a function attribute or command-line switch";
255  });
256  NeedsProtector = true;
257  Strong = true; // Use the same heuristic as strong to determine SSPLayout
258  } else if (F->hasFnAttribute(Attribute::StackProtectStrong))
259  Strong = true;
260  else if (HasPrologue)
261  NeedsProtector = true;
262  else if (!F->hasFnAttribute(Attribute::StackProtect))
263  return false;
264 
265  for (const BasicBlock &BB : *F) {
266  for (const Instruction &I : BB) {
267  if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
268  if (AI->isArrayAllocation()) {
269  auto RemarkBuilder = [&]() {
270  return OptimizationRemark(DEBUG_TYPE, "StackProtectorAllocaOrArray",
271  &I)
272  << "Stack protection applied to function "
273  << ore::NV("Function", F)
274  << " due to a call to alloca or use of a variable length "
275  "array";
276  };
277  if (const auto *CI = dyn_cast<ConstantInt>(AI->getArraySize())) {
278  if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize) {
279  // A call to alloca with size >= SSPBufferSize requires
280  // stack protectors.
281  Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
282  ORE.emit(RemarkBuilder);
283  NeedsProtector = true;
284  } else if (Strong) {
285  // Require protectors for all alloca calls in strong mode.
286  Layout.insert(std::make_pair(AI, SSPLK_SmallArray));
287  ORE.emit(RemarkBuilder);
288  NeedsProtector = true;
289  }
290  } else {
291  // A call to alloca with a variable size requires protectors.
292  Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
293  ORE.emit(RemarkBuilder);
294  NeedsProtector = true;
295  }
296  continue;
297  }
298 
299  bool IsLarge = false;
300  if (ContainsProtectableArray(AI->getAllocatedType(), IsLarge, Strong)) {
301  Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray
302  : SSPLK_SmallArray));
303  ORE.emit([&]() {
304  return OptimizationRemark(DEBUG_TYPE, "StackProtectorBuffer", &I)
305  << "Stack protection applied to function "
306  << ore::NV("Function", F)
307  << " due to a stack allocated buffer or struct containing a "
308  "buffer";
309  });
310  NeedsProtector = true;
311  continue;
312  }
313 
314  if (Strong && HasAddressTaken(AI)) {
315  ++NumAddrTaken;
316  Layout.insert(std::make_pair(AI, SSPLK_AddrOf));
317  ORE.emit([&]() {
318  return OptimizationRemark(DEBUG_TYPE, "StackProtectorAddressTaken",
319  &I)
320  << "Stack protection applied to function "
321  << ore::NV("Function", F)
322  << " due to the address of a local variable being taken";
323  });
324  NeedsProtector = true;
325  }
326  }
327  }
328  }
329 
330  return NeedsProtector;
331 }
332 
333 /// Create a stack guard loading and populate whether SelectionDAG SSP is
334 /// supported.
336  IRBuilder<> &B,
337  bool *SupportsSelectionDAGSP = nullptr) {
338  if (Value *Guard = TLI->getIRStackGuard(B))
339  return B.CreateLoad(Guard, true, "StackGuard");
340 
341  // Use SelectionDAG SSP handling, since there isn't an IR guard.
342  //
343  // This is more or less weird, since we optionally output whether we
344  // should perform a SelectionDAG SP here. The reason is that it's strictly
345  // defined as !TLI->getIRStackGuard(B), where getIRStackGuard is also
346  // mutating. There is no way to get this bit without mutating the IR, so
347  // getting this bit has to happen in this right time.
348  //
349  // We could have define a new function TLI::supportsSelectionDAGSP(), but that
350  // will put more burden on the backends' overriding work, especially when it
351  // actually conveys the same information getIRStackGuard() already gives.
352  if (SupportsSelectionDAGSP)
353  *SupportsSelectionDAGSP = true;
354  TLI->insertSSPDeclarations(*M);
355  return B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackguard));
356 }
357 
358 /// Insert code into the entry block that stores the stack guard
359 /// variable onto the stack:
360 ///
361 /// entry:
362 /// StackGuardSlot = alloca i8*
363 /// StackGuard = <stack guard>
364 /// call void @llvm.stackprotector(StackGuard, StackGuardSlot)
365 ///
366 /// Returns true if the platform/triple supports the stackprotectorcreate pseudo
367 /// node.
368 static bool CreatePrologue(Function *F, Module *M, ReturnInst *RI,
369  const TargetLoweringBase *TLI, AllocaInst *&AI) {
370  bool SupportsSelectionDAGSP = false;
371  IRBuilder<> B(&F->getEntryBlock().front());
372  PointerType *PtrTy = Type::getInt8PtrTy(RI->getContext());
373  AI = B.CreateAlloca(PtrTy, nullptr, "StackGuardSlot");
374 
375  Value *GuardSlot = getStackGuard(TLI, M, B, &SupportsSelectionDAGSP);
376  B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackprotector),
377  {GuardSlot, AI});
378  return SupportsSelectionDAGSP;
379 }
380 
381 /// InsertStackProtectors - Insert code into the prologue and epilogue of the
382 /// function.
383 ///
384 /// - The prologue code loads and stores the stack guard onto the stack.
385 /// - The epilogue checks the value stored in the prologue against the original
386 /// value. It calls __stack_chk_fail if they differ.
387 bool StackProtector::InsertStackProtectors() {
388  bool SupportsSelectionDAGSP =
390  AllocaInst *AI = nullptr; // Place on stack that stores the stack guard.
391 
392  for (Function::iterator I = F->begin(), E = F->end(); I != E;) {
393  BasicBlock *BB = &*I++;
395  if (!RI)
396  continue;
397 
398  // Generate prologue instrumentation if not already generated.
399  if (!HasPrologue) {
400  HasPrologue = true;
401  SupportsSelectionDAGSP &= CreatePrologue(F, M, RI, TLI, AI);
402  }
403 
404  // SelectionDAG based code generation. Nothing else needs to be done here.
405  // The epilogue instrumentation is postponed to SelectionDAG.
406  if (SupportsSelectionDAGSP)
407  break;
408 
409  // Set HasIRCheck to true, so that SelectionDAG will not generate its own
410  // version. SelectionDAG called 'shouldEmitSDCheck' to check whether
411  // instrumentation has already been generated.
412  HasIRCheck = true;
413 
414  // Generate epilogue instrumentation. The epilogue intrumentation can be
415  // function-based or inlined depending on which mechanism the target is
416  // providing.
417  if (Value* GuardCheck = TLI->getSSPStackGuardCheck(*M)) {
418  // Generate the function-based epilogue instrumentation.
419  // The target provides a guard check function, generate a call to it.
420  IRBuilder<> B(RI);
421  LoadInst *Guard = B.CreateLoad(AI, true, "Guard");
422  CallInst *Call = B.CreateCall(GuardCheck, {Guard});
423  llvm::Function *Function = cast<llvm::Function>(GuardCheck);
424  Call->setAttributes(Function->getAttributes());
425  Call->setCallingConv(Function->getCallingConv());
426  } else {
427  // Generate the epilogue with inline instrumentation.
428  // If we do not support SelectionDAG based tail calls, generate IR level
429  // tail calls.
430  //
431  // For each block with a return instruction, convert this:
432  //
433  // return:
434  // ...
435  // ret ...
436  //
437  // into this:
438  //
439  // return:
440  // ...
441  // %1 = <stack guard>
442  // %2 = load StackGuardSlot
443  // %3 = cmp i1 %1, %2
444  // br i1 %3, label %SP_return, label %CallStackCheckFailBlk
445  //
446  // SP_return:
447  // ret ...
448  //
449  // CallStackCheckFailBlk:
450  // call void @__stack_chk_fail()
451  // unreachable
452 
453  // Create the FailBB. We duplicate the BB every time since the MI tail
454  // merge pass will merge together all of the various BB into one including
455  // fail BB generated by the stack protector pseudo instruction.
456  BasicBlock *FailBB = CreateFailBB();
457 
458  // Split the basic block before the return instruction.
459  BasicBlock *NewBB = BB->splitBasicBlock(RI->getIterator(), "SP_return");
460 
461  // Update the dominator tree if we need to.
462  if (DT && DT->isReachableFromEntry(BB)) {
463  DT->addNewBlock(NewBB, BB);
464  DT->addNewBlock(FailBB, BB);
465  }
466 
467  // Remove default branch instruction to the new BB.
469 
470  // Move the newly created basic block to the point right after the old
471  // basic block so that it's in the "fall through" position.
472  NewBB->moveAfter(BB);
473 
474  // Generate the stack protector instructions in the old basic block.
475  IRBuilder<> B(BB);
476  Value *Guard = getStackGuard(TLI, M, B);
477  LoadInst *LI2 = B.CreateLoad(AI, true);
478  Value *Cmp = B.CreateICmpEQ(Guard, LI2);
479  auto SuccessProb =
481  auto FailureProb =
483  MDNode *Weights = MDBuilder(F->getContext())
484  .createBranchWeights(SuccessProb.getNumerator(),
485  FailureProb.getNumerator());
486  B.CreateCondBr(Cmp, NewBB, FailBB, Weights);
487  }
488  }
489 
490  // Return if we didn't modify any basic blocks. i.e., there are no return
491  // statements in the function.
492  return HasPrologue;
493 }
494 
495 /// CreateFailBB - Create a basic block to jump to when the stack protector
496 /// check fails.
497 BasicBlock *StackProtector::CreateFailBB() {
499  BasicBlock *FailBB = BasicBlock::Create(Context, "CallStackCheckFailBlk", F);
500  IRBuilder<> B(FailBB);
502  if (Trip.isOSOpenBSD()) {
503  Constant *StackChkFail =
504  M->getOrInsertFunction("__stack_smash_handler",
505  Type::getVoidTy(Context),
506  Type::getInt8PtrTy(Context));
507 
508  B.CreateCall(StackChkFail, B.CreateGlobalStringPtr(F->getName(), "SSH"));
509  } else {
510  Constant *StackChkFail =
511  M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context));
512 
513  B.CreateCall(StackChkFail, {});
514  }
515  B.CreateUnreachable();
516  return FailBB;
517 }
518 
520  return HasPrologue && !HasIRCheck && dyn_cast<ReturnInst>(BB.getTerminator());
521 }
Return a value (possibly void), from a function.
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:470
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:69
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional &#39;br Cond, TrueDest, FalseDest&#39; instruction.
Definition: IRBuilder.h:779
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:22
LLVMContext & Context
DiagnosticInfoOptimizationBase::Argument NV
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: ValueMap.h:175
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:142
unsigned EnableFastISel
EnableFastISel - This flag enables fast-path instruction selection which trades away generated code q...
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
iterator end()
Definition: Function.h:590
SSPLayoutKind getSSPLayout(const AllocaInst *AI) const
This class represents a function call, abstracting a target machine&#39;s calling convention.
virtual const TargetLowering * getTargetLowering() const
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:728
STATISTIC(NumFunctions, "Total number of functions")
Metadata node.
Definition: Metadata.h:862
An instruction for reading from memory.
Definition: Instructions.h:164
Hexagon Common GEP
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
Definition: Dominators.cpp:290
static bool CreatePrologue(Function *F, Module *M, ReturnInst *RI, const TargetLoweringBase *TLI, AllocaInst *&AI)
Insert code into the entry block that stores the stack guard variable onto the stack: ...
void setCallingConv(CallingConv::ID CC)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
Did not trigger a stack protector.
This class represents the LLVM &#39;select&#39; instruction.
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:170
Class to represent struct types.
Definition: DerivedTypes.h:201
static cl::opt< bool > EnableSelectionDAGSP("enable-selectiondag-sp", cl::init(true), cl::Hidden)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:668
This file contains the simple types necessary to represent the attributes associated with functions a...
DominatorTree & getDomTree()
Definition: Dominators.h:277
The address of this allocation is exposed and triggered protection.
Target-Independent Code Generator Pass Configuration Options.
This class represents a cast from a pointer to an integer.
Class to represent array types.
Definition: DerivedTypes.h:369
Value * CreateGlobalStringPtr(StringRef Str, const Twine &Name="", unsigned AddressSpace=0)
Same as CreateGlobalString, but return a pointer with "i8*" type instead of a pointer to array of i8...
Definition: IRBuilder.h:1372
iterator find(const KeyT &Val)
Definition: ValueMap.h:158
SSPLayoutKind
SSPLayoutKind.
This class represents a no-op cast from one type to another.
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:205
An instruction for storing to memory.
Definition: Instructions.h:306
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:634
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Definition: IRBuilder.h:152
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: ValueMap.h:167
iterator begin()
Definition: Function.h:588
Type::subtype_iterator element_iterator
Definition: DerivedTypes.h:301
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:980
Class to represent pointers.
Definition: DerivedTypes.h:467
bool runOnFunction(Function &Fn) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
#define DEBUG_TYPE
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
const BasicBlock & getEntryBlock() const
Definition: Function.h:572
virtual Value * getIRStackGuard(IRBuilder<> &IRB) const
If the target has a standard location for the stack protector guard, returns the address of that loca...
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Definition: Instructions.h:837
LoadInst * CreateLoad(Value *Ptr, const char *Name)
Definition: IRBuilder.h:1168
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:406
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
UnreachableInst * CreateUnreachable()
Definition: IRBuilder.h:863
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1497
bool isOSOpenBSD() const
Definition: Triple.h:482
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const Instruction & front() const
Definition: BasicBlock.h:264
Diagnostic information for applied optimization remarks.
element_iterator element_end() const
Definition: DerivedTypes.h:304
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:161
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
const Triple & getTargetTriple() const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:101
void adjustForColoring(const AllocaInst *From, const AllocaInst *To)
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1550
self_iterator getIterator()
Definition: ilist_node.h:82
FunctionPass * createStackProtectorPass()
createStackProtectorPass - This pass adds stack protectors to functions.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:194
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:220
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:497
iterator end()
Definition: ValueMap.h:138
Iterator for intrusive lists based on ilist_node.
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
Definition: BasicBlock.cpp:110
void emit(DiagnosticInfoOptimizationBase &OptDiag)
Output the remark via the diagnostic handler and to the optimization record file. ...
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
Insert stack protectors
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:194
Module.h This file contains the declarations for the Module class.
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target&#39;s TargetSubtargetInf...
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
iterator_range< user_iterator > users()
Definition: Value.h:401
element_iterator element_begin() const
Definition: DerivedTypes.h:303
virtual Value * getSSPStackGuardCheck(const Module &M) const
If the target has a standard stack protection check function that performs validation and error handl...
Basic Alias true
INITIALIZE_PASS_BEGIN(StackProtector, DEBUG_TYPE, "Insert stack protectors", false, true) INITIALIZE_PASS_END(StackProtector
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:195
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:220
TargetOptions Options
Definition: TargetMachine.h:96
#define I(x, y, z)
Definition: MD5.cpp:58
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:382
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:556
LLVM Value Representation.
Definition: Value.h:73
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1260
virtual void insertSSPDeclarations(Module &M) const
Inserts necessary declarations for SSP (stack protection) purpose.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:270
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:267
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:120
static Value * getStackGuard(const TargetLoweringBase *TLI, Module *M, IRBuilder<> &B, bool *SupportsSelectionDAGSP=nullptr)
Create a stack guard loading and populate whether SelectionDAG SSP is supported.
bool shouldEmitSDCheck(const BasicBlock &BB) const
The optimization diagnostic interface.
static BranchProbability getBranchProbStackProtector(bool IsLikely)
Array or nested array >= SSP-buffer-size.
bool erase(const KeyT &Val)
Definition: ValueMap.h:193
Array or nested array < SSP-buffer-size.
This file describes how to lower LLVM code to machine code.
an instruction to allocate memory on the stack
Definition: Instructions.h:60
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1663