LLVM  4.0.0
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"
24 #include "llvm/IR/Attributes.h"
25 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/DebugInfo.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/Function.h"
30 #include "llvm/IR/GlobalValue.h"
31 #include "llvm/IR/GlobalVariable.h"
32 #include "llvm/IR/IRBuilder.h"
33 #include "llvm/IR/Instructions.h"
34 #include "llvm/IR/IntrinsicInst.h"
35 #include "llvm/IR/Intrinsics.h"
36 #include "llvm/IR/MDBuilder.h"
37 #include "llvm/IR/Module.h"
40 #include <cstdlib>
41 using namespace llvm;
42 
43 #define DEBUG_TYPE "stack-protector"
44 
45 STATISTIC(NumFunProtected, "Number of functions protected");
46 STATISTIC(NumAddrTaken, "Number of local variables that have their address"
47  " taken.");
48 
49 static cl::opt<bool> EnableSelectionDAGSP("enable-selectiondag-sp",
50  cl::init(true), cl::Hidden);
51 
52 char StackProtector::ID = 0;
53 INITIALIZE_TM_PASS(StackProtector, "stack-protector", "Insert stack protectors",
54  false, true)
55 
57  return new StackProtector(TM);
58 }
59 
62  return AI ? Layout.lookup(AI) : SSPLK_None;
63 }
64 
66  const AllocaInst *To) {
67  // When coloring replaces one alloca with another, transfer the SSPLayoutKind
68  // tag from the remapped to the target alloca. The remapped alloca should
69  // have a size smaller than or equal to the replacement alloca.
70  SSPLayoutMap::iterator I = Layout.find(From);
71  if (I != Layout.end()) {
72  SSPLayoutKind Kind = I->second;
73  Layout.erase(I);
74 
75  // Transfer the tag, but make sure that SSPLK_AddrOf does not overwrite
76  // SSPLK_SmallArray or SSPLK_LargeArray, and make sure that
77  // SSPLK_SmallArray does not overwrite SSPLK_LargeArray.
78  I = Layout.find(To);
79  if (I == Layout.end())
80  Layout.insert(std::make_pair(To, Kind));
81  else if (I->second != SSPLK_LargeArray && Kind != SSPLK_AddrOf)
82  I->second = Kind;
83  }
84 }
85 
87  F = &Fn;
88  M = F->getParent();
90  getAnalysisIfAvailable<DominatorTreeWrapperPass>();
91  DT = DTWP ? &DTWP->getDomTree() : nullptr;
92  TLI = TM->getSubtargetImpl(Fn)->getTargetLowering();
93  HasPrologue = false;
94  HasIRCheck = false;
95 
96  Attribute Attr = Fn.getFnAttribute("stack-protector-buffer-size");
97  if (Attr.isStringAttribute() &&
98  Attr.getValueAsString().getAsInteger(10, SSPBufferSize))
99  return false; // Invalid integer string
100 
101  if (!RequiresStackProtector())
102  return false;
103 
104  // TODO(etienneb): Functions with funclets are not correctly supported now.
105  // Do nothing if this is funclet-based personality.
106  if (Fn.hasPersonalityFn()) {
108  if (isFuncletEHPersonality(Personality))
109  return false;
110  }
111 
112  ++NumFunProtected;
113  return InsertStackProtectors();
114 }
115 
116 /// \param [out] IsLarge is set to true if a protectable array is found and
117 /// it is "large" ( >= ssp-buffer-size). In the case of a structure with
118 /// multiple arrays, this gets set if any of them is large.
119 bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
120  bool Strong,
121  bool InStruct) const {
122  if (!Ty)
123  return false;
124  if (ArrayType *AT = dyn_cast<ArrayType>(Ty)) {
125  if (!AT->getElementType()->isIntegerTy(8)) {
126  // If we're on a non-Darwin platform or we're inside of a structure, don't
127  // add stack protectors unless the array is a character array.
128  // However, in strong mode any array, regardless of type and size,
129  // triggers a protector.
130  if (!Strong && (InStruct || !Trip.isOSDarwin()))
131  return false;
132  }
133 
134  // If an array has more than SSPBufferSize bytes of allocated space, then we
135  // emit stack protectors.
136  if (SSPBufferSize <= M->getDataLayout().getTypeAllocSize(AT)) {
137  IsLarge = true;
138  return true;
139  }
140 
141  if (Strong)
142  // Require a protector for all arrays in strong mode
143  return true;
144  }
145 
146  const StructType *ST = dyn_cast<StructType>(Ty);
147  if (!ST)
148  return false;
149 
150  bool NeedsProtector = false;
152  E = ST->element_end();
153  I != E; ++I)
154  if (ContainsProtectableArray(*I, IsLarge, Strong, true)) {
155  // If the element is a protectable array and is large (>= SSPBufferSize)
156  // then we are done. If the protectable array is not large, then
157  // keep looking in case a subsequent element is a large array.
158  if (IsLarge)
159  return true;
160  NeedsProtector = true;
161  }
162 
163  return NeedsProtector;
164 }
165 
166 bool StackProtector::HasAddressTaken(const Instruction *AI) {
167  for (const User *U : AI->users()) {
168  if (const StoreInst *SI = dyn_cast<StoreInst>(U)) {
169  if (AI == SI->getValueOperand())
170  return true;
171  } else if (const PtrToIntInst *SI = dyn_cast<PtrToIntInst>(U)) {
172  if (AI == SI->getOperand(0))
173  return true;
174  } else if (isa<CallInst>(U)) {
175  return true;
176  } else if (isa<InvokeInst>(U)) {
177  return true;
178  } else if (const SelectInst *SI = dyn_cast<SelectInst>(U)) {
179  if (HasAddressTaken(SI))
180  return true;
181  } else if (const PHINode *PN = dyn_cast<PHINode>(U)) {
182  // Keep track of what PHI nodes we have already visited to ensure
183  // they are only visited once.
184  if (VisitedPHIs.insert(PN).second)
185  if (HasAddressTaken(PN))
186  return true;
187  } else if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
188  if (HasAddressTaken(GEP))
189  return true;
190  } else if (const BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
191  if (HasAddressTaken(BI))
192  return true;
193  }
194  }
195  return false;
196 }
197 
198 /// \brief Check whether or not this function needs a stack protector based
199 /// upon the stack protector level.
200 ///
201 /// We use two heuristics: a standard (ssp) and strong (sspstrong).
202 /// The standard heuristic which will add a guard variable to functions that
203 /// call alloca with a either a variable size or a size >= SSPBufferSize,
204 /// functions with character buffers larger than SSPBufferSize, and functions
205 /// with aggregates containing character buffers larger than SSPBufferSize. The
206 /// strong heuristic will add a guard variables to functions that call alloca
207 /// regardless of size, functions with any buffer regardless of type and size,
208 /// functions with aggregates that contain any buffer regardless of type and
209 /// size, and functions that contain stack-based variables that have had their
210 /// address taken.
211 bool StackProtector::RequiresStackProtector() {
212  bool Strong = false;
213  bool NeedsProtector = false;
214  for (const BasicBlock &BB : *F)
215  for (const Instruction &I : BB)
216  if (const CallInst *CI = dyn_cast<CallInst>(&I))
217  if (CI->getCalledFunction() ==
218  Intrinsic::getDeclaration(F->getParent(),
219  Intrinsic::stackprotector))
220  HasPrologue = true;
221 
222  if (F->hasFnAttribute(Attribute::SafeStack))
223  return false;
224 
225  if (F->hasFnAttribute(Attribute::StackProtectReq)) {
226  NeedsProtector = true;
227  Strong = true; // Use the same heuristic as strong to determine SSPLayout
228  } else if (F->hasFnAttribute(Attribute::StackProtectStrong))
229  Strong = true;
230  else if (HasPrologue)
231  NeedsProtector = true;
232  else if (!F->hasFnAttribute(Attribute::StackProtect))
233  return false;
234 
235  for (const BasicBlock &BB : *F) {
236  for (const Instruction &I : BB) {
237  if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
238  if (AI->isArrayAllocation()) {
239  if (const auto *CI = dyn_cast<ConstantInt>(AI->getArraySize())) {
240  if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize) {
241  // A call to alloca with size >= SSPBufferSize requires
242  // stack protectors.
243  Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
244  NeedsProtector = true;
245  } else if (Strong) {
246  // Require protectors for all alloca calls in strong mode.
247  Layout.insert(std::make_pair(AI, SSPLK_SmallArray));
248  NeedsProtector = true;
249  }
250  } else {
251  // A call to alloca with a variable size requires protectors.
252  Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
253  NeedsProtector = true;
254  }
255  continue;
256  }
257 
258  bool IsLarge = false;
259  if (ContainsProtectableArray(AI->getAllocatedType(), IsLarge, Strong)) {
260  Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray
261  : SSPLK_SmallArray));
262  NeedsProtector = true;
263  continue;
264  }
265 
266  if (Strong && HasAddressTaken(AI)) {
267  ++NumAddrTaken;
268  Layout.insert(std::make_pair(AI, SSPLK_AddrOf));
269  NeedsProtector = true;
270  }
271  }
272  }
273  }
274 
275  return NeedsProtector;
276 }
277 
278 /// Create a stack guard loading and populate whether SelectionDAG SSP is
279 /// supported.
281  IRBuilder<> &B,
282  bool *SupportsSelectionDAGSP = nullptr) {
283  if (Value *Guard = TLI->getIRStackGuard(B))
284  return B.CreateLoad(Guard, true, "StackGuard");
285 
286  // Use SelectionDAG SSP handling, since there isn't an IR guard.
287  //
288  // This is more or less weird, since we optionally output whether we
289  // should perform a SelectionDAG SP here. The reason is that it's strictly
290  // defined as !TLI->getIRStackGuard(B), where getIRStackGuard is also
291  // mutating. There is no way to get this bit without mutating the IR, so
292  // getting this bit has to happen in this right time.
293  //
294  // We could have define a new function TLI::supportsSelectionDAGSP(), but that
295  // will put more burden on the backends' overriding work, especially when it
296  // actually conveys the same information getIRStackGuard() already gives.
297  if (SupportsSelectionDAGSP)
298  *SupportsSelectionDAGSP = true;
299  TLI->insertSSPDeclarations(*M);
300  return B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackguard));
301 }
302 
303 /// Insert code into the entry block that stores the stack guard
304 /// variable onto the stack:
305 ///
306 /// entry:
307 /// StackGuardSlot = alloca i8*
308 /// StackGuard = <stack guard>
309 /// call void @llvm.stackprotector(StackGuard, StackGuardSlot)
310 ///
311 /// Returns true if the platform/triple supports the stackprotectorcreate pseudo
312 /// node.
313 static bool CreatePrologue(Function *F, Module *M, ReturnInst *RI,
314  const TargetLoweringBase *TLI, AllocaInst *&AI) {
315  bool SupportsSelectionDAGSP = false;
316  IRBuilder<> B(&F->getEntryBlock().front());
317  PointerType *PtrTy = Type::getInt8PtrTy(RI->getContext());
318  AI = B.CreateAlloca(PtrTy, nullptr, "StackGuardSlot");
319 
320  Value *GuardSlot = getStackGuard(TLI, M, B, &SupportsSelectionDAGSP);
321  B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackprotector),
322  {GuardSlot, AI});
323  return SupportsSelectionDAGSP;
324 }
325 
326 /// InsertStackProtectors - Insert code into the prologue and epilogue of the
327 /// function.
328 ///
329 /// - The prologue code loads and stores the stack guard onto the stack.
330 /// - The epilogue checks the value stored in the prologue against the original
331 /// value. It calls __stack_chk_fail if they differ.
332 bool StackProtector::InsertStackProtectors() {
333  bool SupportsSelectionDAGSP =
335  AllocaInst *AI = nullptr; // Place on stack that stores the stack guard.
336 
337  for (Function::iterator I = F->begin(), E = F->end(); I != E;) {
338  BasicBlock *BB = &*I++;
340  if (!RI)
341  continue;
342 
343  // Generate prologue instrumentation if not already generated.
344  if (!HasPrologue) {
345  HasPrologue = true;
346  SupportsSelectionDAGSP &= CreatePrologue(F, M, RI, TLI, AI);
347  }
348 
349  // SelectionDAG based code generation. Nothing else needs to be done here.
350  // The epilogue instrumentation is postponed to SelectionDAG.
351  if (SupportsSelectionDAGSP)
352  break;
353 
354  // Set HasIRCheck to true, so that SelectionDAG will not generate its own
355  // version. SelectionDAG called 'shouldEmitSDCheck' to check whether
356  // instrumentation has already been generated.
357  HasIRCheck = true;
358 
359  // Generate epilogue instrumentation. The epilogue intrumentation can be
360  // function-based or inlined depending on which mechanism the target is
361  // providing.
362  if (Value* GuardCheck = TLI->getSSPStackGuardCheck(*M)) {
363  // Generate the function-based epilogue instrumentation.
364  // The target provides a guard check function, generate a call to it.
365  IRBuilder<> B(RI);
366  LoadInst *Guard = B.CreateLoad(AI, true, "Guard");
367  CallInst *Call = B.CreateCall(GuardCheck, {Guard});
368  llvm::Function *Function = cast<llvm::Function>(GuardCheck);
369  Call->setAttributes(Function->getAttributes());
370  Call->setCallingConv(Function->getCallingConv());
371  } else {
372  // Generate the epilogue with inline instrumentation.
373  // If we do not support SelectionDAG based tail calls, generate IR level
374  // tail calls.
375  //
376  // For each block with a return instruction, convert this:
377  //
378  // return:
379  // ...
380  // ret ...
381  //
382  // into this:
383  //
384  // return:
385  // ...
386  // %1 = <stack guard>
387  // %2 = load StackGuardSlot
388  // %3 = cmp i1 %1, %2
389  // br i1 %3, label %SP_return, label %CallStackCheckFailBlk
390  //
391  // SP_return:
392  // ret ...
393  //
394  // CallStackCheckFailBlk:
395  // call void @__stack_chk_fail()
396  // unreachable
397 
398  // Create the FailBB. We duplicate the BB every time since the MI tail
399  // merge pass will merge together all of the various BB into one including
400  // fail BB generated by the stack protector pseudo instruction.
401  BasicBlock *FailBB = CreateFailBB();
402 
403  // Split the basic block before the return instruction.
404  BasicBlock *NewBB = BB->splitBasicBlock(RI->getIterator(), "SP_return");
405 
406  // Update the dominator tree if we need to.
407  if (DT && DT->isReachableFromEntry(BB)) {
408  DT->addNewBlock(NewBB, BB);
409  DT->addNewBlock(FailBB, BB);
410  }
411 
412  // Remove default branch instruction to the new BB.
414 
415  // Move the newly created basic block to the point right after the old
416  // basic block so that it's in the "fall through" position.
417  NewBB->moveAfter(BB);
418 
419  // Generate the stack protector instructions in the old basic block.
420  IRBuilder<> B(BB);
421  Value *Guard = getStackGuard(TLI, M, B);
422  LoadInst *LI2 = B.CreateLoad(AI, true);
423  Value *Cmp = B.CreateICmpEQ(Guard, LI2);
424  auto SuccessProb =
426  auto FailureProb =
428  MDNode *Weights = MDBuilder(F->getContext())
429  .createBranchWeights(SuccessProb.getNumerator(),
430  FailureProb.getNumerator());
431  B.CreateCondBr(Cmp, NewBB, FailBB, Weights);
432  }
433  }
434 
435  // Return if we didn't modify any basic blocks. i.e., there are no return
436  // statements in the function.
437  return HasPrologue;
438 }
439 
440 /// CreateFailBB - Create a basic block to jump to when the stack protector
441 /// check fails.
442 BasicBlock *StackProtector::CreateFailBB() {
443  LLVMContext &Context = F->getContext();
444  BasicBlock *FailBB = BasicBlock::Create(Context, "CallStackCheckFailBlk", F);
445  IRBuilder<> B(FailBB);
446  B.SetCurrentDebugLocation(DebugLoc::get(0, 0, F->getSubprogram()));
447  if (Trip.isOSOpenBSD()) {
448  Constant *StackChkFail =
449  M->getOrInsertFunction("__stack_smash_handler",
450  Type::getVoidTy(Context),
451  Type::getInt8PtrTy(Context), nullptr);
452 
453  B.CreateCall(StackChkFail, B.CreateGlobalStringPtr(F->getName(), "SSH"));
454  } else {
455  Constant *StackChkFail =
456  M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context),
457  nullptr);
458  B.CreateCall(StackChkFail, {});
459  }
460  B.CreateUnreachable();
461  return FailBB;
462 }
463 
465  return HasPrologue && !HasIRCheck && dyn_cast<ReturnInst>(BB.getTerminator());
466 }
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
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:494
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:76
LLVMContext & Context
STATISTIC(NumFunctions,"Total number of functions")
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: ValueMap.h:175
INITIALIZE_TM_PASS(StackProtector,"stack-protector","Insert stack protectors", false, true) FunctionPass *llvm
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:52
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
This class represents a function call, abstracting a target machine's calling convention.
Metadata node.
Definition: Metadata.h:830
const Instruction & front() const
Definition: BasicBlock.h:240
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:234
An instruction for reading from memory.
Definition: Instructions.h:164
Hexagon Common GEP
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:165
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)
element_iterator element_end() const
Definition: DerivedTypes.h:280
Did not trigger a stack protector.
This class represents the LLVM 'select' instruction.
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:21
Type::subtype_iterator element_iterator
Definition: DerivedTypes.h:278
Class to represent struct types.
Definition: DerivedTypes.h:199
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:588
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1218
This file contains the simple types necessary to represent the attributes associated with functions a...
DominatorTree & getDomTree()
Definition: Dominators.h:227
element_iterator element_begin() const
Definition: DerivedTypes.h:279
The address of this allocation is exposed and triggered protection.
This class represents a cast from a pointer to an integer.
virtual Value * getIRStackGuard(IRBuilder<> &IRB) const
If the target has a standard location for the stack protector guard, returns the address of that loca...
Class to represent array types.
Definition: DerivedTypes.h:345
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
Definition: Dominators.cpp:269
iterator find(const KeyT &Val)
Definition: ValueMap.h:158
SSPLayoutKind
SSPLayoutKind.
This class represents a no-op cast from one type to another.
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:949
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
An instruction for storing to memory.
Definition: Instructions.h:300
Class to represent pointers.
Definition: DerivedTypes.h:443
bool runOnFunction(Function &Fn) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
void setAttributes(AttributeSet Attrs)
Set the parameter attributes for this call.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Definition: Instructions.h:830
LoadInst * CreateLoad(Value *Ptr, const char *Name)
Definition: IRBuilder.h:1082
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:395
bool shouldEmitSDCheck(const BasicBlock &BB) const
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:123
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
virtual void insertSSPDeclarations(Module &M) const
Inserts necessary declarations for SSP (stack protection) purpose.
bool isOSOpenBSD() const
Definition: Triple.h:463
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...
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:581
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:154
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:93
void adjustForColoring(const AllocaInst *From, const AllocaInst *To)
self_iterator getIterator()
Definition: ilist_node.h:81
SSPLayoutKind getSSPLayout(const AllocaInst *AI) const
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:654
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:213
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
virtual Value * getSSPStackGuardCheck(const Module &M) const
If the target has a standard stack protection check function that performs validation and error handl...
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:455
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
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
FunctionPass * createStackProtectorPass(const TargetMachine *TM)
createStackProtectorPass - This pass adds stack protectors to functions.
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
Module.h This file contains the declarations for the Module class.
virtual const TargetLowering * getTargetLowering() const
const BasicBlock & getEntryBlock() const
Definition: Function.h:519
AttributeSet getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:176
iterator_range< user_iterator > users()
Definition: Value.h:370
#define I(x, y, z)
Definition: MD5.cpp:54
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:124
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1579
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:287
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:153
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:374
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:178
aarch64 promote const
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:537
LLVM Value Representation.
Definition: Value.h:71
Primary interface to the complete machine description for the target machine.
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:217
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.
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.
an instruction to allocate memory on the stack
Definition: Instructions.h:60