@@ -896,33 +896,39 @@ void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
896
896
897
897
// If preemptible, emit a GLOB_DAT relocation.
898
898
if (sym.isPreemptible ) {
899
- RelType gotRel = ctx.target ->gotRel ;
900
- if (sym.hasFlag (NEEDS_GOT_AUTH)) {
901
- assert (ctx.arg .emachine == EM_AARCH64);
902
- gotRel = R_AARCH64_AUTH_GLOB_DAT;
903
- }
904
- ctx.mainPart ->relaDyn ->addReloc ({gotRel, ctx.in .got .get (), off,
899
+ ctx.mainPart ->relaDyn ->addReloc ({ctx.target ->gotRel , ctx.in .got .get (), off,
905
900
DynamicReloc::AgainstSymbol, sym, 0 ,
906
901
R_ABS});
907
902
return ;
908
903
}
909
904
910
905
// Otherwise, the value is either a link-time constant or the load base
911
- // plus a constant. Signed GOT requires dynamic relocation.
912
- if (sym.hasFlag (NEEDS_GOT_AUTH)) {
913
- ctx.in .got ->getPartition (ctx).relaDyn ->addReloc (
914
- {R_AARCH64_AUTH_RELATIVE, ctx.in .got .get (), off,
915
- DynamicReloc::AddendOnlyWithTargetVA, sym, 0 , R_ABS});
916
- return ;
917
- }
918
-
906
+ // plus a constant.
919
907
if (!ctx.arg .isPic || isAbsolute (sym))
920
908
ctx.in .got ->addConstant ({R_ABS, ctx.target ->symbolicRel , off, 0 , &sym});
921
909
else
922
910
addRelativeReloc (ctx, *ctx.in .got , off, sym, 0 , R_ABS,
923
911
ctx.target ->symbolicRel );
924
912
}
925
913
914
+ static void addGotAuthEntry (Ctx &ctx, Symbol &sym) {
915
+ ctx.in .got ->addEntry (sym);
916
+ uint64_t off = sym.getGotOffset (ctx);
917
+
918
+ // If preemptible, emit a GLOB_DAT relocation.
919
+ if (sym.isPreemptible ) {
920
+ ctx.mainPart ->relaDyn ->addReloc ({R_AARCH64_AUTH_GLOB_DAT, ctx.in .got .get (),
921
+ off, DynamicReloc::AgainstSymbol, sym, 0 ,
922
+ R_ABS});
923
+ return ;
924
+ }
925
+
926
+ // Signed GOT requires dynamic relocation.
927
+ ctx.in .got ->getPartition (ctx).relaDyn ->addReloc (
928
+ {R_AARCH64_AUTH_RELATIVE, ctx.in .got .get (), off,
929
+ DynamicReloc::AddendOnlyWithTargetVA, sym, 0 , R_ABS});
930
+ }
931
+
926
932
static void addTpOffsetGotEntry (Ctx &ctx, Symbol &sym) {
927
933
ctx.in .got ->addEntry (sym);
928
934
uint64_t off = sym.getGotOffset (ctx);
@@ -1797,8 +1803,12 @@ void elf::postScanRelocations(Ctx &ctx) {
1797
1803
return ;
1798
1804
sym.allocateAux (ctx);
1799
1805
1800
- if (flags & NEEDS_GOT)
1801
- addGotEntry (ctx, sym);
1806
+ if (flags & NEEDS_GOT) {
1807
+ if (flags & NEEDS_GOT_AUTH)
1808
+ addGotAuthEntry (ctx, sym);
1809
+ else
1810
+ addGotEntry (ctx, sym);
1811
+ }
1802
1812
if (flags & NEEDS_PLT)
1803
1813
addPltEntry (ctx, *ctx.in .plt , *ctx.in .gotPlt , *ctx.in .relaPlt ,
1804
1814
ctx.target ->pltRel , sym);
0 commit comments