summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Writer.cpp6
-rw-r--r--lld/test/ELF/mips-tls-static.s23
2 files changed, 27 insertions, 2 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 396a2d8882d..b1c08d1fdad 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -604,8 +604,10 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
// __tls_get_addr is defined by the dynamic linker for dynamic ELFs. For
// static linking the linker is required to optimize away any references to
// __tls_get_addr, so it's not defined anywhere. Create a hidden definition
- // to avoid the undefined symbol error.
- if (!Out<ELFT>::DynSymTab)
+ // to avoid the undefined symbol error. As usual as special case is MIPS -
+ // MIPS libc defines __tls_get_addr itself because there are no TLS
+ // optimizations for this target.
+ if (!Out<ELFT>::DynSymTab && Config->EMachine != EM_MIPS)
Symtab<ELFT>::X->addIgnored("__tls_get_addr");
// If linker script do layout we do not need to create any standart symbols.
diff --git a/lld/test/ELF/mips-tls-static.s b/lld/test/ELF/mips-tls-static.s
new file mode 100644
index 00000000000..dbfd7697b24
--- /dev/null
+++ b/lld/test/ELF/mips-tls-static.s
@@ -0,0 +1,23 @@
+# Check handling TLS related relocations and symbols when linking
+# a static executable.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t
+# RUN: ld.lld -static %t -o %t.exe
+# RUN: llvm-readobj -d %t.exe | FileCheck %s
+
+# REQUIRES: mips
+
+# CHECK: LoadName
+
+ .text
+ .global __start
+__start:
+ nop
+
+ .global __tls_get_addr
+__tls_get_addr:
+ nop
+
+ .data
+loc:
+ .word __tls_get_addr
OpenPOWER on IntegriCloud