@@ -848,20 +848,38 @@ void AArch64AsmPrinter::emitHwasanMemaccessSymbols(Module &M) {
848848 }
849849}
850850
851- template <typename MachineModuleInfoTarget>
852- static void emitAuthenticatedPointer (
853- MCStreamer &OutStreamer, MCSymbol *StubLabel,
854- const typename MachineModuleInfoTarget::AuthStubInfo &StubInfo) {
851+ static void emitAuthenticatedPointer (MCStreamer &OutStreamer,
852+ MCSymbol *StubLabel,
853+ const MCExpr *StubAuthPtrRef) {
855854 // sym$auth_ptr$key$disc:
856855 OutStreamer.emitLabel (StubLabel);
857- OutStreamer.emitValue (StubInfo. AuthPtrRef , /* size=*/ 8 );
856+ OutStreamer.emitValue (StubAuthPtrRef , /* size=*/ 8 );
858857}
859858
860859void AArch64AsmPrinter::emitEndOfAsmFile (Module &M) {
861860 emitHwasanMemaccessSymbols (M);
862861
863862 const Triple &TT = TM.getTargetTriple ();
864863 if (TT.isOSBinFormatMachO ()) {
864+ // Output authenticated pointers as indirect symbols, if we have any.
865+ MachineModuleInfoMachO &MMIMacho =
866+ MMI->getObjFileInfo <MachineModuleInfoMachO>();
867+
868+ auto Stubs = MMIMacho.getAuthGVStubList ();
869+
870+ if (!Stubs.empty ()) {
871+ // Switch to the "__auth_ptr" section.
872+ OutStreamer->switchSection (
873+ OutContext.getMachOSection (" __DATA" , " __auth_ptr" , MachO::S_REGULAR,
874+ SectionKind::getMetadata ()));
875+ emitAlignment (Align (8 ));
876+
877+ for (const auto &Stub : Stubs)
878+ emitAuthenticatedPointer (*OutStreamer, Stub.first , Stub.second );
879+
880+ OutStreamer->addBlankLine ();
881+ }
882+
865883 // Funny Darwin hack: This flag tells the linker that no global symbols
866884 // contain code that falls through to other global symbols (e.g. the obvious
867885 // implementation of multiple entry points). If this doesn't occur, the
@@ -882,8 +900,7 @@ void AArch64AsmPrinter::emitEndOfAsmFile(Module &M) {
882900 emitAlignment (Align (8 ));
883901
884902 for (const auto &Stub : Stubs)
885- emitAuthenticatedPointer<MachineModuleInfoELF>(*OutStreamer, Stub.first ,
886- Stub.second );
903+ emitAuthenticatedPointer (*OutStreamer, Stub.first , Stub.second );
887904
888905 OutStreamer->addBlankLine ();
889906 }
@@ -1676,16 +1693,29 @@ void AArch64AsmPrinter::LowerLOADauthptrstatic(const MachineInstr &MI) {
16761693 //
16771694 // Where the $auth_ptr$ symbol is the stub slot containing the signed pointer
16781695 // to symbol.
1679- assert (TM.getTargetTriple ().isOSBinFormatELF () &&
1680- " LOADauthptrstatic is implemented only for ELF" );
1681- const auto &TLOF =
1682- static_cast <const AArch64_ELFTargetObjectFile &>(getObjFileLowering ());
1683-
1684- assert (GAOp.getOffset () == 0 &&
1685- " non-zero offset for $auth_ptr$ stub slots is not supported" );
1686- const MCSymbol *GASym = TM.getSymbol (GAOp.getGlobal ());
1687- MCSymbol *AuthPtrStubSym =
1688- TLOF.getAuthPtrSlotSymbol (TM, &MF->getMMI (), GASym, Key, Disc);
1696+ MCSymbol *AuthPtrStubSym;
1697+ if (TM.getTargetTriple ().isOSBinFormatELF ()) {
1698+ const auto &TLOF =
1699+ static_cast <const AArch64_ELFTargetObjectFile &>(getObjFileLowering ());
1700+
1701+ assert (GAOp.getOffset () == 0 &&
1702+ " non-zero offset for $auth_ptr$ stub slots is not supported" );
1703+ const MCSymbol *GASym = TM.getSymbol (GAOp.getGlobal ());
1704+ AuthPtrStubSym =
1705+ TLOF.getAuthPtrSlotSymbol (TM, &MF->getMMI (), GASym, Key, Disc);
1706+ } else {
1707+ assert (TM.getTargetTriple ().isOSBinFormatMachO () &&
1708+ " LOADauthptrstatic is implemented only for MachO/ELF" );
1709+
1710+ const auto &TLOF = static_cast <const AArch64_MachoTargetObjectFile &>(
1711+ getObjFileLowering ());
1712+
1713+ assert (GAOp.getOffset () == 0 &&
1714+ " non-zero offset for $auth_ptr$ stub slots is not supported" );
1715+ const MCSymbol *GASym = TM.getSymbol (GAOp.getGlobal ());
1716+ AuthPtrStubSym =
1717+ TLOF.getAuthPtrSlotSymbol (TM, &MF->getMMI (), GASym, Key, Disc);
1718+ }
16891719
16901720 MachineOperand StubMOHi =
16911721 MachineOperand::CreateMCSymbol (AuthPtrStubSym, AArch64II::MO_PAGE);
0 commit comments