Skip to content

Commit eb73740

Browse files
committed
Address review comments
1 parent 215173e commit eb73740

File tree

5 files changed

+33
-56
lines changed

5 files changed

+33
-56
lines changed

lld/ELF/Relocations.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,39 +1326,19 @@ unsigned RelocationScanner::handleTlsRelocation(RelExpr expr, RelType type,
13261326
return 1;
13271327
}
13281328

1329-
auto errBothAuthAndNonAuth = [this, &sym, offset]() {
1330-
auto diag = Err(ctx);
1331-
diag << "both AUTH and non-AUTH TLSDESC entries for '" << sym.getName()
1332-
<< "' requested, but only one type of TLSDESC entry per symbol is "
1333-
"supported";
1334-
printLocation(diag, *sec, sym, offset);
1335-
};
1336-
13371329
// Do not optimize signed TLSDESC (as described in pauthabielf64 to LE/IE).
13381330
// https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#general-restrictions
13391331
// > PAUTHELF64 only supports the descriptor based TLS (TLSDESC).
13401332
if (oneof<RE_AARCH64_AUTH_TLSDESC_PAGE, RE_AARCH64_AUTH_TLSDESC>(expr)) {
1341-
assert(ctx.arg.emachine == EM_AARCH64);
1342-
uint16_t flags = sym.flags.load(std::memory_order_relaxed);
1343-
if (!(flags & NEEDS_TLSDESC)) {
1344-
sym.setFlags(NEEDS_TLSDESC | NEEDS_TLSDESC_AUTH);
1345-
} else if (!(flags & NEEDS_TLSDESC_AUTH)) {
1346-
errBothAuthAndNonAuth();
1347-
return 1;
1348-
}
1333+
sym.setFlags(NEEDS_TLSDESC | NEEDS_TLSDESC_AUTH);
13491334
sec->addReloc({expr, type, offset, addend, &sym});
13501335
return 1;
13511336
}
13521337

1353-
if (sym.hasFlag(NEEDS_TLSDESC_AUTH)) {
1354-
assert(ctx.arg.emachine == EM_AARCH64);
1355-
// TLSDESC_CALL hint relocation probably should not be emitted by compiler
1356-
// with signed TLSDESC enabled since it does not give any value, but leave a
1357-
// check against that just in case someone uses it.
1358-
if (expr != R_TLSDESC_CALL)
1359-
errBothAuthAndNonAuth();
1360-
return 1;
1361-
}
1338+
// TLSDESC_CALL hint relocation should not be emitted by compiler with signed
1339+
// TLSDESC enabled.
1340+
if (expr == R_TLSDESC_CALL)
1341+
sym.setFlags(NEEDS_TLSDESC_NONAUTH);
13621342

13631343
bool isRISCV = ctx.arg.emachine == EM_RISCV;
13641344

@@ -1369,7 +1349,7 @@ unsigned RelocationScanner::handleTlsRelocation(RelExpr expr, RelType type,
13691349
// set NEEDS_TLSDESC on the label.
13701350
if (expr != R_TLSDESC_CALL) {
13711351
if (!isRISCV || type == R_RISCV_TLSDESC_HI20)
1372-
sym.setFlags(NEEDS_TLSDESC);
1352+
sym.setFlags(NEEDS_TLSDESC | NEEDS_TLSDESC_NONAUTH);
13731353
sec->addReloc({expr, type, offset, addend, &sym});
13741354
}
13751355
return 1;
@@ -1879,10 +1859,17 @@ void elf::postScanRelocations(Ctx &ctx) {
18791859
GotSection *got = ctx.in.got.get();
18801860

18811861
if (flags & NEEDS_TLSDESC) {
1862+
if ((flags & NEEDS_TLSDESC_AUTH) && (flags & NEEDS_TLSDESC_NONAUTH)) {
1863+
auto diag = Err(ctx);
1864+
diag << "both AUTH and non-AUTH TLSDESC entries for '" << sym.getName()
1865+
<< "' requested, but only one type of TLSDESC entry per symbol is "
1866+
"supported";
1867+
return;
1868+
}
18821869
got->addTlsDescEntry(sym);
18831870
RelType tlsDescRel = ctx.target->tlsDescRel;
18841871
if (flags & NEEDS_TLSDESC_AUTH) {
1885-
assert(ctx.arg.emachine == EM_AARCH64);
1872+
got->addTlsDescAuthEntry();
18861873
tlsDescRel = ELF::R_AARCH64_AUTH_TLSDESC;
18871874
}
18881875
ctx.mainPart->relaDyn->addAddendOnlyRelocIfNonPreemptible(

lld/ELF/Symbols.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enum {
5454
NEEDS_GOT_AUTH = 1 << 9,
5555
NEEDS_GOT_NONAUTH = 1 << 10,
5656
NEEDS_TLSDESC_AUTH = 1 << 11,
57+
NEEDS_TLSDESC_NONAUTH = 1 << 12,
5758
};
5859

5960
// The base class for real symbol classes.

lld/ELF/SyntheticSections.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,14 @@ bool GotSection::addTlsDescEntry(const Symbol &sym) {
678678
assert(sym.auxIdx == ctx.symAux.size() - 1);
679679
ctx.symAux.back().tlsDescIdx = numEntries;
680680
numEntries += 2;
681-
if (sym.hasFlag(NEEDS_TLSDESC_AUTH)) {
682-
assert(ctx.arg.emachine == EM_AARCH64);
683-
authEntries.push_back({(numEntries - 2) * ctx.arg.wordsize, true});
684-
authEntries.push_back({(numEntries - 1) * ctx.arg.wordsize, false});
685-
}
686681
return true;
687682
}
688683

684+
void GotSection::addTlsDescAuthEntry() {
685+
authEntries.push_back({(numEntries - 2) * ctx.arg.wordsize, true});
686+
authEntries.push_back({(numEntries - 1) * ctx.arg.wordsize, false});
687+
}
688+
689689
bool GotSection::addDynTlsEntry(const Symbol &sym) {
690690
assert(sym.auxIdx == ctx.symAux.size() - 1);
691691
ctx.symAux.back().tlsGdIdx = numEntries;

lld/ELF/SyntheticSections.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class GotSection final : public SyntheticSection {
114114
void addEntry(const Symbol &sym);
115115
void addAuthEntry(const Symbol &sym);
116116
bool addTlsDescEntry(const Symbol &sym);
117+
void addTlsDescAuthEntry();
117118
bool addDynTlsEntry(const Symbol &sym);
118119
bool addTlsIndex();
119120
uint32_t getTlsDescOffset(const Symbol &sym) const;

lld/test/ELF/aarch64-tlsdesc-pauth.s

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ a:
2727
adrp x0, :tlsdesc_auth:a
2828
ldr x16, [x0, :tlsdesc_auth_lo12:a]
2929
add x0, x0, :tlsdesc_auth_lo12:a
30-
.tlsdesccall a
3130
blraa x16, x0
3231

3332
// CHECK: adrp x0, 0x[[P]]000
@@ -42,7 +41,6 @@ a:
4241
adrp x0, :tlsdesc_auth:local1
4342
ldr x16, [x0, :tlsdesc_auth_lo12:local1]
4443
add x0, x0, :tlsdesc_auth_lo12:local1
45-
.tlsdesccall local1
4644
blraa x16, x0
4745

4846
// CHECK: adrp x0, 0x[[P]]000
@@ -53,7 +51,6 @@ a:
5351
adrp x0, :tlsdesc_auth:local2
5452
ldr x16, [x0, :tlsdesc_auth_lo12:local2]
5553
add x0, x0, :tlsdesc_auth_lo12:local2
56-
.tlsdesccall local2
5754
blraa x16, x0
5855

5956
// CHECK: adrp x0, 0x[[P]]000
@@ -98,47 +95,38 @@ local2:
9895
//--- err1.s
9996
// RUN: llvm-mc -filetype=obj -triple=aarch64-pc-linux -mattr=+pauth err1.s -o err1.o
10097
// RUN: not ld.lld -shared err1.o -o err1.so 2>&1 | FileCheck --check-prefix=ERR1 --implicit-check-not=error: %s
101-
// ERR1: error: both AUTH and non-AUTH TLSDESC entries for 'a' requested, but only one type of TLSDESC entry per symbol is supported
102-
// ERR1-NEXT: >>> defined in err1.o
103-
// ERR1-NEXT: >>> referenced by err1.o:(.text+0x10)
104-
// ERR1: error: both AUTH and non-AUTH TLSDESC entries for 'a' requested, but only one type of TLSDESC entry per symbol is supported
105-
// ERR1-NEXT: >>> defined in err1.o
106-
// ERR1-NEXT: >>> referenced by err1.o:(.text+0x14)
107-
// ERR1: error: both AUTH and non-AUTH TLSDESC entries for 'a' requested, but only one type of TLSDESC entry per symbol is supported
108-
// ERR1-NEXT: >>> defined in err1.o
109-
// ERR1-NEXT: >>> referenced by err1.o:(.text+0x18)
98+
// ERR1: error: both AUTH and non-AUTH TLSDESC entries for 'a' requested, but only one type of TLSDESC entry per symbol is supported
11099
.text
111100
adrp x0, :tlsdesc_auth:a
112101
ldr x16, [x0, :tlsdesc_auth_lo12:a]
113102
add x0, x0, :tlsdesc_auth_lo12:a
114-
.tlsdesccall a
115103
blraa x16, x0
116104

117105
adrp x0, :tlsdesc:a
118106
ldr x1, [x0, :tlsdesc_lo12:a]
119107
add x0, x0, :tlsdesc_lo12:a
120-
.tlsdesccall a
121108
blr x1
122109

123110
//--- err2.s
124111
// RUN: llvm-mc -filetype=obj -triple=aarch64-pc-linux -mattr=+pauth err2.s -o err2.o
125112
// RUN: not ld.lld -shared err2.o -o err2.so 2>&1 | FileCheck --check-prefix=ERR2 --implicit-check-not=error: %s
126-
// ERR2: error: both AUTH and non-AUTH TLSDESC entries for 'a' requested, but only one type of TLSDESC entry per symbol is supported
127-
// ERR2-NEXT: >>> defined in err2.o
128-
// ERR2-NEXT: >>> referenced by err2.o:(.text+0x10)
129-
// ERR2: error: both AUTH and non-AUTH TLSDESC entries for 'a' requested, but only one type of TLSDESC entry per symbol is supported
130-
// ERR2-NEXT: >>> defined in err2.o
131-
// ERR2-NEXT: >>> referenced by err2.o:(.text+0x14)
132-
// ERR2: error: both AUTH and non-AUTH TLSDESC entries for 'a' requested, but only one type of TLSDESC entry per symbol is supported
133-
// ERR2-NEXT: >>> defined in err2.o
134-
// ERR2-NEXT: >>> referenced by err2.o:(.text+0x18)
113+
// ERR2: error: both AUTH and non-AUTH TLSDESC entries for 'a' requested, but only one type of TLSDESC entry per symbol is supported
135114
.text
136115
adrp x0, :tlsdesc:a
137116
ldr x1, [x0, :tlsdesc_lo12:a]
138117
add x0, x0, :tlsdesc_lo12:a
139-
.tlsdesccall a
140118
blr x1
141119

120+
adrp x0, :tlsdesc_auth:a
121+
ldr x16, [x0, :tlsdesc_auth_lo12:a]
122+
add x0, x0, :tlsdesc_auth_lo12:a
123+
blraa x16, x0
124+
125+
//--- err3.s
126+
// RUN: llvm-mc -filetype=obj -triple=aarch64-pc-linux -mattr=+pauth err3.s -o err3.o
127+
// RUN: not ld.lld -shared err3.o -o err3.so 2>&1 | FileCheck --check-prefix=ERR3 --implicit-check-not=error: %s
128+
// ERR3: error: both AUTH and non-AUTH TLSDESC entries for 'a' requested, but only one type of TLSDESC entry per symbol is supported
129+
.text
142130
adrp x0, :tlsdesc_auth:a
143131
ldr x16, [x0, :tlsdesc_auth_lo12:a]
144132
add x0, x0, :tlsdesc_auth_lo12:a

0 commit comments

Comments
 (0)