diff --git a/llvm/include/llvm/IR/IntrinsicsPowerPC.td b/llvm/include/llvm/IR/IntrinsicsPowerPC.td --- a/llvm/include/llvm/IR/IntrinsicsPowerPC.td +++ b/llvm/include/llvm/IR/IntrinsicsPowerPC.td @@ -217,6 +217,10 @@ : Intrinsic<[llvm_float_ty], [llvm_float_ty, llvm_float_ty, llvm_float_ty, llvm_vararg_ty], [IntrNoMem]>; + def int_ppc_kill_canary + : Intrinsic<[], + [], + [IntrWriteMem, IntrHasSideEffects]>; } let TargetPrefix = "ppc" in { // All PPC intrinsics start with "llvm.ppc.". diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -11103,6 +11103,43 @@ } break; } + case Intrinsic::ppc_kill_canary: { + MachineFunction &MF = DAG.getMachineFunction(); + if (MF.getFunction().hasFnAttribute(Attribute::SafeStack)) { + break; + } + + MachineFrameInfo &MFI = MF.getFrameInfo(); + int SPI = MFI.getStackProtectorIndex(); // should return -1 + + PPCFunctionInfo *FuncInfo = MF.getInfo(); + EVT PtrVT = getPointerTy(MF.getDataLayout()); + SDValue FIN = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); // frame index + + unsigned int deadBird = 0x4C6C566D; // replaces canary word + + SDValue Store = DAG.getStore( // create store instr, stores (deadBird + 0) into addr (frame index + stack protector) + Op->getOperand(0), + DL, + DAG.getNode( // add deadBird, 0, return node result + ISD::ADD, + DL, + PtrVT, + DAG.getConstant(deadBird, DL, PtrVT), + DAG.getConstant(0, DL, PtrVT) + ), + DAG.getNode( // add frame index, stack protector index, return node result + ISD::ADD, + DL, + PtrVT, + FIN, + DAG.getConstant(SPI, DL, PtrVT) + ), + MachinePointerInfo() + ); + return Store; + break; + } default: break; }