@@ -1292,6 +1292,27 @@ static unsigned handleMipsTlsRelocation(Ctx &ctx, RelType type, Symbol &sym,
12921292 return 0 ;
12931293}
12941294
1295+ static unsigned handleAArch64PAuthTlsRelocation (InputSectionBase *sec,
1296+ RelExpr expr, RelType type,
1297+ uint64_t offset, Symbol &sym,
1298+ int64_t addend) {
1299+ // Do not optimize signed TLSDESC to LE/IE (as described in pauthabielf64).
1300+ // https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#general-restrictions
1301+ // > PAUTHELF64 only supports the descriptor based TLS (TLSDESC).
1302+ if (oneof<RE_AARCH64_AUTH_TLSDESC_PAGE, RE_AARCH64_AUTH_TLSDESC>(expr)) {
1303+ sym.setFlags (NEEDS_TLSDESC | NEEDS_TLSDESC_AUTH);
1304+ sec->addReloc ({expr, type, offset, addend, &sym});
1305+ return 1 ;
1306+ }
1307+
1308+ // TLSDESC_CALL hint relocation should not be emitted by compiler with signed
1309+ // TLSDESC enabled.
1310+ if (expr == R_TLSDESC_CALL)
1311+ sym.setFlags (NEEDS_TLSDESC_NONAUTH);
1312+
1313+ return 0 ;
1314+ }
1315+
12951316// Notes about General Dynamic and Local Dynamic TLS models below. They may
12961317// require the generation of a pair of GOT entries that have associated dynamic
12971318// relocations. The pair of GOT entries created are of the form GOT[e0] Module
@@ -1302,6 +1323,11 @@ static unsigned handleMipsTlsRelocation(Ctx &ctx, RelType type, Symbol &sym,
13021323unsigned RelocationScanner::handleTlsRelocation (RelExpr expr, RelType type,
13031324 uint64_t offset, Symbol &sym,
13041325 int64_t addend) {
1326+ if (ctx.arg .emachine == EM_AARCH64)
1327+ if (unsigned processed = handleAArch64PAuthTlsRelocation (
1328+ sec, expr, type, offset, sym, addend))
1329+ return processed;
1330+
13051331 if (expr == R_TPREL || expr == R_TPREL_NEG) {
13061332 if (ctx.arg .shared ) {
13071333 auto diag = Err (ctx);
@@ -1328,20 +1354,6 @@ unsigned RelocationScanner::handleTlsRelocation(RelExpr expr, RelType type,
13281354 return 1 ;
13291355 }
13301356
1331- // Do not optimize signed TLSDESC (as described in pauthabielf64 to LE/IE).
1332- // https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#general-restrictions
1333- // > PAUTHELF64 only supports the descriptor based TLS (TLSDESC).
1334- if (oneof<RE_AARCH64_AUTH_TLSDESC_PAGE, RE_AARCH64_AUTH_TLSDESC>(expr)) {
1335- sym.setFlags (NEEDS_TLSDESC | NEEDS_TLSDESC_AUTH);
1336- sec->addReloc ({expr, type, offset, addend, &sym});
1337- return 1 ;
1338- }
1339-
1340- // TLSDESC_CALL hint relocation should not be emitted by compiler with signed
1341- // TLSDESC enabled.
1342- if (expr == R_TLSDESC_CALL)
1343- sym.setFlags (NEEDS_TLSDESC_NONAUTH);
1344-
13451357 bool isRISCV = ctx.arg .emachine == EM_RISCV;
13461358
13471359 if (oneof<RE_AARCH64_TLSDESC_PAGE, R_TLSDESC, R_TLSDESC_CALL, R_TLSDESC_PC,
@@ -1351,7 +1363,9 @@ unsigned RelocationScanner::handleTlsRelocation(RelExpr expr, RelType type,
13511363 // set NEEDS_TLSDESC on the label.
13521364 if (expr != R_TLSDESC_CALL) {
13531365 if (!isRISCV || type == R_RISCV_TLSDESC_HI20)
1354- sym.setFlags (NEEDS_TLSDESC | NEEDS_TLSDESC_NONAUTH);
1366+ sym.setFlags (
1367+ NEEDS_TLSDESC |
1368+ (ctx.arg .emachine == EM_AARCH64 ? NEEDS_TLSDESC_NONAUTH : 0 ));
13551369 sec->addReloc ({expr, type, offset, addend, &sym});
13561370 }
13571371 return 1 ;
@@ -1862,10 +1876,10 @@ void elf::postScanRelocations(Ctx &ctx) {
18621876
18631877 if (flags & NEEDS_TLSDESC) {
18641878 if ((flags & NEEDS_TLSDESC_AUTH) && (flags & NEEDS_TLSDESC_NONAUTH)) {
1865- auto diag = Err (ctx);
1866- diag << " both AUTH and non-AUTH TLSDESC entries for '" << sym.getName ()
1867- << " ' requested, but only one type of TLSDESC entry per symbol is "
1868- " supported" ;
1879+ Err (ctx)
1880+ << " both AUTH and non-AUTH TLSDESC entries for '" << sym.getName ()
1881+ << " ' requested, but only one type of TLSDESC entry per symbol is "
1882+ " supported" ;
18691883 return ;
18701884 }
18711885 got->addTlsDescEntry (sym);
0 commit comments