summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/SymbolTable.cpp7
-rw-r--r--lld/test/elf2/tls-static.s8
2 files changed, 15 insertions, 0 deletions
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index 14fcb3548a8..d077ce69065 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -133,6 +133,13 @@ template <class ELFT> void SymbolTable::init(uint16_t EMachine) {
// Given that the symbol is effectively unused, we just create a dummy
// hidden one to avoid the undefined symbol error.
addIgnoredSym<ELFT>("_GLOBAL_OFFSET_TABLE_");
+
+ // __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 (Config->Static)
+ addIgnoredSym<ELFT>("__tls_get_addr");
}
template <class ELFT> void SymbolTable::addELFFile(ELFFileBase *File) {
diff --git a/lld/test/elf2/tls-static.s b/lld/test/elf2/tls-static.s
new file mode 100644
index 00000000000..6d4a2a48233
--- /dev/null
+++ b/lld/test/elf2/tls-static.s
@@ -0,0 +1,8 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+// RUN: lld -flavor gnu2 -static %t -o %tout
+// REQUIRES: x86
+
+.global _start
+.text
+_start:
+ call __tls_get_addr
OpenPOWER on IntegriCloud