forked from OSchip/llvm-project
[ELF] - Do not create reserved symbols in case of relocatable output.
This patch stops creating symbols like __ehdr_start, _end/_etext_edata,__tls_get_addr when using -r. This fixes PR30984. Differential revision: https://reviews.llvm.org/D26600 llvm-svn: 286941
This commit is contained in:
parent
463984d4bf
commit
7beff42f8f
|
|
@ -134,6 +134,8 @@ template <class ELFT> void elf::writeResult() { Writer<ELFT>().run(); }
|
||||||
// The main function of the writer.
|
// The main function of the writer.
|
||||||
template <class ELFT> void Writer<ELFT>::run() {
|
template <class ELFT> void Writer<ELFT>::run() {
|
||||||
createSyntheticSections();
|
createSyntheticSections();
|
||||||
|
|
||||||
|
if (!Config->Relocatable)
|
||||||
addReservedSymbols();
|
addReservedSymbols();
|
||||||
|
|
||||||
if (Target->NeedsThunks)
|
if (Target->NeedsThunks)
|
||||||
|
|
@ -604,7 +606,7 @@ template <class ELFT> void Writer<ELFT>::addRelIpltSymbols() {
|
||||||
// The linker is expected to define some symbols depending on
|
// The linker is expected to define some symbols depending on
|
||||||
// the linking result. This function defines such symbols.
|
// the linking result. This function defines such symbols.
|
||||||
template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
|
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
|
// 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.
|
// so that it points to an absolute address which is relative to GOT.
|
||||||
// See "Global Data Symbols" in Chapter 6 in the following document:
|
// See "Global Data Symbols" in Chapter 6 in the following document:
|
||||||
|
|
@ -636,7 +638,6 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
|
||||||
// an undefined symbol in the .o files.
|
// an undefined symbol in the .o files.
|
||||||
// Given that the symbol is effectively unused, we just create a dummy
|
// Given that the symbol is effectively unused, we just create a dummy
|
||||||
// hidden one to avoid the undefined symbol error.
|
// 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
|
// __tls_get_addr is defined by the dynamic linker for dynamic ELFs. For
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
callq __tls_get_addr@PLT
|
||||||
|
|
@ -23,6 +23,12 @@
|
||||||
# CHECK-NEXT: 0000000000011001 *ABS* 00000000 _etext
|
# CHECK-NEXT: 0000000000011001 *ABS* 00000000 _etext
|
||||||
# CHECK-NEXT: 0000000000011000 .text 00000000 _start
|
# 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
|
.global _start,_end,_etext,_edata
|
||||||
.text
|
.text
|
||||||
_start:
|
_start:
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,8 @@
|
||||||
.global _start, __ehdr_start
|
.global _start, __ehdr_start
|
||||||
_start:
|
_start:
|
||||||
.quad __ehdr_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
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,10 @@
|
||||||
// DEFAULT-NEXT: Value: 0x12008
|
// DEFAULT-NEXT: Value: 0x12008
|
||||||
// DEFAULT: ]
|
// 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
|
.global _start,_end
|
||||||
.text
|
.text
|
||||||
_start:
|
_start:
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in New Issue