Skip to content

Commit 77361c7

Browse files
committed
Address review comments
1 parent 88c4867 commit 77361c7

File tree

5 files changed

+18
-22
lines changed

5 files changed

+18
-22
lines changed

lld/ELF/Relocations.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
914914

915915
static void addGotAuthEntry(Ctx &ctx, Symbol &sym) {
916916
ctx.in.got->addEntry(sym);
917+
ctx.in.got->addAuthEntry(sym);
917918
uint64_t off = sym.getGotOffset(ctx);
918919

919920
// If preemptible, emit a GLOB_DAT relocation.
@@ -1096,18 +1097,10 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
10961097
} else if (!sym.isTls() || ctx.arg.emachine != EM_LOONGARCH) {
10971098
// Many LoongArch TLS relocs reuse the RE_LOONGARCH_GOT type, in which
10981099
// case the NEEDS_GOT flag shouldn't get set.
1099-
bool needsGotAuth =
1100-
(expr == RE_AARCH64_AUTH_GOT || expr == RE_AARCH64_AUTH_GOT_PAGE_PC);
1101-
uint16_t flags = sym.flags.load(std::memory_order_relaxed);
1102-
if (!(flags & NEEDS_GOT)) {
1103-
sym.setFlags(needsGotAuth ? (NEEDS_GOT | NEEDS_GOT_AUTH) : NEEDS_GOT);
1104-
} else if (needsGotAuth != static_cast<bool>(flags & NEEDS_GOT_AUTH)) {
1105-
auto diag = Err(ctx);
1106-
diag << "both AUTH and non-AUTH GOT entries for '" << sym.getName()
1107-
<< "' requested, but only one type of GOT entry per symbol is "
1108-
"supported";
1109-
printLocation(diag, *sec, sym, offset);
1110-
}
1100+
if (expr == RE_AARCH64_AUTH_GOT || expr == RE_AARCH64_AUTH_GOT_PAGE_PC)
1101+
sym.setFlags(NEEDS_GOT | NEEDS_GOT_AUTH);
1102+
else
1103+
sym.setFlags(NEEDS_GOT | NEEDS_GOT_NONAUTH);
11111104
}
11121105
} else if (needsPlt(expr)) {
11131106
sym.setFlags(NEEDS_PLT);
@@ -1808,6 +1801,12 @@ void elf::postScanRelocations(Ctx &ctx) {
18081801
sym.allocateAux(ctx);
18091802

18101803
if (flags & NEEDS_GOT) {
1804+
if ((flags & NEEDS_GOT_AUTH) && (flags & NEEDS_GOT_NONAUTH)) {
1805+
auto diag = Err(ctx);
1806+
diag << "both AUTH and non-AUTH GOT entries for '" << sym.getName()
1807+
<< "' requested, but only one type of GOT entry per symbol is "
1808+
"supported";
1809+
}
18111810
if (flags & NEEDS_GOT_AUTH)
18121811
addGotAuthEntry(ctx, sym);
18131812
else

lld/ELF/Symbols.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum {
5252
NEEDS_GOT_DTPREL = 1 << 7,
5353
NEEDS_TLSIE = 1 << 8,
5454
NEEDS_GOT_AUTH = 1 << 9,
55+
NEEDS_GOT_NONAUTH = 1 << 10,
5556
};
5657

5758
// The base class for real symbol classes.

lld/ELF/SyntheticSections.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,10 @@ void GotSection::addConstant(const Relocation &r) { relocations.push_back(r); }
668668
void GotSection::addEntry(const Symbol &sym) {
669669
assert(sym.auxIdx == ctx.symAux.size() - 1);
670670
ctx.symAux.back().gotIdx = numEntries++;
671-
if (sym.hasFlag(NEEDS_GOT_AUTH))
672-
authEntries.push_back({(numEntries - 1) * ctx.arg.wordsize, sym.isFunc()});
671+
}
672+
673+
void GotSection::addAuthEntry(const Symbol &sym) {
674+
authEntries.push_back({(numEntries - 1) * ctx.arg.wordsize, sym.isFunc()});
673675
}
674676

675677
bool GotSection::addTlsDescEntry(const Symbol &sym) {

lld/ELF/SyntheticSections.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class GotSection final : public SyntheticSection {
112112

113113
void addConstant(const Relocation &r);
114114
void addEntry(const Symbol &sym);
115+
void addAuthEntry(const Symbol &sym);
115116
bool addTlsDescEntry(const Symbol &sym);
116117
bool addDynTlsEntry(const Symbol &sym);
117118
bool addTlsIndex();

lld/test/ELF/aarch64-got-relocations-pauth.s

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,8 @@ _start:
7979

8080
#--- err.s
8181
# RUN: llvm-mc -filetype=obj -triple=aarch64 err.s -o err.o
82-
8382
# RUN: not ld.lld err.o a.so -pie -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR --implicit-check-not=error:
84-
85-
# ERR: error: both AUTH and non-AUTH GOT entries for 'bar' requested, but only one type of GOT entry per symbol is supported
86-
# ERR-NEXT: >>> defined in a.so
87-
# ERR-NEXT: >>> referenced by err.o:(.text+0x8)
88-
# ERR: error: both AUTH and non-AUTH GOT entries for 'bar' requested, but only one type of GOT entry per symbol is supported
89-
# ERR-NEXT: >>> defined in a.so
90-
# ERR-NEXT: >>> referenced by err.o:(.text+0xc)
83+
# ERR: error: both AUTH and non-AUTH GOT entries for 'bar' requested, but only one type of GOT entry per symbol is supported
9184

9285
.globl _start
9386
_start:

0 commit comments

Comments
 (0)