typedef typename ELFO::Elf_Shdr Elf_Shdr;
typedef typename ELFO::Elf_Sym Elf_Sym;
- void printSymbol(const Elf_Sym *Symbol, bool IsDynamic);
+ void printSymbol(const Elf_Sym *Symbol, StringRef StrTable, bool IsDynamic);
void printRelocations(const Elf_Shdr *Sec);
void printRelocation(const Elf_Shdr *Sec, typename ELFO::Elf_Rela Rel);
template <typename ELFO>
static std::string getFullSymbolName(const ELFO &Obj,
const typename ELFO::Elf_Sym *Symbol,
- bool IsDynamic) {
- StringRef SymbolName = errorOrDefault(Obj.getSymbolName(Symbol, IsDynamic));
+ StringRef StrTable, bool IsDynamic) {
+ StringRef SymbolName = errorOrDefault(Symbol->getName(StrTable));
if (!IsDynamic)
return SymbolName;
if (opts::SectionSymbols) {
ListScope D(W, "Symbols");
+ const Elf_Shdr *Symtab = Obj->getDotSymtabSec();
+ ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
+ error(StrTableOrErr.getError());
+ StringRef StrTable = *StrTableOrErr;
+
for (const typename ELFO::Elf_Sym &Sym : Obj->symbols()) {
ErrorOr<const Elf_Shdr *> SymSec = Obj->getSection(&Sym);
if (!SymSec)
continue;
if (*SymSec == &Sec)
- printSymbol(&Sym, false);
+ printSymbol(&Sym, StrTable, false);
}
}
template<class ELFT>
void ELFDumper<ELFT>::printSymbols() {
ListScope Group(W, "Symbols");
+
+ const Elf_Shdr *Symtab = Obj->getDotSymtabSec();
+ ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
+ error(StrTableOrErr.getError());
+ StringRef StrTable = *StrTableOrErr;
for (const typename ELFO::Elf_Sym &Sym : Obj->symbols())
- printSymbol(&Sym, false);
+ printSymbol(&Sym, StrTable, false);
}
template<class ELFT>
void ELFDumper<ELFT>::printDynamicSymbols() {
ListScope Group(W, "DynamicSymbols");
+ const Elf_Shdr *Symtab = Obj->getDotDynSymSec();
+ ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
+ error(StrTableOrErr.getError());
+ StringRef StrTable = *StrTableOrErr;
for (const typename ELFO::Elf_Sym &Sym : Obj->dynamic_symbols())
- printSymbol(&Sym, true);
+ printSymbol(&Sym, StrTable, true);
}
template <class ELFT>
void ELFDumper<ELFT>::printSymbol(const typename ELFO::Elf_Sym *Symbol,
- bool IsDynamic) {
+ StringRef StrTable, bool IsDynamic) {
unsigned SectionIndex = 0;
StringRef SectionName;
getSectionNameIndex(*Obj, Symbol, SectionName, SectionIndex);
- std::string FullSymbolName = getFullSymbolName(*Obj, Symbol, IsDynamic);
+ std::string FullSymbolName =
+ getFullSymbolName(*Obj, Symbol, StrTable, IsDynamic);
DictScope D(W, "Symbol");
W.printNumber("Name", FullSymbolName, Symbol->st_name);
void printGotEntry(uint64_t GotAddr, GOTIter BeginIt, GOTIter It);
void printGlobalGotEntry(uint64_t GotAddr, GOTIter BeginIt, GOTIter It,
- const Elf_Sym *Sym, bool IsDynamic);
+ const Elf_Sym *Sym, StringRef StrTable,
+ bool IsDynamic);
void printPLTEntry(uint64_t PLTAddr, GOTIter BeginIt, GOTIter It,
StringRef Purpose);
void printPLTEntry(uint64_t PLTAddr, GOTIter BeginIt, GOTIter It,
- const Elf_Sym *Sym);
+ StringRef StrTable, const Elf_Sym *Sym);
};
}
return;
}
+ const Elf_Shdr *DynSymSec = Obj->getDotDynSymSec();
+ ErrorOr<StringRef> StrTable = Obj->getStringTableForSymtab(*DynSymSec);
+ error(StrTable.getError());
const Elf_Sym *DynSymBegin = Obj->dynamic_symbol_begin();
const Elf_Sym *DynSymEnd = Obj->dynamic_symbol_end();
std::size_t DynSymTotal = std::size_t(std::distance(DynSymBegin, DynSymEnd));
const Elf_Sym *GotDynSym = DynSymBegin + *DtGotSym;
for (; It != GotGlobalEnd; ++It) {
DictScope D(W, "Entry");
- printGlobalGotEntry(GOTShdr->sh_addr, GotBegin, It, GotDynSym++, true);
+ printGlobalGotEntry(GOTShdr->sh_addr, GotBegin, It, GotDynSym++,
+ *StrTable, true);
}
}
W.startLine() << "There is no .rel.plt section in the file.\n";
return;
}
+ ErrorOr<const Elf_Shdr *> SymTableOrErr =
+ Obj->getSection(PLTRelShdr->sh_link);
+ error(SymTableOrErr.getError());
+ ErrorOr<StringRef> StrTable = Obj->getStringTableForSymtab(**SymTableOrErr);
+ error(StrTable.getError());
GOTIter PLTBegin = makeGOTIter(*PLT, 0);
GOTIter PLTEnd = makeGOTIter(*PLT, getGOTTotal(*PLT));
RI != RE && It != PLTEnd; ++RI, ++It) {
const Elf_Sym *Sym =
Obj->getRelocationSymbol(&*PLTRelShdr, &*RI).second;
- printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, Sym);
+ printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, *StrTable, Sym);
}
break;
case ELF::SHT_RELA:
RI != RE && It != PLTEnd; ++RI, ++It) {
const Elf_Sym *Sym =
Obj->getRelocationSymbol(&*PLTRelShdr, &*RI).second;
- printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, Sym);
+ printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, *StrTable, Sym);
}
break;
}
template <class ELFT>
void MipsGOTParser<ELFT>::printGlobalGotEntry(uint64_t GotAddr, GOTIter BeginIt,
GOTIter It, const Elf_Sym *Sym,
+ StringRef StrTable,
bool IsDynamic) {
printGotEntry(GotAddr, BeginIt, It);
getSectionNameIndex(*Obj, Sym, SectionName, SectionIndex);
W.printHex("Section", SectionName, SectionIndex);
- std::string FullSymbolName = getFullSymbolName(*Obj, Sym, IsDynamic);
+ std::string FullSymbolName =
+ getFullSymbolName(*Obj, Sym, StrTable, IsDynamic);
W.printNumber("Name", FullSymbolName, Sym->st_name);
}
template <class ELFT>
void MipsGOTParser<ELFT>::printPLTEntry(uint64_t PLTAddr, GOTIter BeginIt,
- GOTIter It, const Elf_Sym *Sym) {
+ GOTIter It, StringRef StrTable,
+ const Elf_Sym *Sym) {
DictScope D(W, "Entry");
int64_t Offset = std::distance(BeginIt, It) * sizeof(GOTEntry);
W.printHex("Address", PLTAddr + Offset);
getSectionNameIndex(*Obj, Sym, SectionName, SectionIndex);
W.printHex("Section", SectionName, SectionIndex);
- std::string FullSymbolName = getFullSymbolName(*Obj, Sym, true);
+ std::string FullSymbolName = getFullSymbolName(*Obj, Sym, StrTable, true);
W.printNumber("Name", FullSymbolName, Sym->st_name);
}