[lld] 6ca8fde - [ELF] Emit DF_STATIC_TLS only for -shared
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 24 23:17:23 PST 2021
Author: Fangrui Song
Date: 2021-11-24T23:17:13-08:00
New Revision: 6ca8fde226e907db13bc538e721af8724f0e92d0
URL: https://github.com/llvm/llvm-project/commit/6ca8fde226e907db13bc538e721af8724f0e92d0
DIFF: https://github.com/llvm/llvm-project/commit/6ca8fde226e907db13bc538e721af8724f0e92d0.diff
LOG: [ELF] Emit DF_STATIC_TLS only for -shared
This matches GNU ld and saves 2 words for executables.
Added:
Modified:
lld/ELF/SyntheticSections.cpp
lld/test/ELF/i386-tls-opt-iele-nopic.s
lld/test/ELF/x86-64-static-tls-model.s
lld/test/ELF/x86-64-tls-ie.s
Removed:
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index a47b8d758305b..78d41e583e81d 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1382,7 +1382,7 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
}
if (!config->zText)
dtFlags |= DF_TEXTREL;
- if (config->hasTlsIe)
+ if (config->hasTlsIe && config->shared)
dtFlags |= DF_STATIC_TLS;
if (dtFlags)
diff --git a/lld/test/ELF/i386-tls-opt-iele-nopic.s b/lld/test/ELF/i386-tls-opt-iele-nopic.s
index 641552d1b9e41..8dd0cf69f9549 100644
--- a/lld/test/ELF/i386-tls-opt-iele-nopic.s
+++ b/lld/test/ELF/i386-tls-opt-iele-nopic.s
@@ -14,8 +14,8 @@
// GOTREL-NEXT: SHF_ALLOC
// GOTREL-NEXT: SHF_WRITE
// GOTREL-NEXT: ]
-// GOTREL-NEXT: Address: 0x402258
-// GOTREL-NEXT: Offset: 0x258
+// GOTREL-NEXT: Address: 0x402250
+// GOTREL-NEXT: Offset: 0x250
// GOTREL-NEXT: Size: 8
// GOTREL-NEXT: Link: 0
// GOTREL-NEXT: Info: 0
@@ -24,8 +24,8 @@
// GOTREL-NEXT: }
// GOTREL: Relocations [
// GOTREL-NEXT: Section ({{.*}}) .rel.dyn {
-// GOTREL-NEXT: 0x402258 R_386_TLS_TPOFF tlsshared0
-// GOTREL-NEXT: 0x40225C R_386_TLS_TPOFF tlsshared1
+// GOTREL-NEXT: 0x402250 R_386_TLS_TPOFF tlsshared0
+// GOTREL-NEXT: 0x402254 R_386_TLS_TPOFF tlsshared1
// GOTREL-NEXT: }
// GOTREL-NEXT: ]
@@ -45,10 +45,10 @@
// DISASM-NEXT: addl $0xfffffffc, %ecx
// DISASM-NEXT: movl %gs:(%ecx), %eax
/// &.got[0]
-// DISASM-NEXT: movl 0x402258, %ecx
+// DISASM-NEXT: movl 0x402250, %ecx
// DISASM-NEXT: movl %gs:(%ecx), %eax
/// &.got[1]
-// DISASM-NEXT: addl 0x40225c, %ecx
+// DISASM-NEXT: addl 0x402254, %ecx
// DISASM-NEXT: movl %gs:(%ecx), %eax
.type tlslocal0, at object
diff --git a/lld/test/ELF/x86-64-static-tls-model.s b/lld/test/ELF/x86-64-static-tls-model.s
index 997def3a842c1..0908462b40b03 100644
--- a/lld/test/ELF/x86-64-static-tls-model.s
+++ b/lld/test/ELF/x86-64-static-tls-model.s
@@ -1,15 +1,19 @@
# REQUIRES: x86
## In this test R_X86_64_GOTTPOFF is a IE relocation (static TLS model),
-## test check we add STATIC_TLS flag.
+## test check we add STATIC_TLS flag for -shared.
# 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
+# RUN: ld.lld %t.o -o %t.so -shared
+# RUN: llvm-readobj --dynamic-table %t.so | FileCheck %s
+# RUN: ld.lld %t.o -o %t -pie
+# RUN: llvm-readobj --dynamic-table %t | FileCheck %s --check-prefix=EXE
# CHECK: DynamicSection [
# CHECK: FLAGS STATIC_TLS
+# EXE-NOT: FLAGS STATIC_TLS
+
.section ".tdata", "awT", @progbits
.globl var
var:
diff --git a/lld/test/ELF/x86-64-tls-ie.s b/lld/test/ELF/x86-64-tls-ie.s
index 9dd701045008f..e5510f84d5f35 100644
--- a/lld/test/ELF/x86-64-tls-ie.s
+++ b/lld/test/ELF/x86-64-tls-ie.s
@@ -15,7 +15,7 @@
// CHECK-NEXT: SHF_WRITE
// CHECK-NEXT: ]
// CHECK-NEXT: Address: [[ADDR:.*]]
-// CHECK-NEXT: Offset: 0x3C0
+// CHECK-NEXT: Offset: 0x3B0
// CHECK-NEXT: Size: 16
// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 0
@@ -26,21 +26,21 @@
// CHECK: Relocations [
// CHECK-NEXT: Section (5) .rela.dyn {
// CHECK-NEXT: [[ADDR]] R_X86_64_TPOFF64 tls1 0x0
-// CHECK-NEXT: 0x2023C8 R_X86_64_TPOFF64 tls0 0x0
+// CHECK-NEXT: 0x2023B8 R_X86_64_TPOFF64 tls0 0x0
// CHECK-NEXT: }
// CHECK-NEXT: ]
-// 0x2012d0 + 4329 + 7 = 0x2023C0
-// 0x2012dA + 4327 + 7 = 0x2023C8
-// 0x2012e4 + 4317 + 7 = 0x2023C8
+// 0x2012d0 + 4313 + 7 = 0x2023B0
+// 0x2012dA + 4311 + 7 = 0x2023B8
+// 0x2012e4 + 4301 + 7 = 0x2023B8
// DISASM: Disassembly of section .text:
// DISASM-EMPTY:
// DISASM-NEXT: <main>:
-// DISASM-NEXT: 2012d0: {{.*}} movq 4329(%rip), %rax
+// DISASM-NEXT: 2012d0: {{.*}} movq 4313(%rip), %rax
// DISASM-NEXT: 2012d7: {{.*}} movl %fs:(%rax), %eax
-// DISASM-NEXT: 2012da: {{.*}} movq 4327(%rip), %rax
+// DISASM-NEXT: 2012da: {{.*}} movq 4311(%rip), %rax
// DISASM-NEXT: 2012e1: {{.*}} movl %fs:(%rax), %eax
-// DISASM-NEXT: 2012e4: {{.*}} movq 4317(%rip), %rax
+// DISASM-NEXT: 2012e4: {{.*}} movq 4301(%rip), %rax
// DISASM-NEXT: 2012eb: {{.*}} movl %fs:(%rax), %eax
// DISASM-NEXT: 2012ee: {{.*}} retq
More information about the llvm-commits
mailing list