Skip to content

Commit 14ce208

Browse files
authored
[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.
1 parent e1aef5e commit 14ce208

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎lld/ELF/Arch/AArch64.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ RelExpr AArch64::getRelExpr(RelType type, const Symbol &s,
156156
case R_AARCH64_PREL32:
157157
case R_AARCH64_PREL64:
158158
return R_PC;
159+
case R_AARCH64_TLS_DTPREL64:
160+
return R_DTPREL;
159161
case R_AARCH64_NONE:
160162
return R_NONE;
161163
default:
@@ -649,6 +651,9 @@ void AArch64::relocate(uint8_t *loc, const Relocation &rel,
649651
checkInt(ctx, loc, val, 32, rel);
650652
write32(ctx, loc, val);
651653
break;
654+
case R_AARCH64_TLS_DTPREL64:
655+
write64(ctx, loc, val);
656+
break;
652657
case R_AARCH64_ADD_ABS_LO12_NC:
653658
case R_AARCH64_AUTH_GOT_ADD_LO12_NC:
654659
write32Imm12(loc, val);

‎lld/test/ELF/aarch64-tls-dtprel.s‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# REQUIRES: aarch64
2+
# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
3+
# RUN: llvm-readobj -r %t.o | FileCheck %s
4+
# RUN: ld.lld %t.o -o %t
5+
6+
# CHECK: .rela.debug_info {
7+
# CHECK-NEXT: 0x0 R_AARCH64_TLS_DTPREL64 var 0x0
8+
# CHECK-NEXT: 0x8 R_AARCH64_TLS_DTPREL64 var 0x1
9+
# CHECK-NEXT: 0x10 R_AARCH64_TLS_DTPREL64 .tdata 0x0
10+
# CHECK-NEXT: 0x18 R_AARCH64_TLS_DTPREL64 .tdata 0x1
11+
# CHECK-NEXT: }
12+
13+
.section .tdata,"awT",@progbits
14+
.skip 8
15+
.globl var
16+
var:
17+
.word 0
18+
19+
.section .debug_info,"",@progbits
20+
.xword %dtprel(var)
21+
.xword %dtprel(var+1)
22+
.xword %dtprel(.tdata)
23+
.xword %dtprel(.tdata+1)

0 commit comments

Comments
 (0)