Convert obj->getSymbolName to sym->getName.

I doesn't depend on the object anymore.

llvm-svn: 240996
This commit is contained in:
Rafael Espindola 2015-06-29 21:24:55 +00:00
parent 59013c387e
commit 44c2871c09
5 changed files with 18 additions and 17 deletions

View File

@ -371,7 +371,6 @@ public:
///
/// \p SymTab is used to lookup the string table to use to get the symbol's
/// name.
ErrorOr<StringRef> getSymbolName(StringRef StrTab, const Elf_Sym *Symb) const;
ErrorOr<StringRef> getSectionName(const Elf_Shdr *Section) const;
uint64_t getSymbolIndex(const Elf_Sym *sym) const;
ErrorOr<ArrayRef<uint8_t> > getSectionContents(const Elf_Shdr *Sec) const;
@ -881,7 +880,7 @@ const char *ELFFile<ELFT>::getDynamicString(uintX_t Offset) const {
template <class ELFT>
ErrorOr<StringRef>
ELFFile<ELFT>::getStaticSymbolName(const Elf_Sym *Symb) const {
return getSymbolName(DotStrtab, Symb);
return Symb->getName(DotStrtab);
}
template <class ELFT>
@ -898,15 +897,6 @@ ErrorOr<StringRef> ELFFile<ELFT>::getSymbolName(const Elf_Sym *Symb,
return getStaticSymbolName(Symb);
}
template <class ELFT>
ErrorOr<StringRef> ELFFile<ELFT>::getSymbolName(StringRef StrTab,
const Elf_Sym *Sym) const {
uint32_t Offset = Sym->st_name;
if (Offset >= StrTab.size())
return object_error::parse_failed;
return StringRef(StrTab.data() + Offset);
}
template <class ELFT>
ErrorOr<StringRef>
ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
@ -932,7 +922,7 @@ ErrorOr<StringRef> ELFFile<ELFT>::getSymbolVersion(const Elf_Shdr *section,
// Non-dynamic symbols can have versions in their names
// A name of the form 'foo@V1' indicates version 'V1', non-default.
// A name of the form 'foo@@V2' indicates version 'V2', default version.
ErrorOr<StringRef> SymName = getSymbolName(StrTab, symb);
ErrorOr<StringRef> SymName = symb->getName(StrTab);
if (!SymName)
return SymName;
StringRef Name = *SymName;

View File

@ -10,9 +10,11 @@
#ifndef LLVM_OBJECT_ELFTYPES_H
#define LLVM_OBJECT_ELFTYPES_H
#include "llvm/Object/Error.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorOr.h"
namespace llvm {
namespace object {
@ -205,8 +207,18 @@ struct Elf_Sym_Impl : Elf_Sym_Base<ELFT> {
bool isExternal() const {
return getBinding() != ELF::STB_LOCAL;
}
ErrorOr<StringRef> getName(StringRef StrTab) const;
};
template <class ELFT>
ErrorOr<StringRef> Elf_Sym_Impl<ELFT>::getName(StringRef StrTab) const {
uint32_t Offset = this->st_name;
if (Offset >= StrTab.size())
return object_error::parse_failed;
return StringRef(StrTab.data() + Offset);
}
/// Elf_Versym: This is the structure of entries in the SHT_GNU_versym section
/// (.gnu.version). This structure is identical for ELF32 and ELF64.
template <class ELFT>

View File

@ -359,7 +359,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
return EC;
Target = *SecName;
} else {
ErrorOr<StringRef> SymName = EF.getSymbolName(StrTab, symb);
ErrorOr<StringRef> SymName = symb->getName(StrTab);
if (!SymName)
return SymName.getError();
Target = *SymName;

View File

@ -760,8 +760,7 @@ void ELFDumper<ELFT>::printRelocation(const Elf_Shdr *Sec,
const Elf_Shdr *StrTableSec = Obj->getSection(SymTable->sh_link);
ErrorOr<StringRef> StrTableOrErr = Obj->getStringTable(StrTableSec);
if (!error(StrTableOrErr.getError()))
TargetName =
errorOrDefault(Obj->getSymbolName(*StrTableOrErr, Sym.second));
TargetName = errorOrDefault(Sym.second->getName(*StrTableOrErr));
}
if (opts::ExpandRelocs) {

View File

@ -189,7 +189,7 @@ std::error_code ELFDumper<ELFT>::dumpRelocation(const Elf_Shdr *Shdr,
return EC;
StringRef StrTab = *StrTabOrErr;
ErrorOr<StringRef> NameOrErr = Obj.getSymbolName(StrTab, NamePair.second);
ErrorOr<StringRef> NameOrErr = NamePair.second->getName(StrTab);
if (std::error_code EC = NameOrErr.getError())
return EC;
R.Symbol = NameOrErr.get();
@ -314,7 +314,7 @@ ErrorOr<ELFYAML::Group *> ELFDumper<ELFT>::dumpGroup(const Elf_Shdr *Shdr) {
auto sectionContents = Obj.getSectionContents(Shdr);
if (std::error_code ec = sectionContents.getError())
return ec;
ErrorOr<StringRef> symbolName = Obj.getSymbolName(StrTab, symbol);
ErrorOr<StringRef> symbolName = symbol->getName(StrTab);
if (std::error_code EC = symbolName.getError())
return EC;
S->Info = *symbolName;