[lld] r353378 - [LLD][ELF] - Set DF_STATIC_TLS flag for X64 target
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 6 23:59:43 PST 2019
Author: grimar
Date: Wed Feb 6 23:59:43 2019
New Revision: 353378
URL: http://llvm.org/viewvc/llvm-project?rev=353378&view=rev
Log:
[LLD][ELF] - Set DF_STATIC_TLS flag for X64 target
This is the same as D57749, but for x64 target.
"ELF Handling For Thread-Local Storage" p41 says (https://www.akkadia.org/drepper/tls.pdf):
R_X86_64_GOTTPOFF relocation is used for IE TLS models.
Hence if linker sees this relocation we should add DF_STATIC_TLS flag.
Differential revision: https://reviews.llvm.org/D57821
Added:
lld/trunk/test/ELF/x86-64-static-tls-model.s
Modified:
lld/trunk/ELF/Arch/X86_64.cpp
lld/trunk/test/ELF/tls-dynamic.s
lld/trunk/test/ELF/tls-got.s
lld/trunk/test/ELF/tls-initial-exec-local.s
Modified: lld/trunk/ELF/Arch/X86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86_64.cpp?rev=353378&r1=353377&r2=353378&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86_64.cpp (original)
+++ lld/trunk/ELF/Arch/X86_64.cpp Wed Feb 6 23:59:43 2019
@@ -81,6 +81,9 @@ int X86_64<ELFT>::getTlsGdRelaxSkip(RelT
template <class ELFT>
RelExpr X86_64<ELFT>::getRelExpr(RelType Type, const Symbol &S,
const uint8_t *Loc) const {
+ if (Type == R_X86_64_GOTTPOFF)
+ Config->HasStaticTlsModel = true;
+
switch (Type) {
case R_X86_64_8:
case R_X86_64_16:
Modified: lld/trunk/test/ELF/tls-dynamic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/tls-dynamic.s?rev=353378&r1=353377&r2=353378&view=diff
==============================================================================
--- lld/trunk/test/ELF/tls-dynamic.s (original)
+++ lld/trunk/test/ELF/tls-dynamic.s Wed Feb 6 23:59:43 2019
@@ -48,28 +48,28 @@ c:
// CHECK-NEXT: SHF_ALLOC
// CHECK-NEXT: SHF_WRITE
// CHECK-NEXT: ]
-// CHECK-NEXT: Address: 0x30D0
+// CHECK-NEXT: Address: 0x30E0
// CHECK-NEXT: Offset:
// CHECK-NEXT: Size: 40
// CHECK: Relocations [
// CHECK: Section ({{.+}}) .rela.dyn {
-// CHECK-NEXT: 0x30D0 R_X86_64_DTPMOD64 - 0x0
-// CHECK-NEXT: 0x30E0 R_X86_64_DTPMOD64 c 0x0
-// CHECK-NEXT: 0x30E8 R_X86_64_DTPOFF64 c 0x0
-// CHECK-NEXT: 0x30F0 R_X86_64_TPOFF64 c 0x0
+// CHECK-NEXT: 0x30E0 R_X86_64_DTPMOD64 - 0x0
+// CHECK-NEXT: 0x30F0 R_X86_64_DTPMOD64 c 0x0
+// CHECK-NEXT: 0x30F8 R_X86_64_DTPOFF64 c 0x0
+// CHECK-NEXT: 0x3100 R_X86_64_TPOFF64 c 0x0
// CHECK-NEXT: }
-// 4297 = (0x20D0 + -4) - (0x1000 + 3) // PC relative offset to got entry.
-// 4285 = (0x20D0 + -4) - (0x100c + 3) // PC relative offset to got entry.
-// 4267 = (0x20E0 + -4) - (0x102e + 3) // PC relative offset to got entry.
-// 4263 = (0x20F0 + -4) - (0x1042 + 3) // PC relative offset to got entry.
+// 8409 = (0x30E0 + -4) - (0x1000 + 3) // PC relative offset to got entry.
+// 8397 = (0x30F0 + -4) - (0x100c + 3) // PC relative offset to got entry.
+// 8379 = (0x30F8 + -4) - (0x102e + 3) // PC relative offset to got entry.
+// 8375 = (0x3100 + -4) - (0x1042 + 3) // PC relative offset to got entry.
// DIS: Disassembly of section .text:
// DIS-NEXT: .text:
-// DIS-NEXT: 1000: {{.+}} leaq 8393(%rip), %rdi
+// DIS-NEXT: 1000: {{.+}} leaq 8409(%rip), %rdi
// DIS-NEXT: 1007: {{.+}} callq
-// DIS-NEXT: 100c: {{.+}} leaq 8381(%rip), %rdi
+// DIS-NEXT: 100c: {{.+}} leaq 8397(%rip), %rdi
// DIS-NEXT: 1013: {{.+}} callq
// DIS-NEXT: 1018: {{.+}} leaq (%rax), %rcx
// DIS-NEXT: 101f: {{.+}} leaq 4(%rax), %rcx
@@ -77,10 +77,10 @@ c:
// DIS-NEXT: 1028: 00 00
// DIS-NEXT: 102a: 00 00
// DIS-NEXT: 102c: 00 00
-// DIS-NEXT: 102e: {{.+}} leaq 8363(%rip), %rdi
+// DIS-NEXT: 102e: {{.+}} leaq 8379(%rip), %rdi
// DIS-NEXT: 1035: {{.+}} callq
// DIS-NEXT: 103b: {{.+}} leaq (%rax), %rcx
-// DIS-NEXT: 1042: {{.+}} movq 8359(%rip), %rax
+// DIS-NEXT: 1042: {{.+}} movq 8375(%rip), %rax
// DIS-NEXT: 1049: {{.+}} movq %fs:(%rax), %rax
// DIS-NEXT: 104d: {{.+}} movabsq $0, %rax
// DIS-NEXT: 1057: {{.+}} movabsq $4, %rax
Modified: lld/trunk/test/ELF/tls-got.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/tls-got.s?rev=353378&r1=353377&r2=353378&view=diff
==============================================================================
--- lld/trunk/test/ELF/tls-got.s (original)
+++ lld/trunk/test/ELF/tls-got.s Wed Feb 6 23:59:43 2019
@@ -15,7 +15,7 @@
// CHECK-NEXT: SHF_WRITE
// CHECK-NEXT: ]
// CHECK-NEXT: Address: [[ADDR:.*]]
-// CHECK-NEXT: Offset: 0x20B0
+// CHECK-NEXT: Offset: 0x20C0
// CHECK-NEXT: Size: 16
// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 0
@@ -25,23 +25,23 @@
// CHECK: Relocations [
// CHECK-NEXT: Section (4) .rela.dyn {
-// CHECK-NEXT: 0x2020B8 R_X86_64_TPOFF64 tls0 0x0
-// CHECK-NEXT: 0x2020B0 R_X86_64_TPOFF64 tls1 0x0
+// CHECK-NEXT: 0x2020C8 R_X86_64_TPOFF64 tls0 0x0
+// CHECK-NEXT: [[ADDR]] R_X86_64_TPOFF64 tls1 0x0
// CHECK-NEXT: }
// CHECK-NEXT: ]
-//0x201000 + 4265 + 7 = 0x2020B0
-//0x20100A + 4263 + 7 = 0x2020B8
-//0x201014 + 4253 + 7 = 0x2020B8
+//0x201000 + 4281 + 7 = 0x2020C0
+//0x20100A + 4279 + 7 = 0x2020C8
+//0x201014 + 4269 + 7 = 0x2020C8
//DISASM: Disassembly of section .text:
//DISASM-NEXT: main:
-//DISASM-NEXT: 201000: 48 8b 05 a9 10 00 00 movq 4265(%rip), %rax
-//DISASM-NEXT: 201007: 64 8b 00 movl %fs:(%rax), %eax
-//DISASM-NEXT: 20100a: 48 8b 05 a7 10 00 00 movq 4263(%rip), %rax
-//DISASM-NEXT: 201011: 64 8b 00 movl %fs:(%rax), %eax
-//DISASM-NEXT: 201014: 48 8b 05 9d 10 00 00 movq 4253(%rip), %rax
-//DISASM-NEXT: 20101b: 64 8b 00 movl %fs:(%rax), %eax
-//DISASM-NEXT: 20101e: c3 retq
+//DISASM-NEXT: 201000: {{.*}} movq 4281(%rip), %rax
+//DISASM-NEXT: 201007: {{.*}} movl %fs:(%rax), %eax
+//DISASM-NEXT: 20100a: {{.*}} movq 4279(%rip), %rax
+//DISASM-NEXT: 201011: {{.*}} movl %fs:(%rax), %eax
+//DISASM-NEXT: 201014: {{.*}} movq 4269(%rip), %rax
+//DISASM-NEXT: 20101b: {{.*}} movl %fs:(%rax), %eax
+//DISASM-NEXT: 20101e: {{.*}} retq
.section .tdata,"awT", at progbits
Modified: lld/trunk/test/ELF/tls-initial-exec-local.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/tls-initial-exec-local.s?rev=353378&r1=353377&r2=353378&view=diff
==============================================================================
--- lld/trunk/test/ELF/tls-initial-exec-local.s (original)
+++ lld/trunk/test/ELF/tls-initial-exec-local.s Wed Feb 6 23:59:43 2019
@@ -10,21 +10,21 @@
// CHECK-NEXT: SHF_ALLOC (0x2)
// CHECK-NEXT: SHF_WRITE (0x1)
// CHECK-NEXT: ]
-// CHECK-NEXT: Address: 0x2090
+// CHECK-NEXT: Address: 0x20A0
// CHECK: Relocations [
// CHECK-NEXT: Section ({{.*}}) .rela.dyn {
-// CHECK-NEXT: 0x2090 R_X86_64_TPOFF64 - 0x0
-// CHECK-NEXT: 0x2098 R_X86_64_TPOFF64 - 0x4
+// CHECK-NEXT: 0x20A0 R_X86_64_TPOFF64 - 0x0
+// CHECK-NEXT: 0x20A8 R_X86_64_TPOFF64 - 0x4
// CHECK-NEXT: }
// CHECK-NEXT: ]
-// 0x1007 + 4233 = 0x2090
-// 0x100e + 4234 = 0x2098
+// 0x1007 + 4249 = 0x20A0
+// 0x100e + 4250 = 0x20A8
// DISASM: Disassembly of section .text:
// DISASM-NEXT: .text:
-// DISASM-NEXT: 1000: {{.*}} addq 4233(%rip), %rax
-// DISASM-NEXT: 1007: {{.*}} addq 4234(%rip), %rax
+// DISASM-NEXT: 1000: {{.*}} addq 4249(%rip), %rax
+// DISASM-NEXT: 1007: {{.*}} addq 4250(%rip), %rax
addq foo at GOTTPOFF(%rip), %rax
addq bar at GOTTPOFF(%rip), %rax
Added: lld/trunk/test/ELF/x86-64-static-tls-model.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-static-tls-model.s?rev=353378&view=auto
==============================================================================
--- lld/trunk/test/ELF/x86-64-static-tls-model.s (added)
+++ lld/trunk/test/ELF/x86-64-static-tls-model.s Wed Feb 6 23:59:43 2019
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+
+## In this test R_X86_64_GOTTPOFF is a IE relocation (static TLS model),
+## test check we add STATIC_TLS flag.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t1 -shared
+# RUN: llvm-readobj -dynamic-table %t1 | FileCheck %s
+
+# CHECK: DynamicSection [
+# CHECK: FLAGS STATIC_TLS
+
+.section ".tdata", "awT", @progbits
+.globl var
+var:
+
+movq var at GOTTPOFF(%rip), %rax # R_X86_64_GOTTPOFF
+movl %fs:0(%rax), %eax
More information about the llvm-commits
mailing list