[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
Sun Jan 7 11:20:44 PST 2024


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

>From a7f93056e2dc91e06692acacd354e8c48798bad7 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

Close #77201. When linking code with a R_X86_64_TPOFF64 relocation,
LLD exits with an 'unknown relocation' 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/x86-64-tls-pie.s | 23 +++++++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)

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/x86-64-tls-pie.s b/lld/test/ELF/x86-64-tls-pie.s
index 5ef0f54f435d0c..cc49d235ea03b1 100644
--- a/lld/test/ELF/x86-64-tls-pie.s
+++ b/lld/test/ELF/x86-64-tls-pie.s
@@ -1,14 +1,23 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-cloudabi %s -o %t1.o
 # RUN: ld.lld -pie %t1.o -o %t
-# RUN: llvm-readobj -r %t | FileCheck %s
+# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOCS %s
+# RUN: llvm-objdump -d --no-show-raw-insn --no-print-imm-hex --no-leading-addr %t1.o | FileCheck --check-prefix=DIS %s
 
-# Bug 27174: R_X86_64_TPOFF32 and R_X86_64_GOTTPOFF relocations should
-# be eliminated when building a PIE executable, as the static TLS layout
-# is fixed.
+# Bug 27174: R_X86_64_TPOFF32, R_X86_86_TPOFF64, and R_X86_64_GOTTPOFF
+# relocations should be eliminated when building a PIE executable, as the static
+# TLS layout is fixed.
 #
-# CHECK:      Relocations [
-# CHECK-NEXT: ]
+# RELOCS:      Relocations [
+# RELOCS-NEXT: ]
+#
+# DIS: <_start>:
+# DIS-NEXT:                movq    %fs:0, %rax
+# DIS-NEXT:                movl    $3, (%rax)
+# DIS-NEXT:                movq    %fs:0, %rdx
+# DIS-NEXT:                movq    (%rip), %rcx            # 0x23 <_start+0x23>
+# DIS-NEXT:                movl    $3, (%rdx,%rcx)
+# DIS-NEXT:                movabsq 0, %rax
 
 	.globl	_start
 _start:
@@ -19,6 +28,8 @@ _start:
 	movq	i at GOTTPOFF(%rip), %rcx
 	movl	$3, (%rdx,%rcx)
 
+	movabs  i at TPOFF, %rax
+
 	.section	.tbss.i,"awT", at nobits
 	.globl	i
 i:



More information about the llvm-commits mailing list