Skip to content

Commit e1f8260

Browse files
committed
Move pauth-specific code from addGotEntry to addGotAuthEntry
1 parent cfb910d commit e1f8260

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

lld/ELF/Relocations.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -911,33 +911,39 @@ void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
911911

912912
// If preemptible, emit a GLOB_DAT relocation.
913913
if (sym.isPreemptible) {
914-
RelType gotRel = ctx.target->gotRel;
915-
if (sym.hasFlag(NEEDS_GOT_AUTH)) {
916-
assert(ctx.arg.emachine == EM_AARCH64);
917-
gotRel = R_AARCH64_AUTH_GLOB_DAT;
918-
}
919-
ctx.mainPart->relaDyn->addReloc({gotRel, ctx.in.got.get(), off,
914+
ctx.mainPart->relaDyn->addReloc({ctx.target->gotRel, ctx.in.got.get(), off,
920915
DynamicReloc::AgainstSymbol, sym, 0,
921916
R_ABS});
922917
return;
923918
}
924919

925920
// Otherwise, the value is either a link-time constant or the load base
926-
// plus a constant. Signed GOT requires dynamic relocation.
927-
if (sym.hasFlag(NEEDS_GOT_AUTH)) {
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-
return;
932-
}
933-
921+
// plus a constant.
934922
if (!ctx.arg.isPic || isAbsolute(sym))
935923
ctx.in.got->addConstant({R_ABS, ctx.target->symbolicRel, off, 0, &sym});
936924
else
937925
addRelativeReloc(ctx, *ctx.in.got, off, sym, 0, R_ABS,
938926
ctx.target->symbolicRel);
939927
}
940928

929+
static void addGotAuthEntry(Ctx &ctx, Symbol &sym) {
930+
ctx.in.got->addEntry(sym);
931+
uint64_t off = sym.getGotOffset(ctx);
932+
933+
// If preemptible, emit a GLOB_DAT relocation.
934+
if (sym.isPreemptible) {
935+
ctx.mainPart->relaDyn->addReloc({R_AARCH64_AUTH_GLOB_DAT, ctx.in.got.get(),
936+
off, DynamicReloc::AgainstSymbol, sym, 0,
937+
R_ABS});
938+
return;
939+
}
940+
941+
// Signed GOT requires dynamic relocation.
942+
ctx.in.got->getPartition(ctx).relaDyn->addReloc(
943+
{R_AARCH64_AUTH_RELATIVE, ctx.in.got.get(), off,
944+
DynamicReloc::AddendOnlyWithTargetVA, sym, 0, R_ABS});
945+
}
946+
941947
static void addTpOffsetGotEntry(Ctx &ctx, Symbol &sym) {
942948
ctx.in.got->addEntry(sym);
943949
uint64_t off = sym.getGotOffset(ctx);
@@ -1809,8 +1815,12 @@ void elf::postScanRelocations(Ctx &ctx) {
18091815
return;
18101816
sym.allocateAux(ctx);
18111817

1812-
if (flags & NEEDS_GOT)
1813-
addGotEntry(ctx, sym);
1818+
if (flags & NEEDS_GOT) {
1819+
if (flags & NEEDS_GOT_AUTH)
1820+
addGotAuthEntry(ctx, sym);
1821+
else
1822+
addGotEntry(ctx, sym);
1823+
}
18141824
if (flags & NEEDS_PLT)
18151825
addPltEntry(ctx, *ctx.in.plt, *ctx.in.gotPlt, *ctx.in.relaPlt,
18161826
ctx.target->pltRel, sym);

0 commit comments

Comments
 (0)