-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[aarch64] XOR the frame pointer with the stack cookie when protecting the stack #161114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
9c6d4c7
da07652
00dddda
5c230ae
12ded1e
23fbbbb
c61707a
2b02cb2
823bd2f
9f95a65
6606db9
c27d13d
6536678
4493e86
c5b61ae
2763964
414995a
65acb8c
df09547
2e737b9
b9ae3ff
bb1bf30
33de52f
b41ab42
36782f4
5076be4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2311,6 +2311,15 @@ bool AArch64InstrInfo::expandPostRAPseudo(MachineInstr &MI) const { | |
| .addMemOperand(*MI.memoperands_begin()); | ||
| } | ||
| } | ||
| // To match MSVC | ||
| if (Subtarget.getTargetTriple().isOSMSVCRT() && | ||
| !Subtarget.getTargetLowering() | ||
efriedma-quic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ->getTargetMachine() | ||
| .Options.EnableGlobalISel) { | ||
| BuildMI(MBB, MI, DL, get(AArch64::SUBXrr), Reg) | ||
| .addReg(AArch64::SP) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this actually produce the correct instruction? I'm not sure SP is in the right register class; I suspect you end up subtracting from zero. The wouldn't show up in assembly output, but it would show up in disassembly. (SUBXrx64 can refer to SP this way, though.)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reply here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed SUBXrr to SUBXrx64. Could you please check it? |
||
| .addReg(Reg, RegState::Kill); | ||
| } | ||
|
|
||
| MBB.erase(MI); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: llc < %s -mtriple=aarch64-w64-mingw32 | FileCheck %s --check-prefixes=CHECK,CHECK-SD | ||
| ; RUN: llc < %s -mtriple=aarch64-w64-mingw32 -global-isel | FileCheck %s --check-prefixes=CHECK,CHECK-GI | ||
| ; RUN: llc < %s -mtriple=aarch64-w64-mingw32 -global-isel | FileCheck %s --check-prefixes=CHECK-GI | ||
|
||
|
|
||
| @var = external local_unnamed_addr global i32, align 4 | ||
| @dsolocalvar = external dso_local local_unnamed_addr global i32, align 4 | ||
|
|
@@ -89,12 +89,14 @@ define dso_local void @sspFunc() #0 { | |
| ; CHECK-NEXT: add x0, sp, #7 | ||
| ; CHECK-NEXT: ldr x8, [x8, :lo12:.refptr.__stack_chk_guard] | ||
| ; CHECK-NEXT: ldr x8, [x8] | ||
| ; CHECK-NEXT: sub x8, sp, x8 | ||
| ; CHECK-NEXT: str x8, [sp, #8] | ||
| ; CHECK-NEXT: bl ptrUser | ||
| ; CHECK-NEXT: adrp x8, .refptr.__stack_chk_guard | ||
| ; CHECK-NEXT: ldr x8, [x8, :lo12:.refptr.__stack_chk_guard] | ||
| ; CHECK-NEXT: ldr x9, [sp, #8] | ||
| ; CHECK-NEXT: ldr x8, [x8] | ||
| ; CHECK-NEXT: sub x8, sp, x8 | ||
| ; CHECK-NEXT: cmp x8, x9 | ||
| ; CHECK-NEXT: b.ne .LBB6_2 | ||
| ; CHECK-NEXT: // %bb.1: // %entry | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,14 +31,20 @@ declare void @_Z7CapturePi(ptr) | |
|
|
||
| ; WINDOWS-AARCH64: adrp x8, __security_cookie | ||
| ; WINDOWS-AARCH64: ldr x8, [x8, :lo12:__security_cookie] | ||
| ; WINDOWS-AARCH64: sub x8, sp, x8 | ||
| ; WINDOWS-AARCH64: str x8, [sp, #8] | ||
| ; WINDOWS-AARCH64: bl _Z7CapturePi | ||
| ; WINDOWS-AARCH64: ldr x0, [sp, #8] | ||
| ; WINDOWS-AARCH64: ldr x8, [sp, #8] | ||
| ; WINDOWS-AARCH64: mov x9, sp | ||
| ; WINDOWS-AARCH64: add x0, x8, x9 | ||
|
||
| ; WINDOWS-AARCH64: bl __security_check_cookie | ||
|
|
||
| ; WINDOWS-ARM64EC: adrp x8, __security_cookie | ||
| ; WINDOWS-ARM64EC: ldr x8, [x8, :lo12:__security_cookie] | ||
| ; WINDOWS-ARM64EC: sub x8, sp, x8 | ||
| ; WINDOWS-ARM64EC: str x8, [sp, #8] | ||
| ; WINDOWS-ARM64EC: bl "#_Z7CapturePi" | ||
| ; WINDOWS-ARM64EC: ldr x0, [sp, #8] | ||
| ; WINDOWS-ARM64EC: ldr x8, [sp, #8] | ||
| ; WINDOWS-ARM64EC: mov x9, sp | ||
| ; WINDOWS-ARM64EC: add x0, x8, x9 | ||
| ; WINDOWS-ARM64EC: bl "#__security_check_cookie_arm64ec" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe extend this comment a little to explain what exactly we're matching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please review the added comment?