@@ -197,8 +197,9 @@ static bool needsPlt(RelExpr expr) {
197197}
198198
199199bool lld::elf::needsGot (RelExpr expr) {
200- return oneof<R_GOT, R_GOT_OFF, RE_MIPS_GOT_LOCAL_PAGE, RE_MIPS_GOT_OFF,
201- RE_MIPS_GOT_OFF32, RE_AARCH64_GOT_PAGE_PC, R_GOT_PC, R_GOTPLT,
200+ return oneof<R_GOT, RE_AARCH64_AUTH_GOT, R_GOT_OFF, RE_MIPS_GOT_LOCAL_PAGE,
201+ RE_MIPS_GOT_OFF, RE_MIPS_GOT_OFF32, RE_AARCH64_GOT_PAGE_PC,
202+ RE_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC, R_GOTPLT,
202203 RE_AARCH64_GOT_PAGE, RE_LOONGARCH_GOT, RE_LOONGARCH_GOT_PAGE_PC>(
203204 expr);
204205}
@@ -910,6 +911,25 @@ void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
910911 ctx.target ->symbolicRel );
911912}
912913
914+ static void addGotAuthEntry (Ctx &ctx, Symbol &sym) {
915+ ctx.in .got ->addEntry (sym);
916+ ctx.in .got ->addAuthEntry (sym);
917+ uint64_t off = sym.getGotOffset (ctx);
918+
919+ // If preemptible, emit a GLOB_DAT relocation.
920+ if (sym.isPreemptible ) {
921+ ctx.mainPart ->relaDyn ->addReloc ({R_AARCH64_AUTH_GLOB_DAT, ctx.in .got .get (),
922+ off, DynamicReloc::AgainstSymbol, sym, 0 ,
923+ R_ABS});
924+ return ;
925+ }
926+
927+ // Signed GOT requires dynamic relocation.
928+ ctx.in .got ->getPartition (ctx).relaDyn ->addReloc (
929+ {R_AARCH64_AUTH_RELATIVE, ctx.in .got .get (), off,
930+ DynamicReloc::AddendOnlyWithTargetVA, sym, 0 , R_ABS});
931+ }
932+
913933static void addTpOffsetGotEntry (Ctx &ctx, Symbol &sym) {
914934 ctx.in .got ->addEntry (sym);
915935 uint64_t off = sym.getGotOffset (ctx);
@@ -956,11 +976,12 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
956976 // These expressions always compute a constant
957977 if (oneof<R_GOTPLT, R_GOT_OFF, R_RELAX_HINT, RE_MIPS_GOT_LOCAL_PAGE,
958978 RE_MIPS_GOTREL, RE_MIPS_GOT_OFF, RE_MIPS_GOT_OFF32,
959- RE_MIPS_GOT_GP_PC, RE_AARCH64_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC,
979+ RE_MIPS_GOT_GP_PC, RE_AARCH64_GOT_PAGE_PC,
980+ RE_AARCH64_AUTH_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC,
960981 R_GOTPLTONLY_PC, R_PLT_PC, R_PLT_GOTREL, R_PLT_GOTPLT,
961982 R_GOTPLT_GOTREL, R_GOTPLT_PC, RE_PPC32_PLTREL, RE_PPC64_CALL_PLT,
962983 RE_PPC64_RELAX_TOC, RE_RISCV_ADD, RE_AARCH64_GOT_PAGE,
963- RE_LOONGARCH_PLT_PAGE_PC, RE_LOONGARCH_GOT,
984+ RE_AARCH64_AUTH_GOT, RE_LOONGARCH_PLT_PAGE_PC, RE_LOONGARCH_GOT,
964985 RE_LOONGARCH_GOT_PAGE_PC>(e))
965986 return true ;
966987
@@ -1075,7 +1096,10 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
10751096 } else if (!sym.isTls () || ctx.arg .emachine != EM_LOONGARCH) {
10761097 // Many LoongArch TLS relocs reuse the RE_LOONGARCH_GOT type, in which
10771098 // case the NEEDS_GOT flag shouldn't get set.
1078- sym.setFlags (NEEDS_GOT);
1099+ if (expr == RE_AARCH64_AUTH_GOT || expr == RE_AARCH64_AUTH_GOT_PAGE_PC)
1100+ sym.setFlags (NEEDS_GOT | NEEDS_GOT_AUTH);
1101+ else
1102+ sym.setFlags (NEEDS_GOT | NEEDS_GOT_NONAUTH);
10791103 }
10801104 } else if (needsPlt (expr)) {
10811105 sym.setFlags (NEEDS_PLT);
@@ -1750,8 +1774,11 @@ static bool handleNonPreemptibleIfunc(Ctx &ctx, Symbol &sym, uint16_t flags) {
17501774 // don't try to call the PLT as if it were an ifunc resolver.
17511775 d.type = STT_FUNC;
17521776
1753- if (flags & NEEDS_GOT)
1777+ if (flags & NEEDS_GOT) {
1778+ assert (!(flags & NEEDS_GOT_AUTH) &&
1779+ " R_AARCH64_AUTH_IRELATIVE is not supported yet" );
17541780 addGotEntry (ctx, sym);
1781+ }
17551782 } else if (flags & NEEDS_GOT) {
17561783 // Redirect GOT accesses to point to the Igot.
17571784 sym.gotInIgot = true ;
@@ -1772,8 +1799,19 @@ void elf::postScanRelocations(Ctx &ctx) {
17721799 return ;
17731800 sym.allocateAux (ctx);
17741801
1775- if (flags & NEEDS_GOT)
1776- addGotEntry (ctx, sym);
1802+ if (flags & NEEDS_GOT) {
1803+ if ((flags & NEEDS_GOT_AUTH) && (flags & NEEDS_GOT_NONAUTH)) {
1804+ auto diag = Err (ctx);
1805+ diag << " both AUTH and non-AUTH GOT entries for '" << sym.getName ()
1806+ << " ' requested, but only one type of GOT entry per symbol is "
1807+ " supported" ;
1808+ return ;
1809+ }
1810+ if (flags & NEEDS_GOT_AUTH)
1811+ addGotAuthEntry (ctx, sym);
1812+ else
1813+ addGotEntry (ctx, sym);
1814+ }
17771815 if (flags & NEEDS_PLT)
17781816 addPltEntry (ctx, *ctx.in .plt , *ctx.in .gotPlt , *ctx.in .relaPlt ,
17791817 ctx.target ->pltRel , sym);
0 commit comments