[llvm] r246656 - Pass a symbol table to getRelocationSymbol instead of returning one.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 2 08:07:39 PDT 2015
Author: rafael
Date: Wed Sep 2 10:07:39 2015
New Revision: 246656
URL: http://llvm.org/viewvc/llvm-project?rev=246656&view=rev
Log:
Pass a symbol table to getRelocationSymbol instead of returning one.
This removes a report_fatal_error from library and avoids checking a
section property for every section entry.
Modified:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h
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=246656&r1=246655&r2=246656&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Wed Sep 2 10:07:39 2015
@@ -88,8 +88,8 @@ public:
/// \brief Get the symbol table section and symbol for a given relocation.
template <class RelT>
- std::pair<const Elf_Shdr *, const Elf_Sym *>
- getRelocationSymbol(const Elf_Shdr *RelSec, const RelT *Rel) const;
+ const Elf_Sym *getRelocationSymbol(const RelT *Rel,
+ const Elf_Shdr *SymTab) const;
ELFFile(StringRef Object, std::error_code &EC);
@@ -290,17 +290,13 @@ void ELFFile<ELFT>::getRelocationTypeNam
template <class ELFT>
template <class RelT>
-std::pair<const typename ELFFile<ELFT>::Elf_Shdr *,
- const typename ELFFile<ELFT>::Elf_Sym *>
-ELFFile<ELFT>::getRelocationSymbol(const Elf_Shdr *Sec, const RelT *Rel) const {
- if (!Sec->sh_link)
- return std::make_pair(nullptr, nullptr);
- ErrorOr<const Elf_Shdr *> SymTableOrErr = getSection(Sec->sh_link);
- if (std::error_code EC = SymTableOrErr.getError())
- report_fatal_error(EC.message());
- const Elf_Shdr *SymTable = *SymTableOrErr;
- return std::make_pair(
- SymTable, getEntry<Elf_Sym>(SymTable, Rel->getSymbol(isMips64EL())));
+const typename ELFFile<ELFT>::Elf_Sym *
+ELFFile<ELFT>::getRelocationSymbol(const RelT *Rel,
+ const Elf_Shdr *SymTab) const {
+ uint32_t Index = Rel->getSymbol(isMips64EL());
+ if (Index == 0)
+ return nullptr;
+ return getEntry<Elf_Sym>(SymTab, Index);
}
template <class ELFT>
Modified: llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h?rev=246656&r1=246655&r2=246656&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h (original)
+++ llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h Wed Sep 2 10:07:39 2015
@@ -375,6 +375,10 @@ PrinterContext<ET>::FindExceptionTable(u
if (Sec.sh_type != ELF::SHT_REL || Sec.sh_info != IndexSectionIndex)
continue;
+ ErrorOr<const Elf_Shdr *> SymTabOrErr = ELF->getSection(Sec.sh_link);
+ error(SymTabOrErr.getError());
+ const Elf_Shdr *SymTab = *SymTabOrErr;
+
for (const Elf_Rel &R : ELF->rels(&Sec)) {
if (R.r_offset != static_cast<unsigned>(IndexTableOffset))
continue;
@@ -384,11 +388,10 @@ PrinterContext<ET>::FindExceptionTable(u
RelA.r_info = R.r_info;
RelA.r_addend = 0;
- std::pair<const Elf_Shdr *, const Elf_Sym *> Symbol =
- ELF->getRelocationSymbol(&Sec, &RelA);
+ const Elf_Sym *Symbol = ELF->getRelocationSymbol(&RelA, SymTab);
ErrorOr<const Elf_Shdr *> Ret =
- ELF->getSection(Symbol.second, Symbol.first, ShndxTable);
+ ELF->getSection(Symbol, SymTab, ShndxTable);
if (std::error_code EC = Ret.getError())
report_fatal_error(EC.message());
return *Ret;
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=246656&r1=246655&r2=246656&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Wed Sep 2 10:07:39 2015
@@ -100,7 +100,7 @@ private:
StringRef StrTable, bool IsDynamic);
void printRelocations(const Elf_Shdr *Sec);
- void printRelocation(const Elf_Shdr *Sec, Elf_Rela Rel);
+ void printRelocation(Elf_Rela Rel, const Elf_Shdr *SymTab);
void printValue(uint64_t Type, uint64_t Value);
const Elf_Rela *dyn_rela_begin() const;
@@ -1095,6 +1095,10 @@ void ELFDumper<ELFT>::printDynamicReloca
template <class ELFT>
void ELFDumper<ELFT>::printRelocations(const Elf_Shdr *Sec) {
+ ErrorOr<const Elf_Shdr *> SymTabOrErr = Obj->getSection(Sec->sh_link);
+ error(SymTabOrErr.getError());
+ const Elf_Shdr *SymTab = *SymTabOrErr;
+
switch (Sec->sh_type) {
case ELF::SHT_REL:
for (const Elf_Rel &R : Obj->rels(Sec)) {
@@ -1102,35 +1106,32 @@ void ELFDumper<ELFT>::printRelocations(c
Rela.r_offset = R.r_offset;
Rela.r_info = R.r_info;
Rela.r_addend = 0;
- printRelocation(Sec, Rela);
+ printRelocation(Rela, SymTab);
}
break;
case ELF::SHT_RELA:
for (const Elf_Rela &R : Obj->relas(Sec))
- printRelocation(Sec, R);
+ printRelocation(R, SymTab);
break;
}
}
template <class ELFT>
-void ELFDumper<ELFT>::printRelocation(const Elf_Shdr *Sec, Elf_Rela Rel) {
+void ELFDumper<ELFT>::printRelocation(Elf_Rela Rel, const Elf_Shdr *SymTab) {
SmallString<32> RelocName;
Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName);
StringRef TargetName;
- std::pair<const Elf_Shdr *, const Elf_Sym *> Sym =
- Obj->getRelocationSymbol(Sec, &Rel);
- if (Sym.second && Sym.second->getType() == ELF::STT_SECTION) {
- ErrorOr<const Elf_Shdr *> Sec =
- Obj->getSection(Sym.second, Sym.first, ShndxTable);
+ const Elf_Sym *Sym = Obj->getRelocationSymbol(&Rel, SymTab);
+ if (Sym && Sym->getType() == ELF::STT_SECTION) {
+ ErrorOr<const Elf_Shdr *> Sec = Obj->getSection(Sym, SymTab, ShndxTable);
error(Sec.getError());
ErrorOr<StringRef> SecName = Obj->getSectionName(*Sec);
if (SecName)
TargetName = SecName.get();
- } else if (Sym.first) {
- const Elf_Shdr *SymTable = Sym.first;
- ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*SymTable);
+ } else if (Sym) {
+ ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*SymTab);
error(StrTableOrErr.getError());
- TargetName = errorOrDefault(Sym.second->getName(*StrTableOrErr));
+ TargetName = errorOrDefault(Sym->getName(*StrTableOrErr));
}
if (opts::ExpandRelocs) {
@@ -1767,7 +1768,8 @@ template <class ELFT> void MipsGOTParser
ErrorOr<const Elf_Shdr *> SymTableOrErr =
Obj->getSection(PLTRelShdr->sh_link);
error(SymTableOrErr.getError());
- ErrorOr<StringRef> StrTable = Obj->getStringTableForSymtab(**SymTableOrErr);
+ const Elf_Shdr *SymTable = *SymTableOrErr;
+ ErrorOr<StringRef> StrTable = Obj->getStringTableForSymtab(*SymTable);
error(StrTable.getError());
const GOTEntry *PLTBegin = makeGOTIter(*PLT, 0);
@@ -1789,8 +1791,7 @@ template <class ELFT> void MipsGOTParser
for (const Elf_Rel *RI = Obj->rel_begin(PLTRelShdr),
*RE = Obj->rel_end(PLTRelShdr);
RI != RE && It != PLTEnd; ++RI, ++It) {
- const Elf_Sym *Sym =
- Obj->getRelocationSymbol(&*PLTRelShdr, &*RI).second;
+ const Elf_Sym *Sym = Obj->getRelocationSymbol(&*RI, SymTable);
printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, *StrTable, Sym);
}
break;
@@ -1798,8 +1799,7 @@ template <class ELFT> void MipsGOTParser
for (const Elf_Rela *RI = Obj->rela_begin(PLTRelShdr),
*RE = Obj->rela_end(PLTRelShdr);
RI != RE && It != PLTEnd; ++RI, ++It) {
- const Elf_Sym *Sym =
- Obj->getRelocationSymbol(&*PLTRelShdr, &*RI).second;
+ const Elf_Sym *Sym = Obj->getRelocationSymbol(&*RI, SymTable);
printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, *StrTable, Sym);
}
break;
Modified: llvm/trunk/tools/obj2yaml/elf2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/elf2yaml.cpp?rev=246656&r1=246655&r2=246656&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/elf2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/elf2yaml.cpp Wed Sep 2 10:07:39 2015
@@ -34,7 +34,7 @@ class ELFDumper {
std::error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr,
ELFYAML::RelocationSection &S);
template <class RelT>
- std::error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel,
+ std::error_code dumpRelocation(const RelT *Rel, const Elf_Shdr *SymTab,
ELFYAML::Relocation &R);
ErrorOr<ELFYAML::RelocationSection *> dumpRelSection(const Elf_Shdr *Shdr);
@@ -201,18 +201,14 @@ ELFDumper<ELFT>::dumpSymbol(const Elf_Sy
template <class ELFT>
template <class RelT>
-std::error_code ELFDumper<ELFT>::dumpRelocation(const Elf_Shdr *Shdr,
- const RelT *Rel,
+std::error_code ELFDumper<ELFT>::dumpRelocation(const RelT *Rel,
+ const Elf_Shdr *SymTab,
ELFYAML::Relocation &R) {
R.Type = Rel->getType(Obj.isMips64EL());
R.Offset = Rel->r_offset;
R.Addend = 0;
- auto NamePair = Obj.getRelocationSymbol(Shdr, Rel);
- if (!NamePair.first)
- return obj2yaml_error::success;
-
- const Elf_Shdr *SymTab = NamePair.first;
+ const Elf_Sym *Sym = Obj.getRelocationSymbol(Rel, SymTab);
ErrorOr<const Elf_Shdr *> StrTabSec = Obj.getSection(SymTab->sh_link);
if (std::error_code EC = StrTabSec.getError())
return EC;
@@ -221,7 +217,7 @@ std::error_code ELFDumper<ELFT>::dumpRel
return EC;
StringRef StrTab = *StrTabOrErr;
- ErrorOr<StringRef> NameOrErr = NamePair.second->getName(StrTab);
+ ErrorOr<StringRef> NameOrErr = Sym->getName(StrTab);
if (std::error_code EC = NameOrErr.getError())
return EC;
R.Symbol = NameOrErr.get();
@@ -283,9 +279,14 @@ ELFDumper<ELFT>::dumpRelSection(const El
if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
return EC;
+ ErrorOr<const Elf_Shdr *> SymTabOrErr = Obj.getSection(Shdr->sh_link);
+ if (std::error_code EC = SymTabOrErr.getError())
+ return EC;
+ const Elf_Shdr *SymTab = *SymTabOrErr;
+
for (auto RI = Obj.rel_begin(Shdr), RE = Obj.rel_end(Shdr); RI != RE; ++RI) {
ELFYAML::Relocation R;
- if (std::error_code EC = dumpRelocation(Shdr, &*RI, R))
+ if (std::error_code EC = dumpRelocation(&*RI, SymTab, R))
return EC;
S->Relocations.push_back(R);
}
@@ -302,10 +303,15 @@ ELFDumper<ELFT>::dumpRelaSection(const E
if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
return EC;
+ ErrorOr<const Elf_Shdr *> SymTabOrErr = Obj.getSection(Shdr->sh_link);
+ if (std::error_code EC = SymTabOrErr.getError())
+ return EC;
+ const Elf_Shdr *SymTab = *SymTabOrErr;
+
for (auto RI = Obj.rela_begin(Shdr), RE = Obj.rela_end(Shdr); RI != RE;
++RI) {
ELFYAML::Relocation R;
- if (std::error_code EC = dumpRelocation(Shdr, &*RI, R))
+ if (std::error_code EC = dumpRelocation(&*RI, SymTab, R))
return EC;
R.Addend = RI->r_addend;
S->Relocations.push_back(R);
More information about the llvm-commits
mailing list