mirror of
https://github.com/intel/llvm.git
synced 2026-02-02 02:00:03 +08:00
[ELF] Mark linker defined symbols as .hidden when needed.
I noticed that gold mark these as hidden. While at it I rewrote the test for this feature to use yaml rather than an object file as input. Differential Revision: http://reviews.llvm.org/D9418 Reviewed by: ruiu llvm-svn: 236291
This commit is contained in:
@@ -741,14 +741,17 @@ bool ELFFile<ELFT>::redirectReferenceUsingUndefAtom(
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
void RuntimeFile<ELFT>::addAbsoluteAtom(StringRef symbolName) {
|
||||
void RuntimeFile<ELFT>::addAbsoluteAtom(StringRef symbolName, bool isHidden) {
|
||||
assert(!symbolName.empty() && "AbsoluteAtoms must have a name");
|
||||
Elf_Sym *sym = new (this->_readerStorage) Elf_Sym;
|
||||
sym->st_name = 0;
|
||||
sym->st_value = 0;
|
||||
sym->st_shndx = llvm::ELF::SHN_ABS;
|
||||
sym->setBindingAndType(llvm::ELF::STB_GLOBAL, llvm::ELF::STT_OBJECT);
|
||||
sym->setVisibility(llvm::ELF::STV_DEFAULT);
|
||||
if (isHidden)
|
||||
sym->setVisibility(llvm::ELF::STV_HIDDEN);
|
||||
else
|
||||
sym->setVisibility(llvm::ELF::STV_DEFAULT);
|
||||
sym->st_size = 0;
|
||||
ELFAbsoluteAtom<ELFT> *atom = this->createAbsoluteAtom(symbolName, sym, -1);
|
||||
this->addAtom(*atom);
|
||||
|
||||
@@ -398,7 +398,7 @@ public:
|
||||
: ELFFile<ELFT>(name, ctx) {}
|
||||
|
||||
/// \brief add a global absolute atom
|
||||
virtual void addAbsoluteAtom(StringRef symbolName);
|
||||
virtual void addAbsoluteAtom(StringRef symbolName, bool isHidden = false);
|
||||
|
||||
/// \brief add an undefined atom
|
||||
virtual void addUndefinedAtom(StringRef symbolName);
|
||||
|
||||
@@ -81,10 +81,10 @@ std::unique_ptr<RuntimeFile<ELFT>> ExecutableWriter<ELFT>::createRuntimeFile() {
|
||||
file->addAbsoluteAtom("__bss_end");
|
||||
file->addAbsoluteAtom("_end");
|
||||
file->addAbsoluteAtom("end");
|
||||
file->addAbsoluteAtom("__preinit_array_start");
|
||||
file->addAbsoluteAtom("__preinit_array_end");
|
||||
file->addAbsoluteAtom("__init_array_start");
|
||||
file->addAbsoluteAtom("__init_array_end");
|
||||
file->addAbsoluteAtom("__preinit_array_start", true);
|
||||
file->addAbsoluteAtom("__preinit_array_end", true);
|
||||
file->addAbsoluteAtom("__init_array_start", true);
|
||||
file->addAbsoluteAtom("__init_array_end", true);
|
||||
if (this->_ctx.isRelaOutputFormat()) {
|
||||
file->addAbsoluteAtom("__rela_iplt_start");
|
||||
file->addAbsoluteAtom("__rela_iplt_end");
|
||||
@@ -92,8 +92,8 @@ std::unique_ptr<RuntimeFile<ELFT>> ExecutableWriter<ELFT>::createRuntimeFile() {
|
||||
file->addAbsoluteAtom("__rel_iplt_start");
|
||||
file->addAbsoluteAtom("__rel_iplt_end");
|
||||
}
|
||||
file->addAbsoluteAtom("__fini_array_start");
|
||||
file->addAbsoluteAtom("__fini_array_end");
|
||||
file->addAbsoluteAtom("__fini_array_start", true);
|
||||
file->addAbsoluteAtom("__fini_array_end", true);
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -187,7 +187,7 @@ OMAGICSECTIONS: Address: 0x0
|
||||
OMAGICSECTIONS: Offset: 0x1E8
|
||||
OMAGICSECTIONS: Size: 504
|
||||
OMAGICSECTIONS: Link: 13
|
||||
OMAGICSECTIONS: Info: 2
|
||||
OMAGICSECTIONS: Info: 8
|
||||
OMAGICSECTIONS: AddressAlignment: 8
|
||||
OMAGICSECTIONS: EntrySize: 24
|
||||
OMAGICSECTIONS: }
|
||||
|
||||
@@ -1,6 +1,92 @@
|
||||
RUN: lld -flavor gnu -target x86_64-linux -o %t %p/Inputs/init_array.x86-64 \
|
||||
RUN: -e __init_array_start
|
||||
RUN: llvm-objdump -t -section-headers %t | FileCheck %s
|
||||
#RUN: yaml2obj -format=elf %s -o=%t.o
|
||||
#RUN: lld -flavor gnu -target x86_64-linux %t.o -o %t1 -e=main
|
||||
#RUN: llvm-objdump -t -section-headers %t | FileCheck %s
|
||||
|
||||
CHECK: .init_array {{[0-9]+}} [[ADDR:[0-9]+]]
|
||||
CHECK: [[ADDR]] g *ABS* {{[0-9]+}} __init_array_start
|
||||
#CHECK: .init_array {{[0-9]+}} [[ADDR:[0-9]+]]
|
||||
#CHECK: [[ADDR]] l *ABS* {{[0-9]+}} .hidden __init_array_start
|
||||
|
||||
---
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
OSABI: ELFOSABI_FREEBSD
|
||||
Type: ET_REL
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Name: .text
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
|
||||
AddressAlign: 0x0000000000000010
|
||||
Content: 554889E5B800000000C745FC000000008B0C2500000000894DF85DC3
|
||||
- Name: .rela.text
|
||||
Type: SHT_RELA
|
||||
Link: .symtab
|
||||
AddressAlign: 0x0000000000000008
|
||||
Info: .text
|
||||
Relocations:
|
||||
- Offset: 0x0000000000000013
|
||||
Symbol: a
|
||||
Type: R_X86_64_32S
|
||||
- Name: .data
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ SHF_WRITE, SHF_ALLOC ]
|
||||
AddressAlign: 0x0000000000000004
|
||||
Content: '05000000'
|
||||
- Name: .bss
|
||||
Type: SHT_NOBITS
|
||||
Flags: [ SHF_WRITE, SHF_ALLOC ]
|
||||
AddressAlign: 0x0000000000000004
|
||||
Content: ''
|
||||
- Name: .comment
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ SHF_MERGE, SHF_STRINGS ]
|
||||
AddressAlign: 0x0000000000000001
|
||||
Content: 004672656542534420636C616E672076657273696F6E20332E342E312028746167732F52454C454153455F33342F646F74312D66696E616C203230383033322920323031343035313200
|
||||
- Name: .note.GNU-stack
|
||||
Type: SHT_PROGBITS
|
||||
AddressAlign: 0x0000000000000001
|
||||
Content: ''
|
||||
- Name: .eh_frame
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ SHF_ALLOC ]
|
||||
AddressAlign: 0x0000000000000008
|
||||
Content: 1400000000000000017A5200017810011B0C0708900100001C0000001C000000000000001C00000000410E108602430D0600000000000000
|
||||
- Name: .rela.eh_frame
|
||||
Type: SHT_RELA
|
||||
Link: .symtab
|
||||
AddressAlign: 0x0000000000000008
|
||||
Info: .eh_frame
|
||||
Relocations:
|
||||
- Offset: 0x0000000000000020
|
||||
Symbol: .text
|
||||
Type: R_X86_64_PC32
|
||||
Symbols:
|
||||
Local:
|
||||
- Name: .text
|
||||
Type: STT_SECTION
|
||||
Section: .text
|
||||
- Name: .data
|
||||
Type: STT_SECTION
|
||||
Section: .data
|
||||
- Name: .bss
|
||||
Type: STT_SECTION
|
||||
Section: .bss
|
||||
- Name: .comment
|
||||
Type: STT_SECTION
|
||||
Section: .comment
|
||||
- Name: .note.GNU-stack
|
||||
Type: STT_SECTION
|
||||
Section: .note.GNU-stack
|
||||
- Name: .eh_frame
|
||||
Type: STT_SECTION
|
||||
Section: .eh_frame
|
||||
Global:
|
||||
- Name: a
|
||||
Type: STT_OBJECT
|
||||
Section: .data
|
||||
Size: 0x0000000000000004
|
||||
- Name: main
|
||||
Type: STT_FUNC
|
||||
Section: .text
|
||||
Size: 0x000000000000001C
|
||||
...
|
||||
|
||||
Reference in New Issue
Block a user