Skip to content

Commit 4ab6eee

Browse files
jroelofsdtellenbach
andcommitted
fixes from David to make it actually NFC
Co-Authored-By: David Tellenbach <[email protected]>
1 parent 6f8a36e commit 4ab6eee

File tree

9 files changed

+34
-39
lines changed

9 files changed

+34
-39
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,8 @@ void AArch64FrameLowering::resetCFIToInitialState(
723723
CFIBuilder.buildDefCFA(AArch64::SP, 0);
724724

725725
// Flip the RA sign state.
726-
if (MFI.shouldSignReturnAddress(MF))
726+
if (MFI.shouldSignReturnAddress(MF) &&
727+
!MF.getTarget().getTargetTriple().isOSDarwin())
727728
MFI.branchProtectionPAuthLR() ? CFIBuilder.buildNegateRAStateWithPC()
728729
: CFIBuilder.buildNegateRAState();
729730

@@ -984,7 +985,8 @@ bool AArch64FrameLowering::shouldSignReturnAddressEverywhere(
984985
if (MF.getTarget().getMCAsmInfo()->usesWindowsCFI())
985986
return false;
986987
const AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
987-
bool SignReturnAddressAll = AFI->shouldSignReturnAddress(/*SpillsLR=*/false);
988+
bool SignReturnAddressAll =
989+
AFI->shouldSignReturnAddress(MF, /*SpillsLR=*/false);
988990
return SignReturnAddressAll;
989991
}
990992

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9555,8 +9555,10 @@ outliningCandidatesSigningScopeConsensus(const outliner::Candidate &a,
95559555
const auto &MFIa = a.getMF()->getInfo<AArch64FunctionInfo>();
95569556
const auto &MFIb = b.getMF()->getInfo<AArch64FunctionInfo>();
95579557

9558-
return MFIa->shouldSignReturnAddress(false) == MFIb->shouldSignReturnAddress(false) &&
9559-
MFIa->shouldSignReturnAddress(true) == MFIb->shouldSignReturnAddress(true);
9558+
return MFIa->shouldSignReturnAddress(*a.getMF(), false) ==
9559+
MFIb->shouldSignReturnAddress(*b.getMF(), false) &&
9560+
MFIa->shouldSignReturnAddress(*a.getMF(), true) ==
9561+
MFIb->shouldSignReturnAddress(*b.getMF(), true);
95609562
}
95619563

95629564
static bool
@@ -9626,10 +9628,8 @@ AArch64InstrInfo::getOutliningCandidateInfo(
96269628
// Performing a tail call may require extra checks when PAuth is enabled.
96279629
// If PAuth is disabled, set it to zero for uniformity.
96289630
unsigned NumBytesToCheckLRInTCEpilogue = 0;
9629-
if (RepeatedSequenceLocs[0]
9630-
.getMF()
9631-
->getInfo<AArch64FunctionInfo>()
9632-
->shouldSignReturnAddress(true)) {
9631+
const MachineFunction &MF = *RepeatedSequenceLocs[0].getMF();
9632+
if (MF.getInfo<AArch64FunctionInfo>()->shouldSignReturnAddress(MF, true)) {
96339633
// One PAC and one AUT instructions
96349634
NumBytesToCreateFrame += 8;
96359635

@@ -10433,7 +10433,7 @@ void AArch64InstrInfo::buildOutlinedFrame(
1043310433
Et = MBB.insert(Et, LDRXpost);
1043410434
}
1043510435

10436-
bool ShouldSignReturnAddr = FI->shouldSignReturnAddress(!IsLeafFunction);
10436+
bool ShouldSignReturnAddr = FI->shouldSignReturnAddress(MF, !IsLeafFunction);
1043710437

1043810438
// If this is a tail call outlined function, then there's already a return.
1043910439
if (OF.FrameConstructionID == MachineOutlinerTailCall ||

llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,18 @@ MachineFunctionInfo *AArch64FunctionInfo::clone(
172172
return DestMF.cloneInfo<AArch64FunctionInfo>(*this);
173173
}
174174

175-
bool AArch64FunctionInfo::shouldSignReturnAddress(bool SpillsLR) const {
175+
static bool shouldAuthenticateLR(const MachineFunction &MF) {
176+
// Return address authentication can be enabled at the function level, using
177+
// the "ptrauth-returns" attribute.
178+
const AArch64Subtarget &Subtarget = MF.getSubtarget<AArch64Subtarget>();
179+
return Subtarget.isTargetMachO() &&
180+
MF.getFunction().hasFnAttribute("ptrauth-returns");
181+
}
182+
183+
bool AArch64FunctionInfo::shouldSignReturnAddress(const MachineFunction &MF,
184+
bool SpillsLR) const {
185+
if (SpillsLR && shouldAuthenticateLR(MF))
186+
return true;
176187
if (!SignReturnAddress)
177188
return false;
178189
if (SignReturnAddressAll)
@@ -188,7 +199,7 @@ static bool isLRSpilled(const MachineFunction &MF) {
188199

189200
bool AArch64FunctionInfo::shouldSignReturnAddress(
190201
const MachineFunction &MF) const {
191-
return shouldSignReturnAddress(isLRSpilled(MF));
202+
return shouldSignReturnAddress(MF, isLRSpilled(MF));
192203
}
193204

194205
bool AArch64FunctionInfo::needsShadowCallStackPrologueEpilogue(

llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
596596
}
597597

598598
bool shouldSignReturnAddress(const MachineFunction &MF) const;
599-
bool shouldSignReturnAddress(bool SpillsLR) const;
599+
bool shouldSignReturnAddress(const MachineFunction &MF, bool SpillsLR) const;
600600

601601
bool needsShadowCallStackPrologueEpilogue(MachineFunction &MF) const;
602602

llvm/lib/Target/AArch64/AArch64PointerAuth.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
#include "AArch64Subtarget.h"
1515
#include "llvm/CodeGen/CFIInstBuilder.h"
1616
#include "llvm/CodeGen/MachineBasicBlock.h"
17+
#include "llvm/CodeGen/MachineFrameInfo.h"
1718
#include "llvm/CodeGen/MachineInstrBuilder.h"
1819
#include "llvm/CodeGen/MachineModuleInfo.h"
20+
#include "llvm/IR/CallingConv.h"
1921

2022
using namespace llvm;
2123
using namespace llvm::AArch64PAuth;
@@ -96,6 +98,9 @@ static void emitPACCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
9698
if (!EmitCFI)
9799
return;
98100

101+
if (MBB.getParent()->getTarget().getTargetTriple().isOSDarwin())
102+
return;
103+
99104
auto &MF = *MBB.getParent();
100105
auto &MFnI = *MF.getInfo<AArch64FunctionInfo>();
101106

@@ -116,7 +121,7 @@ void AArch64PointerAuth::signLR(MachineFunction &MF,
116121
// Debug location must be unknown, see AArch64FrameLowering::emitPrologue.
117122
DebugLoc DL;
118123

119-
if (UseBKey) {
124+
if (UseBKey && !MF.getTarget().getTargetTriple().isOSDarwin()) {
120125
BuildMI(MBB, MBBI, DL, TII->get(AArch64::EMITBKEY))
121126
.setMIFlag(MachineInstr::FrameSetup);
122127
}
@@ -133,17 +138,15 @@ void AArch64PointerAuth::signLR(MachineFunction &MF,
133138
if (MFnI.branchProtectionPAuthLR() && Subtarget->hasPAuthLR()) {
134139
emitPACCFI(MBB, MBBI, MachineInstr::FrameSetup, EmitCFI);
135140
BuildMI(MBB, MBBI, DL,
136-
TII->get(MFnI.shouldSignWithBKey() ? AArch64::PACIBSPPC
137-
: AArch64::PACIASPPC))
141+
TII->get(UseBKey ? AArch64::PACIBSPPC : AArch64::PACIASPPC))
138142
.setMIFlag(MachineInstr::FrameSetup)
139143
->setPreInstrSymbol(MF, MFnI.getSigningInstrLabel());
140144
} else {
141145
BuildPACM(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameSetup);
142146
if (MFnI.branchProtectionPAuthLR())
143147
emitPACCFI(MBB, MBBI, MachineInstr::FrameSetup, EmitCFI);
144148
BuildMI(MBB, MBBI, DL,
145-
TII->get(MFnI.shouldSignWithBKey() ? AArch64::PACIBSP
146-
: AArch64::PACIASP))
149+
TII->get(UseBKey ? AArch64::PACIBSP : AArch64::PACIASP))
147150
.setMIFlag(MachineInstr::FrameSetup)
148151
->setPreInstrSymbol(MF, MFnI.getSigningInstrLabel());
149152
if (!MFnI.branchProtectionPAuthLR())

llvm/lib/Target/AArch64/AArch64PrologueEpilogue.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,7 @@ void AArch64EpilogueEmitter::finalizeEpilogue() const {
18431843
}
18441844
if (EmitCFI)
18451845
emitCalleeSavedGPRRestores(MBB.getFirstTerminator());
1846+
18461847
if (AFI->shouldSignReturnAddress(MF)) {
18471848
// If pac-ret+leaf is in effect, PAUTH_EPILOGUE pseudo instructions
18481849
// are inserted by emitPacRetPlusLeafHardening().

llvm/test/CodeGen/AArch64/ptrauth-invoke-wrapper-globals.ll

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
; CHECK-NEXT: .cfi_personality 155, ___gxx_personality_v0
88
; CHECK-NEXT: .cfi_lsda 16, [[EXCEPT:Lexception[0-9]+]]
99
; CHECK-NEXT: ; %bb.0:
10-
; CHECK-NEXT: .cfi_b_key_frame
1110
; CHECK-NEXT: pacibsp
12-
; CHECK-NEXT: .cfi_negate_ra_state
1311
; CHECK-NEXT: stp x20, x19, [sp, #-32]!
1412
; CHECK-NEXT: stp x29, x30, [sp, #16]
1513
; CHECK-NEXT: .cfi_def_cfa_offset 32
@@ -59,9 +57,7 @@ continuebb:
5957
; CHECK-NEXT: .cfi_personality 155, ___gxx_personality_v0
6058
; CHECK-NEXT: .cfi_lsda 16, [[EXCEPT:Lexception[0-9]+]]
6159
; CHECK-NEXT: ; %bb.0:
62-
; CHECK-NEXT: .cfi_b_key_frame
6360
; CHECK-NEXT: pacibsp
64-
; CHECK-NEXT: .cfi_negate_ra_state
6561
; CHECK-NEXT: stp x20, x19, [sp, #-32]!
6662
; CHECK-NEXT: stp x29, x30, [sp, #16]
6763
; CHECK-NEXT: .cfi_def_cfa_offset 32
@@ -116,9 +112,7 @@ continuebb:
116112
; CHECK-NEXT: .cfi_personality 155, ___gxx_personality_v0
117113
; CHECK-NEXT: .cfi_lsda 16, [[EXCEPT:Lexception[0-9]+]]
118114
; CHECK-NEXT: ; %bb.0:
119-
; CHECK-NEXT: .cfi_b_key_frame
120115
; CHECK-NEXT: pacibsp
121-
; CHECK-NEXT: .cfi_negate_ra_state
122116
; CHECK-NEXT: stp x20, x19, [sp, #-32]!
123117
; CHECK-NEXT: stp x29, x30, [sp, #16]
124118
; CHECK-NEXT: .cfi_def_cfa_offset 32

llvm/test/CodeGen/AArch64/swiftcorocc-call.ll

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ declare i64 @g(ptr, ptr)
1010
define i64 @test_call_to_swiftcoro() #0 {
1111
; CHECK-LABEL: test_call_to_swiftcoro:
1212
; CHECK: ; %bb.0:
13-
; CHECK-NEXT: .cfi_b_key_frame
1413
; CHECK-NEXT: pacibsp
15-
; CHECK-NEXT: .cfi_negate_ra_state
1614
; CHECK-NEXT: stp x26, x25, [sp, #-32]! ; 16-byte Folded Spill
1715
; CHECK-NEXT: stp x29, x30, [sp, #16] ; 16-byte Folded Spill
1816
; CHECK-NEXT: add x29, sp, #16
@@ -43,9 +41,7 @@ define i64 @test_call_to_swiftcoro() #0 {
4341
define i64 @test_call_to_normal() #0 {
4442
; CHECK-LABEL: test_call_to_normal:
4543
; CHECK: ; %bb.0:
46-
; CHECK-NEXT: .cfi_b_key_frame
4744
; CHECK-NEXT: pacibsp
48-
; CHECK-NEXT: .cfi_negate_ra_state
4945
; CHECK-NEXT: sub sp, sp, #48
5046
; CHECK-NEXT: stp x26, x25, [sp, #16] ; 16-byte Folded Spill
5147
; CHECK-NEXT: stp x29, x30, [sp, #32] ; 16-byte Folded Spill
@@ -75,9 +71,7 @@ define i64 @test_call_to_normal() #0 {
7571
define swiftcorocc i64 @test_call() #0 {
7672
; CHECK-LABEL: test_call:
7773
; CHECK: ; %bb.0:
78-
; CHECK-NEXT: .cfi_b_key_frame
7974
; CHECK-NEXT: pacibsp
80-
; CHECK-NEXT: .cfi_negate_ra_state
8175
; CHECK-NEXT: sub sp, sp, #48
8276
; CHECK-NEXT: stp x26, x25, [sp, #16] ; 16-byte Folded Spill
8377
; CHECK-NEXT: stp x29, x30, [sp, #32] ; 16-byte Folded Spill
@@ -105,9 +99,7 @@ define swiftcorocc i64 @test_call() #0 {
10599
define i64 @test_call_normal() #0 {
106100
; CHECK-LABEL: test_call_normal:
107101
; CHECK: ; %bb.0:
108-
; CHECK-NEXT: .cfi_b_key_frame
109102
; CHECK-NEXT: pacibsp
110-
; CHECK-NEXT: .cfi_negate_ra_state
111103
; CHECK-NEXT: sub sp, sp, #48
112104
; CHECK-NEXT: stp x26, x25, [sp, #16] ; 16-byte Folded Spill
113105
; CHECK-NEXT: stp x29, x30, [sp, #32] ; 16-byte Folded Spill

llvm/test/CodeGen/AArch64/swiftcorocc-ret-popless.ll

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ declare i64 @g(ptr, ptr)
77
define swiftcorocc i64 @test_intrin_basic() #0 {
88
; CHECK-LABEL: test_intrin_basic:
99
; CHECK: ; %bb.0:
10-
; CHECK-NEXT: .cfi_b_key_frame
1110
; CHECK-NEXT: pacibsp
12-
; CHECK-NEXT: .cfi_negate_ra_state
1311
; CHECK-NEXT: stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
1412
; CHECK-NEXT: mov x29, sp
1513
; CHECK-NEXT: .cfi_def_cfa w29, 16
@@ -24,9 +22,7 @@ define swiftcorocc i64 @test_intrin_basic() #0 {
2422
define swiftcorocc i64 @test_intrin() #0 {
2523
; CHECK-LABEL: test_intrin:
2624
; CHECK: ; %bb.0:
27-
; CHECK-NEXT: .cfi_b_key_frame
2825
; CHECK-NEXT: pacibsp
29-
; CHECK-NEXT: .cfi_negate_ra_state
3026
; CHECK-NEXT: sub sp, sp, #48
3127
; CHECK-NEXT: stp x26, x25, [sp, #16] ; 16-byte Folded Spill
3228
; CHECK-NEXT: stp x29, x30, [sp, #32] ; 16-byte Folded Spill
@@ -67,9 +63,7 @@ else:
6763
define swiftcorocc i64 @test_vla(i32 %n) #0 {
6864
; SDISEL-LABEL: test_vla:
6965
; SDISEL: ; %bb.0:
70-
; SDISEL-NEXT: .cfi_b_key_frame
7166
; SDISEL-NEXT: pacibsp
72-
; SDISEL-NEXT: .cfi_negate_ra_state
7367
; SDISEL-NEXT: stp x26, x25, [sp, #-32]! ; 16-byte Folded Spill
7468
; SDISEL-NEXT: stp x29, x30, [sp, #16] ; 16-byte Folded Spill
7569
; SDISEL-NEXT: add x29, sp, #16
@@ -104,9 +98,7 @@ define swiftcorocc i64 @test_vla(i32 %n) #0 {
10498
;
10599
; GISEL-LABEL: test_vla:
106100
; GISEL: ; %bb.0:
107-
; GISEL-NEXT: .cfi_b_key_frame
108101
; GISEL-NEXT: pacibsp
109-
; GISEL-NEXT: .cfi_negate_ra_state
110102
; GISEL-NEXT: stp x26, x25, [sp, #-32]! ; 16-byte Folded Spill
111103
; GISEL-NEXT: stp x29, x30, [sp, #16] ; 16-byte Folded Spill
112104
; GISEL-NEXT: add x29, sp, #16

0 commit comments

Comments
 (0)