[llvm] r240996 - Convert obj->getSymbolName to sym->getName.
Rafael Espindola
rafael.espindola at gmail.com
Mon Jun 29 14:24:55 PDT 2015
Author: rafael
Date: Mon Jun 29 16:24:55 2015
New Revision: 240996
URL: http://llvm.org/viewvc/llvm-project?rev=240996&view=rev
Log:
Convert obj->getSymbolName to sym->getName.
I doesn't depend on the object anymore.
Modified:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/include/llvm/Object/ELFTypes.h
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
llvm/trunk/tools/obj2yaml/elf2yaml.cpp
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=240996&r1=240995&r2=240996&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Mon Jun 29 16:24:55 2015
@@ -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>::getDynamicStr
template <class ELFT>
ErrorOr<StringRef>
ELFFile<ELFT>::getStaticSymbolName(const Elf_Sym *Symb) const {
- return getSymbolName(DotStrtab, Symb);
+ return Symb->getName(DotStrtab);
}
template <class ELFT>
@@ -899,15 +898,6 @@ ErrorOr<StringRef> ELFFile<ELFT>::getSym
}
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 {
uint32_t Offset = Section->sh_name;
@@ -932,7 +922,7 @@ ErrorOr<StringRef> ELFFile<ELFT>::getSym
// Non-dynamic symbols can have versions in their names
// A name of the form 'foo at 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;
Modified: llvm/trunk/include/llvm/Object/ELFTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFTypes.h?rev=240996&r1=240995&r2=240996&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFTypes.h (original)
+++ llvm/trunk/include/llvm/Object/ELFTypes.h Mon Jun 29 16:24:55 2015
@@ -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>
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=240996&r1=240995&r2=240996&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Mon Jun 29 16:24:55 2015
@@ -359,7 +359,7 @@ static std::error_code getRelocationValu
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;
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=240996&r1=240995&r2=240996&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Mon Jun 29 16:24:55 2015
@@ -760,8 +760,7 @@ void ELFDumper<ELFT>::printRelocation(co
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) {
Modified: llvm/trunk/tools/obj2yaml/elf2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/elf2yaml.cpp?rev=240996&r1=240995&r2=240996&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/elf2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/elf2yaml.cpp Mon Jun 29 16:24:55 2015
@@ -189,7 +189,7 @@ std::error_code ELFDumper<ELFT>::dumpRel
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
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;
More information about the llvm-commits
mailing list