Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -134,7 +134,9 @@ // The main function of the writer. template void Writer::run() { createSyntheticSections(); - addReservedSymbols(); + + if (!Config->Relocatable) + addReservedSymbols(); if (Target->NeedsThunks) forEachRelSec(createThunks); @@ -604,7 +606,7 @@ // The linker is expected to define some symbols depending on // the linking result. This function defines such symbols. template void Writer::addReservedSymbols() { - if (Config->EMachine == EM_MIPS && !Config->Relocatable) { + if (Config->EMachine == EM_MIPS) { // Define _gp for MIPS. st_value of _gp symbol will be updated by Writer // so that it points to an absolute address which is relative to GOT. // See "Global Data Symbols" in Chapter 6 in the following document: @@ -636,8 +638,7 @@ // an undefined symbol in the .o files. // Given that the symbol is effectively unused, we just create a dummy // hidden one to avoid the undefined symbol error. - if (!Config->Relocatable) - Symtab::X->addIgnored("_GLOBAL_OFFSET_TABLE_"); + Symtab::X->addIgnored("_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 Index: lld/trunk/test/ELF/Inputs/relocatable-tls.s =================================================================== --- lld/trunk/test/ELF/Inputs/relocatable-tls.s +++ lld/trunk/test/ELF/Inputs/relocatable-tls.s @@ -0,0 +1 @@ +callq __tls_get_addr@PLT Index: lld/trunk/test/ELF/edata-etext.s =================================================================== --- lld/trunk/test/ELF/edata-etext.s +++ lld/trunk/test/ELF/edata-etext.s @@ -23,6 +23,12 @@ # CHECK-NEXT: 0000000000011001 *ABS* 00000000 _etext # CHECK-NEXT: 0000000000011000 .text 00000000 _start +# RUN: ld.lld -r %t.o -o %t2 +# RUN: llvm-objdump -t %t2 | FileCheck %s --check-prefix=RELOCATABLE +# RELOCATABLE: 0000000000000000 *UND* 00000000 _edata +# RELOCATABLE-NEXT: 0000000000000000 *UND* 00000000 _end +# RELOCATABLE-NEXT: 0000000000000000 *UND* 00000000 _etext + .global _start,_end,_etext,_edata .text _start: Index: lld/trunk/test/ELF/ehdr_start.s =================================================================== --- lld/trunk/test/ELF/ehdr_start.s +++ lld/trunk/test/ELF/ehdr_start.s @@ -9,3 +9,8 @@ .global _start, __ehdr_start _start: .quad __ehdr_start + +# RUN: ld.lld -r %t.o -o %t.r +# RUN: llvm-objdump -t %t.r | FileCheck %s --check-prefix=RELOCATABLE + +# RELOCATABLE: 0000000000000000 *UND* 00000000 __ehdr_start Index: lld/trunk/test/ELF/end.s =================================================================== --- lld/trunk/test/ELF/end.s +++ lld/trunk/test/ELF/end.s @@ -23,6 +23,10 @@ // DEFAULT-NEXT: Value: 0x12008 // DEFAULT: ] +// RUN: ld.lld -r %t.o -o %t2 +// RUN: llvm-objdump -t %t2 | FileCheck %s --check-prefix=RELOCATABLE +// RELOCATABLE: 0000000000000000 *UND* 00000000 _end + .global _start,_end .text _start: Index: lld/trunk/test/ELF/relocatable-tls.s =================================================================== --- lld/trunk/test/ELF/relocatable-tls.s +++ lld/trunk/test/ELF/relocatable-tls.s @@ -0,0 +1,15 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ +# RUN: %S/Inputs/relocatable-tls.s -o %t2.o + +# RUN: ld.lld -r %t2.o -o %t3.r +# RUN: llvm-objdump -t %t3.r | FileCheck --check-prefix=RELOCATABLE %s +# RELOCATABLE: SYMBOL TABLE: +# RELOCATABLE: 0000000000000000 *UND* 00000000 __tls_get_addr + +# RUN: ld.lld -shared %t2.o %t3.r -o %t4.out +# RUN: llvm-objdump -t %t4.out | FileCheck --check-prefix=DSO %s +# DSO: SYMBOL TABLE: +# DSO: 0000000000000000 *UND* 00000000 __tls_get_addr + +callq __tls_get_addr@PLT