[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:23:34 PDT 2021


jrtc27 updated this revision to Diff 340903.
jrtc27 added a comment.

Use the more conventional .pie rather than -pie.exe for the tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101382/new/

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
+# RUN: llvm-objdump -d -s -t --no-show-raw-insn %t.pie \
+# RUN:   | FileCheck -check-prefix=DIS %s
+# RUN: llvm-readobj -r -A %t.pie | 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
+# RUN: llvm-objdump -d -s -t --no-show-raw-insn %t.pie \
+# RUN:   | FileCheck -check-prefix=DIS %s
+# RUN: llvm-readobj -r -A %t.pie | 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.340903.patch
Type: text/x-patch
Size: 3194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210427/4c68bd00/attachment.bin>


More information about the llvm-commits mailing list