summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Robinson <paul.robinson@sony.com>2019-03-06 19:57:43 +0000
committerPaul Robinson <paul.robinson@sony.com>2019-03-06 19:57:43 +0000
commit05efe0fdc472e1f57e36b7f42476946c59c7128b (patch)
tree1fbea154054205ca47068afd41161285222aee0c
parent05c0afe842cfd54eca4aa870c345bd53e8ce20ce (diff)
downloadbcm5719-llvm-05efe0fdc472e1f57e36b7f42476946c59c7128b.tar.gz
bcm5719-llvm-05efe0fdc472e1f57e36b7f42476946c59c7128b.zip
[PS4] Emit a trap after a stack-protector fail call.
llvm-svn: 355542
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp6
-rw-r--r--llvm/test/CodeGen/X86/ps4-ssp-nop.ll39
2 files changed, 45 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 33921a2c56d..31768b2f9b2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -2537,6 +2537,12 @@ SelectionDAGBuilder::visitSPDescriptorFailure(StackProtectorDescriptor &SPD) {
SDValue Chain =
TLI.makeLibCall(DAG, RTLIB::STACKPROTECTOR_CHECK_FAIL, MVT::isVoid,
None, false, getCurSDLoc(), false, false).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.
+ // Passing 'true' for doesNotReturn above won't generate the trap for us.
+ if (TM.getTargetTriple().isPS4CPU())
+ Chain = DAG.getNode(ISD::TRAP, getCurSDLoc(), MVT::Other, Chain);
+
DAG.setRoot(Chain);
}
diff --git a/llvm/test/CodeGen/X86/ps4-ssp-nop.ll b/llvm/test/CodeGen/X86/ps4-ssp-nop.ll
new file mode 100644
index 00000000000..9fefeca92e5
--- /dev/null
+++ b/llvm/test/CodeGen/X86/ps4-ssp-nop.ll
@@ -0,0 +1,39 @@
+; 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-scei-ps4 -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-scei-ps4 -enable-selectiondag-sp=true -O2 -o - | FileCheck %s
+
+
+; CHECK: check_input:
+; CHECK: callq __stack_chk_fail
+; CHECK-NEXT: ud2
+; CHECK: .size check_input
+; CHECK-NEXT: .cfi_endproc
+
+@.str = private unnamed_addr constant [37 x i8] c"????????????????????????????????????\00", align 1
+
+define signext i8 @check_input(i8* %input) nounwind uwtable ssp {
+entry:
+ %input.addr = alloca i8*, align 8
+ %buf = alloca [16 x i8], align 16
+ store i8* %input, i8** %input.addr, align 8
+ %arraydecay = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i32 0, i32 0
+ %0 = load i8*, i8** %input.addr, align 8
+ %call = call i8* @strcpy(i8* %arraydecay, i8* %0) nounwind
+ %arrayidx = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i32 0, i64 0
+ %1 = load i8, i8* %arrayidx, align 1
+ ret i8 %1
+}
+
+declare i8* @strcpy(i8*, i8*) nounwind
+
+define i32 @main() nounwind uwtable ssp {
+entry:
+ %retval = alloca i32, align 4
+ store i32 0, i32* %retval
+ %call = call signext i8 @check_input(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i32 0, i32 0))
+ %conv = sext i8 %call to i32
+ ret i32 %conv
+}
OpenPOWER on IntegriCloud