LLVM  3.7.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"
22 #include "llvm/CodeGen/Analysis.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/DerivedTypes.h"
28 #include "llvm/IR/Function.h"
29 #include "llvm/IR/GlobalValue.h"
30 #include "llvm/IR/GlobalVariable.h"
31 #include "llvm/IR/IRBuilder.h"
32 #include "llvm/IR/Instructions.h"
33 #include "llvm/IR/IntrinsicInst.h"
34 #include "llvm/IR/Intrinsics.h"
35 #include "llvm/IR/MDBuilder.h"
36 #include "llvm/IR/Module.h"
39 #include <cstdlib>
40 using namespace llvm;
41 
42 #define DEBUG_TYPE "stack-protector"
43 
44 STATISTIC(NumFunProtected, "Number of functions protected");
45 STATISTIC(NumAddrTaken, "Number of local variables that have their address"
46  " taken.");
47 
48 static cl::opt<bool> EnableSelectionDAGSP("enable-selectiondag-sp",
49  cl::init(true), cl::Hidden);
50 
51 char StackProtector::ID = 0;
52 INITIALIZE_PASS(StackProtector, "stack-protector", "Insert stack protectors",
53  false, true)
54 
56  return new StackProtector(TM);
57 }
58 
61  return AI ? Layout.lookup(AI) : SSPLK_None;
62 }
63 
65  const AllocaInst *To) {
66  // When coloring replaces one alloca with another, transfer the SSPLayoutKind
67  // tag from the remapped to the target alloca. The remapped alloca should
68  // have a size smaller than or equal to the replacement alloca.
69  SSPLayoutMap::iterator I = Layout.find(From);
70  if (I != Layout.end()) {
71  SSPLayoutKind Kind = I->second;
72  Layout.erase(I);
73 
74  // Transfer the tag, but make sure that SSPLK_AddrOf does not overwrite
75  // SSPLK_SmallArray or SSPLK_LargeArray, and make sure that
76  // SSPLK_SmallArray does not overwrite SSPLK_LargeArray.
77  I = Layout.find(To);
78  if (I == Layout.end())
79  Layout.insert(std::make_pair(To, Kind));
80  else if (I->second != SSPLK_LargeArray && Kind != SSPLK_AddrOf)
81  I->second = Kind;
82  }
83 }
84 
86  F = &Fn;
87  M = F->getParent();
89  getAnalysisIfAvailable<DominatorTreeWrapperPass>();
90  DT = DTWP ? &DTWP->getDomTree() : nullptr;
91  TLI = TM->getSubtargetImpl(Fn)->getTargetLowering();
92 
93  Attribute Attr = Fn.getFnAttribute("stack-protector-buffer-size");
94  if (Attr.isStringAttribute() &&
95  Attr.getValueAsString().getAsInteger(10, SSPBufferSize))
96  return false; // Invalid integer string
97 
98  if (!RequiresStackProtector())
99  return false;
100 
101  ++NumFunProtected;
102  return InsertStackProtectors();
103 }
104 
105 /// \param [out] IsLarge is set to true if a protectable array is found and
106 /// it is "large" ( >= ssp-buffer-size). In the case of a structure with
107 /// multiple arrays, this gets set if any of them is large.
108 bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
109  bool Strong,
110  bool InStruct) const {
111  if (!Ty)
112  return false;
113  if (ArrayType *AT = dyn_cast<ArrayType>(Ty)) {
114  if (!AT->getElementType()->isIntegerTy(8)) {
115  // If we're on a non-Darwin platform or we're inside of a structure, don't
116  // add stack protectors unless the array is a character array.
117  // However, in strong mode any array, regardless of type and size,
118  // triggers a protector.
119  if (!Strong && (InStruct || !Trip.isOSDarwin()))
120  return false;
121  }
122 
123  // If an array has more than SSPBufferSize bytes of allocated space, then we
124  // emit stack protectors.
125  if (SSPBufferSize <= M->getDataLayout().getTypeAllocSize(AT)) {
126  IsLarge = true;
127  return true;
128  }
129 
130  if (Strong)
131  // Require a protector for all arrays in strong mode
132  return true;
133  }
134 
135  const StructType *ST = dyn_cast<StructType>(Ty);
136  if (!ST)
137  return false;
138 
139  bool NeedsProtector = false;
141  E = ST->element_end();
142  I != E; ++I)
143  if (ContainsProtectableArray(*I, IsLarge, Strong, true)) {
144  // If the element is a protectable array and is large (>= SSPBufferSize)
145  // then we are done. If the protectable array is not large, then
146  // keep looking in case a subsequent element is a large array.
147  if (IsLarge)
148  return true;
149  NeedsProtector = true;
150  }
151 
152  return NeedsProtector;
153 }
154 
155 bool StackProtector::HasAddressTaken(const Instruction *AI) {
156  for (const User *U : AI->users()) {
157  if (const StoreInst *SI = dyn_cast<StoreInst>(U)) {
158  if (AI == SI->getValueOperand())
159  return true;
160  } else if (const PtrToIntInst *SI = dyn_cast<PtrToIntInst>(U)) {
161  if (AI == SI->getOperand(0))
162  return true;
163  } else if (isa<CallInst>(U)) {
164  return true;
165  } else if (isa<InvokeInst>(U)) {
166  return true;
167  } else if (const SelectInst *SI = dyn_cast<SelectInst>(U)) {
168  if (HasAddressTaken(SI))
169  return true;
170  } else if (const PHINode *PN = dyn_cast<PHINode>(U)) {
171  // Keep track of what PHI nodes we have already visited to ensure
172  // they are only visited once.
173  if (VisitedPHIs.insert(PN).second)
174  if (HasAddressTaken(PN))
175  return true;
176  } else if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
177  if (HasAddressTaken(GEP))
178  return true;
179  } else if (const BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
180  if (HasAddressTaken(BI))
181  return true;
182  }
183  }
184  return false;
185 }
186 
187 /// \brief Check whether or not this function needs a stack protector based
188 /// upon the stack protector level.
189 ///
190 /// We use two heuristics: a standard (ssp) and strong (sspstrong).
191 /// The standard heuristic which will add a guard variable to functions that
192 /// call alloca with a either a variable size or a size >= SSPBufferSize,
193 /// functions with character buffers larger than SSPBufferSize, and functions
194 /// with aggregates containing character buffers larger than SSPBufferSize. The
195 /// strong heuristic will add a guard variables to functions that call alloca
196 /// regardless of size, functions with any buffer regardless of type and size,
197 /// functions with aggregates that contain any buffer regardless of type and
198 /// size, and functions that contain stack-based variables that have had their
199 /// address taken.
200 bool StackProtector::RequiresStackProtector() {
201  bool Strong = false;
202  bool NeedsProtector = false;
204  NeedsProtector = true;
205  Strong = true; // Use the same heuristic as strong to determine SSPLayout
207  Strong = true;
209  return false;
210 
211  for (const BasicBlock &BB : *F) {
212  for (const Instruction &I : BB) {
213  if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
214  if (AI->isArrayAllocation()) {
215  // SSP-Strong: Enable protectors for any call to alloca, regardless
216  // of size.
217  if (Strong)
218  return true;
219 
220  if (const auto *CI = dyn_cast<ConstantInt>(AI->getArraySize())) {
221  if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize) {
222  // A call to alloca with size >= SSPBufferSize requires
223  // stack protectors.
224  Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
225  NeedsProtector = true;
226  } else if (Strong) {
227  // Require protectors for all alloca calls in strong mode.
228  Layout.insert(std::make_pair(AI, SSPLK_SmallArray));
229  NeedsProtector = true;
230  }
231  } else {
232  // A call to alloca with a variable size requires protectors.
233  Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
234  NeedsProtector = true;
235  }
236  continue;
237  }
238 
239  bool IsLarge = false;
240  if (ContainsProtectableArray(AI->getAllocatedType(), IsLarge, Strong)) {
241  Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray
242  : SSPLK_SmallArray));
243  NeedsProtector = true;
244  continue;
245  }
246 
247  if (Strong && HasAddressTaken(AI)) {
248  ++NumAddrTaken;
249  Layout.insert(std::make_pair(AI, SSPLK_AddrOf));
250  NeedsProtector = true;
251  }
252  }
253  }
254  }
255 
256  return NeedsProtector;
257 }
258 
260  return !I->mayHaveSideEffects() && !I->mayReadFromMemory() &&
262 }
263 
264 /// Identify if RI has a previous instruction in the "Tail Position" and return
265 /// it. Otherwise return 0.
266 ///
267 /// This is based off of the code in llvm::isInTailCallPosition. The difference
268 /// is that it inverts the first part of llvm::isInTailCallPosition since
269 /// isInTailCallPosition is checking if a call is in a tail call position, and
270 /// we are searching for an unknown tail call that might be in the tail call
271 /// position. Once we find the call though, the code uses the same refactored
272 /// code, returnTypeIsEligibleForTailCall.
274  const TargetLoweringBase *TLI) {
275  // Establish a reasonable upper bound on the maximum amount of instructions we
276  // will look through to find a tail call.
277  unsigned SearchCounter = 0;
278  const unsigned MaxSearch = 4;
279  bool NoInterposingChain = true;
280 
281  for (BasicBlock::reverse_iterator I = std::next(BB->rbegin()), E = BB->rend();
282  I != E && SearchCounter < MaxSearch; ++I) {
283  Instruction *Inst = &*I;
284 
285  // Skip over debug intrinsics and do not allow them to affect our MaxSearch
286  // counter.
287  if (isa<DbgInfoIntrinsic>(Inst))
288  continue;
289 
290  // If we find a call and the following conditions are satisifed, then we
291  // have found a tail call that satisfies at least the target independent
292  // requirements of a tail call:
293  //
294  // 1. The call site has the tail marker.
295  //
296  // 2. The call site either will not cause the creation of a chain or if a
297  // chain is necessary there are no instructions in between the callsite and
298  // the call which would create an interposing chain.
299  //
300  // 3. The return type of the function does not impede tail call
301  // optimization.
302  if (CallInst *CI = dyn_cast<CallInst>(Inst)) {
303  if (CI->isTailCall() &&
304  (InstructionWillNotHaveChain(CI) || NoInterposingChain) &&
305  returnTypeIsEligibleForTailCall(BB->getParent(), CI, RI, *TLI))
306  return CI;
307  }
308 
309  // If we did not find a call see if we have an instruction that may create
310  // an interposing chain.
311  NoInterposingChain =
312  NoInterposingChain && InstructionWillNotHaveChain(Inst);
313 
314  // Increment max search.
315  SearchCounter++;
316  }
317 
318  return nullptr;
319 }
320 
321 /// Insert code into the entry block that stores the __stack_chk_guard
322 /// variable onto the stack:
323 ///
324 /// entry:
325 /// StackGuardSlot = alloca i8*
326 /// StackGuard = load __stack_chk_guard
327 /// call void @llvm.stackprotect.create(StackGuard, StackGuardSlot)
328 ///
329 /// Returns true if the platform/triple supports the stackprotectorcreate pseudo
330 /// node.
331 static bool CreatePrologue(Function *F, Module *M, ReturnInst *RI,
332  const TargetLoweringBase *TLI, const Triple &TT,
333  AllocaInst *&AI, Value *&StackGuardVar) {
334  bool SupportsSelectionDAGSP = false;
335  PointerType *PtrTy = Type::getInt8PtrTy(RI->getContext());
336  unsigned AddressSpace, Offset;
337  if (TLI->getStackCookieLocation(AddressSpace, Offset)) {
338  Constant *OffsetVal =
340 
341  StackGuardVar =
343  AddressSpace));
344  } else if (TT.isOSOpenBSD()) {
345  StackGuardVar = M->getOrInsertGlobal("__guard_local", PtrTy);
346  cast<GlobalValue>(StackGuardVar)
347  ->setVisibility(GlobalValue::HiddenVisibility);
348  } else {
349  SupportsSelectionDAGSP = true;
350  StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy);
351  }
352 
353  IRBuilder<> B(&F->getEntryBlock().front());
354  AI = B.CreateAlloca(PtrTy, nullptr, "StackGuardSlot");
355  LoadInst *LI = B.CreateLoad(StackGuardVar, "StackGuard");
356  B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackprotector),
357  {LI, AI});
358 
359  return SupportsSelectionDAGSP;
360 }
361 
362 /// InsertStackProtectors - Insert code into the prologue and epilogue of the
363 /// function.
364 ///
365 /// - The prologue code loads and stores the stack guard onto the stack.
366 /// - The epilogue checks the value stored in the prologue against the original
367 /// value. It calls __stack_chk_fail if they differ.
368 bool StackProtector::InsertStackProtectors() {
369  bool HasPrologue = false;
370  bool SupportsSelectionDAGSP =
372  AllocaInst *AI = nullptr; // Place on stack that stores the stack guard.
373  Value *StackGuardVar = nullptr; // The stack guard variable.
374 
375  for (Function::iterator I = F->begin(), E = F->end(); I != E;) {
376  BasicBlock *BB = I++;
378  if (!RI)
379  continue;
380 
381  if (!HasPrologue) {
382  HasPrologue = true;
383  SupportsSelectionDAGSP &=
384  CreatePrologue(F, M, RI, TLI, Trip, AI, StackGuardVar);
385  }
386 
387  if (SupportsSelectionDAGSP) {
388  // Since we have a potential tail call, insert the special stack check
389  // intrinsic.
390  Instruction *InsertionPt = nullptr;
391  if (CallInst *CI = FindPotentialTailCall(BB, RI, TLI)) {
392  InsertionPt = CI;
393  } else {
394  InsertionPt = RI;
395  // At this point we know that BB has a return statement so it *DOES*
396  // have a terminator.
397  assert(InsertionPt != nullptr &&
398  "BB must have a terminator instruction at this point.");
399  }
400 
401  Function *Intrinsic =
402  Intrinsic::getDeclaration(M, Intrinsic::stackprotectorcheck);
403  CallInst::Create(Intrinsic, StackGuardVar, "", InsertionPt);
404  } else {
405  // If we do not support SelectionDAG based tail calls, generate IR level
406  // tail calls.
407  //
408  // For each block with a return instruction, convert this:
409  //
410  // return:
411  // ...
412  // ret ...
413  //
414  // into this:
415  //
416  // return:
417  // ...
418  // %1 = load __stack_chk_guard
419  // %2 = load StackGuardSlot
420  // %3 = cmp i1 %1, %2
421  // br i1 %3, label %SP_return, label %CallStackCheckFailBlk
422  //
423  // SP_return:
424  // ret ...
425  //
426  // CallStackCheckFailBlk:
427  // call void @__stack_chk_fail()
428  // unreachable
429 
430  // Create the FailBB. We duplicate the BB every time since the MI tail
431  // merge pass will merge together all of the various BB into one including
432  // fail BB generated by the stack protector pseudo instruction.
433  BasicBlock *FailBB = CreateFailBB();
434 
435  // Split the basic block before the return instruction.
436  BasicBlock *NewBB = BB->splitBasicBlock(RI, "SP_return");
437 
438  // Update the dominator tree if we need to.
439  if (DT && DT->isReachableFromEntry(BB)) {
440  DT->addNewBlock(NewBB, BB);
441  DT->addNewBlock(FailBB, BB);
442  }
443 
444  // Remove default branch instruction to the new BB.
446 
447  // Move the newly created basic block to the point right after the old
448  // basic block so that it's in the "fall through" position.
449  NewBB->moveAfter(BB);
450 
451  // Generate the stack protector instructions in the old basic block.
452  IRBuilder<> B(BB);
453  LoadInst *LI1 = B.CreateLoad(StackGuardVar);
454  LoadInst *LI2 = B.CreateLoad(AI);
455  Value *Cmp = B.CreateICmpEQ(LI1, LI2);
456  unsigned SuccessWeight =
458  unsigned FailureWeight =
460  MDNode *Weights = MDBuilder(F->getContext())
461  .createBranchWeights(SuccessWeight, FailureWeight);
462  B.CreateCondBr(Cmp, NewBB, FailBB, Weights);
463  }
464  }
465 
466  // Return if we didn't modify any basic blocks. i.e., there are no return
467  // statements in the function.
468  if (!HasPrologue)
469  return false;
470 
471  return true;
472 }
473 
474 /// CreateFailBB - Create a basic block to jump to when the stack protector
475 /// check fails.
476 BasicBlock *StackProtector::CreateFailBB() {
477  LLVMContext &Context = F->getContext();
478  BasicBlock *FailBB = BasicBlock::Create(Context, "CallStackCheckFailBlk", F);
479  IRBuilder<> B(FailBB);
480  if (Trip.isOSOpenBSD()) {
481  Constant *StackChkFail =
482  M->getOrInsertFunction("__stack_smash_handler",
483  Type::getVoidTy(Context),
484  Type::getInt8PtrTy(Context), nullptr);
485 
486  B.CreateCall(StackChkFail, B.CreateGlobalStringPtr(F->getName(), "SSH"));
487  } else {
488  Constant *StackChkFail =
489  M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context),
490  nullptr);
491  B.CreateCall(StackChkFail, {});
492  }
493  B.CreateUnreachable();
494  return FailBB;
495 }
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
addNewBlock - 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:347
ReturnInst - Return a value (possibly void), from a function.
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
Definition: Instruction.cpp:70
STATISTIC(NumFunctions,"Total number of functions")
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: ValueMap.h:149
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:114
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:141
CallInst - This class represents a function call, abstracting a target machine's calling convention...
static PointerType * get(Type *ElementType, unsigned AddressSpace)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
Definition: Type.cpp:738
bool mayHaveSideEffects() const
mayHaveSideEffects - Return true if the instruction may have side effects.
Definition: Instruction.h:387
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1822
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:111
Metadata node.
Definition: Metadata.h:740
const Instruction & front() const
Definition: BasicBlock.h:243
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:225
reverse_iterator rend()
Definition: BasicBlock.h:238
LoadInst - an instruction for reading from memory.
Definition: Instructions.h:177
reverse_iterator rbegin()
Definition: BasicBlock.h:236
Hexagon Common GEP
bool returnTypeIsEligibleForTailCall(const Function *F, const Instruction *I, const ReturnInst *Ret, const TargetLoweringBase &TLI)
Test if given that the input instruction is in the tail call position if the return type or any attri...
static CallInst * FindPotentialTailCall(BasicBlock *BB, ReturnInst *RI, const TargetLoweringBase *TLI)
Identify if RI has a previous instruction in the "Tail Position" and return it.
element_iterator element_end() const
Definition: DerivedTypes.h:280
Did not trigger a stack protector.
SelectInst - This class represents the LLVM 'select' instruction.
Type::subtype_iterator element_iterator
Definition: DerivedTypes.h:278
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
StructType - Class to represent struct types.
Definition: DerivedTypes.h:191
static cl::opt< bool > EnableSelectionDAGSP("enable-selectiondag-sp", cl::init(true), cl::Hidden)
INITIALIZE_PASS(StackProtector,"stack-protector","Insert stack protectors", false, true) FunctionPass *llvm
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:517
This file contains the simple types necessary to represent the attributes associated with functions a...
DominatorTree & getDomTree()
Definition: Dominators.h:213
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.
static bool InstructionWillNotHaveChain(const Instruction *I)
bool mayReadFromMemory() const
mayReadFromMemory - Return true if this instruction may read memory.
ArrayType - Class to represent array types.
Definition: DerivedTypes.h:336
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
Definition: Dominators.cpp:265
iterator find(const KeyT &Val)
Definition: ValueMap.h:132
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:866
StoreInst - an instruction for storing to memory.
Definition: Instructions.h:316
Stack protection.
Definition: Attributes.h:110
PointerType - Class to represent pointers.
Definition: DerivedTypes.h:449
bool runOnFunction(Function &Fn) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
virtual bool getStackCookieLocation(unsigned &, unsigned &) const
Return true if the target stores stack protector cookies at a fixed offset in some non-standard addre...
InstListType::reverse_iterator reverse_iterator
Definition: BasicBlock.h:95
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
Definition: Instructions.h:830
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:325
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:115
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
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:41
Constant * getOrInsertGlobal(StringRef Name, Type *Ty)
Look up the specified global in the module symbol table.
Definition: Module.cpp:217
bool isOSOpenBSD() const
Definition: Triple.h:412
This is an important base class in LLVM.
Definition: Constant.h:41
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool CreatePrologue(Function *F, Module *M, ReturnInst *RI, const TargetLoweringBase *TLI, const Triple &TT, AllocaInst *&AI, Value *&StackGuardVar)
Insert code into the entry block that stores the __stack_chk_guard variable onto the stack: ...
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:225
static uint32_t getBranchWeightStackProtector(bool IsLikely)
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:294
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:103
void adjustForColoring(const AllocaInst *From, const AllocaInst *To)
SSPLayoutKind getSSPLayout(const AllocaInst *AI) const
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:519
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:283
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X or iOS).
Definition: Triple.h:404
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:112
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.
Module.h This file contains the declarations for the Module class.
virtual const TargetLowering * getTargetLowering() const
AddressSpace
Definition: NVPTXBaseInfo.h:22
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:582
const BasicBlock & getEntryBlock() const
Definition: Function.h:442
iterator_range< user_iterator > users()
Definition: Value.h:300
LLVM_ATTRIBUTE_UNUSED_RESULT 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:285
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:217
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:239
#define I(x, y, z)
Definition: MD5.cpp:54
Strong Stack protection.
Definition: Attributes.h:112
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
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:115
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:348
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:140
aarch64 promote const
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:365
LLVM Value Representation.
Definition: Value.h:69
Primary interface to the complete machine description for the target machine.
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
isSafeToSpeculativelyExecute - Return true if the instruction does not have any effects besides calcu...
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:203
Stack protection required.
Definition: Attributes.h:111
Array or nested array >= SSP-buffer-size.
bool erase(const KeyT &Val)
Definition: ValueMap.h:168
Array or nested array < SSP-buffer-size.
AllocaInst - an instruction to allocate memory on the stack.
Definition: Instructions.h:76