[lld] r249365 - [elf2] Ignore __tls_get_addr when static linking.

Michael J. Spencer via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 17:45:43 PDT 2015


Author: mspencer
Date: Mon Oct  5 19:45:42 2015
New Revision: 249365

URL: http://llvm.org/viewvc/llvm-project?rev=249365&view=rev
Log:
[elf2] Ignore __tls_get_addr when static linking.

Added:
    lld/trunk/test/elf2/tls-static.s
Modified:
    lld/trunk/ELF/SymbolTable.cpp

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=249365&r1=249364&r2=249365&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Mon Oct  5 19:45:42 2015
@@ -133,6 +133,13 @@ template <class ELFT> void SymbolTable::
   // 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) {

Added: lld/trunk/test/elf2/tls-static.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/tls-static.s?rev=249365&view=auto
==============================================================================
--- lld/trunk/test/elf2/tls-static.s (added)
+++ lld/trunk/test/elf2/tls-static.s Mon Oct  5 19:45:42 2015
@@ -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




More information about the llvm-commits mailing list