Skip to content

Commit

Permalink
[PS5] Trap after noreturn calls, with special case for stack-check-fail
Browse files Browse the repository at this point in the history
  • Loading branch information
pogo59 committed Jun 15, 2022
1 parent 16547f9 commit 654a835
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
7 changes: 3 additions & 4 deletions llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Expand Up @@ -3261,14 +3261,13 @@ bool IRTranslator::emitSPDescriptorFailure(StackProtectorDescriptor &SPD,
return false;
}

// On PS4, the "return address" must still be within the calling function,
// even if it's at the very end, so emit an explicit TRAP here.
// Passing 'true' for doesNotReturn above won't generate the trap for us.
// On PS4/PS5, the "return address" must still be within the calling
// function, even if it's at the very end, so emit an explicit TRAP here.
// WebAssembly needs an unreachable instruction after a non-returning call,
// because the function return type can be different from __stack_chk_fail's
// return type (void).
const TargetMachine &TM = MF->getTarget();
if (TM.getTargetTriple().isPS4() || TM.getTargetTriple().isWasm()) {
if (TM.getTargetTriple().isPS() || TM.getTargetTriple().isWasm()) {
LLVM_DEBUG(dbgs() << "Unhandled trap emission for stack protector fail\n");
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Expand Up @@ -2747,10 +2747,10 @@ SelectionDAGBuilder::visitSPDescriptorFailure(StackProtectorDescriptor &SPD) {
SDValue Chain =
TLI.makeLibCall(DAG, RTLIB::STACKPROTECTOR_CHECK_FAIL, MVT::isVoid,
None, CallOptions, getCurSDLoc()).second;
// On PS4, the "return address" must still be within the calling function,
// even if it's at the very end, so emit an explicit TRAP here.
// On PS4/PS5, the "return address" must still be within the calling
// function, even if it's at the very end, so emit an explicit TRAP here.
// Passing 'true' for doesNotReturn above won't generate the trap for us.
if (TM.getTargetTriple().isPS4())
if (TM.getTargetTriple().isPS())
Chain = DAG.getNode(ISD::TRAP, getCurSDLoc(), MVT::Other, Chain);
// WebAssembly needs an unreachable instruction after a non-returning call,
// because the function return type can be different from __stack_chk_fail's
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/X86/X86TargetMachine.cpp
Expand Up @@ -222,9 +222,9 @@ X86TargetMachine::X86TargetMachine(const Target &T, const Triple &TT,
getEffectiveX86CodeModel(CM, JIT, TT.getArch() == Triple::x86_64),
OL),
TLOF(createTLOF(getTargetTriple())), IsJIT(JIT) {
// On PS4, the "return address" of a 'noreturn' call must still be within
// On PS4/PS5, the "return address" of a 'noreturn' call must still be within
// the calling function, and TrapUnreachable is an easy way to get that.
if (TT.isPS4() || TT.isOSBinFormatMachO()) {
if (TT.isPS() || TT.isOSBinFormatMachO()) {
this->Options.TrapUnreachable = true;
this->Options.NoTrapAfterNoreturn = TT.isOSBinFormatMachO();
}
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/X86/ps4-noreturn.ll
@@ -1,4 +1,5 @@
; RUN: llc < %s -mtriple=x86_64-scei-ps4 | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-sie-ps5 | FileCheck %s

declare i32 @personality(...)

Expand Down
4 changes: 4 additions & 0 deletions llvm/test/CodeGen/X86/ps4-ssp-nop.ll
@@ -1,9 +1,13 @@
; Verify that a ud2 is generated after the call to __stack_chk_fail.

; RUN: llc < %s -mtriple=x86_64-scei-ps4 -enable-selectiondag-sp=false -O0 -o - | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-sie-ps5 -enable-selectiondag-sp=false -O0 -o - | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-scei-ps4 -enable-selectiondag-sp=false -O2 -o - | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-sie-ps5 -enable-selectiondag-sp=false -O2 -o - | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-scei-ps4 -enable-selectiondag-sp=true -O0 -o - | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-sie-ps5 -enable-selectiondag-sp=true -O0 -o - | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-scei-ps4 -enable-selectiondag-sp=true -O2 -o - | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-sie-ps5 -enable-selectiondag-sp=true -O2 -o - | FileCheck %s


; CHECK: check_input:
Expand Down

0 comments on commit 654a835

Please sign in to comment.