[lld] [lld][ELF][X86] Add missing X86_64_TPOFF64 case in switches (PR #77208)

Nicholas Mosier via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 6 12:18:22 PST 2024


https://github.com/nmosier created https://github.com/llvm/llvm-project/pull/77208

This patch fixes GitHub issue #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.

>From 7f1b477d7fc2d9a2ccec0d51143bed56098e2e7f Mon Sep 17 00:00:00 2001
From: Nicholas Mosier <nmosier at stanford.edu>
Date: Sat, 6 Jan 2024 20:13:18 +0000
Subject: [PATCH] [lld][ELF][X86] Add missing X86_64_TPOFF64 case in switches

This patch fixes GitHub issue #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.
---
 lld/ELF/Arch/X86_64.cpp      |  2 ++
 lld/test/ELF/tls-largecode.s | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 lld/test/ELF/tls-largecode.s

diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp
index 2135ac23486451..c28e01e4819584 100644
--- a/lld/ELF/Arch/X86_64.cpp
+++ b/lld/ELF/Arch/X86_64.cpp
@@ -358,6 +358,7 @@ RelExpr X86_64::getRelExpr(RelType type, const Symbol &s,
   case R_X86_64_DTPOFF64:
     return R_DTPREL;
   case R_X86_64_TPOFF32:
+  case R_X86_64_TPOFF64:
     return R_TPREL;
   case R_X86_64_TLSDESC_CALL:
     return R_TLSDESC_CALL;
@@ -791,6 +792,7 @@ void X86_64::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
     write32le(loc, val);
     break;
   case R_X86_64_64:
+  case R_X86_64_TPOFF64:
   case R_X86_64_DTPOFF64:
   case R_X86_64_PC64:
   case R_X86_64_SIZE64:
diff --git a/lld/test/ELF/tls-largecode.s b/lld/test/ELF/tls-largecode.s
new file mode 100644
index 00000000000000..9de4b7c7e9449b
--- /dev/null
+++ b/lld/test/ELF/tls-largecode.s
@@ -0,0 +1,32 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+// RUN: ld.lld %t -o %tout
+
+	.text
+	.file	"large.c"
+	.section	.ltext,"axl", at progbits
+	.globl	main                            # -- Begin function main
+	.p2align	4, 0x90
+	.type	main, at function
+main:                                   # @main
+	.cfi_startproc
+# %bb.0:                                # %entry
+	movabsq	$x at TPOFF, %rax
+	movl	$0, %fs:(%rax)
+	xorl	%eax, %eax
+	retq
+.Lfunc_end0:
+	.size	main, .Lfunc_end0-main
+	.cfi_endproc
+                                        # -- End function
+	.type	x, at object                       # @x
+	.section	.tbss,"awT", at nobits
+	.globl	x
+	.p2align	2, 0x0
+x:
+	.long	0                               # 0x0
+	.size	x, 4
+
+	.ident	"clang version 18.0.0git (git at github.com:nmosier/llvm-project.git 7a8d700563cac95b555bdfbe16329ed24b316ea7)"
+	.section	".note.GNU-stack","", at progbits
+	.addrsig



More information about the llvm-commits mailing list