// The main function of the writer.
template <class ELFT> void Writer<ELFT>::run() {
createSyntheticSections();
- addReservedSymbols();
+
+ if (!Config->Relocatable)
+ addReservedSymbols();
if (Target->NeedsThunks)
forEachRelSec(createThunks<ELFT>);
// The linker is expected to define some symbols depending on
// the linking result. This function defines such symbols.
template <class ELFT> void Writer<ELFT>::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:
// 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<ELFT>::X->addIgnored("_GLOBAL_OFFSET_TABLE_");
+ Symtab<ELFT>::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
--- /dev/null
+callq __tls_get_addr@PLT
# 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:
.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
// 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:
--- /dev/null
+# 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