comparison lib/CodeGen/StackProtector.cpp @ 134:3a76565eade5 LLVM5.0.1

update 5.0.1
author mir3636
date Sat, 17 Feb 2018 09:57:20 +0900
parents 803732b1fca8
children c2174574ed3a
comparison
equal deleted inserted replaced
133:c60214abe0e8 134:3a76565eade5
12 // are allocated. Upon exiting the block, the stored value is checked. If it's 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. 13 // changed, then there was some sort of violation and the program aborts.
14 // 14 //
15 //===----------------------------------------------------------------------===// 15 //===----------------------------------------------------------------------===//
16 16
17 #include "llvm/CodeGen/StackProtector.h"
17 #include "llvm/ADT/SmallPtrSet.h" 18 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/Statistic.h" 19 #include "llvm/ADT/Statistic.h"
19 #include "llvm/Analysis/BranchProbabilityInfo.h" 20 #include "llvm/Analysis/BranchProbabilityInfo.h"
20 #include "llvm/Analysis/EHPersonalities.h" 21 #include "llvm/Analysis/EHPersonalities.h"
21 #include "llvm/Analysis/OptimizationRemarkEmitter.h" 22 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
22 #include "llvm/CodeGen/Passes.h" 23 #include "llvm/CodeGen/Passes.h"
23 #include "llvm/CodeGen/StackProtector.h" 24 #include "llvm/CodeGen/TargetLowering.h"
24 #include "llvm/CodeGen/TargetPassConfig.h" 25 #include "llvm/CodeGen/TargetPassConfig.h"
26 #include "llvm/CodeGen/TargetSubtargetInfo.h"
25 #include "llvm/IR/Attributes.h" 27 #include "llvm/IR/Attributes.h"
26 #include "llvm/IR/BasicBlock.h" 28 #include "llvm/IR/BasicBlock.h"
27 #include "llvm/IR/Constants.h" 29 #include "llvm/IR/Constants.h"
28 #include "llvm/IR/DataLayout.h" 30 #include "llvm/IR/DataLayout.h"
29 #include "llvm/IR/DebugInfo.h" 31 #include "llvm/IR/DebugInfo.h"
40 #include "llvm/IR/Type.h" 42 #include "llvm/IR/Type.h"
41 #include "llvm/IR/User.h" 43 #include "llvm/IR/User.h"
42 #include "llvm/Pass.h" 44 #include "llvm/Pass.h"
43 #include "llvm/Support/Casting.h" 45 #include "llvm/Support/Casting.h"
44 #include "llvm/Support/CommandLine.h" 46 #include "llvm/Support/CommandLine.h"
45 #include "llvm/Target/TargetLowering.h"
46 #include "llvm/Target/TargetMachine.h" 47 #include "llvm/Target/TargetMachine.h"
47 #include "llvm/Target/TargetOptions.h" 48 #include "llvm/Target/TargetOptions.h"
48 #include "llvm/Target/TargetSubtargetInfo.h"
49 #include <utility> 49 #include <utility>
50 50
51 using namespace llvm; 51 using namespace llvm;
52 52
53 #define DEBUG_TYPE "stack-protector" 53 #define DEBUG_TYPE "stack-protector"
383 /// 383 ///
384 /// - The prologue code loads and stores the stack guard onto the stack. 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 385 /// - The epilogue checks the value stored in the prologue against the original
386 /// value. It calls __stack_chk_fail if they differ. 386 /// value. It calls __stack_chk_fail if they differ.
387 bool StackProtector::InsertStackProtectors() { 387 bool StackProtector::InsertStackProtectors() {
388 // If the target wants to XOR the frame pointer into the guard value, it's
389 // impossible to emit the check in IR, so the target *must* support stack
390 // protection in SDAG.
388 bool SupportsSelectionDAGSP = 391 bool SupportsSelectionDAGSP =
389 EnableSelectionDAGSP && !TM->Options.EnableFastISel; 392 TLI->useStackGuardXorFP() ||
393 (EnableSelectionDAGSP && !TM->Options.EnableFastISel);
390 AllocaInst *AI = nullptr; // Place on stack that stores the stack guard. 394 AllocaInst *AI = nullptr; // Place on stack that stores the stack guard.
391 395
392 for (Function::iterator I = F->begin(), E = F->end(); I != E;) { 396 for (Function::iterator I = F->begin(), E = F->end(); I != E;) {
393 BasicBlock *BB = &*I++; 397 BasicBlock *BB = &*I++;
394 ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator()); 398 ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator());