Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -799,15 +799,6 @@ ElfSym::GlobalOffsetTable = addOptionalRegular( "_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(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 Index: test/ELF/arm-tls-norelax-gd-le.s =================================================================== --- test/ELF/arm-tls-norelax-gd-le.s +++ test/ELF/arm-tls-norelax-gd-le.s @@ -35,3 +35,7 @@ // 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 Index: test/ELF/tls-static.s =================================================================== --- test/ELF/tls-static.s +++ test/ELF/tls-static.s @@ -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@TLSGD(%rip), %rdi + data16 + data16 + rex64 + callq __tls_get_addr@PLT -// CHECK: error: undefined symbol: __tls_get_addr -// CHECK: >>> referenced by {{.*}}:(.text+0x1) + +.section .tdata,"awT",@progbits +.global foobar +foobar: + .long 42