@@ -170,8 +170,7 @@ class AArch64AsmPrinter : public AsmPrinter {
170170 Register ScratchReg,
171171 AArch64PACKey::ID Key,
172172 AArch64PAuth::AuthCheckMethod Method,
173- bool ShouldTrap,
174- const MCSymbol *OnFailure);
173+ const MCSymbol *OnFailure = nullptr );
175174
176175 // Check authenticated LR before tail calling.
177176 void emitPtrauthTailCallHardening (const MachineInstr *TC);
@@ -2004,14 +2003,19 @@ Register AArch64AsmPrinter::emitPtrauthDiscriminator(uint16_t Disc,
20042003 return ScratchReg;
20052004}
20062005
2007- // / Emits a code sequence to check an authenticated pointer value.
2006+ // / Emit a code sequence to check an authenticated pointer value.
20082007// /
2009- // / If OnFailure argument is passed, jump there on check failure instead
2010- // / of proceeding to the next instruction (only if ShouldTrap is false).
2008+ // / This function emits a sequence of instructions that checks if TestedReg was
2009+ // / authenticated successfully. On success, execution continues at the next
2010+ // / instruction after the sequence.
2011+ // /
2012+ // / The action performed on failure depends on the OnFailure argument:
2013+ // / * if OnFailure is not nullptr, control is transferred to that label after
2014+ // / clearing the PAC field
2015+ // / * otherwise, BRK instruction is emitted to generate an error
20112016void AArch64AsmPrinter::emitPtrauthCheckAuthenticatedValue (
20122017 Register TestedReg, Register ScratchReg, AArch64PACKey::ID Key,
2013- AArch64PAuth::AuthCheckMethod Method, bool ShouldTrap,
2014- const MCSymbol *OnFailure) {
2018+ AArch64PAuth::AuthCheckMethod Method, const MCSymbol *OnFailure) {
20152019 // Insert a sequence to check if authentication of TestedReg succeeded,
20162020 // such as:
20172021 //
@@ -2048,7 +2052,7 @@ void AArch64AsmPrinter::emitPtrauthCheckAuthenticatedValue(
20482052 .addReg (getWRegFromXReg (ScratchReg))
20492053 .addReg (TestedReg)
20502054 .addImm (0 ));
2051- assert (ShouldTrap && !OnFailure && " DummyLoad always traps on error" );
2055+ assert (!OnFailure && " DummyLoad always traps on error" );
20522056 return ;
20532057 }
20542058
@@ -2102,15 +2106,14 @@ void AArch64AsmPrinter::emitPtrauthCheckAuthenticatedValue(
21022106 llvm_unreachable (" Unsupported check method" );
21032107 }
21042108
2105- if (ShouldTrap) {
2106- assert (!OnFailure && " Cannot specify OnFailure with ShouldTrap" );
2109+ if (!OnFailure) {
21072110 // Trapping sequences do a 'brk'.
21082111 // brk #<0xc470 + aut key>
21092112 EmitToStreamer (MCInstBuilder (AArch64::BRK).addImm (0xc470 | Key));
21102113 } else {
21112114 // Non-trapping checked sequences return the stripped result in TestedReg,
2112- // skipping over success-only code (such as re-signing the pointer) if
2113- // there is one .
2115+ // skipping over success-only code (such as re-signing the pointer) by
2116+ // jumping to OnFailure label .
21142117 // Note that this can introduce an authentication oracle (such as based on
21152118 // the high bits of the re-signed value).
21162119
@@ -2135,12 +2138,9 @@ void AArch64AsmPrinter::emitPtrauthCheckAuthenticatedValue(
21352138 MCInstBuilder (XPACOpc).addReg (TestedReg).addReg (TestedReg));
21362139 }
21372140
2138- if (OnFailure) {
2139- // b Lend
2140- EmitToStreamer (
2141- MCInstBuilder (AArch64::B)
2142- .addExpr (MCSymbolRefExpr::create (OnFailure, OutContext)));
2143- }
2141+ // b Lend
2142+ const auto *OnFailureExpr = MCSymbolRefExpr::create (OnFailure, OutContext);
2143+ EmitToStreamer (MCInstBuilder (AArch64::B).addExpr (OnFailureExpr));
21442144 }
21452145
21462146 // If the auth check succeeds, we can continue.
@@ -2167,9 +2167,8 @@ void AArch64AsmPrinter::emitPtrauthTailCallHardening(const MachineInstr *TC) {
21672167 " Neither x16 nor x17 is available as a scratch register" );
21682168 AArch64PACKey::ID Key =
21692169 AArch64FI->shouldSignWithBKey () ? AArch64PACKey::IB : AArch64PACKey::IA;
2170- emitPtrauthCheckAuthenticatedValue (
2171- AArch64::LR, ScratchReg, Key, LRCheckMethod,
2172- /* ShouldTrap=*/ true , /* OnFailure=*/ nullptr );
2170+ emitPtrauthCheckAuthenticatedValue (AArch64::LR, ScratchReg, Key,
2171+ LRCheckMethod);
21732172}
21742173
21752174void AArch64AsmPrinter::emitPtrauthAuthResign (
@@ -2243,9 +2242,8 @@ void AArch64AsmPrinter::emitPtrauthAuthResign(
22432242 if (IsAUTPAC && !ShouldTrap)
22442243 EndSym = createTempSymbol (" resign_end_" );
22452244
2246- emitPtrauthCheckAuthenticatedValue (AUTVal, Scratch, AUTKey,
2247- AArch64PAuth::AuthCheckMethod::XPAC,
2248- ShouldTrap, EndSym);
2245+ emitPtrauthCheckAuthenticatedValue (
2246+ AUTVal, Scratch, AUTKey, AArch64PAuth::AuthCheckMethod::XPAC, EndSym);
22492247 }
22502248
22512249 // We already emitted unchecked and checked-but-non-trapping AUTs.
@@ -2630,9 +2628,7 @@ void AArch64AsmPrinter::LowerMOVaddrPAC(const MachineInstr &MI) {
26302628 : AArch64PACKey::DA);
26312629
26322630 emitPtrauthCheckAuthenticatedValue (AArch64::X16, AArch64::X17, AuthKey,
2633- AArch64PAuth::AuthCheckMethod::XPAC,
2634- /* ShouldTrap=*/ true ,
2635- /* OnFailure=*/ nullptr );
2631+ AArch64PAuth::AuthCheckMethod::XPAC);
26362632 }
26372633 } else {
26382634 EmitToStreamer (MCInstBuilder (AArch64::LDRXui)
@@ -2765,9 +2761,7 @@ void AArch64AsmPrinter::LowerLOADgotAUTH(const MachineInstr &MI) {
27652761 (AuthOpcode == AArch64::AUTIA ? AArch64PACKey::IA : AArch64PACKey::DA);
27662762
27672763 emitPtrauthCheckAuthenticatedValue (AuthResultReg, AArch64::X17, AuthKey,
2768- AArch64PAuth::AuthCheckMethod::XPAC,
2769- /* ShouldTrap=*/ true ,
2770- /* OnFailure=*/ nullptr );
2764+ AArch64PAuth::AuthCheckMethod::XPAC);
27712765
27722766 emitMovXReg (DstReg, AuthResultReg);
27732767 }
0 commit comments