Index: lib/Target/PowerPC/PPCISelLowering.h =================================================================== --- lib/Target/PowerPC/PPCISelLowering.h +++ lib/Target/PowerPC/PPCISelLowering.h @@ -672,6 +672,10 @@ unsigned getExceptionSelectorRegister(const Constant *PersonalityFn) const override; + /// Return nullptr if we want to manually lower the stack guard load. + /// Otherwise return a global address. + Value *getStackGuardAddr(Module &M) const override; + private: struct ReuseLoadInfo { SDValue Ptr; Index: lib/Target/PowerPC/PPCISelLowering.cpp =================================================================== --- lib/Target/PowerPC/PPCISelLowering.cpp +++ lib/Target/PowerPC/PPCISelLowering.cpp @@ -11578,3 +11578,10 @@ const TargetLibraryInfo *LibInfo) const { return PPC::createFastISel(FuncInfo, LibInfo); } + +Value *PPCTargetLowering::getStackGuardAddr(Module &M) const { + if (Subtarget.isTargetLinux()) { + return nullptr; + } + return TargetLowering::getStackGuardAddr(M); +} Index: lib/Target/PowerPC/PPCInstrInfo.h =================================================================== --- lib/Target/PowerPC/PPCInstrInfo.h +++ lib/Target/PowerPC/PPCInstrInfo.h @@ -272,6 +272,8 @@ ArrayRef> getSerializableBitmaskMachineOperandTargetFlags() const override; + + bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override; }; } Index: lib/Target/PowerPC/PPCInstrInfo.cpp =================================================================== --- lib/Target/PowerPC/PPCInstrInfo.cpp +++ lib/Target/PowerPC/PPCInstrInfo.cpp @@ -1846,3 +1846,17 @@ return makeArrayRef(TargetFlags); } +bool PPCInstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const { + switch (MI->getOpcode()) { + case TargetOpcode::LOAD_STACK_GUARD: { + const int64_t Offset = Subtarget.isPPC64() ? -0x7010 : -0x7008; + const unsigned Reg = Subtarget.isPPC64() ? PPC::X13 : PPC::R2; + MI->setDesc(get(PPC::LD)); + MachineInstrBuilder(*MI->getParent()->getParent(), MI) + .addImm(Offset) + .addReg(Reg); + return true; + } + } + return false; +} Index: lib/Target/PowerPC/PPCSubtarget.h =================================================================== --- lib/Target/PowerPC/PPCSubtarget.h +++ lib/Target/PowerPC/PPCSubtarget.h @@ -275,6 +275,7 @@ bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); } bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); } + bool isTargetLinux() const { return TargetTriple.isOSLinux(); } bool isDarwinABI() const { return isTargetMachO() || isDarwin(); } bool isSVR4ABI() const { return !isDarwinABI(); } Index: test/CodeGen/PowerPC/stack-protector.ll =================================================================== --- test/CodeGen/PowerPC/stack-protector.ll +++ test/CodeGen/PowerPC/stack-protector.ll @@ -1,6 +1,17 @@ -; RUN: llc -march=ppc32 -mtriple=ppc32-unknown-linux < %s | FileCheck %s -; CHECK: __stack_chk_guard -; CHECK: __stack_chk_fail +; RUN: llc -mtriple=powerpc-apple-darwin8 < %s | FileCheck -check-prefix=DARWIN32 %s +; RUN: llc -mtriple=powerpc64-apple-darwin < %s | FileCheck -check-prefix=DARWIN64 %s +; RUN: llc -mtriple=ppc32-unknown-linux < %s | FileCheck -check-prefix=LINUX32 %s +; RUN: llc -mtriple=powerpc64le-unknown-linux < %s | FileCheck -check-prefix=LINUX64 %s + +; DARWIN32: __stack_chk_guard +; DARWIN64: __stack_chk_guard +; LINUX32: ld {{[0-9]+}}, -28680(2) +; LINUX64: ld {{[0-9]+}}, -28688(13) + +; DARWIN32: __stack_chk_fail +; DARWIN64: __stack_chk_fail +; LINUX32: __stack_chk_fail +; LINUX64: __stack_chk_fail @"\01LC" = internal constant [11 x i8] c"buf == %s\0A\00" ; <[11 x i8]*> [#uses=1]