elf2yaml: Use existing section walk to find the symbol table. NFC.
llvm-svn: 244447
This commit is contained in:
parent
291f64fd03
commit
94515abfd7
|
@ -68,15 +68,19 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
|
||||||
Y->Header.Flags = Obj.getHeader()->e_flags;
|
Y->Header.Flags = Obj.getHeader()->e_flags;
|
||||||
Y->Header.Entry = Obj.getHeader()->e_entry;
|
Y->Header.Entry = Obj.getHeader()->e_entry;
|
||||||
|
|
||||||
|
const Elf_Shdr *Symtab = nullptr;
|
||||||
|
|
||||||
// Dump sections
|
// Dump sections
|
||||||
for (const Elf_Shdr &Sec : Obj.sections()) {
|
for (const Elf_Shdr &Sec : Obj.sections()) {
|
||||||
switch (Sec.sh_type) {
|
switch (Sec.sh_type) {
|
||||||
case ELF::SHT_NULL:
|
case ELF::SHT_NULL:
|
||||||
case ELF::SHT_SYMTAB:
|
|
||||||
case ELF::SHT_DYNSYM:
|
case ELF::SHT_DYNSYM:
|
||||||
case ELF::SHT_STRTAB:
|
case ELF::SHT_STRTAB:
|
||||||
// Do not dump these sections.
|
// Do not dump these sections.
|
||||||
break;
|
break;
|
||||||
|
case ELF::SHT_SYMTAB:
|
||||||
|
Symtab = &Sec;
|
||||||
|
break;
|
||||||
case ELF::SHT_RELA: {
|
case ELF::SHT_RELA: {
|
||||||
ErrorOr<ELFYAML::RelocationSection *> S = dumpRelaSection(&Sec);
|
ErrorOr<ELFYAML::RelocationSection *> S = dumpRelaSection(&Sec);
|
||||||
if (std::error_code EC = S.getError())
|
if (std::error_code EC = S.getError())
|
||||||
|
@ -122,14 +126,13 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump symbols
|
// Dump symbols
|
||||||
const Elf_Shdr *Symtab = Obj.getDotSymtabSec();
|
|
||||||
ErrorOr<StringRef> StrTableOrErr = Obj.getStringTableForSymtab(*Symtab);
|
ErrorOr<StringRef> StrTableOrErr = Obj.getStringTableForSymtab(*Symtab);
|
||||||
if (std::error_code EC = StrTableOrErr.getError())
|
if (std::error_code EC = StrTableOrErr.getError())
|
||||||
return EC;
|
return EC;
|
||||||
StringRef StrTable = *StrTableOrErr;
|
StringRef StrTable = *StrTableOrErr;
|
||||||
|
|
||||||
bool IsFirstSym = true;
|
bool IsFirstSym = true;
|
||||||
for (const Elf_Sym &Sym : Obj.symbols(Obj.getDotSymtabSec())) {
|
for (const Elf_Sym &Sym : Obj.symbols(Symtab)) {
|
||||||
if (IsFirstSym) {
|
if (IsFirstSym) {
|
||||||
IsFirstSym = false;
|
IsFirstSym = false;
|
||||||
continue;
|
continue;
|
||||||
|
@ -172,7 +175,7 @@ std::error_code ELFDumper<ELFT>::dumpSymbol(const Elf_Sym *Sym,
|
||||||
return EC;
|
return EC;
|
||||||
S.Name = NameOrErr.get();
|
S.Name = NameOrErr.get();
|
||||||
|
|
||||||
ErrorOr<const Elf_Shdr *> ShdrOrErr = Obj.getSection(&*Sym);
|
ErrorOr<const Elf_Shdr *> ShdrOrErr = Obj.getSection(Sym);
|
||||||
if (std::error_code EC = ShdrOrErr.getError())
|
if (std::error_code EC = ShdrOrErr.getError())
|
||||||
return EC;
|
return EC;
|
||||||
const Elf_Shdr *Shdr = *ShdrOrErr;
|
const Elf_Shdr *Shdr = *ShdrOrErr;
|
||||||
|
|
Loading…
Reference in New Issue