llvm.org GIT mirror llvm / 04fe7bc
[yaml2obj][obj2yaml] - Teach yaml2obj/obj2yaml tools about STB_GNU_UNIQUE symbols. yaml2obj/obj2yaml does not support the symbols with STB_GNU_UNIQUE yet. Currently, obj2yaml fails with llvm_unreachable when met such a symbol. I faced it when investigated the https://bugs.llvm.org/show_bug.cgi?id=41196. Differential revision: https://reviews.llvm.org/D59875 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357158 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 6 months ago
6 changed file(s) with 77 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
101101 uint8_t Other;
102102 };
103103
104 struct LocalGlobalWeakSymbols {
104 struct SymbolsDef {
105105 std::vector Local;
106106 std::vector Global;
107107 std::vector Weak;
108 std::vector GNUUnique;
108109 };
109110
110111 struct SectionOrType {
287288 // cleaner and nicer if we read them from the YAML as a separate
288289 // top-level key, which automatically ensures that invariants like there
289290 // being a single SHT_SYMTAB section are upheld.
290 LocalGlobalWeakSymbols Symbols;
291 LocalGlobalWeakSymbols DynamicSymbols;
291 SymbolsDef Symbols;
292 SymbolsDef DynamicSymbols;
292293 };
293294
294295 } // end namespace ELFYAML
435436 static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol);
436437 };
437438
438 template <>
439 struct MappingTraits {
440 static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols);
439 template <> struct MappingTraits {
440 static void mapping(IO &IO, ELFYAML::SymbolsDef &Symbols);
441441 };
442442
443443 template <> struct MappingTraits {
863863 return StringRef();
864864 }
865865
866 void MappingTraits::mapping(
867 IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
866 void MappingTraits::mapping(IO &IO,
867 ELFYAML::SymbolsDef &Symbols) {
868868 IO.mapOptional("Local", Symbols.Local);
869869 IO.mapOptional("Global", Symbols.Global);
870870 IO.mapOptional("Weak", Symbols.Weak);
871 IO.mapOptional("GNUUnique", Symbols.GNUUnique);
871872 }
872873
873874 static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
0 # RUN: yaml2obj %s -o %t
1 # RUN: obj2yaml %t | FileCheck %s
2
3 ## Check obj2yaml is able to dump the STB_GNU_UNIQUE symbol.
4
5 # CHECK: --- !ELF
6 # CHECK-NEXT: FileHeader:
7 # CHECK-NEXT: Class: ELFCLASS64
8 # CHECK-NEXT: Data: ELFDATA2LSB
9 # CHECK-NEXT: OSABI: ELFOSABI_GNU
10 # CHECK-NEXT: Type: ET_REL
11 # CHECK-NEXT: Machine: EM_X86_64
12 # CHECK-NEXT: Symbols:
13 # CHECK-NEXT: GNUUnique:
14 # CHECK-NEXT: - Name: foo
15 # CHECK-NEXT: Type: STT_OBJECT
16 # CHECK-NEXT: DynamicSymbols: {}
17 # CHECK-NEXT: ...
18
19 --- !ELF
20 FileHeader:
21 Class: ELFCLASS64
22 Data: ELFDATA2LSB
23 OSABI: ELFOSABI_GNU
24 Type: ET_REL
25 Machine: EM_X86_64
26 Symbols:
27 GNUUnique:
28 - Name: foo
29 Type: STT_OBJECT
0 # RUN: yaml2obj %s -o %t
1 # RUN: llvm-readobj -symbols %t | FileCheck %s
2
3 ## Check yaml2obj is able to create the STB_GNU_UNIQUE symbol.
4
5 # CHECK: Name: foo
6 # CHECK-NEXT: Value:
7 # CHECK-NEXT: Size:
8 # CHECK-NEXT: Binding: Unique
9
10 --- !ELF
11 FileHeader:
12 Class: ELFCLASS64
13 Data: ELFDATA2LSB
14 OSABI: ELFOSABI_GNU
15 Type: ET_REL
16 Machine: EM_X86_64
17 Symbols:
18 GNUUnique:
19 - Name: foo
20 Type: STT_OBJECT
4141 ArrayRef ShndxTable;
4242
4343 std::error_code dumpSymbols(const Elf_Shdr *Symtab,
44 ELFYAML::LocalGlobalWeakSymbols &Symbols);
44 ELFYAML::SymbolsDef &Symbols);
4545 std::error_code dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
4646 StringRef StrTable, ELFYAML::Symbol &S);
4747 std::error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S);
225225 }
226226
227227 template
228 std::error_code
229 ELFDumper::dumpSymbols(const Elf_Shdr *Symtab,
230 ELFYAML::LocalGlobalWeakSymbols &Symbols) {
228 std::error_code ELFDumper::dumpSymbols(const Elf_Shdr *Symtab,
229 ELFYAML::SymbolsDef &Symbols) {
231230 if (!Symtab)
232231 return std::error_code();
233232
260259 break;
261260 case ELF::STB_WEAK:
262261 Symbols.Weak.push_back(S);
262 break;
263 case ELF::STB_GNU_UNIQUE:
264 Symbols.GNUUnique.push_back(S);
263265 break;
264266 default:
265267 llvm_unreachable("Unknown ELF symbol binding");
132132 const ELFYAML::Object &Doc;
133133
134134 bool buildSectionIndex();
135 bool buildSymbolIndex(const ELFYAML::LocalGlobalWeakSymbols &);
135 bool buildSymbolIndex(const ELFYAML::SymbolsDef &);
136136 void initELFHeader(Elf_Ehdr &Header);
137137 void initProgramHeaders(std::vector &PHeaders);
138138 bool initSectionHeaders(std::vector &SHeaders,
361361 addSymbols(Symbols.Local, Syms, ELF::STB_LOCAL, Strtab);
362362 addSymbols(Symbols.Global, Syms, ELF::STB_GLOBAL, Strtab);
363363 addSymbols(Symbols.Weak, Syms, ELF::STB_WEAK, Strtab);
364 addSymbols(Symbols.GNUUnique, Syms, ELF::STB_GNU_UNIQUE, Strtab);
364365
365366 writeArrayData(
366367 CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign),
794795 }
795796
796797 template
797 bool ELFState::buildSymbolIndex(
798 const ELFYAML::LocalGlobalWeakSymbols &Symbols) {
798 bool ELFState::buildSymbolIndex(const ELFYAML::SymbolsDef &Symbols) {
799799 std::size_t I = 0;
800800 for (const std::vector &V :
801 {Symbols.Local, Symbols.Global, Symbols.Weak}) {
801 {Symbols.Local, Symbols.Global, Symbols.Weak, Symbols.GNUUnique}) {
802802 for (const auto &Sym : V) {
803803 ++I;
804804 if (Sym.Name.empty())
814814
815815 template void ELFState::finalizeStrings() {
816816 auto AddSymbols = [](StringTableBuilder &StrTab,
817 const ELFYAML::LocalGlobalWeakSymbols &Symbols) {
817 const ELFYAML::SymbolsDef &Symbols) {
818818 for (const auto &Sym : Symbols.Local)
819819 StrTab.add(Sym.Name);
820820 for (const auto &Sym : Symbols.Global)
821821 StrTab.add(Sym.Name);
822822 for (const auto &Sym : Symbols.Weak)
823 StrTab.add(Sym.Name);
824 for (const auto &Sym : Symbols.GNUUnique)
823825 StrTab.add(Sym.Name);
824826 };
825827
918920 }
919921
920922 template bool ELFState::hasDynamicSymbols() const {
921 return Doc.DynamicSymbols.Global.size() > 0 ||
922 Doc.DynamicSymbols.Weak.size() > 0 ||
923 Doc.DynamicSymbols.Local.size() > 0;
923 return !Doc.DynamicSymbols.Global.empty() ||
924 !Doc.DynamicSymbols.Weak.empty() ||
925 !Doc.DynamicSymbols.Local.empty() ||
926 !Doc.DynamicSymbols.GNUUnique.empty();
924927 }
925928
926929 template