Skip to content

Commit 84fdd9d

Browse files
committed
[X86] Fix prolog/epilog mismatch for stack protectors on win32-macho.
The xor'ing behaviour is only used for msvc/crt environments, when we're targeting macho the guard load code doesn't know about the xor in the epilog. Disable xor'ing when targeting win32-macho to be consistent. Differential Revision: https://reviews.llvm.org/D71095
1 parent f3efd69 commit 84fdd9d

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ bool X86TargetLowering::useLoadStackGuardNode() const {
19861986

19871987
bool X86TargetLowering::useStackGuardXorFP() const {
19881988
// Currently only MSVC CRTs XOR the frame pointer into the stack guard value.
1989-
return Subtarget.getTargetTriple().isOSMSVCRT();
1989+
return Subtarget.getTargetTriple().isOSMSVCRT() && !Subtarget.isTargetMachO();
19901990
}
19911991

19921992
SDValue X86TargetLowering::emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=x86_64-pc-windows-macho -O0 < %s -o - | FileCheck %s
3+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
4+
target triple = "x86_64-pc-windows-macho"
5+
6+
; This test checks that on Win32 MachO targets we don't xor the cookie with rbp before checking.
7+
8+
@.str = private unnamed_addr constant [15 x i8] c"Hello World!\0A \00", align 1
9+
define dso_local i32 @main(i32 %argc, i8** %argv, ...) #0 {
10+
; CHECK-LABEL: main:
11+
; CHECK: ## %bb.0: ## %entry
12+
; CHECK-NEXT: pushq %rbp
13+
; CHECK-NEXT: .cfi_def_cfa_offset 16
14+
; CHECK-NEXT: .cfi_offset %rbp, -16
15+
; CHECK-NEXT: movq %rsp, %rbp
16+
; CHECK-NEXT: .cfi_def_cfa_register %rbp
17+
; CHECK-NEXT: subq $336, %rsp ## imm = 0x150
18+
; CHECK-NEXT: movq ___security_cookie@{{.*}}(%rip), %rax
19+
; CHECK-NEXT: movq (%rax), %rax
20+
; CHECK-NEXT: movq %rax, -8(%rbp)
21+
; CHECK-NEXT: movl %ecx, -276(%rbp)
22+
; CHECK-NEXT: movq %rdx, -288(%rbp)
23+
; CHECK-NEXT: movslq -276(%rbp), %rax
24+
; CHECK-NEXT: movb $1, -272(%rbp,%rax)
25+
; CHECK-NEXT: leaq {{.*}}(%rip), %rcx
26+
; CHECK-NEXT: callq _printf
27+
; CHECK-NEXT: movq -8(%rbp), %rcx
28+
; CHECK-NEXT: movl %eax, {{[-0-9]+}}(%r{{[sb]}}p) ## 4-byte Spill
29+
; CHECK-NEXT: callq ___security_check_cookie
30+
; CHECK-NEXT: xorl %eax, %eax
31+
; CHECK-NEXT: addq $336, %rsp ## imm = 0x150
32+
; CHECK-NEXT: popq %rbp
33+
; CHECK-NEXT: retq
34+
entry:
35+
%argc.addr = alloca i32, align 4
36+
%argv.addr = alloca i8**, align 8
37+
%Buffer = alloca [256 x i8], align 16
38+
store i32 %argc, i32* %argc.addr, align 4
39+
store i8** %argv, i8*** %argv.addr, align 8
40+
%0 = load i32, i32* %argc.addr, align 4
41+
%idxprom = sext i32 %0 to i64
42+
%arrayidx = getelementptr inbounds [256 x i8], [256 x i8]* %Buffer, i64 0, i64 %idxprom
43+
store i8 1, i8* %arrayidx, align 1
44+
%call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
45+
ret i32 0
46+
}
47+
declare dso_local i32 @printf(i8*, ...) #1
48+
49+
attributes #0 = { sspstrong "frame-pointer"="all" "stack-protector-buffer-size"="8"}
50+
attributes #1 = { "frame-pointer"="all" "stack-protector-buffer-size"="8" }
51+
52+
!llvm.module.flags = !{!0, !1}
53+
!llvm.ident = !{!2}
54+
55+
!0 = !{i32 1, !"wchar_size", i32 4}
56+
!1 = !{i32 7, !"PIC Level", i32 2}
57+
!2 = !{!"clang version 10.0.0"}

0 commit comments

Comments
 (0)