[lld] 1d50501 - [ELF][MIPS] Don't emit dynamic relocations for PIE non-preemptible TLS

Jessica Clarke via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 27 11:05:00 PDT 2021


Author: Jessica Clarke
Date: 2021-04-27T19:04:50+01:00
New Revision: 1d505016efa29ce1e9b11baf8ab2d7950e9bdcc7

URL: https://github.com/llvm/llvm-project/commit/1d505016efa29ce1e9b11baf8ab2d7950e9bdcc7
DIFF: https://github.com/llvm/llvm-project/commit/1d505016efa29ce1e9b11baf8ab2d7950e9bdcc7.diff

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

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.

Reviewed By: MaskRay, atanasyan

Differential Revision: https://reviews.llvm.org/D101382

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index cd81aa657701..818bbdd0d42a 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1005,7 +1005,7 @@ void MipsGotSection::build() {
       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 @@ void MipsGotSection::build() {
         // 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 @@ void MipsGotSection::writeTo(uint8_t *buf) {
     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);
       }

diff  --git a/lld/test/ELF/mips-tls-64.s b/lld/test/ELF/mips-tls-64.s
index a3657cea51c0..5f22156ab531 100644
--- a/lld/test/ELF/mips-tls-64.s
+++ b/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

diff  --git a/lld/test/ELF/mips-tls.s b/lld/test/ELF/mips-tls.s
index 4463ec114d48..4976ec3ecbcd 100644
--- a/lld/test/ELF/mips-tls.s
+++ b/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


        


More information about the llvm-commits mailing list