diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2014-08-07 23:08:24 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2014-08-07 23:08:24 +0000 |
commit | 5acc58fcfb403d1638856133088727c4e1a22fce (patch) | |
tree | 703dbd5fe012afcf1eb68ec66c210732c6c69da8 /llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | |
parent | 80c8b2742fc6efa79f31d28359923b366a588277 (diff) | |
download | llvm-5acc58fcfb403d1638856133088727c4e1a22fce.zip llvm-5acc58fcfb403d1638856133088727c4e1a22fce.tar.gz llvm-5acc58fcfb403d1638856133088727c4e1a22fce.tar.bz2 |
[stack protector] Look through bitcasts to get global variable
__stack_chk_guard.
Handle the case where the pointer operand of the load instruction that loads the
stack guard is not a global variable but instead a bitcast.
%StackGuard = load i8** bitcast (i64** @__stack_chk_guard to i8**)
call void @llvm.stackprotector(i8* %StackGuard, i8** %StackGuardSlot)
Original test case provided by Ana Pazos.
This fixes PR20558.
llvm-svn: 215167
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index cc6eac7..c88aad66 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1814,12 +1814,14 @@ void SelectionDAGBuilder::visitSPDescriptorParent(StackProtectorDescriptor &SPD, SDValue Guard; - // If useLoadStackGuardNode returns true, retrieve the guard value from - // the virtual register holding the value. Otherwise, emit a volatile load - // to retrieve the stack guard value. - if (TLI->useLoadStackGuardNode()) - Guard = DAG.getCopyFromReg(DAG.getEntryNode(), getCurSDLoc(), - SPD.getGuardReg(), PtrTy); + // If GuardReg is set and useLoadStackGuardNode returns true, retrieve the + // guard value from the virtual register holding the value. Otherwise, emit a + // volatile load to retrieve the stack guard value. + unsigned GuardReg = SPD.getGuardReg(); + + if (GuardReg && TLI->useLoadStackGuardNode()) + Guard = DAG.getCopyFromReg(DAG.getEntryNode(), getCurSDLoc(), GuardReg, + PtrTy); else Guard = DAG.getLoad(PtrTy, getCurSDLoc(), DAG.getEntryNode(), GuardPtr, MachinePointerInfo(IRGuard, 0), @@ -5263,13 +5265,21 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) { MachineFrameInfo *MFI = MF.getFrameInfo(); EVT PtrTy = TLI->getPointerTy(); SDValue Src, Chain = getRoot(); + const Value *Ptr = cast<LoadInst>(I.getArgOperand(0))->getPointerOperand(); + const GlobalVariable *GV = dyn_cast<GlobalVariable>(Ptr); - if (TLI->useLoadStackGuardNode()) { + // See if Ptr is a bitcast. If it is, look through it and see if we can get + // global variable __stack_chk_guard. + if (!GV) + if (const Operator *BC = dyn_cast<Operator>(Ptr)) + if (BC->getOpcode() == Instruction::BitCast) + GV = dyn_cast<GlobalVariable>(BC->getOperand(0)); + + if (GV && TLI->useLoadStackGuardNode()) { // Emit a LOAD_STACK_GUARD node. MachineSDNode *Node = DAG.getMachineNode(TargetOpcode::LOAD_STACK_GUARD, sdl, PtrTy, Chain); - LoadInst *LI = cast<LoadInst>(I.getArgOperand(0)); - MachinePointerInfo MPInfo(LI->getPointerOperand()); + MachinePointerInfo MPInfo(GV); MachineInstr::mmo_iterator MemRefs = MF.allocateMemRefsArray(1); unsigned Flags = MachineMemOperand::MOLoad | MachineMemOperand::MOInvariant; |