diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp --- a/lld/ELF/SyntheticSections.cpp +++ b/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 &p : g.tls) write(p.second, p.first, p.first->isPreemptible ? 0 : -0x7000); for (const std::pair &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 --- 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.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 diff --git a/lld/test/ELF/mips-tls.s b/lld/test/ELF/mips-tls.s --- 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.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