Skip to content

Commit 1078d05

Browse files
committed
Move pauth-specific code from addGotEntry to addGotAuthEntry
1 parent 401c1e4 commit 1078d05

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
@@ -896,33 +896,39 @@ void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
896896

897897
// If preemptible, emit a GLOB_DAT relocation.
898898
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,
905900
DynamicReloc::AgainstSymbol, sym, 0,
906901
R_ABS});
907902
return;
908903
}
909904

910905
// 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.
919907
if (!ctx.arg.isPic || isAbsolute(sym))
920908
ctx.in.got->addConstant({R_ABS, ctx.target->symbolicRel, off, 0, &sym});
921909
else
922910
addRelativeReloc(ctx, *ctx.in.got, off, sym, 0, R_ABS,
923911
ctx.target->symbolicRel);
924912
}
925913

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+
926932
static void addTpOffsetGotEntry(Ctx &ctx, Symbol &sym) {
927933
ctx.in.got->addEntry(sym);
928934
uint64_t off = sym.getGotOffset(ctx);
@@ -1797,8 +1803,12 @@ void elf::postScanRelocations(Ctx &ctx) {
17971803
return;
17981804
sym.allocateAux(ctx);
17991805

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+
}
18021812
if (flags & NEEDS_PLT)
18031813
addPltEntry(ctx, *ctx.in.plt, *ctx.in.gotPlt, *ctx.in.relaPlt,
18041814
ctx.target->pltRel, sym);

0 commit comments

Comments
 (0)