[LLD][AArch64] Handle R_AARCH64_TLS_DTPREL64 in non-alloc sections (#183962)

Clang plan to emit R_AARCH64_TLS_DTPREL64 in .debug_info (see PR
#146572). LLD currently fails to recognize this relocation.

This prevent the debugger from correctly locating TLS variables when
using the DWARF DW_OP_GNU_push_tls_address or DW_AT_location with DTPREL
offsets.

This patch adds support for R_AARCH64_TLS_DTPREL64, adds its mapping to
R_DTPREL.
This commit is contained in:
Shivam Gupta 2026-03-31 08:47:54 +05:30 committed by GitHub
parent e1aef5ed5f
commit 14ce208a45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -156,6 +156,8 @@ RelExpr AArch64::getRelExpr(RelType type, const Symbol &s,
case R_AARCH64_PREL32:
case R_AARCH64_PREL64:
return R_PC;
case R_AARCH64_TLS_DTPREL64:
return R_DTPREL;
case R_AARCH64_NONE:
return R_NONE;
default:
@ -649,6 +651,9 @@ void AArch64::relocate(uint8_t *loc, const Relocation &rel,
checkInt(ctx, loc, val, 32, rel);
write32(ctx, loc, val);
break;
case R_AARCH64_TLS_DTPREL64:
write64(ctx, loc, val);
break;
case R_AARCH64_ADD_ABS_LO12_NC:
case R_AARCH64_AUTH_GOT_ADD_LO12_NC:
write32Imm12(loc, val);

View File

@ -0,0 +1,23 @@
# REQUIRES: aarch64
# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
# RUN: llvm-readobj -r %t.o | FileCheck %s
# RUN: ld.lld %t.o -o %t
# CHECK: .rela.debug_info {
# CHECK-NEXT: 0x0 R_AARCH64_TLS_DTPREL64 var 0x0
# CHECK-NEXT: 0x8 R_AARCH64_TLS_DTPREL64 var 0x1
# CHECK-NEXT: 0x10 R_AARCH64_TLS_DTPREL64 .tdata 0x0
# CHECK-NEXT: 0x18 R_AARCH64_TLS_DTPREL64 .tdata 0x1
# CHECK-NEXT: }
.section .tdata,"awT",@progbits
.skip 8
.globl var
var:
.word 0
.section .debug_info,"",@progbits
.xword %dtprel(var)
.xword %dtprel(var+1)
.xword %dtprel(.tdata)
.xword %dtprel(.tdata+1)