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

via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 6 12:19:00 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld

Author: Nicholas Mosier (nmosier)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/77208.diff


2 Files Affected:

- (modified) lld/ELF/Arch/X86_64.cpp (+2) 
- (added) lld/test/ELF/tls-largecode.s (+32) 


``````````diff
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

``````````

</details>


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


More information about the llvm-commits mailing list