@@ -860,9 +860,10 @@ void AArch64AsmPrinter::emitHwasanMemaccessSymbols(Module &M) {
860860 }
861861}
862862
863- static void
864- emitAuthenticatedPointer (MCStreamer &OutStreamer, MCSymbol *StubLabel,
865- const MachineModuleInfoMachO::AuthStubInfo &StubInfo) {
863+ template <typename MachineModuleInfoTarget>
864+ static void emitAuthenticatedPointer (
865+ MCStreamer &OutStreamer, MCSymbol *StubLabel,
866+ const typename MachineModuleInfoTarget::AuthStubInfo &StubInfo) {
866867 // L_foo$addend$auth_ptr$ib$23:
867868 OutStreamer.emitLabel (StubLabel);
868869 OutStreamer.emitValue (StubInfo.AuthPtrRef , /* size=*/ 8 );
@@ -888,7 +889,8 @@ void AArch64AsmPrinter::emitEndOfAsmFile(Module &M) {
888889 emitAlignment (Align (8 ));
889890
890891 for (auto &Stub : Stubs)
891- emitAuthenticatedPointer (*OutStreamer, Stub.first , Stub.second );
892+ emitAuthenticatedPointer<MachineModuleInfoMachO>(
893+ *OutStreamer, Stub.first , Stub.second );
892894
893895 OutStreamer->addBlankLine ();
894896 }
@@ -901,9 +903,27 @@ void AArch64AsmPrinter::emitEndOfAsmFile(Module &M) {
901903 OutStreamer->emitAssemblerFlag (MCAF_SubsectionsViaSymbols);
902904 }
903905
906+ if (TT.isOSBinFormatELF ()) {
907+ // Output authenticated pointers as indirect symbols, if we have any.
908+ MachineModuleInfoELF &MMIELF = MMI->getObjFileInfo <MachineModuleInfoELF>();
909+
910+ auto Stubs = MMIELF.getAuthGVStubList ();
911+
912+ if (!Stubs.empty ()) {
913+ const TargetLoweringObjectFile &TLOF = getObjFileLowering ();
914+ OutStreamer->switchSection (TLOF.getDataSection ());
915+ emitAlignment (Align (8 ));
916+
917+ for (auto &Stub : Stubs)
918+ emitAuthenticatedPointer<MachineModuleInfoELF>(*OutStreamer, Stub.first ,
919+ Stub.second );
920+
921+ OutStreamer->addBlankLine ();
922+ }
923+ }
924+
904925 // Emit stack and fault map information.
905926 FM.serializeToFaultMapSection ();
906-
907927}
908928
909929void AArch64AsmPrinter::emitLOHs () {
@@ -1877,8 +1897,8 @@ AArch64AsmPrinter::lowerPtrAuthGlobalConstant(const GlobalPtrAuthInfo &PAI) {
18771897
18781898 std::string Buf;
18791899 raw_string_ostream OS (Buf);
1880- OS << " Couldn 't resolve target base/addend of llvm.ptrauth global '"
1881- << *BaseGVB << " '" ;
1900+ OS << " couldn 't resolve target base/addend of llvm.ptrauth global '"
1901+ << *BaseGVB << " '" ;
18821902 BaseGV->getContext ().emitError (OS.str ());
18831903 }
18841904
@@ -1892,16 +1912,20 @@ AArch64AsmPrinter::lowerPtrAuthGlobalConstant(const GlobalPtrAuthInfo &PAI) {
18921912 Sym, MCConstantExpr::create ((-Offset).getSExtValue (), Ctx), Ctx);
18931913
18941914 uint64_t KeyID = PAI.getKey ()->getZExtValue ();
1895- if (!isUInt< 2 >( KeyID) )
1915+ if (KeyID > AArch64PACKey::LAST )
18961916 BaseGV->getContext ().emitError (
1897- " Invalid AArch64 PAC Key ID '" + utostr (KeyID) + " ' in llvm.ptrauth global '" +
1917+ " AArch64 PAC key ID '" + Twine (KeyID) + " ' out of range [0, " +
1918+ Twine (static_cast <int >(AArch64PACKey::LAST)) +
1919+ " ] in llvm.ptrauth "
1920+ " global '" +
18981921 BaseGV->getName () + " '" );
18991922
19001923 uint64_t Disc = PAI.getDiscriminator ()->getZExtValue ();
19011924 if (!isUInt<16 >(Disc))
1902- BaseGV->getContext ().emitError (" Invalid AArch64 Discriminator '" +
1903- utostr (Disc) + " ' in llvm.ptrauth global '" +
1904- BaseGV->getName () + " '" );
1925+ BaseGV->getContext ().emitError (
1926+ " AArch64 PAC discriminator '" + Twine (Disc) +
1927+ " ' out of range [0, 0xFFFF] in llvm.ptrauth global '" +
1928+ BaseGV->getName () + " '" );
19051929
19061930 // Finally build the complete @AUTH expr.
19071931 return AArch64AuthMCExpr::create (Sym, Disc, AArch64PACKey::ID (KeyID),
0 commit comments