@@ -520,14 +520,6 @@ void AArch64PrologueEmitter::verifyPrologueClobbers() const {
520520}
521521#endif
522522
523- static bool shouldAuthenticateLR (const MachineFunction &MF) {
524- // Return address authentication can be enabled at the function level, using
525- // the "ptrauth-returns" attribute.
526- const AArch64Subtarget &Subtarget = MF.getSubtarget <AArch64Subtarget>();
527- return Subtarget.isTargetMachO () &&
528- MF.getFunction ().hasFnAttribute (" ptrauth-returns" );
529- }
530-
531523void AArch64PrologueEmitter::determineLocalsStackSize (
532524 uint64_t StackSize, uint64_t PrologueSaveSize) {
533525 AFI->setLocalStackSize (StackSize - PrologueSaveSize);
@@ -709,18 +701,6 @@ void AArch64PrologueEmitter::emitPrologue() {
709701 BuildMI (MBB, PrologueBeginI, DL, TII->get (AArch64::EMITMTETAGGED))
710702 .setMIFlag (MachineInstr::FrameSetup);
711703
712- // If we're saving LR, sign it first.
713- if (shouldAuthenticateLR (MF)) {
714- if (LLVM_UNLIKELY (!Subtarget.hasPAuth ()))
715- report_fatal_error (" arm64e LR authentication requires ptrauth" );
716- for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo ()) {
717- if (Info.getReg () != AArch64::LR)
718- continue ;
719- BuildMI (MBB, PrologueBeginI, DL, TII->get (AArch64::PACIBSP))
720- .setMIFlags (MachineInstr::FrameSetup);
721- }
722- }
723-
724704 // We signal the presence of a Swift extended frame to external tools by
725705 // storing FP with 0b0001 in bits 63:60. In normal userland operation a simple
726706 // ORR is sufficient, it is assumed a Swift kernel would initialize the TBI
@@ -1407,66 +1387,6 @@ void AArch64EpilogueEmitter::emitEpilogue() {
14071387 if (MF.getFunction ().getCallingConv () == CallingConv::GHC)
14081388 return ;
14091389
1410- // If we're restoring LR, authenticate it before returning.
1411- // Use scope_exit to ensure we do that last on all return paths.
1412- auto InsertAuthLROnExit = make_scope_exit ([&]() {
1413- if (shouldAuthenticateLR (MF)) {
1414- if (LLVM_UNLIKELY (!Subtarget.hasPAuth ()))
1415- report_fatal_error (" arm64e LR authentication requires ptrauth" );
1416- for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo ()) {
1417- if (Info.getReg () != AArch64::LR)
1418- continue ;
1419- MachineBasicBlock::iterator TI = MBB.getFirstTerminator ();
1420-
1421- // When we're doing a popless ret (i.e., that doesn't restore SP), we
1422- // can't rely on the exit SP being the same as the entry, but they need
1423- // to match for the LR auth to succeed. Instead, derive the entry SP
1424- // from our FP (using a -16 static offset for the size of the frame
1425- // record itself), save that into X16, and use that as the discriminator
1426- // in an AUTIB.
1427- if (IsSwiftCoroPartialReturn) {
1428- const auto *TRI = Subtarget.getRegisterInfo ();
1429-
1430- MachineBasicBlock::iterator EpilogStartI = MBB.getFirstTerminator ();
1431- MachineBasicBlock::iterator Begin = MBB.begin ();
1432- while (EpilogStartI != Begin) {
1433- --EpilogStartI;
1434- if (!EpilogStartI->getFlag (MachineInstr::FrameDestroy)) {
1435- ++EpilogStartI;
1436- break ;
1437- }
1438- if (EpilogStartI->readsRegister (AArch64::X16, TRI) ||
1439- EpilogStartI->modifiesRegister (AArch64::X16, TRI))
1440- report_fatal_error (" unable to use x16 for popless ret LR auth" );
1441- }
1442-
1443- emitFrameOffset (MBB, EpilogStartI, DL, AArch64::X16, AArch64::FP,
1444- StackOffset::getFixed (16 ), TII,
1445- MachineInstr::FrameDestroy);
1446- BuildMI (MBB, TI, DL, TII->get (AArch64::AUTIB), AArch64::LR)
1447- .addUse (AArch64::LR)
1448- .addUse (AArch64::X16)
1449- .setMIFlag (MachineInstr::FrameDestroy);
1450- return ;
1451- }
1452-
1453- if (TI != MBB.end () && TI->getOpcode () == AArch64::RET_ReallyLR) {
1454- // If there is a terminator and it's a RET, we can fold AUTH into it.
1455- // Be careful to keep the implicitly returned registers.
1456- // By now, we don't need the ReallyLR pseudo, since it's only there
1457- // to make it possible for LR to be used for non-RET purposes, and
1458- // that happens in RA and PEI.
1459- BuildMI (MBB, TI, DL, TII->get (AArch64::RETAB)).copyImplicitOps (*TI);
1460- MBB.erase (TI);
1461- } else {
1462- // Otherwise, we could be in a shrink-wrapped or tail-calling block.
1463- BuildMI (MBB, TI, DL, TII->get (AArch64::AUTIBSP));
1464- }
1465- }
1466- }
1467- });
1468-
1469-
14701390 // How much of the stack used by incoming arguments this function is expected
14711391 // to restore in this particular epilogue.
14721392 int64_t ArgumentStackToRestore = AFL.getArgumentStackToRestore (MF, MBB);
0 commit comments