Skip to content

Commit c5e3598

Browse files
authored
[lld][ELF][X86] Add missing X86_64_TPOFF64 case in switches (#77208)
Close #77201. When linking code with a R_X86_64_TPOFF64 relocation, LLD exits with an 'unknown reloaction' error message due to two missing cases in relocation switch statements. This patch adds in those cases so that LLD successfully links code R_X86_64_TPOFF64 relocations.
1 parent fece981 commit c5e3598

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lld/ELF/Arch/X86_64.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ RelExpr X86_64::getRelExpr(RelType type, const Symbol &s,
358358
case R_X86_64_DTPOFF64:
359359
return R_DTPREL;
360360
case R_X86_64_TPOFF32:
361+
case R_X86_64_TPOFF64:
361362
return R_TPREL;
362363
case R_X86_64_TLSDESC_CALL:
363364
return R_TLSDESC_CALL;
@@ -791,6 +792,7 @@ void X86_64::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
791792
write32le(loc, val);
792793
break;
793794
case R_X86_64_64:
795+
case R_X86_64_TPOFF64:
794796
case R_X86_64_DTPOFF64:
795797
case R_X86_64_PC64:
796798
case R_X86_64_SIZE64:

lld/test/ELF/x86-64-tls-pie.s

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-cloudabi %s -o %t1.o
33
# RUN: ld.lld -pie %t1.o -o %t
4-
# RUN: llvm-readobj -r %t | FileCheck %s
4+
# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOCS %s
5+
# RUN: llvm-objdump -d --no-show-raw-insn --no-print-imm-hex --no-leading-addr %t1.o | FileCheck --check-prefix=DIS %s
56

67
# Bug 27174: R_X86_64_TPOFF32 and R_X86_64_GOTTPOFF relocations should
78
# be eliminated when building a PIE executable, as the static TLS layout
89
# is fixed.
910
#
10-
# CHECK: Relocations [
11-
# CHECK-NEXT: ]
11+
# RELOCS: Relocations [
12+
# RELOCS-NEXT: ]
13+
#
14+
# DIS: <_start>:
15+
# DIS-NEXT: movq %fs:0, %rax
16+
# DIS-NEXT: movl $3, (%rax)
17+
# DIS-NEXT: movq %fs:0, %rdx
18+
# DIS-NEXT: movq (%rip), %rcx
19+
# DIS-NEXT: movl $3, (%rdx,%rcx)
20+
# DIS-NEXT: movabsq 0, %rax
1221

1322
.globl _start
1423
_start:
@@ -19,6 +28,9 @@ _start:
1928
movq i@GOTTPOFF(%rip), %rcx
2029
movl $3, (%rdx,%rcx)
2130

31+
# This additionally tests support for R_X86_64_TPOFF64 relocations.
32+
movabs i@TPOFF, %rax
33+
2234
.section .tbss.i,"awT",@nobits
2335
.globl i
2436
i:

0 commit comments

Comments
 (0)