[lld] r315334 - Don't create a dummy __tls_get_addr.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 10:27:34 PDT 2017


Author: rafael
Date: Tue Oct 10 10:27:34 2017
New Revision: 315334

URL: http://llvm.org/viewvc/llvm-project?rev=315334&view=rev
Log:
Don't create a dummy __tls_get_addr.

We just don't need one with the current setup.

We only error on undefined references that are used by some
relocation.

If we managed to relax all uses of __tls_get_addr, no relocation uses
it and we don't produce an error.

This is less code and fixes the case were we fail to relax. Before we
would produce a broken output, but now we produce an error.

Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/arm-tls-norelax-gd-le.s
    lld/trunk/test/ELF/tls-static.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=315334&r1=315333&r2=315334&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Oct 10 10:27:34 2017
@@ -799,15 +799,6 @@ template <class ELFT> void Writer<ELFT>:
   ElfSym::GlobalOffsetTable = addOptionalRegular<ELFT>(
       "_GLOBAL_OFFSET_TABLE_", GotSection, Target->GotBaseSymOff);
 
-  // __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 (!InX::DynSymTab)
-    if (SymbolBody *S = Symtab->find("__tls_get_addr"))
-      if (!S->isInCurrentDSO())
-        Symtab->addAbsolute<ELFT>(S->getName(), STV_HIDDEN);
-
   // __ehdr_start is the location of ELF file headers. Note that we define
   // this symbol unconditionally even when using a linker script, which
   // differs from the behavior implemented by GNU linker which only define

Modified: lld/trunk/test/ELF/arm-tls-norelax-gd-le.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/arm-tls-norelax-gd-le.s?rev=315334&r1=315333&r2=315334&view=diff
==============================================================================
--- lld/trunk/test/ELF/arm-tls-norelax-gd-le.s (original)
+++ lld/trunk/test/ELF/arm-tls-norelax-gd-le.s Tue Oct 10 10:27:34 2017
@@ -35,3 +35,7 @@ x:
 // Module index is always 1 for executable
 // CHECK-NEXT:  13060 01000000 00000000
 
+
+// Without any definition of __tls_get_addr we get an error
+// RUN: not ld.lld  %t.o -o %t 2>&1 | FileCheck --check-prefix=ERR %s
+// ERR: error: undefined symbol: __tls_get_addr

Modified: lld/trunk/test/ELF/tls-static.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/tls-static.s?rev=315334&r1=315333&r2=315334&view=diff
==============================================================================
--- lld/trunk/test/ELF/tls-static.s (original)
+++ lld/trunk/test/ELF/tls-static.s Tue Oct 10 10:27:34 2017
@@ -3,12 +3,20 @@
 // RUN: ld.lld -static %t -o %tout
 // RUN: ld.lld %t -o %tout
 // RUN: ld.lld -shared %tso -o %tshared
-// RUN: not ld.lld -static %t %tshared -o %tout 2>&1 | FileCheck %s
+// RUN: ld.lld -static %t %tshared -o %tout
 // REQUIRES: x86
 
 .global _start
 _start:
-  call __tls_get_addr
+  data16
+  leaq  foobar at TLSGD(%rip), %rdi
+  data16
+  data16
+  rex64
+  callq  __tls_get_addr at PLT
 
-// CHECK: error: undefined symbol: __tls_get_addr
-// CHECK: >>> referenced by {{.*}}:(.text+0x1)
+
+.section        .tdata,"awT", at progbits
+.global  foobar
+foobar:
+  .long   42




More information about the llvm-commits mailing list