llvm-readobj: use the associated string table to print symbols. NFI.

This just removes some cases that require ELFFile to eagerly parse the ELF
file.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242794 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-07-21 16:02:10 +00:00
parent 791500fa0d
commit fcadda639e
2 changed files with 58 additions and 20 deletions

View File

@@ -239,6 +239,8 @@ public:
const Elf_Hash *getHashTable() const { return HashTable; }
ErrorOr<StringRef> getStringTable(const Elf_Shdr *Section) const;
ErrorOr<StringRef> getStringTableForSymtab(const Elf_Shdr &Section) const;
const char *getDynamicString(uintX_t Offset) const;
ErrorOr<StringRef> getSymbolVersion(const Elf_Shdr *section,
const Elf_Sym *Symb,
@@ -646,10 +648,7 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
return;
}
dot_symtab_sec = &Sec;
ErrorOr<const Elf_Shdr *> SectionOrErr = getSection(Sec.sh_link);
if ((EC = SectionOrErr.getError()))
return;
ErrorOr<StringRef> SymtabOrErr = getStringTable(*SectionOrErr);
ErrorOr<StringRef> SymtabOrErr = getStringTableForSymtab(Sec);
if ((EC = SymtabOrErr.getError()))
return;
DotStrtab = *SymtabOrErr;
@@ -878,6 +877,17 @@ ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const {
return Data;
}
template <class ELFT>
ErrorOr<StringRef>
ELFFile<ELFT>::getStringTableForSymtab(const Elf_Shdr &Sec) const {
if (Sec.sh_type != ELF::SHT_SYMTAB && Sec.sh_type != ELF::SHT_DYNSYM)
return object_error::parse_failed;
ErrorOr<const Elf_Shdr *> SectionOrErr = getSection(Sec.sh_link);
if (std::error_code EC = SectionOrErr.getError())
return EC;
return getStringTable(*SectionOrErr);
}
template <class ELFT>
const char *ELFFile<ELFT>::getDynamicString(uintX_t Offset) const {
if (Offset >= DynStrRegion.Size)