@@ -704,6 +704,8 @@ static void addRelativeReloc(Ctx &ctx, InputSectionBase &isec,
704704 uint64_t offsetInSec, Symbol &sym, int64_t addend,
705705 RelExpr expr, RelType type) {
706706 Partition &part = isec.getPartition (ctx);
707+ bool isAArch64Auth =
708+ ctx.arg .emachine == EM_AARCH64 && type == R_AARCH64_AUTH_ABS64;
707709
708710 // Add a relative relocation. If relrDyn section is enabled, and the
709711 // relocation offset is guaranteed to be even, add the relocation to
@@ -712,18 +714,26 @@ static void addRelativeReloc(Ctx &ctx, InputSectionBase &isec,
712714 // don't store the addend values, so we must write it to the relocated
713715 // address.
714716 //
717+ // When symbol values are determined in finalizeAddressDependentContent,
718+ // some .relr.auth.dyn relocations may be moved to .rela.dyn.
719+ //
715720 // MTE globals may need to store the original addend as well so cannot use
716721 // relrDyn. TODO: It should be unambiguous when not using R_ADDEND_NEG below?
717722 RelrBaseSection *relrDyn = part.relrDyn .get ();
723+ if (isAArch64Auth)
724+ relrDyn = part.relrAuthDyn .get ();
718725 if (sym.isTagged ())
719726 relrDyn = nullptr ;
720727 if (relrDyn && isec.addralign >= 2 && offsetInSec % 2 == 0 ) {
721728 relrDyn->addRelativeReloc <shard>(isec, offsetInSec, sym, addend, type,
722729 expr);
723730 return ;
724731 }
725- part.relaDyn ->addRelativeReloc <shard>(ctx.target ->relativeRel , isec,
726- offsetInSec, sym, addend, type, expr);
732+ RelType relativeType = ctx.target ->relativeRel ;
733+ if (isAArch64Auth)
734+ relativeType = R_AARCH64_AUTH_RELATIVE;
735+ part.relaDyn ->addRelativeReloc <shard>(relativeType, isec, offsetInSec, sym,
736+ addend, type, expr);
727737 // With MTE globals, we always want to derive the address tag by `ldg`-ing
728738 // the symbol. When we have a RELATIVE relocation though, we no longer have
729739 // a reference to the symbol. Because of this, when we have an addend that
@@ -993,7 +1003,9 @@ void RelocScan::process(RelExpr expr, RelType type, uint64_t offset,
9931003 if (canWrite) {
9941004 RelType rel = ctx.target ->getDynRel (type);
9951005 if (oneof<R_GOT, RE_LOONGARCH_GOT>(expr) ||
996- (rel == ctx.target ->symbolicRel && !sym.isPreemptible )) {
1006+ ((rel == ctx.target ->symbolicRel ||
1007+ (ctx.arg .emachine == EM_AARCH64 && type == R_AARCH64_AUTH_ABS64)) &&
1008+ !sym.isPreemptible )) {
9971009 addRelativeReloc<true >(ctx, *sec, offset, sym, addend, expr, type);
9981010 return ;
9991011 }
@@ -1002,28 +1014,6 @@ void RelocScan::process(RelExpr expr, RelType type, uint64_t offset,
10021014 rel = ctx.target ->relativeRel ;
10031015 std::lock_guard<std::mutex> lock (ctx.relocMutex );
10041016 Partition &part = sec->getPartition (ctx);
1005- // For a preemptible symbol, we can't use a relative relocation. For an
1006- // undefined symbol, we can't compute offset at link-time and use a
1007- // relative relocation. Use a symbolic relocation instead.
1008- // Handle the composition with Memtag like addRelativeReloc.
1009- if (ctx.arg .emachine == EM_AARCH64 && type == R_AARCH64_AUTH_ABS64 &&
1010- !sym.isPreemptible ) {
1011- if (!sym.isTagged () && part.relrAuthDyn && sec->addralign >= 2 &&
1012- offset % 2 == 0 ) {
1013- // When symbol values are determined in
1014- // finalizeAddressDependentContent, some .relr.auth.dyn relocations
1015- // may be moved to .rela.dyn.
1016- part.relrAuthDyn ->addRelativeReloc (*sec, offset, sym, addend, type,
1017- expr);
1018- } else {
1019- part.relaDyn ->addReloc ({R_AARCH64_AUTH_RELATIVE, sec, offset, false ,
1020- sym, addend, R_ABS});
1021- if (sym.isTagged () &&
1022- (addend < 0 || static_cast <uint64_t >(addend) >= sym.getSize ()))
1023- sec->addReloc ({R_ADDEND_NEG, type, offset, addend, &sym});
1024- }
1025- return ;
1026- }
10271017 if (LLVM_UNLIKELY (type == ctx.target ->iRelSymbolicRel )) {
10281018 if (sym.isPreemptible ) {
10291019 auto diag = Err (ctx);
0 commit comments