llvm.org GIT mirror llvm / 2295449
elf2yaml: Use existing section walk to find the symbol table. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244447 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
1 changed file(s) with 7 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
6767 Y->Header.Flags = Obj.getHeader()->e_flags;
6868 Y->Header.Entry = Obj.getHeader()->e_entry;
6969
70 const Elf_Shdr *Symtab = nullptr;
71
7072 // Dump sections
7173 for (const Elf_Shdr &Sec : Obj.sections()) {
7274 switch (Sec.sh_type) {
7375 case ELF::SHT_NULL:
74 case ELF::SHT_SYMTAB:
7576 case ELF::SHT_DYNSYM:
7677 case ELF::SHT_STRTAB:
7778 // Do not dump these sections.
7879 break;
80 case ELF::SHT_SYMTAB:
81 Symtab = &Sec;
82 break;
7983 case ELF::SHT_RELA: {
8084 ErrorOr S = dumpRelaSection(&Sec);
8185 if (std::error_code EC = S.getError())
121125 }
122126
123127 // Dump symbols
124 const Elf_Shdr *Symtab = Obj.getDotSymtabSec();
125128 ErrorOr StrTableOrErr = Obj.getStringTableForSymtab(*Symtab);
126129 if (std::error_code EC = StrTableOrErr.getError())
127130 return EC;
128131 StringRef StrTable = *StrTableOrErr;
129132
130133 bool IsFirstSym = true;
131 for (const Elf_Sym &Sym : Obj.symbols(Obj.getDotSymtabSec())) {
134 for (const Elf_Sym &Sym : Obj.symbols(Symtab)) {
132135 if (IsFirstSym) {
133136 IsFirstSym = false;
134137 continue;
171174 return EC;
172175 S.Name = NameOrErr.get();
173176
174 ErrorOr ShdrOrErr = Obj.getSection(&*Sym);
177 ErrorOr ShdrOrErr = Obj.getSection(Sym);
175178 if (std::error_code EC = ShdrOrErr.getError())
176179 return EC;
177180 const Elf_Shdr *Shdr = *ShdrOrErr;