[lld] 35c3f56 - [ELF][X86] Write R_X86_64_TLSDESC addends with -z rel
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 27 09:35:37 PDT 2021
Author: Fangrui Song
Date: 2021-10-27T09:35:30-07:00
New Revision: 35c3f5610c969091359a92f31e5a2745f5d49739
URL: https://github.com/llvm/llvm-project/commit/35c3f5610c969091359a92f31e5a2745f5d49739
DIFF: https://github.com/llvm/llvm-project/commit/35c3f5610c969091359a92f31e5a2745f5d49739.diff
LOG: [ELF][X86] Write R_X86_64_TLSDESC addends with -z rel
Similar to D100544 for AArch64.
Reviewed By: arichardson
Differential Revision: https://reviews.llvm.org/D112592
Added:
Modified:
lld/ELF/Arch/X86_64.cpp
lld/test/ELF/x86-64-tlsdesc-gd.s
Removed:
################################################################################
diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp
index d42acd263ba77..4cb95d45bf02c 100644
--- a/lld/ELF/Arch/X86_64.cpp
+++ b/lld/ELF/Arch/X86_64.cpp
@@ -724,6 +724,8 @@ int64_t X86_64::getImplicitAddend(const uint8_t *buf, RelType type) const {
case R_X86_64_IRELATIVE:
case R_X86_64_RELATIVE:
return read64le(buf);
+ case R_X86_64_TLSDESC:
+ return read64le(buf + 8);
case R_X86_64_JUMP_SLOT:
case R_X86_64_NONE:
// These relocations are defined as not having an implicit addend.
@@ -785,6 +787,10 @@ void X86_64::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
case R_X86_64_PLTOFF64:
write64le(loc, val);
break;
+ case R_X86_64_TLSDESC:
+ // The addend is stored in the second 64-bit word.
+ write64le(loc + 8, val);
+ break;
default:
llvm_unreachable("unknown relocation");
}
diff --git a/lld/test/ELF/x86-64-tlsdesc-gd.s b/lld/test/ELF/x86-64-tlsdesc-gd.s
index 350b254fad078..626bad04d938f 100644
--- a/lld/test/ELF/x86-64-tlsdesc-gd.s
+++ b/lld/test/ELF/x86-64-tlsdesc-gd.s
@@ -1,12 +1,15 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
-# RUN: echo '.tbss; .globl b; b:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
+# RUN: echo '.tbss; .globl c; c: .zero 4' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
# RUN: ld.lld -shared -soname=t1.so %t1.o -o %t1.so
# RUN: ld.lld -shared %t.o %t1.o -o %t.so
-# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=GD-REL %s
+# RUN: llvm-readobj -r -x .got %t.so | FileCheck --check-prefix=GD-RELA %s
# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=GD %s
+# RUN: ld.lld -shared %t.o %t1.o -o %t-rel.so -z rel
+# RUN: llvm-readobj -r -x .got %t-rel.so | FileCheck --check-prefix=GD-REL %s
+
# RUN: ld.lld %t.o %t1.o -o %t
# RUN: llvm-readelf -r %t | FileCheck --check-prefix=NOREL %s
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s
@@ -15,43 +18,70 @@
# RUN: llvm-readobj -r %t | FileCheck --check-prefix=IE-REL %s
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=IE %s
-# GD-REL: .rela.dyn {
-# GD-REL-NEXT: 0x2380 R_X86_64_TLSDESC a 0x0
-# GD-REL-NEXT: 0x2390 R_X86_64_TLSDESC b 0x0
-# GD-REL-NEXT: }
+# GD-RELA: .rela.dyn {
+# GD-RELA-NEXT: 0x23B8 R_X86_64_TLSDESC - 0xB
+# GD-RELA-NEXT: 0x23A8 R_X86_64_TLSDESC a 0x0
+# GD-RELA-NEXT: 0x23C8 R_X86_64_TLSDESC c 0x0
+# GD-RELA-NEXT: }
+# GD-RELA: Hex dump of section '.got':
+# GD-RELA-NEXT: 0x000023a8 00000000 00000000 00000000 00000000
+# GD-RELA-NEXT: 0x000023b8 00000000 00000000 00000000 00000000
+# GD-RELA-NEXT: 0x000023c8 00000000 00000000 00000000 00000000
+
+# GD-REL: .rel.dyn {
+# GD-REL-NEXT: 0x23A0 R_X86_64_TLSDESC -
+# GD-REL-NEXT: 0x2390 R_X86_64_TLSDESC a
+# GD-REL-NEXT: 0x23B0 R_X86_64_TLSDESC c
+# GD-REL-NEXT: }
+# GD-REL: Hex dump of section '.got':
+# GD-REL-NEXT: 0x00002390 00000000 00000000 00000000 00000000
+# GD-REL-NEXT: 0x000023a0 00000000 00000000 0b000000 00000000
+# GD-REL-NEXT: 0x000023b0 00000000 00000000 00000000 00000000
+
+## &.rela.dyn[a]-pc = 0x23A8-0x12e7 = 4289
+# GD: leaq 4289(%rip), %rax
+# GD-NEXT: 12e7: callq *(%rax)
+# GD-NEXT: movl %fs:(%rax), %eax
-# 0x2380-0x12cf = 4273
-# GD: leaq 4273(%rip), %rax
-# GD-NEXT: 12cf: callq *(%rax)
+## &.rela.dyn[b]-pc = 0x23B8-0x12f3 = 4293
+# GD-NEXT: leaq 4293(%rip), %rax
+# GD-NEXT: 12f3: callq *(%rax)
# GD-NEXT: movl %fs:(%rax), %eax
-# 0x2390-0x12db = 4277
-# GD-NEXT: leaq 4277(%rip), %rax
-# GD-NEXT: 12db: callq *(%rax)
+## &.rela.dyn[c]-pc = 0x23C8-0x12f3 = 4297
+# GD-NEXT: leaq 4297(%rip), %rax
+# GD-NEXT: 12ff: callq *(%rax)
# GD-NEXT: movl %fs:(%rax), %eax
# NOREL: no relocations
-## offset(a) = -4
-# LE: movq $-4, %rax
+## tpoff(a) = st_value(a) - tls_size = -8
+# LE: movq $-8, %rax
+# LE-NEXT: nop
+# LE-NEXT: movl %fs:(%rax), %eax
+## tpoff(b) = st_value(b) - tls_size = -5
+# LE: movq $-5, %rax
# LE-NEXT: nop
# LE-NEXT: movl %fs:(%rax), %eax
-## offset(b) = 0
-# LE: movq $0, %rax
+## tpoff(c) = st_value(c) - tls_size = -4
+# LE: movq $-4, %rax
# LE-NEXT: nop
# LE-NEXT: movl %fs:(%rax), %eax
# IE-REL: .rela.dyn {
-# IE-REL-NEXT: 0x202360 R_X86_64_TPOFF64 b 0x0
+# IE-REL-NEXT: 0x202370 R_X86_64_TPOFF64 c 0x0
# IE-REL-NEXT: }
## a is relaxed to use LE.
# IE: movq $-4, %rax
# IE-NEXT: nop
# IE-NEXT: movl %fs:(%rax), %eax
-## 0x202360 - 0x20129b = 4293
-# IE-NEXT: movq 4293(%rip), %rax
-# IE-NEXT: 20129b: nop
+# IE-NEXT: movq $-1, %rax
+# IE-NEXT: nop
+# IE-NEXT: movl %fs:(%rax), %eax
+## &.rela.dyn[c]-pc = 0x202370 - 0x2012a7 = 4297
+# IE-NEXT: movq 4297(%rip), %rax
+# IE-NEXT: 2012a7: nop
# IE-NEXT: movl %fs:(%rax), %eax
leaq a at tlsdesc(%rip), %rax
@@ -62,8 +92,14 @@ leaq b at tlsdesc(%rip), %rax
call *b at tlscall(%rax)
movl %fs:(%rax), %eax
+leaq c at tlsdesc(%rip), %rax
+call *c at tlscall(%rax)
+movl %fs:(%rax), %eax
+
.section .tbss
.globl a
.zero 8
a:
-.zero 4
+.zero 3
+b:
+.zero 1
More information about the llvm-commits
mailing list