[PATCH] D101382: [ELF][MIPS] Don't emit dynamic relocations for PIE non-preemptible TLS

Jessica Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 27 10:20:09 PDT 2021


jrtc27 created this revision.
jrtc27 added reviewers: MaskRay, atanasyan.
Herald added subscribers: arichardson, sdardis, emaste.
jrtc27 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Whilst not wrong (unless using static PIE where the relocations are
likely not implemented by the runtime), this is inefficient, as the TLS
module indices and offsets are independent of the executable's load
address.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101382

Files:
  lld/ELF/SyntheticSections.cpp
  lld/test/ELF/mips-tls-64.s
  lld/test/ELF/mips-tls.s


Index: lld/test/ELF/mips-tls.s
===================================================================
--- lld/test/ELF/mips-tls.s
+++ lld/test/ELF/mips-tls.s
@@ -16,6 +16,11 @@
 # RUN:   | FileCheck -check-prefix=DIS %s
 # RUN: llvm-readobj -r -A %t.exe | FileCheck %s
 
+# RUN: ld.lld -pie %t.o %t.so -script %t.script -o %t-pie.exe
+# RUN: llvm-objdump -d -s -t --no-show-raw-insn %t-pie.exe \
+# RUN:   | FileCheck -check-prefix=DIS %s
+# RUN: llvm-readobj -r -A %t-pie.exe | FileCheck %s
+
 # RUN: ld.lld -shared %t.o %t.so -script %t.script -o %t-out.so
 # RUN: llvm-objdump -d -s -t --no-show-raw-insn %t-out.so \
 # RUN:   | FileCheck -check-prefix=DIS-SO %s
Index: lld/test/ELF/mips-tls-64.s
===================================================================
--- lld/test/ELF/mips-tls-64.s
+++ lld/test/ELF/mips-tls-64.s
@@ -16,6 +16,11 @@
 # RUN:   | FileCheck -check-prefix=DIS %s
 # RUN: llvm-readobj -r -A %t.exe | FileCheck %s
 
+# RUN: ld.lld -pie %t.o %t.so -script %t.script -o %t-pie.exe
+# RUN: llvm-objdump -d -s -t --no-show-raw-insn %t-pie.exe \
+# RUN:   | FileCheck -check-prefix=DIS %s
+# RUN: llvm-readobj -r -A %t-pie.exe | FileCheck %s
+
 # RUN: ld.lld -shared %t.o %t.so -script %t.script -o %t-out.so
 # RUN: llvm-objdump -d -s -t --no-show-raw-insn %t-out.so \
 # RUN:   | FileCheck -check-prefix=DIS-SO %s
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -1005,7 +1005,7 @@
       Symbol *s = p.first;
       uint64_t offset = p.second * config->wordsize;
       if (s == nullptr) {
-        if (!config->isPic)
+        if (!config->shared)
           continue;
         mainPart->relaDyn->addReloc(target->tlsModuleIndexRel, this, offset, s);
       } else {
@@ -1013,7 +1013,7 @@
         // for the module index. Therefore only checking for
         // S->isPreemptible is not sufficient (this happens e.g. for
         // thread-locals that have been marked as local through a linker script)
-        if (!s->isPreemptible && !config->isPic)
+        if (!s->isPreemptible && !config->shared)
           continue;
         mainPart->relaDyn->addReloc(target->tlsModuleIndexRel, this, offset, s);
         // However, we can skip writing the TLS offset reloc for non-preemptible
@@ -1119,13 +1119,13 @@
     for (const std::pair<Symbol *, size_t> &p : g.tls)
       write(p.second, p.first, p.first->isPreemptible ? 0 : -0x7000);
     for (const std::pair<Symbol *, size_t> &p : g.dynTlsSymbols) {
-      if (p.first == nullptr && !config->isPic)
+      if (p.first == nullptr && !config->shared)
         write(p.second, nullptr, 1);
       else if (p.first && !p.first->isPreemptible) {
-        // If we are emitting PIC code with relocations we mustn't write
+        // If we are emitting a shared libary with relocations we mustn't write
         // anything to the GOT here. When using Elf_Rel relocations the value
         // one will be treated as an addend and will cause crashes at runtime
-        if (!config->isPic)
+        if (!config->shared)
           write(p.second, nullptr, 1);
         write(p.second + 1, p.first, -0x8000);
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101382.340899.patch
Type: text/x-patch
Size: 3218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210427/127f4c81/attachment.bin>


More information about the llvm-commits mailing list