[lld] r236291 - [ELF] Mark linker defined symbols as .hidden when needed.
Davide Italiano
davide at freebsd.org
Thu Apr 30 17:07:11 PDT 2015
Author: davide
Date: Thu Apr 30 19:07:11 2015
New Revision: 236291
URL: http://llvm.org/viewvc/llvm-project?rev=236291&view=rev
Log:
[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
Removed:
lld/trunk/test/elf/Inputs/init_array.x86-64
Modified:
lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp
lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
lld/trunk/lib/ReaderWriter/ELF/ExecutableWriter.h
lld/trunk/test/elf/X86_64/omagic.test
lld/trunk/test/elf/init_array.test
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp?rev=236291&r1=236290&r2=236291&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp Thu Apr 30 19:07:11 2015
@@ -741,14 +741,17 @@ bool ELFFile<ELFT>::redirectReferenceUsi
}
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);
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=236291&r1=236290&r2=236291&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Thu Apr 30 19:07:11 2015
@@ -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);
Modified: lld/trunk/lib/ReaderWriter/ELF/ExecutableWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ExecutableWriter.h?rev=236291&r1=236290&r2=236291&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ExecutableWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ExecutableWriter.h Thu Apr 30 19:07:11 2015
@@ -81,10 +81,10 @@ std::unique_ptr<RuntimeFile<ELFT>> Execu
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>> Execu
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;
}
Removed: lld/trunk/test/elf/Inputs/init_array.x86-64
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/init_array.x86-64?rev=236290&view=auto
==============================================================================
Binary files lld/trunk/test/elf/Inputs/init_array.x86-64 (original) and lld/trunk/test/elf/Inputs/init_array.x86-64 (removed) differ
Modified: lld/trunk/test/elf/X86_64/omagic.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/omagic.test?rev=236291&r1=236290&r2=236291&view=diff
==============================================================================
--- lld/trunk/test/elf/X86_64/omagic.test (original)
+++ lld/trunk/test/elf/X86_64/omagic.test Thu Apr 30 19:07:11 2015
@@ -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: }
Modified: lld/trunk/test/elf/init_array.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/init_array.test?rev=236291&r1=236290&r2=236291&view=diff
==============================================================================
--- lld/trunk/test/elf/init_array.test (original)
+++ lld/trunk/test/elf/init_array.test Thu Apr 30 19:07:11 2015
@@ -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
+...
More information about the llvm-commits
mailing list