[lld] 2b15308 - [ELF] Set DF_STATIC_TLS for AArch64/PPC32/PPC64

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 16 12:08:17 PDT 2022


Author: Fangrui Song
Date: 2022-10-16T12:08:08-07:00
New Revision: 2b153088be4ae35b0ee76c54a85cc0b9eb416e88

URL: https://github.com/llvm/llvm-project/commit/2b153088be4ae35b0ee76c54a85cc0b9eb416e88
DIFF: https://github.com/llvm/llvm-project/commit/2b153088be4ae35b0ee76c54a85cc0b9eb416e88.diff

LOG: [ELF] Set DF_STATIC_TLS for AArch64/PPC32/PPC64

Added: 
    

Modified: 
    lld/ELF/Arch/Hexagon.cpp
    lld/ELF/Arch/RISCV.cpp
    lld/ELF/Arch/X86.cpp
    lld/ELF/Arch/X86_64.cpp
    lld/ELF/Config.h
    lld/ELF/Relocations.cpp
    lld/ELF/SyntheticSections.cpp
    lld/test/ELF/aarch64-tls-ie.s
    lld/test/ELF/arm-tls-ie32.s
    lld/test/ELF/ppc32-tls-ie.s
    lld/test/ELF/ppc64-tls-ie.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index 567ef0b4370ba..bc26653697c78 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -145,7 +145,6 @@ RelExpr Hexagon::getRelExpr(RelType type, const Symbol &s,
   case R_HEX_IE_GOT_32_6_X:
   case R_HEX_IE_GOT_HI16:
   case R_HEX_IE_GOT_LO16:
-    config->hasTlsIe = true;
     return R_GOTPLT;
   case R_HEX_TPREL_11_X:
   case R_HEX_TPREL_16:

diff  --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 347784bb080df..7207db0c6fe6c 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -284,7 +284,6 @@ RelExpr RISCV::getRelExpr(const RelType type, const Symbol &s,
   case R_RISCV_TLS_GD_HI20:
     return R_TLSGD_PC;
   case R_RISCV_TLS_GOT_HI20:
-    config->hasTlsIe = true;
     return R_GOT_PC;
   case R_RISCV_TPREL_HI20:
   case R_RISCV_TPREL_LO12_I:

diff  --git a/lld/ELF/Arch/X86.cpp b/lld/ELF/Arch/X86.cpp
index d4c2f9aa9489a..d136d45d9e555 100644
--- a/lld/ELF/Arch/X86.cpp
+++ b/lld/ELF/Arch/X86.cpp
@@ -77,9 +77,6 @@ int X86::getTlsGdRelaxSkip(RelType type) const {
 
 RelExpr X86::getRelExpr(RelType type, const Symbol &s,
                         const uint8_t *loc) const {
-  if (type == R_386_TLS_IE || type == R_386_TLS_GOTIE)
-    config->hasTlsIe = true;
-
   switch (type) {
   case R_386_8:
   case R_386_16:

diff  --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp
index e7fb229e08e08..3fe73aeb27541 100644
--- a/lld/ELF/Arch/X86_64.cpp
+++ b/lld/ELF/Arch/X86_64.cpp
@@ -317,9 +317,6 @@ bool X86_64::deleteFallThruJmpInsn(InputSection &is, InputFile *file,
 
 RelExpr X86_64::getRelExpr(RelType type, const Symbol &s,
                            const uint8_t *loc) const {
-  if (type == R_X86_64_GOTTPOFF)
-    config->hasTlsIe = true;
-
   switch (type) {
   case R_X86_64_8:
   case R_X86_64_16:

diff  --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 1a69bd867fb42..9e7b93064ef23 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -436,6 +436,8 @@ struct Ctx {
       backwardReferences;
   // True if SHT_LLVM_SYMPART is used.
   std::atomic<bool> hasSympart{false};
+  // True if there are TLS IE relocations. Set DF_STATIC_TLS if -shared.
+  std::atomic<bool> hasTlsIe{false};
   // True if we need to reserve two .got entries for local-dynamic TLS model.
   std::atomic<bool> needsTlsLd{false};
 

diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 7e03fc5ffb137..aa930e2df2f0c 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1283,6 +1283,7 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
 
   if (oneof<R_GOT, R_GOTPLT, R_GOT_PC, R_AARCH64_GOT_PAGE_PC, R_GOT_OFF,
             R_TLSIE_HINT>(expr)) {
+    ctx.hasTlsIe.store(true, std::memory_order_relaxed);
     // Initial-Exec relocs can be relaxed to Local-Exec if the symbol is locally
     // defined.
     if (toExecRelax && isLocalInExecutable) {

diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 50478e7dcb02b..1297811c7b814 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1348,7 +1348,7 @@ DynamicSection<ELFT>::computeContents() {
   }
   if (!config->zText)
     dtFlags |= DF_TEXTREL;
-  if (config->hasTlsIe && config->shared)
+  if (ctx.hasTlsIe && config->shared)
     dtFlags |= DF_STATIC_TLS;
 
   if (dtFlags)

diff  --git a/lld/test/ELF/aarch64-tls-ie.s b/lld/test/ELF/aarch64-tls-ie.s
index c1b4dce9653d3..4e1b52a089e36 100644
--- a/lld/test/ELF/aarch64-tls-ie.s
+++ b/lld/test/ELF/aarch64-tls-ie.s
@@ -8,15 +8,16 @@
 # RUN: llvm-readobj -d -r %t | FileCheck %s --check-prefix=LE-REL
 # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefix=LE
 
+# IE-REL:      FLAGS STATIC_TLS
 # IE-REL:      .rela.dyn {
-# IE-REL-NEXT:   0x20380 R_AARCH64_TLS_TPREL64 - 0xC
-# IE-REL-NEXT:   0x20378 R_AARCH64_TLS_TPREL64 a 0x0
+# IE-REL-NEXT:   0x20390 R_AARCH64_TLS_TPREL64 - 0xC
+# IE-REL-NEXT:   0x20388 R_AARCH64_TLS_TPREL64 a 0x0
 # IE-REL-NEXT: }
 
 # IE:          adrp    x0, 0x20000
-# IE-NEXT:     ldr     x0, [x0, #0x378]
+# IE-NEXT:     ldr     x0, [x0, #0x388]
 # IE-NEXT:     adrp    x1, 0x20000
-# IE-NEXT:     ldr     x1, [x1, #0x380]
+# IE-NEXT:     ldr     x1, [x1, #0x390]
 
 # LE-REL-NOT:  FLAGS
 # LE-REL:      Relocations [

diff  --git a/lld/test/ELF/arm-tls-ie32.s b/lld/test/ELF/arm-tls-ie32.s
index e203cdd16d76c..7260700bae527 100644
--- a/lld/test/ELF/arm-tls-ie32.s
+++ b/lld/test/ELF/arm-tls-ie32.s
@@ -1,7 +1,7 @@
 // REQUIRES: arm
 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi
 // RUN: ld.lld %t.o -o %t.so -shared
-// RUN: llvm-readobj -S --dyn-relocations %t.so | FileCheck --check-prefix=SEC %s
+// RUN: llvm-readobj -S -d --dyn-relocations %t.so | FileCheck --check-prefix=SEC %s
 // RUN: llvm-objdump -d --triple=armv7a-linux-gnueabi %t.so | FileCheck %s
 
 /// Test the handling of the initial-exec TLS model. Relative location within
@@ -73,14 +73,15 @@ x:
 // SEC-NEXT:    SHF_ALLOC
 // SEC-NEXT:    SHF_WRITE
 // SEC-NEXT: ]
-// SEC-NEXT: Address: 0x20254
+// SEC-NEXT: Address: 0x2025C
 // SEC:      Size: 12
 
 
+// SEC: FLAGS STATIC_TLS
 // SEC: Dynamic Relocations {
-// SEC:  0x2025C R_ARM_TLS_TPOFF32
-// SEC:  0x20254 R_ARM_TLS_TPOFF32 x
-// SEC:  0x20258 R_ARM_TLS_TPOFF32 y
+// SEC:  0x20264 R_ARM_TLS_TPOFF32
+// SEC:  0x2025C R_ARM_TLS_TPOFF32 x
+// SEC:  0x20260 R_ARM_TLS_TPOFF32 y
 
 // CHECK: Disassembly of section .text:
 // CHECK-EMPTY:
@@ -89,9 +90,9 @@ x:
 // CHECK-NEXT:    101ec: e320f000        nop
 // CHECK-NEXT:    101f0: e320f000        nop
 
-/// (0x20254 - 0x101f4) + (0x101f4 - 0x101e8 - 8) = 0x10064
-// CHECK:         101f4: 64 00 01 00
-/// (0x20258 - 0x101f8) + (0x101f8 - 0x101ec - 8) = 0x10064
-// CHECK-NEXT:    101f8: 64 00 01 00
-/// (0x2025c - 0x101f8) + (0x101f8 - 0x101f0 - 8) = 0x10064
-// CHECK-NEXT:    101fc: 64 00 01 00
+/// (0x20264 - 0x101f4) + (0x101f4 - 0x101e8 - 8) = 0x1006c
+// CHECK:         101f4: 6c 00 01 00
+/// (0x2025C - 0x101f8) + (0x101f8 - 0x101ec - 8) = 0x1006c
+// CHECK-NEXT:    101f8: 6c 00 01 00
+/// (0x20260 - 0x101f8) + (0x101f8 - 0x101f0 - 8) = 0x1006c
+// CHECK-NEXT:    101fc: 6c 00 01 00

diff  --git a/lld/test/ELF/ppc32-tls-ie.s b/lld/test/ELF/ppc32-tls-ie.s
index 91571294fc517..f9f46452484a6 100644
--- a/lld/test/ELF/ppc32-tls-ie.s
+++ b/lld/test/ELF/ppc32-tls-ie.s
@@ -2,17 +2,18 @@
 # RUN: llvm-mc -filetype=obj -triple=powerpc %s -o %t.o
 
 # RUN: ld.lld -shared %t.o -o %t.so
-# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=IE-REL %s
+# RUN: llvm-readobj -d -r %t.so | FileCheck --check-prefix=IE-REL %s
 # RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=IE %s
 
 # RUN: ld.lld %t.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
 
+# IE-REL:      FLAGS STATIC_TLS
 ## A non-preemptable symbol (b) has 0 st_shndx.
 # IE-REL:      .rela.dyn {
-# IE-REL-NEXT:   0x20230 R_PPC_TPREL32 - 0xC
-# IE-REL-NEXT:   0x2022C R_PPC_TPREL32 a 0x0
+# IE-REL-NEXT:   0x20238 R_PPC_TPREL32 - 0xC
+# IE-REL-NEXT:   0x20234 R_PPC_TPREL32 a 0x0
 # IE-REL-NEXT: }
 
 ## &.got[3] - _GLOBAL_OFFSET_TABLE_ = 12

diff  --git a/lld/test/ELF/ppc64-tls-ie.s b/lld/test/ELF/ppc64-tls-ie.s
index 5a778f2296fe7..8c03ba292ca6b 100644
--- a/lld/test/ELF/ppc64-tls-ie.s
+++ b/lld/test/ELF/ppc64-tls-ie.s
@@ -4,7 +4,7 @@
 # RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=INPUT-REL %s
 ## IE
 # RUN: ld.lld -shared %t.o -o %t.so
-# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=IE-REL %s
+# RUN: llvm-readobj -d -r %t.so | FileCheck --check-prefix=IE-REL %s
 # RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=IE %s
 ## IE -> LE
 # RUN: ld.lld %t.o -o %t
@@ -15,18 +15,19 @@
 # RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=INPUT-REL %s
 ## IE
 # RUN: ld.lld -shared %t.o -o %t.so
-# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=IE-REL %s
+# RUN: llvm-readobj -d -r %t.so | FileCheck --check-prefix=IE-REL %s
 # RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=IE %s
 ## IE -> LE
 # RUN: ld.lld %t.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
 
+# IE-REL:      FLAGS STATIC_TLS
 # IE-REL:      .rela.dyn {
-# IE-REL-NEXT:   0x204A8 R_PPC64_TPREL64 c 0x0
-# IE-REL-NEXT:   0x204B0 R_PPC64_TPREL64 s 0x0
-# IE-REL-NEXT:   0x204B8 R_PPC64_TPREL64 i 0x0
-# IE-REL-NEXT:   0x204C0 R_PPC64_TPREL64 l 0x0
+# IE-REL-NEXT:   0x204B8 R_PPC64_TPREL64 c 0x0
+# IE-REL-NEXT:   0x204C0 R_PPC64_TPREL64 s 0x0
+# IE-REL-NEXT:   0x204C8 R_PPC64_TPREL64 i 0x0
+# IE-REL-NEXT:   0x204D0 R_PPC64_TPREL64 l 0x0
 # IE-REL-NEXT: }
 
 # INPUT-REL: R_PPC64_GOT_TPREL16_HA c 0x0


        


More information about the llvm-commits mailing list