[llvm] 310af42 - [llvm-readelf/obj] - Cleanup the code. NFCI.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 02:58:55 PDT 2020
Author: Georgii Rymar
Date: 2020-09-23T12:58:22+03:00
New Revision: 310af42ed9ab259ad05ed46d459203b3473ba66e
URL: https://github.com/llvm/llvm-project/commit/310af42ed9ab259ad05ed46d459203b3473ba66e
DIFF: https://github.com/llvm/llvm-project/commit/310af42ed9ab259ad05ed46d459203b3473ba66e.diff
LOG: [llvm-readelf/obj] - Cleanup the code. NFCI.
This:
1) Replaces pointers with references in many places.
2) Adds few TODOs about fixing possible unhandled errors (in ARMEHABIPrinter.h).
3) Replaces `auto`s with actual types.
4) Removes excessive arguments.
5) Adds `const ELFFile<ELFT> &Obj;` member to `ELFDumper` to simplify the code.
Differential revision: https://reviews.llvm.org/D88097
Added:
Modified:
llvm/tools/llvm-readobj/ARMEHABIPrinter.h
llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
llvm/tools/llvm-readobj/ELFDumper.cpp
llvm/tools/llvm-readobj/ObjDumper.cpp
llvm/tools/llvm-readobj/ObjDumper.h
llvm/tools/llvm-readobj/llvm-readobj.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-readobj/ARMEHABIPrinter.h b/llvm/tools/llvm-readobj/ARMEHABIPrinter.h
index 613c4b78b1c2..a743d808845e 100644
--- a/llvm/tools/llvm-readobj/ARMEHABIPrinter.h
+++ b/llvm/tools/llvm-readobj/ARMEHABIPrinter.h
@@ -327,7 +327,7 @@ class PrinterContext {
typedef typename ET::Word Elf_Word;
ScopedPrinter &SW;
- const object::ELFFile<ET> *ELF;
+ const object::ELFFile<ET> &ELF;
StringRef FileName;
const Elf_Shdr *Symtab;
ArrayRef<Elf_Word> ShndxTable;
@@ -351,7 +351,7 @@ class PrinterContext {
void PrintOpcodes(const uint8_t *Entry, size_t Length, off_t Offset) const;
public:
- PrinterContext(ScopedPrinter &SW, const object::ELFFile<ET> *ELF,
+ PrinterContext(ScopedPrinter &SW, const object::ELFFile<ET> &ELF,
StringRef FileName, const Elf_Shdr *Symtab)
: SW(SW), ELF(ELF), FileName(FileName), Symtab(Symtab) {}
@@ -367,12 +367,12 @@ PrinterContext<ET>::FunctionAtAddress(unsigned Section,
uint64_t Address) const {
if (!Symtab)
return inconvertibleErrorCode();
- auto StrTableOrErr = ELF->getStringTableForSymtab(*Symtab);
+ auto StrTableOrErr = ELF.getStringTableForSymtab(*Symtab);
if (!StrTableOrErr)
reportError(StrTableOrErr.takeError(), FileName);
StringRef StrTable = *StrTableOrErr;
- for (const Elf_Sym &Sym : unwrapOrError(FileName, ELF->symbols(Symtab)))
+ for (const Elf_Sym &Sym : unwrapOrError(FileName, ELF.symbols(Symtab)))
if (Sym.st_shndx == Section && Sym.st_value == Address &&
Sym.getType() == ELF::STT_FUNC) {
auto NameOrErr = Sym.getName(StrTable);
@@ -398,16 +398,16 @@ PrinterContext<ET>::FindExceptionTable(unsigned IndexSectionIndex,
/// handling table. Use this symbol to recover the actual exception handling
/// table.
- for (const Elf_Shdr &Sec : unwrapOrError(FileName, ELF->sections())) {
+ for (const Elf_Shdr &Sec : unwrapOrError(FileName, ELF.sections())) {
if (Sec.sh_type != ELF::SHT_REL || Sec.sh_info != IndexSectionIndex)
continue;
- auto SymTabOrErr = ELF->getSection(Sec.sh_link);
+ auto SymTabOrErr = ELF.getSection(Sec.sh_link);
if (!SymTabOrErr)
reportError(SymTabOrErr.takeError(), FileName);
const Elf_Shdr *SymTab = *SymTabOrErr;
- for (const Elf_Rel &R : unwrapOrError(FileName, ELF->rels(Sec))) {
+ for (const Elf_Rel &R : unwrapOrError(FileName, ELF.rels(Sec))) {
if (R.r_offset != static_cast<unsigned>(IndexTableOffset))
continue;
@@ -417,9 +417,9 @@ PrinterContext<ET>::FindExceptionTable(unsigned IndexSectionIndex,
RelA.r_addend = 0;
const Elf_Sym *Symbol =
- unwrapOrError(FileName, ELF->getRelocationSymbol(RelA, SymTab));
+ unwrapOrError(FileName, ELF.getRelocationSymbol(RelA, SymTab));
- auto Ret = ELF->getSection(*Symbol, SymTab, ShndxTable);
+ auto Ret = ELF.getSection(*Symbol, SymTab, ShndxTable);
if (!Ret)
report_fatal_error(errorToErrorCode(Ret.takeError()).message());
return *Ret;
@@ -432,7 +432,8 @@ template <typename ET>
void PrinterContext<ET>::PrintExceptionTable(const Elf_Shdr *IT,
const Elf_Shdr *EHT,
uint64_t TableEntryOffset) const {
- Expected<ArrayRef<uint8_t>> Contents = ELF->getSectionContents(*EHT);
+ // TODO: handle failure.
+ Expected<ArrayRef<uint8_t>> Contents = ELF.getSectionContents(*EHT);
if (!Contents)
return;
@@ -499,7 +500,8 @@ void PrinterContext<ET>::PrintOpcodes(const uint8_t *Entry,
template <typename ET>
void PrinterContext<ET>::PrintIndexTable(unsigned SectionIndex,
const Elf_Shdr *IT) const {
- Expected<ArrayRef<uint8_t>> Contents = ELF->getSectionContents(*IT);
+ // TODO: handle failure.
+ Expected<ArrayRef<uint8_t>> Contents = ELF.getSectionContents(*IT);
if (!Contents)
return;
@@ -553,7 +555,8 @@ void PrinterContext<ET>::PrintIndexTable(unsigned SectionIndex,
FindExceptionTable(SectionIndex, Entry * IndexTableEntrySize + 4);
if (EHT)
- if (auto Name = ELF->getSectionName(*EHT))
+ // TODO: handle failure.
+ if (Expected<StringRef> Name = ELF.getSectionName(*EHT))
SW.printString("ExceptionHandlingTable", *Name);
uint64_t TableEntryOffset = PREL31(Word1, IT->sh_addr);
@@ -570,12 +573,13 @@ void PrinterContext<ET>::PrintUnwindInformation() const {
DictScope UI(SW, "UnwindInformation");
int SectionIndex = 0;
- for (const Elf_Shdr &Sec : unwrapOrError(FileName, ELF->sections())) {
+ for (const Elf_Shdr &Sec : unwrapOrError(FileName, ELF.sections())) {
if (Sec.sh_type == ELF::SHT_ARM_EXIDX) {
DictScope UIT(SW, "UnwindIndexTable");
SW.printNumber("SectionIndex", SectionIndex);
- if (auto SectionName = ELF->getSectionName(Sec))
+ // TODO: handle failure.
+ if (Expected<StringRef> SectionName = ELF.getSectionName(Sec))
SW.printString("SectionName", *SectionName);
SW.printHex("SectionOffset", Sec.sh_offset);
diff --git a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
index 52db477ba726..804f35ca14f9 100644
--- a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
+++ b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
@@ -33,13 +33,13 @@ template <typename ELFT> class PrinterContext {
using Elf_Phdr = typename ELFT::Phdr;
ScopedPrinter &W;
- const object::ELFObjectFile<ELFT> *ObjF;
+ const object::ELFObjectFile<ELFT> &ObjF;
void printEHFrameHdr(const Elf_Phdr *EHFramePHdr) const;
void printEHFrame(const Elf_Shdr *EHFrameShdr) const;
public:
- PrinterContext(ScopedPrinter &W, const object::ELFObjectFile<ELFT> *ObjF)
+ PrinterContext(ScopedPrinter &W, const object::ELFObjectFile<ELFT> &ObjF)
: W(W), ObjF(ObjF) {}
void printUnwindInformation() const;
@@ -47,11 +47,11 @@ template <typename ELFT> class PrinterContext {
template <class ELFT>
static const typename ELFT::Shdr *
-findSectionByAddress(const object::ELFObjectFile<ELFT> *ObjF, uint64_t Addr) {
+findSectionByAddress(const object::ELFObjectFile<ELFT> &ObjF, uint64_t Addr) {
Expected<typename ELFT::ShdrRange> SectionsOrErr =
- ObjF->getELFFile()->sections();
+ ObjF.getELFFile()->sections();
if (!SectionsOrErr)
- reportError(SectionsOrErr.takeError(), ObjF->getFileName());
+ reportError(SectionsOrErr.takeError(), ObjF.getFileName());
for (const typename ELFT::Shdr &Shdr : *SectionsOrErr)
if (Shdr.sh_addr == Addr)
@@ -61,11 +61,11 @@ findSectionByAddress(const object::ELFObjectFile<ELFT> *ObjF, uint64_t Addr) {
template <typename ELFT>
void PrinterContext<ELFT>::printUnwindInformation() const {
- const object::ELFFile<ELFT> *Obj = ObjF->getELFFile();
+ const object::ELFFile<ELFT> &Obj = *ObjF.getELFFile();
- Expected<typename ELFT::PhdrRange> PhdrsOrErr = Obj->program_headers();
+ Expected<typename ELFT::PhdrRange> PhdrsOrErr = Obj.program_headers();
if (!PhdrsOrErr)
- reportError(PhdrsOrErr.takeError(), ObjF->getFileName());
+ reportError(PhdrsOrErr.takeError(), ObjF.getFileName());
for (const Elf_Phdr &Phdr : *PhdrsOrErr) {
if (Phdr.p_type != ELF::PT_GNU_EH_FRAME)
@@ -74,20 +74,19 @@ void PrinterContext<ELFT>::printUnwindInformation() const {
if (Phdr.p_memsz != Phdr.p_filesz)
reportError(object::createError(
"p_memsz does not match p_filesz for GNU_EH_FRAME"),
- ObjF->getFileName());
+ ObjF.getFileName());
printEHFrameHdr(&Phdr);
break;
}
- Expected<typename ELFT::ShdrRange> SectionsOrErr =
- ObjF->getELFFile()->sections();
+ Expected<typename ELFT::ShdrRange> SectionsOrErr = Obj.sections();
if (!SectionsOrErr)
- reportError(SectionsOrErr.takeError(), ObjF->getFileName());
+ reportError(SectionsOrErr.takeError(), ObjF.getFileName());
for (const Elf_Shdr &Shdr : *SectionsOrErr) {
- Expected<StringRef> NameOrErr = Obj->getSectionName(Shdr);
+ Expected<StringRef> NameOrErr = Obj.getSectionName(Shdr);
if (!NameOrErr)
- reportError(NameOrErr.takeError(), ObjF->getFileName());
+ reportError(NameOrErr.takeError(), ObjF.getFileName());
if (*NameOrErr == ".eh_frame")
printEHFrame(&Shdr);
}
@@ -101,18 +100,18 @@ void PrinterContext<ELFT>::printEHFrameHdr(const Elf_Phdr *EHFramePHdr) const {
W.startLine() << format("Offset: 0x%" PRIx64 "\n", (uint64_t)EHFramePHdr->p_offset);
W.startLine() << format("Size: 0x%" PRIx64 "\n", (uint64_t)EHFramePHdr->p_memsz);
- const object::ELFFile<ELFT> *Obj = ObjF->getELFFile();
+ const object::ELFFile<ELFT> &Obj = *ObjF.getELFFile();
if (const Elf_Shdr *EHFrameHdr =
findSectionByAddress(ObjF, EHFramePHdr->p_vaddr)) {
- Expected<StringRef> NameOrErr = Obj->getSectionName(*EHFrameHdr);
+ Expected<StringRef> NameOrErr = Obj.getSectionName(*EHFrameHdr);
if (!NameOrErr)
- reportError(NameOrErr.takeError(), ObjF->getFileName());
+ reportError(NameOrErr.takeError(), ObjF.getFileName());
W.printString("Corresponding Section", *NameOrErr);
}
- Expected<ArrayRef<uint8_t>> Content = Obj->getSegmentContents(*EHFramePHdr);
+ Expected<ArrayRef<uint8_t>> Content = Obj.getSegmentContents(*EHFramePHdr);
if (!Content)
- reportError(Content.takeError(), ObjF->getFileName());
+ reportError(Content.takeError(), ObjF.getFileName());
DataExtractor DE(*Content,
ELFT::TargetEndianness == support::endianness::little,
@@ -126,25 +125,25 @@ void PrinterContext<ELFT>::printEHFrameHdr(const Elf_Phdr *EHFramePHdr) const {
if (Version != 1)
reportError(
object::createError("only version 1 of .eh_frame_hdr is supported"),
- ObjF->getFileName());
+ ObjF.getFileName());
uint64_t EHFramePtrEnc = DE.getU8(&Offset);
W.startLine() << format("eh_frame_ptr_enc: 0x%" PRIx64 "\n", EHFramePtrEnc);
if (EHFramePtrEnc != (dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4))
reportError(object::createError("unexpected encoding eh_frame_ptr_enc"),
- ObjF->getFileName());
+ ObjF.getFileName());
uint64_t FDECountEnc = DE.getU8(&Offset);
W.startLine() << format("fde_count_enc: 0x%" PRIx64 "\n", FDECountEnc);
if (FDECountEnc != dwarf::DW_EH_PE_udata4)
reportError(object::createError("unexpected encoding fde_count_enc"),
- ObjF->getFileName());
+ ObjF.getFileName());
uint64_t TableEnc = DE.getU8(&Offset);
W.startLine() << format("table_enc: 0x%" PRIx64 "\n", TableEnc);
if (TableEnc != (dwarf::DW_EH_PE_datarel | dwarf::DW_EH_PE_sdata4))
reportError(object::createError("unexpected encoding table_enc"),
- ObjF->getFileName());
+ ObjF.getFileName());
auto EHFramePtr = DE.getSigned(&Offset, 4) + EHFrameHdrAddress + 4;
W.startLine() << format("eh_frame_ptr: 0x%" PRIx64 "\n", EHFramePtr);
@@ -164,7 +163,7 @@ void PrinterContext<ELFT>::printEHFrameHdr(const Elf_Phdr *EHFramePHdr) const {
if (InitialPC < PrevPC)
reportError(object::createError("initial_location is out of order"),
- ObjF->getFileName());
+ ObjF.getFileName());
PrevPC = InitialPC;
++NumEntries;
@@ -181,20 +180,20 @@ void PrinterContext<ELFT>::printEHFrame(const Elf_Shdr *EHFrameShdr) const {
W.indent();
Expected<ArrayRef<uint8_t>> DataOrErr =
- ObjF->getELFFile()->getSectionContents(*EHFrameShdr);
+ ObjF.getELFFile()->getSectionContents(*EHFrameShdr);
if (!DataOrErr)
- reportError(DataOrErr.takeError(), ObjF->getFileName());
+ reportError(DataOrErr.takeError(), ObjF.getFileName());
// Construct DWARFDataExtractor to handle relocations ("PC Begin" fields).
- std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*ObjF, nullptr);
+ std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(ObjF, nullptr);
DWARFDataExtractor DE(DICtx->getDWARFObj(),
DICtx->getDWARFObj().getEHFrameSection(),
ELFT::TargetEndianness == support::endianness::little,
ELFT::Is64Bits ? 8 : 4);
- DWARFDebugFrame EHFrame(Triple::ArchType(ObjF->getArch()), /*IsEH=*/true,
+ DWARFDebugFrame EHFrame(Triple::ArchType(ObjF.getArch()), /*IsEH=*/true,
/*EHFrameAddress=*/Address);
if (Error E = EHFrame.parse(DE))
- reportError(std::move(E), ObjF->getFileName());
+ reportError(std::move(E), ObjF.getFileName());
for (const dwarf::FrameEntry &Entry : EHFrame) {
if (const dwarf::CIE *CIE = dyn_cast<dwarf::CIE>(&Entry)) {
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index bb1403b0f1dd..ed777b37c309 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -230,7 +230,7 @@ template <class ELFT> class Relocation {
template <typename ELFT> class ELFDumper : public ObjDumper {
public:
- ELFDumper(const object::ELFObjectFile<ELFT> *ObjF, ScopedPrinter &Writer);
+ ELFDumper(const object::ELFObjectFile<ELFT> &ObjF, ScopedPrinter &Writer);
void printFileHeaders() override;
void printSectionHeaders() override;
@@ -246,7 +246,7 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
void printProgramHeaders(bool PrintProgramHeaders,
cl::boolOrDefault PrintSectionMapping) override;
void printHashTable() override;
- void printGnuHashTable(const object::ObjectFile *Obj) override;
+ void printGnuHashTable() override;
void printLoadName() override;
void printVersionInfo() override;
void printGroupSections() override;
@@ -265,7 +265,7 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
void printELFLinkerOptions() override;
void printStackSizes() override;
- const object::ELFObjectFile<ELFT> *getElfObject() const { return ObjF; };
+ const object::ELFObjectFile<ELFT> &getElfObject() const { return ObjF; };
private:
std::unique_ptr<DumpStyle<ELFT>> ELFDumperStyle;
@@ -274,30 +274,29 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
Expected<DynRegionInfo> createDRI(uint64_t Offset, uint64_t Size,
uint64_t EntSize) {
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
- if (Offset + Size < Offset || Offset + Size > Obj->getBufSize())
+ if (Offset + Size < Offset || Offset + Size > Obj.getBufSize())
return createError("offset (0x" + Twine::utohexstr(Offset) +
") + size (0x" + Twine::utohexstr(Size) +
") is greater than the file size (0x" +
- Twine::utohexstr(Obj->getBufSize()) + ")");
- return DynRegionInfo(Obj->base() + Offset, Size, EntSize,
- ObjF->getFileName());
+ Twine::utohexstr(Obj.getBufSize()) + ")");
+ return DynRegionInfo(Obj.base() + Offset, Size, EntSize,
+ ObjF.getFileName());
}
void printAttributes();
void printMipsReginfo();
void printMipsOptions();
- std::pair<const Elf_Phdr *, const Elf_Shdr *>
- findDynamic(const ELFFile<ELFT> *Obj);
- void loadDynamicTable(const ELFFile<ELFT> *Obj);
- void parseDynamicTable(const ELFFile<ELFT> *Obj);
+ std::pair<const Elf_Phdr *, const Elf_Shdr *> findDynamic();
+ void loadDynamicTable();
+ void parseDynamicTable();
- Expected<StringRef> getSymbolVersion(const Elf_Sym *symb,
+ Expected<StringRef> getSymbolVersion(const Elf_Sym &Sym,
bool &IsDefault) const;
Error LoadVersionMap() const;
- const object::ELFObjectFile<ELFT> *ObjF;
+ const object::ELFObjectFile<ELFT> &ObjF;
+ const ELFFile<ELFT> &Obj;
DynRegionInfo DynRelRegion;
DynRegionInfo DynRelaRegion;
DynRegionInfo DynRelrRegion;
@@ -355,12 +354,12 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
Elf_Rel_Range dyn_rels() const;
Elf_Rela_Range dyn_relas() const;
Elf_Relr_Range dyn_relrs() const;
- std::string getFullSymbolName(const Elf_Sym *Symbol, unsigned SymIndex,
+ std::string getFullSymbolName(const Elf_Sym &Symbol, unsigned SymIndex,
Optional<StringRef> StrTable,
bool IsDynamic) const;
- Expected<unsigned> getSymbolSectionIndex(const Elf_Sym *Symbol,
+ Expected<unsigned> getSymbolSectionIndex(const Elf_Sym &Symbol,
unsigned SymIndex) const;
- Expected<StringRef> getSymbolSectionName(const Elf_Sym *Symbol,
+ Expected<StringRef> getSymbolSectionName(const Elf_Sym &Symbol,
unsigned SectionIndex) const;
std::string getStaticSymbolName(uint32_t Index) const;
StringRef getDynamicString(uint64_t Value) const;
@@ -385,13 +384,13 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
const Elf_Hash *getHashTable() const { return HashTable; }
const Elf_GnuHash *getGnuHashTable() const { return GnuHashTable; }
- Expected<ArrayRef<Elf_Versym>> getVersionTable(const Elf_Shdr *Sec,
+ Expected<ArrayRef<Elf_Versym>> getVersionTable(const Elf_Shdr &Sec,
ArrayRef<Elf_Sym> *SymTab,
StringRef *StrTab) const;
Expected<std::vector<VerDef>>
- getVersionDefinitions(const Elf_Shdr *Sec) const;
+ getVersionDefinitions(const Elf_Shdr &Sec) const;
Expected<std::vector<VerNeed>>
- getVersionDependencies(const Elf_Shdr *Sec) const;
+ getVersionDependencies(const Elf_Shdr &Sec) const;
Expected<RelSymbol<ELFT>> getRelocationTarget(const Relocation<ELFT> &R,
const Elf_Shdr *SymTab) const;
@@ -412,21 +411,21 @@ static std::string describe(const ELFFile<ELFT> &Obj,
template <class ELFT>
std::string ELFDumper<ELFT>::describe(const Elf_Shdr &Sec) const {
- return ::describe(*ObjF->getELFFile(), Sec);
+ return ::describe(Obj, Sec);
}
template <class ELFT>
static Expected<StringRef> getLinkAsStrtab(const ELFFile<ELFT> &Obj,
- const typename ELFT::Shdr *Sec) {
+ const typename ELFT::Shdr &Sec) {
Expected<const typename ELFT::Shdr *> StrTabSecOrErr =
- Obj.getSection(Sec->sh_link);
+ Obj.getSection(Sec.sh_link);
if (!StrTabSecOrErr)
- return createError("invalid section linked to " + describe(Obj, *Sec) +
+ return createError("invalid section linked to " + describe(Obj, Sec) +
": " + toString(StrTabSecOrErr.takeError()));
Expected<StringRef> StrTabOrErr = Obj.getStringTable(**StrTabSecOrErr);
if (!StrTabOrErr)
- return createError("invalid string table linked to " + describe(Obj, *Sec) +
+ return createError("invalid string table linked to " + describe(Obj, Sec) +
": " + toString(StrTabOrErr.takeError()));
return *StrTabOrErr;
}
@@ -434,55 +433,52 @@ static Expected<StringRef> getLinkAsStrtab(const ELFFile<ELFT> &Obj,
// Returns the linked symbol table and associated string table for a given section.
template <class ELFT>
static Expected<std::pair<typename ELFT::SymRange, StringRef>>
-getLinkAsSymtab(const ELFFile<ELFT> &Obj, const typename ELFT::Shdr *Sec,
+getLinkAsSymtab(const ELFFile<ELFT> &Obj, const typename ELFT::Shdr &Sec,
unsigned ExpectedType) {
Expected<const typename ELFT::Shdr *> SymtabOrErr =
- Obj.getSection(Sec->sh_link);
+ Obj.getSection(Sec.sh_link);
if (!SymtabOrErr)
- return createError("invalid section linked to " + describe(Obj, *Sec) +
+ return createError("invalid section linked to " + describe(Obj, Sec) +
": " + toString(SymtabOrErr.takeError()));
if ((*SymtabOrErr)->sh_type != ExpectedType)
return createError(
- "invalid section linked to " + describe(Obj, *Sec) + ": expected " +
+ "invalid section linked to " + describe(Obj, Sec) + ": expected " +
object::getELFSectionTypeName(Obj.getHeader().e_machine, ExpectedType) +
", but got " +
object::getELFSectionTypeName(Obj.getHeader().e_machine,
(*SymtabOrErr)->sh_type));
- Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Obj, *SymtabOrErr);
+ Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Obj, **SymtabOrErr);
if (!StrTabOrErr)
return createError(
"can't get a string table for the symbol table linked to " +
- describe(Obj, *Sec) + ": " + toString(StrTabOrErr.takeError()));
+ describe(Obj, Sec) + ": " + toString(StrTabOrErr.takeError()));
Expected<typename ELFT::SymRange> SymsOrErr = Obj.symbols(*SymtabOrErr);
if (!SymsOrErr)
- return createError("unable to read symbols from the " +
- describe(Obj, *Sec) + ": " +
- toString(SymsOrErr.takeError()));
+ return createError("unable to read symbols from the " + describe(Obj, Sec) +
+ ": " + toString(SymsOrErr.takeError()));
return std::make_pair(*SymsOrErr, *StrTabOrErr);
}
template <class ELFT>
Expected<ArrayRef<typename ELFT::Versym>>
-ELFDumper<ELFT>::getVersionTable(const Elf_Shdr *Sec, ArrayRef<Elf_Sym> *SymTab,
+ELFDumper<ELFT>::getVersionTable(const Elf_Shdr &Sec, ArrayRef<Elf_Sym> *SymTab,
StringRef *StrTab) const {
assert((!SymTab && !StrTab) || (SymTab && StrTab));
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
-
- if (uintptr_t(Obj->base() + Sec->sh_offset) % sizeof(uint16_t) != 0)
- return createError("the " + describe(*Sec) + " is misaligned");
+ if (uintptr_t(Obj.base() + Sec.sh_offset) % sizeof(uint16_t) != 0)
+ return createError("the " + describe(Sec) + " is misaligned");
Expected<ArrayRef<Elf_Versym>> VersionsOrErr =
- Obj->template getSectionContentsAsArray<Elf_Versym>(*Sec);
+ Obj.template getSectionContentsAsArray<Elf_Versym>(Sec);
if (!VersionsOrErr)
- return createError("cannot read content of " + describe(*Sec) + ": " +
+ return createError("cannot read content of " + describe(Sec) + ": " +
toString(VersionsOrErr.takeError()));
Expected<std::pair<ArrayRef<Elf_Sym>, StringRef>> SymTabOrErr =
- getLinkAsSymtab(*Obj, Sec, SHT_DYNSYM);
+ getLinkAsSymtab(Obj, Sec, SHT_DYNSYM);
if (!SymTabOrErr) {
reportUniqueWarning(SymTabOrErr.takeError());
return *VersionsOrErr;
@@ -490,11 +486,11 @@ ELFDumper<ELFT>::getVersionTable(const Elf_Shdr *Sec, ArrayRef<Elf_Sym> *SymTab,
if (SymTabOrErr->first.size() != VersionsOrErr->size())
reportUniqueWarning(
- createError(describe(*Sec) + ": the number of entries (" +
+ createError(describe(Sec) + ": the number of entries (" +
Twine(VersionsOrErr->size()) +
") does not match the number of symbols (" +
Twine(SymTabOrErr->first.size()) +
- ") in the symbol table with index " + Twine(Sec->sh_link)));
+ ") in the symbol table with index " + Twine(Sec.sh_link)));
if (SymTab)
std::tie(*SymTab, *StrTab) = *SymTabOrErr;
@@ -503,16 +499,14 @@ ELFDumper<ELFT>::getVersionTable(const Elf_Shdr *Sec, ArrayRef<Elf_Sym> *SymTab,
template <class ELFT>
Expected<std::vector<VerDef>>
-ELFDumper<ELFT>::getVersionDefinitions(const Elf_Shdr *Sec) const {
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
-
- Expected<StringRef> StrTabOrErr = getLinkAsStrtab(*Obj, Sec);
+ELFDumper<ELFT>::getVersionDefinitions(const Elf_Shdr &Sec) const {
+ Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Obj, Sec);
if (!StrTabOrErr)
return StrTabOrErr.takeError();
- Expected<ArrayRef<uint8_t>> ContentsOrErr = Obj->getSectionContents(*Sec);
+ Expected<ArrayRef<uint8_t>> ContentsOrErr = Obj.getSectionContents(Sec);
if (!ContentsOrErr)
- return createError("cannot read content of " + describe(*Sec) + ": " +
+ return createError("cannot read content of " + describe(Sec) + ": " +
toString(ContentsOrErr.takeError()));
const uint8_t *Start = ContentsOrErr->data();
@@ -521,7 +515,7 @@ ELFDumper<ELFT>::getVersionDefinitions(const Elf_Shdr *Sec) const {
auto ExtractNextAux = [&](const uint8_t *&VerdauxBuf,
unsigned VerDefNdx) -> Expected<VerdAux> {
if (VerdauxBuf + sizeof(Elf_Verdaux) > End)
- return createError("invalid " + describe(*Sec) + ": version definition " +
+ return createError("invalid " + describe(Sec) + ": version definition " +
Twine(VerDefNdx) +
" refers to an auxiliary entry that goes past the end "
"of the section");
@@ -540,20 +534,20 @@ ELFDumper<ELFT>::getVersionDefinitions(const Elf_Shdr *Sec) const {
std::vector<VerDef> Ret;
const uint8_t *VerdefBuf = Start;
- for (unsigned I = 1; I <= /*VerDefsNum=*/Sec->sh_info; ++I) {
+ for (unsigned I = 1; I <= /*VerDefsNum=*/Sec.sh_info; ++I) {
if (VerdefBuf + sizeof(Elf_Verdef) > End)
- return createError("invalid " + describe(*Sec) + ": version definition " +
+ return createError("invalid " + describe(Sec) + ": version definition " +
Twine(I) + " goes past the end of the section");
if (uintptr_t(VerdefBuf) % sizeof(uint32_t) != 0)
return createError(
- "invalid " + describe(*Sec) +
+ "invalid " + describe(Sec) +
": found a misaligned version definition entry at offset 0x" +
Twine::utohexstr(VerdefBuf - Start));
unsigned Version = *reinterpret_cast<const Elf_Half *>(VerdefBuf);
if (Version != 1)
- return createError("unable to dump " + describe(*Sec) + ": version " +
+ return createError("unable to dump " + describe(Sec) + ": version " +
Twine(Version) + " is not yet supported");
const Elf_Verdef *D = reinterpret_cast<const Elf_Verdef *>(VerdefBuf);
@@ -568,7 +562,7 @@ ELFDumper<ELFT>::getVersionDefinitions(const Elf_Shdr *Sec) const {
const uint8_t *VerdauxBuf = VerdefBuf + D->vd_aux;
for (unsigned J = 0; J < D->vd_cnt; ++J) {
if (uintptr_t(VerdauxBuf) % sizeof(uint32_t) != 0)
- return createError("invalid " + describe(*Sec) +
+ return createError("invalid " + describe(Sec) +
": found a misaligned auxiliary entry at offset 0x" +
Twine::utohexstr(VerdauxBuf - Start));
@@ -590,18 +584,17 @@ ELFDumper<ELFT>::getVersionDefinitions(const Elf_Shdr *Sec) const {
template <class ELFT>
Expected<std::vector<VerNeed>>
-ELFDumper<ELFT>::getVersionDependencies(const Elf_Shdr *Sec) const {
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
+ELFDumper<ELFT>::getVersionDependencies(const Elf_Shdr &Sec) const {
StringRef StrTab;
- Expected<StringRef> StrTabOrErr = getLinkAsStrtab(*Obj, Sec);
+ Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Obj, Sec);
if (!StrTabOrErr)
reportUniqueWarning(StrTabOrErr.takeError());
else
StrTab = *StrTabOrErr;
- Expected<ArrayRef<uint8_t>> ContentsOrErr = Obj->getSectionContents(*Sec);
+ Expected<ArrayRef<uint8_t>> ContentsOrErr = Obj.getSectionContents(Sec);
if (!ContentsOrErr)
- return createError("cannot read content of " + describe(*Sec) + ": " +
+ return createError("cannot read content of " + describe(Sec) + ": " +
toString(ContentsOrErr.takeError()));
const uint8_t *Start = ContentsOrErr->data();
@@ -609,20 +602,20 @@ ELFDumper<ELFT>::getVersionDependencies(const Elf_Shdr *Sec) const {
const uint8_t *VerneedBuf = Start;
std::vector<VerNeed> Ret;
- for (unsigned I = 1; I <= /*VerneedNum=*/Sec->sh_info; ++I) {
+ for (unsigned I = 1; I <= /*VerneedNum=*/Sec.sh_info; ++I) {
if (VerneedBuf + sizeof(Elf_Verdef) > End)
- return createError("invalid " + describe(*Sec) + ": version dependency " +
+ return createError("invalid " + describe(Sec) + ": version dependency " +
Twine(I) + " goes past the end of the section");
if (uintptr_t(VerneedBuf) % sizeof(uint32_t) != 0)
return createError(
- "invalid " + describe(*Sec) +
+ "invalid " + describe(Sec) +
": found a misaligned version dependency entry at offset 0x" +
Twine::utohexstr(VerneedBuf - Start));
unsigned Version = *reinterpret_cast<const Elf_Half *>(VerneedBuf);
if (Version != 1)
- return createError("unable to dump " + describe(*Sec) + ": version " +
+ return createError("unable to dump " + describe(Sec) + ": version " +
Twine(Version) + " is not yet supported");
const Elf_Verneed *Verneed =
@@ -641,13 +634,13 @@ ELFDumper<ELFT>::getVersionDependencies(const Elf_Shdr *Sec) const {
const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux;
for (unsigned J = 0; J < Verneed->vn_cnt; ++J) {
if (uintptr_t(VernauxBuf) % sizeof(uint32_t) != 0)
- return createError("invalid " + describe(*Sec) +
+ return createError("invalid " + describe(Sec) +
": found a misaligned auxiliary entry at offset 0x" +
Twine::utohexstr(VernauxBuf - Start));
if (VernauxBuf + sizeof(Elf_Vernaux) > End)
return createError(
- "invalid " + describe(*Sec) + ": version dependency " + Twine(I) +
+ "invalid " + describe(Sec) + ": version dependency " + Twine(I) +
" refers to an auxiliary entry that goes past the end "
"of the section");
@@ -676,7 +669,6 @@ void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const {
Optional<StringRef> StrTable;
size_t Entries = 0;
Elf_Sym_Range Syms(nullptr, nullptr);
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
const Elf_Shdr *SymtabSec = IsDynamic ? DotDynsymSec : DotSymtabSec;
if (IsDynamic) {
@@ -685,14 +677,14 @@ void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const {
Entries = Syms.size();
} else if (DotSymtabSec) {
if (Expected<StringRef> StrTableOrErr =
- Obj->getStringTableForSymtab(*DotSymtabSec))
+ Obj.getStringTableForSymtab(*DotSymtabSec))
StrTable = *StrTableOrErr;
else
reportUniqueWarning(createError(
"unable to get the string table for the SHT_SYMTAB section: " +
toString(StrTableOrErr.takeError())));
- if (Expected<Elf_Sym_Range> SymsOrErr = Obj->symbols(DotSymtabSec))
+ if (Expected<Elf_Sym_Range> SymsOrErr = Obj.symbols(DotSymtabSec))
Syms = *SymsOrErr;
else
reportUniqueWarning(
@@ -710,8 +702,8 @@ void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const {
}) != Syms.end();
ELFDumperStyle->printSymtabMessage(SymtabSec, Entries, NonVisibilityBitsUsed);
- for (const auto &Sym : Syms)
- ELFDumperStyle->printSymbol(&Sym, &Sym - Syms.begin(), StrTable, IsDynamic,
+ for (const Elf_Sym &Sym : Syms)
+ ELFDumperStyle->printSymbol(Sym, &Sym - Syms.begin(), StrTable, IsDynamic,
NonVisibilityBitsUsed);
}
@@ -721,9 +713,9 @@ template <typename ELFT> class DumpStyle {
public:
TYPEDEF_ELF_TYPES(ELFT)
- DumpStyle(ELFDumper<ELFT> *Dumper)
- : Obj(*Dumper->getElfObject()->getELFFile()),
- ElfObj(*Dumper->getElfObject()), Dumper(Dumper) {
+ DumpStyle(const ELFDumper<ELFT> &Dumper)
+ : Obj(*Dumper.getElfObject().getELFFile()), ElfObj(Dumper.getElfObject()),
+ Dumper(Dumper) {
FileName = ElfObj.getFileName();
}
@@ -740,7 +732,7 @@ template <typename ELFT> class DumpStyle {
virtual void printDynamicRelocations() = 0;
virtual void printSymtabMessage(const Elf_Shdr *Symtab, size_t Offset,
bool NonVisibilityBitsUsed) {}
- virtual void printSymbol(const Elf_Sym *Symbol, unsigned SymIndex,
+ virtual void printSymbol(const Elf_Sym &Symbol, unsigned SymIndex,
Optional<StringRef> StrTable, bool IsDynamic,
bool NonVisibilityBitsUsed) = 0;
virtual void printProgramHeaders(bool PrintProgramHeaders,
@@ -766,8 +758,8 @@ template <typename ELFT> class DumpStyle {
virtual void printStackSizeEntry(uint64_t Size, StringRef FuncName) = 0;
virtual void printMipsGOT(const MipsGOTParser<ELFT> &Parser) = 0;
virtual void printMipsPLT(const MipsGOTParser<ELFT> &Parser) = 0;
- virtual void printMipsABIFlags(const ELFObjectFile<ELFT> *Obj) = 0;
- const ELFDumper<ELFT> *dumper() const { return Dumper; }
+ virtual void printMipsABIFlags() = 0;
+ const ELFDumper<ELFT> &dumper() const { return Dumper; }
protected:
void printDependentLibsHelper(
@@ -792,7 +784,7 @@ template <typename ELFT> class DumpStyle {
const ELFObjectFile<ELFT> &ElfObj;
private:
- const ELFDumper<ELFT> *Dumper;
+ const ELFDumper<ELFT> &Dumper;
};
template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
@@ -801,10 +793,10 @@ template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
public:
TYPEDEF_ELF_TYPES(ELFT)
- GNUStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper)
+ GNUStyle(ScopedPrinter &W, const ELFDumper<ELFT> &Dumper)
: DumpStyle<ELFT>(Dumper),
- OS(static_cast<formatted_raw_ostream&>(W.getOStream())) {
- assert (&W.getOStream() == &llvm::fouts());
+ OS(static_cast<formatted_raw_ostream &>(W.getOStream())) {
+ assert(&W.getOStream() == &llvm::fouts());
}
void printFileHeaders() override;
@@ -832,7 +824,7 @@ template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
void printStackSizeEntry(uint64_t Size, StringRef FuncName) override;
void printMipsGOT(const MipsGOTParser<ELFT> &Parser) override;
void printMipsPLT(const MipsGOTParser<ELFT> &Parser) override;
- void printMipsABIFlags(const ELFObjectFile<ELFT> *Obj) override;
+ void printMipsABIFlags() override;
private:
void printHashHistogram(const Elf_Hash &HashTable);
@@ -851,7 +843,7 @@ template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
template <typename T, typename TEnum>
std::string printEnum(T Value, ArrayRef<EnumEntry<TEnum>> EnumValues) {
- for (const auto &EnumItem : EnumValues)
+ for (const EnumEntry<TEnum> &EnumItem : EnumValues)
if (EnumItem.Value == Value)
return std::string(EnumItem.AltName);
return to_hexString(Value, false);
@@ -862,7 +854,7 @@ template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
TEnum EnumMask1 = {}, TEnum EnumMask2 = {},
TEnum EnumMask3 = {}) {
std::string Str;
- for (const auto &Flag : EnumValues) {
+ for (const EnumEntry<TEnum> &Flag : EnumValues) {
if (Flag.Value == 0)
continue;
@@ -899,14 +891,14 @@ template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
void printRelRelaReloc(const Relocation<ELFT> &R,
const RelSymbol<ELFT> &RelSym);
- void printSymbol(const Elf_Sym *Symbol, unsigned SymIndex,
+ void printSymbol(const Elf_Sym &Symbol, unsigned SymIndex,
Optional<StringRef> StrTable, bool IsDynamic,
bool NonVisibilityBitsUsed) override;
void printDynamicRelocHeader(unsigned Type, StringRef Name,
const DynRegionInfo &Reg) override;
void printDynamicReloc(const Relocation<ELFT> &R) override;
- std::string getSymbolSectionNdx(const Elf_Sym *Symbol, unsigned SymIndex);
+ std::string getSymbolSectionNdx(const Elf_Sym &Symbol, unsigned SymIndex);
void printProgramHeaders();
void printSectionMapping();
void printGNUVersionSectionProlog(const typename ELFT::Shdr *Sec,
@@ -923,14 +915,14 @@ void ELFDumper<ELFT>::reportUniqueWarning(Error Err) const {
template <class ELFT>
void DumpStyle<ELFT>::reportUniqueWarning(Error Err) const {
- this->dumper()->reportUniqueWarning(std::move(Err));
+ this->dumper().reportUniqueWarning(std::move(Err));
}
template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> {
public:
TYPEDEF_ELF_TYPES(ELFT)
- LLVMStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper)
+ LLVMStyle(ScopedPrinter &W, const ELFDumper<ELFT> &Dumper)
: DumpStyle<ELFT>(Dumper), W(W) {}
void printFileHeaders() override;
@@ -955,7 +947,7 @@ template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> {
void printStackSizeEntry(uint64_t Size, StringRef FuncName) override;
void printMipsGOT(const MipsGOTParser<ELFT> &Parser) override;
void printMipsPLT(const MipsGOTParser<ELFT> &Parser) override;
- void printMipsABIFlags(const ELFObjectFile<ELFT> *Obj) override;
+ void printMipsABIFlags() override;
private:
void printReloc(const Relocation<ELFT> &R, unsigned RelIndex,
@@ -966,8 +958,8 @@ template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> {
void printRelRelaReloc(const Relocation<ELFT> &R, StringRef SymbolName);
void printSymbols();
void printDynamicSymbols();
- void printSymbolSection(const Elf_Sym *Symbol, unsigned SymIndex);
- void printSymbol(const Elf_Sym *Symbol, unsigned SymIndex,
+ void printSymbolSection(const Elf_Sym &Symbol, unsigned SymIndex);
+ void printSymbol(const Elf_Sym &Symbol, unsigned SymIndex,
Optional<StringRef> StrTable, bool IsDynamic,
bool /*NonVisibilityBitsUsed*/) override;
void printProgramHeaders();
@@ -983,7 +975,7 @@ namespace llvm {
template <class ELFT>
static std::unique_ptr<ObjDumper> createELFDumper(const ELFObjectFile<ELFT> &Obj,
ScopedPrinter &Writer) {
- return std::make_unique<ELFDumper<ELFT>>(&Obj, Writer);
+ return std::make_unique<ELFDumper<ELFT>>(Obj, Writer);
}
std::unique_ptr<ObjDumper> createELFDumper(const object::ELFObjectFileBase &Obj,
@@ -1028,7 +1020,7 @@ template <class ELFT> Error ELFDumper<ELFT>::LoadVersionMap() const {
if (SymbolVersionDefSection) {
Expected<std::vector<VerDef>> Defs =
- this->getVersionDefinitions(SymbolVersionDefSection);
+ this->getVersionDefinitions(*SymbolVersionDefSection);
if (!Defs)
return Defs.takeError();
for (const VerDef &Def : *Defs)
@@ -1037,7 +1029,7 @@ template <class ELFT> Error ELFDumper<ELFT>::LoadVersionMap() const {
if (SymbolVersionNeedSection) {
Expected<std::vector<VerNeed>> Deps =
- this->getVersionDependencies(SymbolVersionNeedSection);
+ this->getVersionDependencies(*SymbolVersionNeedSection);
if (!Deps)
return Deps.takeError();
for (const VerNeed &Dep : *Deps)
@@ -1049,7 +1041,7 @@ template <class ELFT> Error ELFDumper<ELFT>::LoadVersionMap() const {
}
template <typename ELFT>
-Expected<StringRef> ELFDumper<ELFT>::getSymbolVersion(const Elf_Sym *Sym,
+Expected<StringRef> ELFDumper<ELFT>::getSymbolVersion(const Elf_Sym &Sym,
bool &IsDefault) const {
// This is a dynamic symbol. Look in the GNU symbol version table.
if (!SymbolVersionSection) {
@@ -1060,14 +1052,13 @@ Expected<StringRef> ELFDumper<ELFT>::getSymbolVersion(const Elf_Sym *Sym,
assert(DynSymRegion && "DynSymRegion has not been initialised");
// Determine the position in the symbol table of this entry.
- size_t EntryIndex = (reinterpret_cast<uintptr_t>(Sym) -
+ size_t EntryIndex = (reinterpret_cast<uintptr_t>(&Sym) -
reinterpret_cast<uintptr_t>(DynSymRegion->Addr)) /
sizeof(Elf_Sym);
// Get the corresponding version index entry.
if (Expected<const Elf_Versym *> EntryOrErr =
- ObjF->getELFFile()->template getEntry<Elf_Versym>(
- *SymbolVersionSection, EntryIndex))
+ Obj.template getEntry<Elf_Versym>(*SymbolVersionSection, EntryIndex))
return this->getSymbolVersionByIndex((*EntryOrErr)->vs_index, IsDefault);
else
return EntryOrErr.takeError();
@@ -1080,7 +1071,6 @@ ELFDumper<ELFT>::getRelocationTarget(const Relocation<ELFT> &R,
if (R.Symbol == 0)
return RelSymbol<ELFT>(nullptr, "");
- const ELFFile<ELFT> &Obj = *ObjF->getELFFile();
Expected<const Elf_Sym *> SymOrErr =
Obj.template getEntry<Elf_Sym>(*SymTab, R.Symbol);
if (!SymOrErr)
@@ -1113,7 +1103,7 @@ ELFDumper<ELFT>::getRelocationTarget(const Relocation<ELFT> &R,
const Elf_Sym *FirstSym =
cantFail(Obj.template getEntry<Elf_Sym>(*SymTab, 0));
std::string SymbolName = getFullSymbolName(
- Sym, FirstSym - Sym, *StrTableOrErr, SymTab->sh_type == SHT_DYNSYM);
+ *Sym, FirstSym - Sym, *StrTableOrErr, SymTab->sh_type == SHT_DYNSYM);
return RelSymbol<ELFT>(Sym, SymbolName);
}
@@ -1130,13 +1120,12 @@ std::string ELFDumper<ELFT>::getStaticSymbolName(uint32_t Index) const {
return "<?>";
};
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
Expected<const typename ELFT::Sym *> SymOrErr =
- Obj->getSymbol(DotSymtabSec, Index);
+ Obj.getSymbol(DotSymtabSec, Index);
if (!SymOrErr)
return Warn(SymOrErr.takeError());
- Expected<StringRef> StrTabOrErr = Obj->getStringTableForSymtab(*DotSymtabSec);
+ Expected<StringRef> StrTabOrErr = Obj.getStringTableForSymtab(*DotSymtabSec);
if (!StrTabOrErr)
return Warn(StrTabOrErr.takeError());
@@ -1174,7 +1163,7 @@ ELFDumper<ELFT>::getSymbolVersionByIndex(uint32_t SymbolVersionIndex,
}
template <typename ELFT>
-std::string ELFDumper<ELFT>::getFullSymbolName(const Elf_Sym *Symbol,
+std::string ELFDumper<ELFT>::getFullSymbolName(const Elf_Sym &Symbol,
unsigned SymIndex,
Optional<StringRef> StrTable,
bool IsDynamic) const {
@@ -1182,14 +1171,14 @@ std::string ELFDumper<ELFT>::getFullSymbolName(const Elf_Sym *Symbol,
return "<?>";
std::string SymbolName;
- if (Expected<StringRef> NameOrErr = Symbol->getName(*StrTable)) {
+ if (Expected<StringRef> NameOrErr = Symbol.getName(*StrTable)) {
SymbolName = maybeDemangle(*NameOrErr);
} else {
reportUniqueWarning(NameOrErr.takeError());
return "<?>";
}
- if (SymbolName.empty() && Symbol->getType() == ELF::STT_SECTION) {
+ if (SymbolName.empty() && Symbol.getType() == ELF::STT_SECTION) {
Expected<unsigned> SectionIndex = getSymbolSectionIndex(Symbol, SymIndex);
if (!SectionIndex) {
reportUniqueWarning(SectionIndex.takeError());
@@ -1207,7 +1196,7 @@ std::string ELFDumper<ELFT>::getFullSymbolName(const Elf_Sym *Symbol,
return SymbolName;
bool IsDefault;
- Expected<StringRef> VersionOrErr = getSymbolVersion(&*Symbol, IsDefault);
+ Expected<StringRef> VersionOrErr = getSymbolVersion(Symbol, IsDefault);
if (!VersionOrErr) {
reportUniqueWarning(VersionOrErr.takeError());
return SymbolName + "@<corrupt>";
@@ -1222,11 +1211,11 @@ std::string ELFDumper<ELFT>::getFullSymbolName(const Elf_Sym *Symbol,
template <typename ELFT>
Expected<unsigned>
-ELFDumper<ELFT>::getSymbolSectionIndex(const Elf_Sym *Symbol,
+ELFDumper<ELFT>::getSymbolSectionIndex(const Elf_Sym &Symbol,
unsigned SymIndex) const {
- unsigned Ndx = Symbol->st_shndx;
+ unsigned Ndx = Symbol.st_shndx;
if (Ndx == SHN_XINDEX)
- return object::getExtendedSymbolTableIndex<ELFT>(*Symbol, SymIndex,
+ return object::getExtendedSymbolTableIndex<ELFT>(Symbol, SymIndex,
ShndxTable);
if (Ndx != SHN_UNDEF && Ndx < SHN_LORESERVE)
return Ndx;
@@ -1257,20 +1246,19 @@ ELFDumper<ELFT>::getSymbolSectionIndex(const Elf_Sym *Symbol,
template <typename ELFT>
Expected<StringRef>
-ELFDumper<ELFT>::getSymbolSectionName(const Elf_Sym *Symbol,
+ELFDumper<ELFT>::getSymbolSectionName(const Elf_Sym &Symbol,
unsigned SectionIndex) const {
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
- Expected<const Elf_Shdr *> SecOrErr = Obj->getSection(SectionIndex);
+ Expected<const Elf_Shdr *> SecOrErr = Obj.getSection(SectionIndex);
if (!SecOrErr)
return SecOrErr.takeError();
- return Obj->getSectionName(**SecOrErr);
+ return Obj.getSectionName(**SecOrErr);
}
template <class ELFO>
static const typename ELFO::Elf_Shdr *
-findNotEmptySectionByAddress(const ELFO *Obj, StringRef FileName,
+findNotEmptySectionByAddress(const ELFO &Obj, StringRef FileName,
uint64_t Addr) {
- for (const typename ELFO::Elf_Shdr &Shdr : cantFail(Obj->sections()))
+ for (const typename ELFO::Elf_Shdr &Shdr : cantFail(Obj.sections()))
if (Shdr.sh_addr == Addr && Shdr.sh_size > 0)
return &Shdr;
return nullptr;
@@ -1850,10 +1838,10 @@ static const char *getElfMipsOptionsOdkType(unsigned Odk) {
template <typename ELFT>
std::pair<const typename ELFT::Phdr *, const typename ELFT::Shdr *>
-ELFDumper<ELFT>::findDynamic(const ELFFile<ELFT> *Obj) {
+ELFDumper<ELFT>::findDynamic() {
// Try to locate the PT_DYNAMIC header.
const Elf_Phdr *DynamicPhdr = nullptr;
- if (Expected<ArrayRef<Elf_Phdr>> PhdrsOrErr = Obj->program_headers()) {
+ if (Expected<ArrayRef<Elf_Phdr>> PhdrsOrErr = Obj.program_headers()) {
for (const Elf_Phdr &Phdr : *PhdrsOrErr) {
if (Phdr.p_type != ELF::PT_DYNAMIC)
continue;
@@ -1868,7 +1856,7 @@ ELFDumper<ELFT>::findDynamic(const ELFFile<ELFT> *Obj) {
// Try to locate the .dynamic section in the sections header table.
const Elf_Shdr *DynamicSec = nullptr;
- for (const Elf_Shdr &Sec : cantFail(Obj->sections())) {
+ for (const Elf_Shdr &Sec : cantFail(Obj.sections())) {
if (Sec.sh_type != ELF::SHT_DYNAMIC)
continue;
DynamicSec = &Sec;
@@ -1876,7 +1864,7 @@ ELFDumper<ELFT>::findDynamic(const ELFFile<ELFT> *Obj) {
}
if (DynamicPhdr && ((DynamicPhdr->p_offset + DynamicPhdr->p_filesz >
- ObjF->getMemoryBufferRef().getBufferSize()) ||
+ ObjF.getMemoryBufferRef().getBufferSize()) ||
(DynamicPhdr->p_offset + DynamicPhdr->p_filesz <
DynamicPhdr->p_offset))) {
reportUniqueWarning(createError(
@@ -1884,7 +1872,7 @@ ELFDumper<ELFT>::findDynamic(const ELFFile<ELFT> *Obj) {
Twine::utohexstr(DynamicPhdr->p_offset) + ") + file size (0x" +
Twine::utohexstr(DynamicPhdr->p_filesz) +
") exceeds the size of the file (0x" +
- Twine::utohexstr(ObjF->getMemoryBufferRef().getBufferSize()) + ")"));
+ Twine::utohexstr(ObjF.getMemoryBufferRef().getBufferSize()) + ")"));
// Don't use the broken dynamic header.
DynamicPhdr = nullptr;
}
@@ -1893,30 +1881,28 @@ ELFDumper<ELFT>::findDynamic(const ELFFile<ELFT> *Obj) {
if (DynamicSec->sh_addr + DynamicSec->sh_size >
DynamicPhdr->p_vaddr + DynamicPhdr->p_memsz ||
DynamicSec->sh_addr < DynamicPhdr->p_vaddr)
- reportWarning(createError(describe(*DynamicSec) +
- " is not contained within the "
- "PT_DYNAMIC segment"),
- ObjF->getFileName());
+ reportUniqueWarning(createError(describe(*DynamicSec) +
+ " is not contained within the "
+ "PT_DYNAMIC segment"));
if (DynamicSec->sh_addr != DynamicPhdr->p_vaddr)
- reportWarning(createError(describe(*DynamicSec) +
- " is not at the start of "
- "PT_DYNAMIC segment"),
- ObjF->getFileName());
+ reportUniqueWarning(createError(describe(*DynamicSec) +
+ " is not at the start of "
+ "PT_DYNAMIC segment"));
}
return std::make_pair(DynamicPhdr, DynamicSec);
}
template <typename ELFT>
-void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) {
+void ELFDumper<ELFT>::loadDynamicTable() {
const Elf_Phdr *DynamicPhdr;
const Elf_Shdr *DynamicSec;
- std::tie(DynamicPhdr, DynamicSec) = findDynamic(Obj);
+ std::tie(DynamicPhdr, DynamicSec) = findDynamic();
if (!DynamicPhdr && !DynamicSec)
return;
- DynRegionInfo FromPhdr(ObjF->getFileName());
+ DynRegionInfo FromPhdr(ObjF.getFileName());
bool IsPhdrTableValid = false;
if (DynamicPhdr) {
// Use cantFail(), because p_offset/p_filesz fields of a PT_DYNAMIC are
@@ -1932,7 +1918,7 @@ void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) {
// Ignore sh_entsize and use the expected value for entry size explicitly.
// This allows us to dump dynamic sections with a broken sh_entsize
// field.
- DynRegionInfo FromSec(ObjF->getFileName());
+ DynRegionInfo FromSec(ObjF.getFileName());
bool IsSecTableValid = false;
if (DynamicSec) {
Expected<DynRegionInfo> RegOrErr =
@@ -1954,10 +1940,9 @@ void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) {
if (!DynamicPhdr || !DynamicSec) {
if ((DynamicPhdr && IsPhdrTableValid) || (DynamicSec && IsSecTableValid)) {
DynamicTable = DynamicPhdr ? FromPhdr : FromSec;
- parseDynamicTable(Obj);
+ parseDynamicTable();
} else {
- reportWarning(createError("no valid dynamic table was found"),
- ObjF->getFileName());
+ reportUniqueWarning(createError("no valid dynamic table was found"));
}
return;
}
@@ -1967,14 +1952,12 @@ void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) {
// verify that.
if (FromPhdr.Addr != FromSec.Addr)
- reportWarning(createError("SHT_DYNAMIC section header and PT_DYNAMIC "
- "program header disagree about "
- "the location of the dynamic table"),
- ObjF->getFileName());
+ reportUniqueWarning(createError("SHT_DYNAMIC section header and PT_DYNAMIC "
+ "program header disagree about "
+ "the location of the dynamic table"));
if (!IsPhdrTableValid && !IsSecTableValid) {
- reportWarning(createError("no valid dynamic table was found"),
- ObjF->getFileName());
+ reportUniqueWarning(createError("no valid dynamic table was found"));
return;
}
@@ -1982,43 +1965,39 @@ void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) {
// in a section header.
if (IsPhdrTableValid) {
if (!IsSecTableValid)
- reportWarning(
- createError(
- "SHT_DYNAMIC dynamic table is invalid: PT_DYNAMIC will be used"),
- ObjF->getFileName());
+ reportUniqueWarning(createError(
+ "SHT_DYNAMIC dynamic table is invalid: PT_DYNAMIC will be used"));
DynamicTable = FromPhdr;
} else {
- reportWarning(
- createError(
- "PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used"),
- ObjF->getFileName());
+ reportUniqueWarning(createError(
+ "PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used"));
DynamicTable = FromSec;
}
- parseDynamicTable(Obj);
+ parseDynamicTable();
}
template <typename ELFT>
-ELFDumper<ELFT>::ELFDumper(const object::ELFObjectFile<ELFT> *ObjF,
+ELFDumper<ELFT>::ELFDumper(const object::ELFObjectFile<ELFT> &O,
ScopedPrinter &Writer)
- : ObjDumper(Writer), ObjF(ObjF), DynRelRegion(ObjF->getFileName()),
- DynRelaRegion(ObjF->getFileName()), DynRelrRegion(ObjF->getFileName()),
- DynPLTRelRegion(ObjF->getFileName()), DynamicTable(ObjF->getFileName()) {
+ : ObjDumper(Writer), ObjF(O), Obj(*O.getELFFile()),
+ DynRelRegion(O.getFileName()), DynRelaRegion(O.getFileName()),
+ DynRelrRegion(O.getFileName()), DynPLTRelRegion(O.getFileName()),
+ DynamicTable(O.getFileName()) {
// Dumper reports all non-critical errors as warnings.
// It does not print the same warning more than once.
WarningHandler = [this](const Twine &Msg) {
if (Warnings.insert(Msg.str()).second)
- reportWarning(createError(Msg), this->ObjF->getFileName());
+ reportWarning(createError(Msg), ObjF.getFileName());
return Error::success();
};
if (opts::Output == opts::GNU)
- ELFDumperStyle.reset(new GNUStyle<ELFT>(Writer, this));
+ ELFDumperStyle.reset(new GNUStyle<ELFT>(Writer, *this));
else
- ELFDumperStyle.reset(new LLVMStyle<ELFT>(Writer, this));
+ ELFDumperStyle.reset(new LLVMStyle<ELFT>(Writer, *this));
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
- typename ELFT::ShdrRange Sections = cantFail(Obj->sections());
+ typename ELFT::ShdrRange Sections = cantFail(Obj.sections());
for (const Elf_Shdr &Sec : Sections) {
switch (Sec.sh_type) {
case ELF::SHT_SYMTAB:
@@ -2036,10 +2015,10 @@ ELFDumper<ELFT>::ELFDumper(const object::ELFObjectFile<ELFT> *ObjF,
DynSymRegion = *RegOrErr;
DynSymRegion->Context = describe(Sec);
- if (Expected<StringRef> E = Obj->getStringTableForSymtab(Sec))
+ if (Expected<StringRef> E = Obj.getStringTableForSymtab(Sec))
DynamicStringTable = *E;
else
- reportWarning(E.takeError(), ObjF->getFileName());
+ reportWarning(E.takeError(), ObjF.getFileName());
} else {
reportUniqueWarning(createError(
"unable to read dynamic symbols from " + describe(Sec) + ": " +
@@ -2048,7 +2027,7 @@ ELFDumper<ELFT>::ELFDumper(const object::ELFObjectFile<ELFT> *ObjF,
}
break;
case ELF::SHT_SYMTAB_SHNDX:
- ShndxTable = unwrapOrError(ObjF->getFileName(), Obj->getSHNDXTable(Sec));
+ ShndxTable = unwrapOrError(ObjF.getFileName(), Obj.getSHNDXTable(Sec));
break;
case ELF::SHT_GNU_versym:
if (!SymbolVersionSection)
@@ -2073,19 +2052,19 @@ ELFDumper<ELFT>::ELFDumper(const object::ELFObjectFile<ELFT> *ObjF,
}
}
- loadDynamicTable(Obj);
+ loadDynamicTable();
}
template <typename ELFT>
-void ELFDumper<ELFT>::parseDynamicTable(const ELFFile<ELFT> *Obj) {
+void ELFDumper<ELFT>::parseDynamicTable() {
auto toMappedAddr = [&](uint64_t Tag, uint64_t VAddr) -> const uint8_t * {
- auto MappedAddrOrError = ObjF->getELFFile()->toMappedAddr(VAddr);
+ auto MappedAddrOrError = Obj.toMappedAddr(VAddr);
if (!MappedAddrOrError) {
Error Err =
- createError("Unable to parse DT_" + Obj->getDynamicTagAsString(Tag) +
+ createError("Unable to parse DT_" + Obj.getDynamicTagAsString(Tag) +
": " + llvm::toString(MappedAddrOrError.takeError()));
- reportWarning(std::move(Err), ObjF->getFileName());
+ reportWarning(std::move(Err), ObjF.getFileName());
return nullptr;
}
return MappedAddrOrError.get();
@@ -2116,7 +2095,7 @@ void ELFDumper<ELFT>::parseDynamicTable(const ELFFile<ELFT> *Obj) {
// If we can't map the DT_SYMTAB value to an address (e.g. when there are
// no program headers), we ignore its value.
if (const uint8_t *VA = toMappedAddr(Dyn.getTag(), Dyn.getPtr())) {
- DynSymFromTable.emplace(ObjF->getFileName());
+ DynSymFromTable.emplace(ObjF.getFileName());
DynSymFromTable->Addr = VA;
DynSymFromTable->EntSize = sizeof(Elf_Sym);
DynSymFromTable->EntSizePrintName = "";
@@ -2130,7 +2109,7 @@ void ELFDumper<ELFT>::parseDynamicTable(const ELFFile<ELFT> *Obj) {
Twine::utohexstr(Val) +
" is not the size of a symbol (0x" +
Twine::utohexstr(sizeof(Elf_Sym)) + ")"),
- ObjF->getFileName());
+ ObjF.getFileName());
break;
}
case ELF::DT_RELA:
@@ -2184,7 +2163,7 @@ void ELFDumper<ELFT>::parseDynamicTable(const ELFFile<ELFT> *Obj) {
else
reportError(createError(Twine("unknown DT_PLTREL value of ") +
Twine((uint64_t)Dyn.getVal())),
- ObjF->getFileName());
+ ObjF.getFileName());
DynPLTRelRegion.EntSizePrintName = "";
break;
case ELF::DT_JMPREL:
@@ -2198,9 +2177,8 @@ void ELFDumper<ELFT>::parseDynamicTable(const ELFFile<ELFT> *Obj) {
}
if (StringTableBegin) {
- const uint64_t FileSize = ObjF->getELFFile()->getBufSize();
- const uint64_t Offset =
- (const uint8_t *)StringTableBegin - ObjF->getELFFile()->base();
+ const uint64_t FileSize = Obj.getBufSize();
+ const uint64_t Offset = (const uint8_t *)StringTableBegin - Obj.base();
if (StringTableSize > FileSize - Offset)
reportUniqueWarning(createError(
"the dynamic string table at 0x" + Twine::utohexstr(Offset) +
@@ -2256,11 +2234,10 @@ void ELFDumper<ELFT>::parseDynamicTable(const ELFFile<ELFT> *Obj) {
// Derive the dynamic symbol table size from the DT_HASH hash table, if
// present.
if (HashTable && DynSymRegion) {
- const uint64_t FileSize = ObjF->getELFFile()->getBufSize();
+ const uint64_t FileSize = Obj.getBufSize();
const uint64_t DerivedSize =
(uint64_t)HashTable->nchain * DynSymRegion->EntSize;
- const uint64_t Offset =
- (const uint8_t *)DynSymRegion->Addr - ObjF->getELFFile()->base();
+ const uint64_t Offset = (const uint8_t *)DynSymRegion->Addr - Obj.base();
if (DerivedSize > FileSize - Offset)
reportUniqueWarning(createError(
"the size (0x" + Twine::utohexstr(DerivedSize) +
@@ -2418,29 +2395,20 @@ static const EnumEntry<unsigned> ElfDynamicDTMipsFlags[] = {
template <typename T, typename TFlag>
void printFlags(T Value, ArrayRef<EnumEntry<TFlag>> Flags, raw_ostream &OS) {
- using FlagEntry = EnumEntry<TFlag>;
- using FlagVector = SmallVector<FlagEntry, 10>;
- FlagVector SetFlags;
-
- for (const auto &Flag : Flags) {
- if (Flag.Value == 0)
- continue;
-
- if ((Value & Flag.Value) == Flag.Value)
+ SmallVector<EnumEntry<TFlag>, 10> SetFlags;
+ for (const EnumEntry<TFlag> &Flag : Flags)
+ if (Flag.Value != 0 && (Value & Flag.Value) == Flag.Value)
SetFlags.push_back(Flag);
- }
- for (const auto &Flag : SetFlags) {
+ for (const EnumEntry<TFlag> &Flag : SetFlags)
OS << Flag.Name << " ";
- }
}
template <class ELFT>
const typename ELFT::Shdr *
ELFDumper<ELFT>::findSectionByName(StringRef Name) const {
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
- for (const Elf_Shdr &Shdr : cantFail(Obj->sections())) {
- if (Expected<StringRef> NameOrErr = Obj->getSectionName(Shdr)) {
+ for (const Elf_Shdr &Shdr : cantFail(Obj.sections())) {
+ if (Expected<StringRef> NameOrErr = Obj.getSectionName(Shdr)) {
if (*NameOrErr == Name)
return &Shdr;
} else {
@@ -2473,7 +2441,7 @@ std::string ELFDumper<ELFT>::getDynamicEntry(uint64_t Type,
};
// Handle custom printing of architecture specific tags
- switch (ObjF->getELFFile()->getHeader().e_machine) {
+ switch (Obj.getHeader().e_machine) {
case EM_AARCH64:
switch (Type) {
case DT_AARCH64_BTI_PLT:
@@ -2635,9 +2603,9 @@ StringRef ELFDumper<ELFT>::getDynamicString(uint64_t Value) const {
return "<?>";
};
- const uint64_t FileSize = ObjF->getELFFile()->getBufSize();
+ const uint64_t FileSize = Obj.getBufSize();
const uint64_t Offset =
- (const uint8_t *)DynamicStringTable.data() - ObjF->getELFFile()->base();
+ (const uint8_t *)DynamicStringTable.data() - Obj.base();
if (DynamicStringTable.size() > FileSize - Offset)
return WarnAndReturn(" with size 0x" +
Twine::utohexstr(DynamicStringTable.size()) +
@@ -2669,10 +2637,8 @@ template <class ELFT> void ELFDumper<ELFT>::printUnwindInfo() {
namespace {
template <> void ELFDumper<ELF32LE>::printUnwindInfo() {
- const ELFFile<ELF32LE> *Obj = ObjF->getELFFile();
- const unsigned Machine = Obj->getHeader().e_machine;
- if (Machine == EM_ARM) {
- ARM::EHABI::PrinterContext<ELF32LE> Ctx(W, Obj, ObjF->getFileName(),
+ if (Obj.getHeader().e_machine == EM_ARM) {
+ ARM::EHABI::PrinterContext<ELF32LE> Ctx(W, Obj, ObjF.getFileName(),
DotSymtabSec);
Ctx.PrintUnwindInformation();
}
@@ -2754,7 +2720,7 @@ template <typename ELFT> void ELFDumper<ELFT>::printHashTable() {
return;
bool IsHeaderValid;
- Error Err = checkHashTable(*ObjF->getELFFile(), HashTable, &IsHeaderValid);
+ Error Err = checkHashTable(Obj, HashTable, &IsHeaderValid);
if (IsHeaderValid) {
W.printNumber("Num Buckets", HashTable->nbucket);
W.printNumber("Num Chains", HashTable->nchain);
@@ -2804,14 +2770,13 @@ getGnuHashTableChains(Optional<DynRegionInfo> DynSymRegion,
}
template <typename ELFT>
-void ELFDumper<ELFT>::printGnuHashTable(const object::ObjectFile *Obj) {
+void ELFDumper<ELFT>::printGnuHashTable() {
DictScope D(W, "GnuHashTable");
if (!GnuHashTable)
return;
bool IsHeaderValid;
- Error Err = checkGNUHashTable<ELFT>(*ObjF->getELFFile(), GnuHashTable,
- &IsHeaderValid);
+ Error Err = checkGNUHashTable<ELFT>(Obj, GnuHashTable, &IsHeaderValid);
if (IsHeaderValid) {
W.printNumber("Num Buckets", GnuHashTable->nbuckets);
W.printNumber("First Hashed Symbol Index", GnuHashTable->symndx);
@@ -2848,24 +2813,23 @@ template <typename ELFT> void ELFDumper<ELFT>::printLoadName() {
}
template <class ELFT> void ELFDumper<ELFT>::printArchSpecificInfo() {
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
- switch (Obj->getHeader().e_machine) {
+ switch (Obj.getHeader().e_machine) {
case EM_ARM:
case EM_RISCV:
printAttributes();
break;
case EM_MIPS: {
- ELFDumperStyle->printMipsABIFlags(ObjF);
+ ELFDumperStyle->printMipsABIFlags();
printMipsOptions();
printMipsReginfo();
MipsGOTParser<ELFT> Parser(*this);
if (Error E = Parser.findGOT(dynamic_table(), dynamic_symbols()))
- reportError(std::move(E), ObjF->getFileName());
+ reportError(std::move(E), ObjF.getFileName());
else if (!Parser.isGotEmpty())
ELFDumperStyle->printMipsGOT(Parser);
if (Error E = Parser.findPLT(dynamic_table()))
- reportError(std::move(E), ObjF->getFileName());
+ reportError(std::move(E), ObjF.getFileName());
else if (!Parser.isPltEmpty())
ELFDumperStyle->printMipsPLT(Parser);
break;
@@ -2875,31 +2839,28 @@ template <class ELFT> void ELFDumper<ELFT>::printArchSpecificInfo() {
}
}
-namespace {
-
template <class ELFT> void ELFDumper<ELFT>::printAttributes() {
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
- if (!Obj->isLE()) {
+ if (!Obj.isLE()) {
W.startLine() << "Attributes not implemented.\n";
return;
}
- const unsigned Machine = Obj->getHeader().e_machine;
+ const unsigned Machine = Obj.getHeader().e_machine;
assert((Machine == EM_ARM || Machine == EM_RISCV) &&
"Attributes not implemented.");
DictScope BA(W, "BuildAttributes");
- for (const Elf_Shdr &Sec : cantFail(Obj->sections())) {
+ for (const Elf_Shdr &Sec : cantFail(Obj.sections())) {
if (Sec.sh_type != ELF::SHT_ARM_ATTRIBUTES &&
Sec.sh_type != ELF::SHT_RISCV_ATTRIBUTES)
continue;
ArrayRef<uint8_t> Contents =
- unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(Sec));
+ unwrapOrError(ObjF.getFileName(), Obj.getSectionContents(Sec));
if (Contents[0] != ELFAttrs::Format_Version) {
reportWarning(createError(Twine("unrecognised FormatVersion: 0x") +
Twine::utohexstr(Contents[0])),
- ObjF->getFileName());
+ ObjF.getFileName());
continue;
}
W.printHex("FormatVersion", Contents[0]);
@@ -2909,14 +2870,16 @@ template <class ELFT> void ELFDumper<ELFT>::printAttributes() {
// TODO: Delete the redundant FormatVersion check above.
if (Machine == EM_ARM) {
if (Error E = ARMAttributeParser(&W).parse(Contents, support::little))
- reportWarning(std::move(E), ObjF->getFileName());
+ reportWarning(std::move(E), ObjF.getFileName());
} else if (Machine == EM_RISCV) {
if (Error E = RISCVAttributeParser(&W).parse(Contents, support::little))
- reportWarning(std::move(E), ObjF->getFileName());
+ reportWarning(std::move(E), ObjF.getFileName());
}
}
}
+namespace {
+
template <class ELFT> class MipsGOTParser {
public:
TYPEDEF_ELF_TYPES(ELFT)
@@ -2924,7 +2887,7 @@ template <class ELFT> class MipsGOTParser {
using Entries = ArrayRef<Entry>;
const bool IsStatic;
- const ELFO * const Obj;
+ const ELFO &Obj;
const ELFDumper<ELFT> &Dumper;
MipsGOTParser(const ELFDumper<ELFT> &D);
@@ -2978,10 +2941,10 @@ template <class ELFT> class MipsGOTParser {
template <class ELFT>
MipsGOTParser<ELFT>::MipsGOTParser(const ELFDumper<ELFT> &D)
- : IsStatic(D.dynamic_table().empty()), Obj(D.getElfObject()->getELFFile()),
+ : IsStatic(D.dynamic_table().empty()), Obj(*D.getElfObject().getELFFile()),
Dumper(D), GotSec(nullptr), LocalNum(0), GlobalNum(0), PltSec(nullptr),
PltRelSec(nullptr), PltSymTable(nullptr),
- FileName(D.getElfObject()->getFileName()) {}
+ FileName(D.getElfObject().getFileName()) {}
template <class ELFT>
Error MipsGOTParser<ELFT>::findGOT(Elf_Dyn_Range DynTable,
@@ -2997,7 +2960,7 @@ Error MipsGOTParser<ELFT>::findGOT(Elf_Dyn_Range DynTable,
return Error::success();
ArrayRef<uint8_t> Content =
- unwrapOrError(FileName, Obj->getSectionContents(*GotSec));
+ unwrapOrError(FileName, Obj.getSectionContents(*GotSec));
GotEntries = Entries(reinterpret_cast<const Entry *>(Content.data()),
Content.size() / sizeof(Entry));
LocalNum = GotEntries.size();
@@ -3047,7 +3010,7 @@ Error MipsGOTParser<ELFT>::findGOT(Elf_Dyn_Range DynTable,
GlobalNum = DynSymTotal - *DtGotSym;
ArrayRef<uint8_t> Content =
- unwrapOrError(FileName, Obj->getSectionContents(*GotSec));
+ unwrapOrError(FileName, Obj.getSectionContents(*GotSec));
GotEntries = Entries(reinterpret_cast<const Entry *>(Content.data()),
Content.size() / sizeof(Entry));
GotDynSyms = DynSyms.drop_front(*DtGotSym);
@@ -3091,7 +3054,7 @@ Error MipsGOTParser<ELFT>::findPLT(Elf_Dyn_Range DynTable) {
Twine::utohexstr(*DtJmpRel));
if (Expected<ArrayRef<uint8_t>> PltContentOrErr =
- Obj->getSectionContents(*PltSec))
+ Obj.getSectionContents(*PltSec))
PltEntries =
Entries(reinterpret_cast<const Entry *>(PltContentOrErr->data()),
PltContentOrErr->size() / sizeof(Entry));
@@ -3100,19 +3063,19 @@ Error MipsGOTParser<ELFT>::findPLT(Elf_Dyn_Range DynTable) {
toString(PltContentOrErr.takeError()));
if (Expected<const Elf_Shdr *> PltSymTableOrErr =
- Obj->getSection(PltRelSec->sh_link))
+ Obj.getSection(PltRelSec->sh_link))
PltSymTable = *PltSymTableOrErr;
else
return createError("unable to get a symbol table linked to the " +
- describe(*Obj, *PltRelSec) + ": " +
+ describe(Obj, *PltRelSec) + ": " +
toString(PltSymTableOrErr.takeError()));
if (Expected<StringRef> StrTabOrErr =
- Obj->getStringTableForSymtab(*PltSymTable))
+ Obj.getStringTableForSymtab(*PltSymTable))
PltStrTable = *StrTabOrErr;
else
return createError("unable to get a string table for the " +
- describe(*Obj, *PltSymTable) + ": " +
+ describe(Obj, *PltSymTable) + ": " +
toString(StrTabOrErr.takeError()));
return Error::success();
@@ -3215,13 +3178,13 @@ const typename MipsGOTParser<ELFT>::Elf_Sym *
MipsGOTParser<ELFT>::getPltSym(const Entry *E) const {
int64_t Offset = std::distance(getPltEntries().data(), E);
if (PltRelSec->sh_type == ELF::SHT_REL) {
- Elf_Rel_Range Rels = unwrapOrError(FileName, Obj->rels(*PltRelSec));
+ Elf_Rel_Range Rels = unwrapOrError(FileName, Obj.rels(*PltRelSec));
return unwrapOrError(FileName,
- Obj->getRelocationSymbol(Rels[Offset], PltSymTable));
+ Obj.getRelocationSymbol(Rels[Offset], PltSymTable));
} else {
- Elf_Rela_Range Rels = unwrapOrError(FileName, Obj->relas(*PltRelSec));
+ Elf_Rela_Range Rels = unwrapOrError(FileName, Obj.relas(*PltRelSec));
return unwrapOrError(FileName,
- Obj->getRelocationSymbol(Rels[Offset], PltSymTable));
+ Obj.getRelocationSymbol(Rels[Offset], PltSymTable));
}
}
@@ -3316,9 +3279,8 @@ template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() {
return;
}
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
Expected<ArrayRef<uint8_t>> ContentsOrErr =
- Obj->getSectionContents(*RegInfoSec);
+ Obj.getSectionContents(*RegInfoSec);
if (!ContentsOrErr) {
this->reportUniqueWarning(createError(
"unable to read the content of the .reginfo section (" +
@@ -3376,7 +3338,6 @@ readMipsOptions(const uint8_t *SecBegin, ArrayRef<uint8_t> &SecData,
}
template <class ELFT> void ELFDumper<ELFT>::printMipsOptions() {
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
const Elf_Shdr *MipsOpts = findSectionByName(".MIPS.options");
if (!MipsOpts) {
W.startLine() << "There is no .MIPS.options section in the file.\n";
@@ -3386,7 +3347,7 @@ template <class ELFT> void ELFDumper<ELFT>::printMipsOptions() {
DictScope GS(W, "MIPS Options");
ArrayRef<uint8_t> Data =
- unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(*MipsOpts));
+ unwrapOrError(ObjF.getFileName(), Obj.getSectionContents(*MipsOpts));
const uint8_t *const SecBegin = Data.begin();
while (!Data.empty()) {
bool IsSupported;
@@ -3414,7 +3375,6 @@ template <class ELFT> void ELFDumper<ELFT>::printMipsOptions() {
}
template <class ELFT> void ELFDumper<ELFT>::printStackMap() const {
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
const Elf_Shdr *StackMapSection = findSectionByName(".llvm_stackmaps");
if (!StackMapSection)
return;
@@ -3426,7 +3386,7 @@ template <class ELFT> void ELFDumper<ELFT>::printStackMap() const {
};
Expected<ArrayRef<uint8_t>> ContentOrErr =
- Obj->getSectionContents(*StackMapSection);
+ Obj.getSectionContents(*StackMapSection);
if (!ContentOrErr) {
Warn(ContentOrErr.takeError());
return;
@@ -3648,7 +3608,7 @@ template <class ELFT>
void GNUStyle<ELFT>::printReloc(const Relocation<ELFT> &R, unsigned RelIndex,
const Elf_Shdr &Sec, const Elf_Shdr *SymTab) {
Expected<RelSymbol<ELFT>> Target =
- this->dumper()->getRelocationTarget(R, SymTab);
+ this->dumper().getRelocationTarget(R, SymTab);
if (!Target)
this->reportUniqueWarning(createError(
"unable to print relocation " + Twine(RelIndex) + " in " +
@@ -3853,13 +3813,13 @@ template <class ELFT> void GNUStyle<ELFT>::printSectionHeaders() {
{"Address", 41}, {"Off", 58 - Bias}, {"Size", 65 - Bias},
{"ES", 72 - Bias}, {"Flg", 75 - Bias}, {"Lk", 79 - Bias},
{"Inf", 82 - Bias}, {"Al", 86 - Bias}};
- for (auto &F : Fields)
+ for (const Field &F : Fields)
printField(F);
OS << "\n";
StringRef SecStrTable;
if (Expected<StringRef> SecStrTableOrErr = this->Obj.getSectionStringTable(
- Sections, this->dumper()->WarningHandler))
+ Sections, this->dumper().WarningHandler))
SecStrTable = *SecStrTableOrErr;
else
this->reportUniqueWarning(SecStrTableOrErr.takeError());
@@ -3925,9 +3885,9 @@ void GNUStyle<ELFT>::printSymtabMessage(const Elf_Shdr *Symtab, size_t Entries,
}
template <class ELFT>
-std::string GNUStyle<ELFT>::getSymbolSectionNdx(const Elf_Sym *Symbol,
+std::string GNUStyle<ELFT>::getSymbolSectionNdx(const Elf_Sym &Symbol,
unsigned SymIndex) {
- unsigned SectionIndex = Symbol->st_shndx;
+ unsigned SectionIndex = Symbol.st_shndx;
switch (SectionIndex) {
case ELF::SHN_UNDEF:
return "UND";
@@ -3937,9 +3897,9 @@ std::string GNUStyle<ELFT>::getSymbolSectionNdx(const Elf_Sym *Symbol,
return "COM";
case ELF::SHN_XINDEX: {
Expected<uint32_t> IndexOrErr = object::getExtendedSymbolTableIndex<ELFT>(
- *Symbol, SymIndex, this->dumper()->getShndxTable());
+ Symbol, SymIndex, this->dumper().getShndxTable());
if (!IndexOrErr) {
- assert(Symbol->st_shndx == SHN_XINDEX &&
+ assert(Symbol.st_shndx == SHN_XINDEX &&
"getExtendedSymbolTableIndex should only fail due to an invalid "
"SHT_SYMTAB_SHNDX table/reference");
this->reportUniqueWarning(IndexOrErr.takeError());
@@ -3968,18 +3928,18 @@ std::string GNUStyle<ELFT>::getSymbolSectionNdx(const Elf_Sym *Symbol,
}
template <class ELFT>
-void GNUStyle<ELFT>::printSymbol(const Elf_Sym *Symbol, unsigned SymIndex,
+void GNUStyle<ELFT>::printSymbol(const Elf_Sym &Symbol, unsigned SymIndex,
Optional<StringRef> StrTable, bool IsDynamic,
bool NonVisibilityBitsUsed) {
unsigned Bias = ELFT::Is64Bits ? 8 : 0;
Field Fields[8] = {0, 8, 17 + Bias, 23 + Bias,
31 + Bias, 38 + Bias, 48 + Bias, 51 + Bias};
Fields[0].Str = to_string(format_decimal(SymIndex, 6)) + ":";
- Fields[1].Str = to_string(
- format_hex_no_prefix(Symbol->st_value, ELFT::Is64Bits ? 16 : 8));
- Fields[2].Str = to_string(format_decimal(Symbol->st_size, 5));
+ Fields[1].Str =
+ to_string(format_hex_no_prefix(Symbol.st_value, ELFT::Is64Bits ? 16 : 8));
+ Fields[2].Str = to_string(format_decimal(Symbol.st_size, 5));
- unsigned char SymbolType = Symbol->getType();
+ unsigned char SymbolType = Symbol.getType();
if (this->Obj.getHeader().e_machine == ELF::EM_AMDGPU &&
SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS)
Fields[3].Str = printEnum(SymbolType, makeArrayRef(AMDGPUSymbolTypes));
@@ -3987,19 +3947,19 @@ void GNUStyle<ELFT>::printSymbol(const Elf_Sym *Symbol, unsigned SymIndex,
Fields[3].Str = printEnum(SymbolType, makeArrayRef(ElfSymbolTypes));
Fields[4].Str =
- printEnum(Symbol->getBinding(), makeArrayRef(ElfSymbolBindings));
+ printEnum(Symbol.getBinding(), makeArrayRef(ElfSymbolBindings));
Fields[5].Str =
- printEnum(Symbol->getVisibility(), makeArrayRef(ElfSymbolVisibilities));
- if (Symbol->st_other & ~0x3)
+ printEnum(Symbol.getVisibility(), makeArrayRef(ElfSymbolVisibilities));
+ if (Symbol.st_other & ~0x3)
Fields[5].Str +=
- " [<other: " + to_string(format_hex(Symbol->st_other, 2)) + ">]";
+ " [<other: " + to_string(format_hex(Symbol.st_other, 2)) + ">]";
Fields[6].Column += NonVisibilityBitsUsed ? 13 : 0;
Fields[6].Str = getSymbolSectionNdx(Symbol, SymIndex);
Fields[7].Str =
- this->dumper()->getFullSymbolName(Symbol, SymIndex, StrTable, IsDynamic);
- for (auto &Entry : Fields)
+ this->dumper().getFullSymbolName(Symbol, SymIndex, StrTable, IsDynamic);
+ for (const Field &Entry : Fields)
printField(Entry);
OS << "\n";
}
@@ -4028,11 +3988,11 @@ void GNUStyle<ELFT>::printHashedSymbol(const Elf_Sym *Symbol, unsigned SymIndex,
printEnum(Symbol->getBinding(), makeArrayRef(ElfSymbolBindings));
Fields[6].Str =
printEnum(Symbol->getVisibility(), makeArrayRef(ElfSymbolVisibilities));
- Fields[7].Str = getSymbolSectionNdx(Symbol, SymIndex);
+ Fields[7].Str = getSymbolSectionNdx(*Symbol, SymIndex);
Fields[8].Str =
- this->dumper()->getFullSymbolName(Symbol, SymIndex, StrTable, true);
+ this->dumper().getFullSymbolName(*Symbol, SymIndex, StrTable, true);
- for (auto &Entry : Fields)
+ for (const Field &Entry : Fields)
printField(Entry);
OS << "\n";
}
@@ -4042,14 +4002,14 @@ void GNUStyle<ELFT>::printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) {
if (!PrintSymbols && !PrintDynamicSymbols)
return;
// GNU readelf prints both the .dynsym and .symtab with --symbols.
- this->dumper()->printSymbolsHelper(true);
+ this->dumper().printSymbolsHelper(true);
if (PrintSymbols)
- this->dumper()->printSymbolsHelper(false);
+ this->dumper().printSymbolsHelper(false);
}
template <class ELFT>
void GNUStyle<ELFT>::printHashTableSymbols(const Elf_Hash &SysVHash) {
- StringRef StringTable = this->dumper()->getDynamicStringTable();
+ StringRef StringTable = this->dumper().getDynamicStringTable();
if (StringTable.empty())
return;
@@ -4059,10 +4019,10 @@ void GNUStyle<ELFT>::printHashTableSymbols(const Elf_Hash &SysVHash) {
OS << " Num Buc: Value Size Type Bind Vis Ndx Name";
OS << "\n";
- Elf_Sym_Range DynSyms = this->dumper()->dynamic_symbols();
+ Elf_Sym_Range DynSyms = this->dumper().dynamic_symbols();
const Elf_Sym *FirstSym = DynSyms.empty() ? nullptr : &DynSyms[0];
if (!FirstSym) {
- Optional<DynRegionInfo> DynSymRegion = this->dumper()->getDynSymRegion();
+ Optional<DynRegionInfo> DynSymRegion = this->dumper().getDynSymRegion();
this->reportUniqueWarning(
createError(Twine("unable to print symbols for the .hash table: the "
"dynamic symbol table ") +
@@ -4096,14 +4056,14 @@ void GNUStyle<ELFT>::printHashTableSymbols(const Elf_Hash &SysVHash) {
template <class ELFT>
void GNUStyle<ELFT>::printGnuHashTableSymbols(const Elf_GnuHash &GnuHash) {
- StringRef StringTable = this->dumper()->getDynamicStringTable();
+ StringRef StringTable = this->dumper().getDynamicStringTable();
if (StringTable.empty())
return;
- Elf_Sym_Range DynSyms = this->dumper()->dynamic_symbols();
+ Elf_Sym_Range DynSyms = this->dumper().dynamic_symbols();
const Elf_Sym *FirstSym = DynSyms.empty() ? nullptr : &DynSyms[0];
if (!FirstSym) {
- Optional<DynRegionInfo> DynSymRegion = this->dumper()->getDynSymRegion();
+ Optional<DynRegionInfo> DynSymRegion = this->dumper().getDynSymRegion();
this->reportUniqueWarning(createError(
Twine("unable to print symbols for the .gnu.hash table: the "
"dynamic symbol table ") +
@@ -4129,7 +4089,7 @@ void GNUStyle<ELFT>::printGnuHashTableSymbols(const Elf_GnuHash &GnuHash) {
}
template <class ELFT> void GNUStyle<ELFT>::printHashSymbols() {
- if (const Elf_Hash *SysVHash = this->dumper()->getHashTable()) {
+ if (const Elf_Hash *SysVHash = this->dumper().getHashTable()) {
OS << "\n Symbol table of .hash for image:\n";
if (Error E = checkHashTable<ELFT>(this->Obj, SysVHash))
this->reportUniqueWarning(std::move(E));
@@ -4138,7 +4098,7 @@ template <class ELFT> void GNUStyle<ELFT>::printHashSymbols() {
}
// Try printing the .gnu.hash table.
- if (const Elf_GnuHash *GnuHash = this->dumper()->getGnuHashTable()) {
+ if (const Elf_GnuHash *GnuHash = this->dumper().getGnuHashTable()) {
OS << "\n Symbol table of .gnu.hash for image:\n";
if (ELFT::Is64Bits)
OS << " Num Buc: Value Size Type Bind Vis Ndx Name";
@@ -4282,8 +4242,8 @@ template <class ELFT> void GNUStyle<ELFT>::printProgramHeaders() {
Fields[5].Str = to_string(format_hex(Phdr.p_memsz, SizeWidth));
Fields[6].Str = printPhdrFlags(Phdr.p_flags);
Fields[7].Str = to_string(format_hex(Phdr.p_align, 1));
- for (auto Field : Fields)
- printField(Field);
+ for (const Field &F : Fields)
+ printField(F);
if (Phdr.p_type == ELF::PT_INTERP) {
OS << "\n";
auto ReportBadInterp = [&](const Twine &Msg) {
@@ -4369,7 +4329,7 @@ namespace {
template <class ELFT>
RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> &Obj, StringRef FileName,
- const ELFDumper<ELFT> *Dumper,
+ const ELFDumper<ELFT> &Dumper,
const Relocation<ELFT> &Reloc) {
auto WarnAndReturn = [&](const typename ELFT::Sym *Sym,
const Twine &Reason) -> RelSymbol<ELFT> {
@@ -4380,7 +4340,7 @@ RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> &Obj, StringRef FileName,
return {Sym, "<corrupt>"};
};
- ArrayRef<typename ELFT::Sym> Symbols = Dumper->dynamic_symbols();
+ ArrayRef<typename ELFT::Sym> Symbols = Dumper.dynamic_symbols();
const typename ELFT::Sym *FirstSym = Symbols.begin();
if (!FirstSym)
return WarnAndReturn(nullptr, "no dynamic symbol table found");
@@ -4395,7 +4355,7 @@ RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> &Obj, StringRef FileName,
Twine(Symbols.size()) + ")");
const typename ELFT::Sym *Sym = FirstSym + Reloc.Symbol;
- Expected<StringRef> ErrOrName = Sym->getName(Dumper->getDynamicStringTable());
+ Expected<StringRef> ErrOrName = Sym->getName(Dumper.getDynamicStringTable());
if (!ErrOrName)
return WarnAndReturn(Sym, toString(ErrOrName.takeError()));
@@ -4419,15 +4379,13 @@ static size_t getMaxDynamicTagSize(const ELFFile<ELFT> &Obj,
}
template <class ELFT> void GNUStyle<ELFT>::printDynamic() {
- Elf_Dyn_Range Table = this->dumper()->dynamic_table();
+ Elf_Dyn_Range Table = this->dumper().dynamic_table();
if (Table.empty())
return;
- const DynRegionInfo &DynamicTableRegion =
- this->dumper()->getDynamicTableRegion();
-
OS << "Dynamic section at offset "
- << format_hex(reinterpret_cast<const uint8_t *>(DynamicTableRegion.Addr) -
+ << format_hex(reinterpret_cast<const uint8_t *>(
+ this->dumper().getDynamicTableRegion().Addr) -
this->Obj.base(),
1)
<< " contains " << Table.size() << " entries:\n";
@@ -4445,7 +4403,7 @@ template <class ELFT> void GNUStyle<ELFT>::printDynamic() {
uintX_t Tag = Entry.getTag();
std::string Type =
std::string("(") + this->Obj.getDynamicTagAsString(Tag).c_str() + ")";
- std::string Value = this->dumper()->getDynamicEntry(Tag, Entry.getVal());
+ std::string Value = this->dumper().getDynamicEntry(Tag, Entry.getVal());
OS << " " << format_hex(Tag, ELFT::Is64Bits ? 18 : 10)
<< format(ValueFmt.c_str(), Type.c_str()) << Value << "\n";
}
@@ -4457,29 +4415,29 @@ template <class ELFT> void GNUStyle<ELFT>::printDynamicRelocations() {
template <class ELFT> void DumpStyle<ELFT>::printDynamicRelocationsHelper() {
const bool IsMips64EL = this->Obj.isMips64EL();
- const DynRegionInfo &DynRelaRegion = this->dumper()->getDynRelaRegion();
+ const DynRegionInfo &DynRelaRegion = this->dumper().getDynRelaRegion();
if (DynRelaRegion.Size > 0) {
printDynamicRelocHeader(ELF::SHT_RELA, "RELA", DynRelaRegion);
- for (const Elf_Rela &Rela : this->dumper()->dyn_relas())
+ for (const Elf_Rela &Rela : this->dumper().dyn_relas())
printDynamicReloc(Relocation<ELFT>(Rela, IsMips64EL));
}
- const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion();
+ const DynRegionInfo &DynRelRegion = this->dumper().getDynRelRegion();
if (DynRelRegion.Size > 0) {
printDynamicRelocHeader(ELF::SHT_REL, "REL", DynRelRegion);
- for (const Elf_Rel &Rel : this->dumper()->dyn_rels())
+ for (const Elf_Rel &Rel : this->dumper().dyn_rels())
printDynamicReloc(Relocation<ELFT>(Rel, IsMips64EL));
}
- const DynRegionInfo &DynRelrRegion = this->dumper()->getDynRelrRegion();
+ const DynRegionInfo &DynRelrRegion = this->dumper().getDynRelrRegion();
if (DynRelrRegion.Size > 0) {
printDynamicRelocHeader(ELF::SHT_REL, "RELR", DynRelrRegion);
- Elf_Relr_Range Relrs = this->dumper()->dyn_relrs();
+ Elf_Relr_Range Relrs = this->dumper().dyn_relrs();
for (const Elf_Rel &Rel : Obj.decode_relrs(Relrs))
printDynamicReloc(Relocation<ELFT>(Rel, IsMips64EL));
}
- const DynRegionInfo &DynPLTRelRegion = this->dumper()->getDynPLTRelRegion();
+ const DynRegionInfo &DynPLTRelRegion = this->dumper().getDynPLTRelRegion();
if (DynPLTRelRegion.Size) {
if (DynPLTRelRegion.EntSize == sizeof(Elf_Rela)) {
printDynamicRelocHeader(ELF::SHT_RELA, "PLT", DynPLTRelRegion);
@@ -4525,7 +4483,7 @@ void GNUStyle<ELFT>::printVersionSymbolSection(const Elf_Shdr *Sec) {
printGNUVersionSectionProlog(Sec, "Version symbols",
Sec->sh_size / sizeof(Elf_Versym));
Expected<ArrayRef<Elf_Versym>> VerTableOrErr =
- this->dumper()->getVersionTable(Sec, /*SymTab=*/nullptr,
+ this->dumper().getVersionTable(*Sec, /*SymTab=*/nullptr,
/*StrTab=*/nullptr);
if (!VerTableOrErr) {
this->reportUniqueWarning(VerTableOrErr.takeError());
@@ -4543,7 +4501,7 @@ void GNUStyle<ELFT>::printVersionSymbolSection(const Elf_Shdr *Sec) {
bool IsDefault;
Expected<StringRef> NameOrErr =
- this->dumper()->getSymbolVersionByIndex(Ndx, IsDefault);
+ this->dumper().getSymbolVersionByIndex(Ndx, IsDefault);
if (!NameOrErr) {
if (!NameOrErr)
this->reportUniqueWarning(
@@ -4599,7 +4557,7 @@ void GNUStyle<ELFT>::printVersionDefinitionSection(const Elf_Shdr *Sec) {
printGNUVersionSectionProlog(Sec, "Version definition", Sec->sh_info);
- Expected<std::vector<VerDef>> V = this->dumper()->getVersionDefinitions(Sec);
+ Expected<std::vector<VerDef>> V = this->dumper().getVersionDefinitions(*Sec);
if (!V) {
this->reportUniqueWarning(V.takeError());
return;
@@ -4628,7 +4586,7 @@ void GNUStyle<ELFT>::printVersionDependencySection(const Elf_Shdr *Sec) {
printGNUVersionSectionProlog(Sec, "Version needs", VerneedNum);
Expected<std::vector<VerNeed>> V =
- this->dumper()->getVersionDependencies(Sec);
+ this->dumper().getVersionDependencies(*Sec);
if (!V) {
this->reportUniqueWarning(V.takeError());
return;
@@ -4704,7 +4662,7 @@ void GNUStyle<ELFT>::printHashHistogram(const Elf_Hash &HashTable) {
template <class ELFT>
void GNUStyle<ELFT>::printGnuHashHistogram(const Elf_GnuHash &GnuHashTable) {
Expected<ArrayRef<Elf_Word>> ChainsOrErr = getGnuHashTableChains<ELFT>(
- this->dumper()->getDynSymRegion(), &GnuHashTable);
+ this->dumper().getDynSymRegion(), &GnuHashTable);
if (!ChainsOrErr) {
this->reportUniqueWarning(
createError("unable to print the GNU hash table histogram: " +
@@ -4762,7 +4720,7 @@ void GNUStyle<ELFT>::printGnuHashHistogram(const Elf_GnuHash &GnuHashTable) {
// buckets, and the cumulative coverage of symbols for each set of buckets.
template <class ELFT> void GNUStyle<ELFT>::printHashHistograms() {
// Print histogram for the .hash section.
- if (const Elf_Hash *HashTable = this->dumper()->getHashTable()) {
+ if (const Elf_Hash *HashTable = this->dumper().getHashTable()) {
if (Error E = checkHashTable<ELFT>(this->Obj, HashTable))
this->reportUniqueWarning(std::move(E));
else
@@ -4770,7 +4728,7 @@ template <class ELFT> void GNUStyle<ELFT>::printHashHistograms() {
}
// Print histogram for the .gnu.hash section.
- if (const Elf_GnuHash *GnuHashTable = this->dumper()->getGnuHashTable()) {
+ if (const Elf_GnuHash *GnuHashTable = this->dumper().getGnuHashTable()) {
if (Error E = checkGNUHashTable<ELFT>(this->Obj, GnuHashTable))
this->reportUniqueWarning(std::move(E));
else
@@ -4973,7 +4931,7 @@ template <typename ELFT> static GNUAbiTag getGNUAbiTag(ArrayRef<uint8_t> Desc) {
static std::string getGNUBuildId(ArrayRef<uint8_t> Desc) {
std::string str;
raw_string_ostream OS(str);
- for (const auto &B : Desc)
+ for (uint8_t B : Desc)
OS << format_hex_no_prefix(B, 2);
return OS.str();
}
@@ -5005,7 +4963,7 @@ static void printGNUNote(raw_ostream &OS, uint32_t NoteType,
break;
case ELF::NT_GNU_PROPERTY_TYPE_0:
OS << " Properties:";
- for (const auto &Property : getGNUPropertyList<ELFT>(Desc))
+ for (const std::string &Property : getGNUPropertyList<ELFT>(Desc))
OS << " " << Property << "\n";
break;
}
@@ -5044,7 +5002,7 @@ static AMDGPUNote getAMDGPUNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
default:
return {"", ""};
case ELF::NT_AMDGPU_METADATA: {
- auto MsgPackString =
+ StringRef MsgPackString =
StringRef(reinterpret_cast<const char *>(Desc.data()), Desc.size());
msgpack::Document MsgPackDoc;
if (!MsgPackDoc.readFromBlob(MsgPackString, /*Multi=*/false))
@@ -5337,7 +5295,7 @@ template <class ELFT> void GNUStyle<ELFT>::printNotes() {
PrintHeader(expectedToOptional(this->Obj.getSectionName(S)), S.sh_offset,
S.sh_size);
Error Err = Error::success();
- for (auto Note : this->Obj.notes(S, Err))
+ for (const Elf_Note &Note : this->Obj.notes(S, Err))
ProcessNote(Note);
if (Err)
reportError(std::move(Err), this->FileName);
@@ -5356,7 +5314,7 @@ template <class ELFT> void GNUStyle<ELFT>::printNotes() {
continue;
PrintHeader(/*SecName=*/None, P.p_offset, P.p_filesz);
Error Err = Error::success();
- for (auto Note : this->Obj.notes(P, Err))
+ for (const Elf_Note &Note : this->Obj.notes(P, Err))
ProcessNote(Note);
if (Err)
reportError(std::move(Err), this->FileName);
@@ -5480,7 +5438,7 @@ template <class ELFT>
StringRef DumpStyle<ELFT>::getPrintableSectionName(const Elf_Shdr &Sec) const {
StringRef Name = "<?>";
if (Expected<StringRef> SecNameOrErr =
- Obj.getSectionName(Sec, this->dumper()->WarningHandler))
+ Obj.getSectionName(Sec, this->dumper().WarningHandler))
Name = *SecNameOrErr;
else
this->reportUniqueWarning(createError("unable to get the name of " +
@@ -5841,10 +5799,10 @@ void GNUStyle<ELFT>::printMipsGOT(const MipsGOTParser<ELFT> &Parser) {
else
OS << " Address Access Initial Sym.Val. Type Ndx Name\n";
for (auto &E : Parser.getGlobalEntries()) {
- const Elf_Sym *Sym = Parser.getGotSym(&E);
- const Elf_Sym *FirstSym = &this->dumper()->dynamic_symbols()[0];
- std::string SymName = this->dumper()->getFullSymbolName(
- Sym, FirstSym - Sym, this->dumper()->getDynamicStringTable(), false);
+ const Elf_Sym &Sym = *Parser.getGotSym(&E);
+ const Elf_Sym &FirstSym = this->dumper().dynamic_symbols()[0];
+ std::string SymName = this->dumper().getFullSymbolName(
+ Sym, &FirstSym - &Sym, this->dumper().getDynamicStringTable(), false);
OS.PadToColumn(2);
OS << to_string(format_hex_no_prefix(Parser.getGotAddress(&E), 8 + Bias));
@@ -5853,12 +5811,12 @@ void GNUStyle<ELFT>::printMipsGOT(const MipsGOTParser<ELFT> &Parser) {
OS.PadToColumn(22 + Bias);
OS << to_string(format_hex_no_prefix(E, 8 + Bias));
OS.PadToColumn(31 + 2 * Bias);
- OS << to_string(format_hex_no_prefix(Sym->st_value, 8 + Bias));
+ OS << to_string(format_hex_no_prefix(Sym.st_value, 8 + Bias));
OS.PadToColumn(40 + 3 * Bias);
- OS << printEnum(Sym->getType(), makeArrayRef(ElfSymbolTypes));
+ OS << printEnum(Sym.getType(), makeArrayRef(ElfSymbolTypes));
OS.PadToColumn(48 + 3 * Bias);
OS << getSymbolSectionNdx(
- Sym, Sym - this->dumper()->dynamic_symbols().begin());
+ Sym, &Sym - this->dumper().dynamic_symbols().begin());
OS.PadToColumn(52 + 3 * Bias);
OS << SymName << "\n";
}
@@ -5894,24 +5852,24 @@ void GNUStyle<ELFT>::printMipsPLT(const MipsGOTParser<ELFT> &Parser) {
OS << " Entries:\n";
OS << " Address Initial Sym.Val. Type Ndx Name\n";
for (auto &E : Parser.getPltEntries()) {
- const Elf_Sym *Sym = Parser.getPltSym(&E);
- const Elf_Sym *FirstSym =
- cantFail(this->Obj.template getEntry<const Elf_Sym>(
+ const Elf_Sym &Sym = *Parser.getPltSym(&E);
+ const Elf_Sym &FirstSym =
+ *cantFail(this->Obj.template getEntry<const Elf_Sym>(
*Parser.getPltSymTable(), 0));
- std::string SymName = this->dumper()->getFullSymbolName(
- Sym, FirstSym - Sym, this->dumper()->getDynamicStringTable(), false);
+ std::string SymName = this->dumper().getFullSymbolName(
+ Sym, &FirstSym - &Sym, this->dumper().getDynamicStringTable(), false);
OS.PadToColumn(2);
OS << to_string(format_hex_no_prefix(Parser.getPltAddress(&E), 8 + Bias));
OS.PadToColumn(11 + Bias);
OS << to_string(format_hex_no_prefix(E, 8 + Bias));
OS.PadToColumn(20 + 2 * Bias);
- OS << to_string(format_hex_no_prefix(Sym->st_value, 8 + Bias));
+ OS << to_string(format_hex_no_prefix(Sym.st_value, 8 + Bias));
OS.PadToColumn(29 + 3 * Bias);
- OS << printEnum(Sym->getType(), makeArrayRef(ElfSymbolTypes));
+ OS << printEnum(Sym.getType(), makeArrayRef(ElfSymbolTypes));
OS.PadToColumn(37 + 3 * Bias);
OS << getSymbolSectionNdx(
- Sym, Sym - this->dumper()->dynamic_symbols().begin());
+ Sym, &Sym - this->dumper().dynamic_symbols().begin());
OS.PadToColumn(41 + 3 * Bias);
OS << SymName << "\n";
}
@@ -5920,15 +5878,14 @@ void GNUStyle<ELFT>::printMipsPLT(const MipsGOTParser<ELFT> &Parser) {
template <class ELFT>
Expected<const Elf_Mips_ABIFlags<ELFT> *>
-getMipsAbiFlagsSection(const ELFObjectFile<ELFT> *ObjF,
- const ELFDumper<ELFT> &Dumper) {
+getMipsAbiFlagsSection(const ELFDumper<ELFT> &Dumper) {
const typename ELFT::Shdr *Sec = Dumper.findSectionByName(".MIPS.abiflags");
if (Sec == nullptr)
return nullptr;
- const ELFFile<ELFT> *Obj = ObjF->getELFFile();
constexpr StringRef ErrPrefix = "unable to read the .MIPS.abiflags section: ";
- Expected<ArrayRef<uint8_t>> DataOrErr = Obj->getSectionContents(*Sec);
+ Expected<ArrayRef<uint8_t>> DataOrErr =
+ Dumper.getElfObject().getELFFile()->getSectionContents(*Sec);
if (!DataOrErr)
return createError(ErrPrefix + toString(DataOrErr.takeError()));
@@ -5938,11 +5895,10 @@ getMipsAbiFlagsSection(const ELFObjectFile<ELFT> *ObjF,
return reinterpret_cast<const Elf_Mips_ABIFlags<ELFT> *>(DataOrErr->data());
}
-template <class ELFT>
-void GNUStyle<ELFT>::printMipsABIFlags(const ELFObjectFile<ELFT> *ObjF) {
+template <class ELFT> void GNUStyle<ELFT>::printMipsABIFlags() {
const Elf_Mips_ABIFlags<ELFT> *Flags = nullptr;
if (Expected<const Elf_Mips_ABIFlags<ELFT> *> SecOrErr =
- getMipsAbiFlagsSection(ObjF, *this->dumper()))
+ getMipsAbiFlagsSection(this->dumper()))
Flags = *SecOrErr;
else
this->reportUniqueWarning(SecOrErr.takeError());
@@ -6088,7 +6044,7 @@ template <class ELFT>
void LLVMStyle<ELFT>::printReloc(const Relocation<ELFT> &R, unsigned RelIndex,
const Elf_Shdr &Sec, const Elf_Shdr *SymTab) {
Expected<RelSymbol<ELFT>> Target =
- this->dumper()->getRelocationTarget(R, SymTab);
+ this->dumper().getRelocationTarget(R, SymTab);
if (!Target) {
this->reportUniqueWarning(createError(
"unable to print relocation " + Twine(RelIndex) + " in " +
@@ -6150,19 +6106,18 @@ template <class ELFT> void LLVMStyle<ELFT>::printSectionHeaders() {
if (opts::SectionSymbols) {
ListScope D(W, "Symbols");
- if (const Elf_Shdr *Symtab = this->dumper()->getDotSymtabSec()) {
+ if (const Elf_Shdr *Symtab = this->dumper().getDotSymtabSec()) {
StringRef StrTable = unwrapOrError(
this->FileName, this->Obj.getStringTableForSymtab(*Symtab));
typename ELFT::SymRange Symbols =
unwrapOrError(this->FileName, this->Obj.symbols(Symtab));
for (const Elf_Sym &Sym : Symbols) {
- const Elf_Shdr *SymSec =
- unwrapOrError(this->FileName,
- this->Obj.getSection(
- Sym, Symtab, this->dumper()->getShndxTable()));
+ const Elf_Shdr *SymSec = unwrapOrError(
+ this->FileName, this->Obj.getSection(
+ Sym, Symtab, this->dumper().getShndxTable()));
if (SymSec == &Sec)
- printSymbol(&Sym, &Sym - &Symbols[0], StrTable, false, false);
+ printSymbol(Sym, &Sym - &Symbols[0], StrTable, false, false);
}
}
}
@@ -6178,33 +6133,33 @@ template <class ELFT> void LLVMStyle<ELFT>::printSectionHeaders() {
}
template <class ELFT>
-void LLVMStyle<ELFT>::printSymbolSection(const Elf_Sym *Symbol,
+void LLVMStyle<ELFT>::printSymbolSection(const Elf_Sym &Symbol,
unsigned SymIndex) {
auto GetSectionSpecialType = [&]() -> Optional<StringRef> {
- if (Symbol->isUndefined())
+ if (Symbol.isUndefined())
return StringRef("Undefined");
- if (Symbol->isProcessorSpecific())
+ if (Symbol.isProcessorSpecific())
return StringRef("Processor Specific");
- if (Symbol->isOSSpecific())
+ if (Symbol.isOSSpecific())
return StringRef("Operating System Specific");
- if (Symbol->isAbsolute())
+ if (Symbol.isAbsolute())
return StringRef("Absolute");
- if (Symbol->isCommon())
+ if (Symbol.isCommon())
return StringRef("Common");
- if (Symbol->isReserved() && Symbol->st_shndx != SHN_XINDEX)
+ if (Symbol.isReserved() && Symbol.st_shndx != SHN_XINDEX)
return StringRef("Reserved");
return None;
};
if (Optional<StringRef> Type = GetSectionSpecialType()) {
- W.printHex("Section", *Type, Symbol->st_shndx);
+ W.printHex("Section", *Type, Symbol.st_shndx);
return;
}
Expected<unsigned> SectionIndex =
- this->dumper()->getSymbolSectionIndex(Symbol, SymIndex);
+ this->dumper().getSymbolSectionIndex(Symbol, SymIndex);
if (!SectionIndex) {
- assert(Symbol->st_shndx == SHN_XINDEX &&
+ assert(Symbol.st_shndx == SHN_XINDEX &&
"getSymbolSectionIndex should only fail due to an invalid "
"SHT_SYMTAB_SHNDX table/reference");
this->reportUniqueWarning(SectionIndex.takeError());
@@ -6213,11 +6168,11 @@ void LLVMStyle<ELFT>::printSymbolSection(const Elf_Sym *Symbol,
}
Expected<StringRef> SectionName =
- this->dumper()->getSymbolSectionName(Symbol, *SectionIndex);
+ this->dumper().getSymbolSectionName(Symbol, *SectionIndex);
if (!SectionName) {
// Don't report an invalid section name if the section headers are missing.
// In such situations, all sections will be "invalid".
- if (!this->dumper()->getElfObject()->sections().empty())
+ if (!this->dumper().getElfObject().sections().empty())
this->reportUniqueWarning(SectionName.takeError());
else
consumeError(SectionName.takeError());
@@ -6228,24 +6183,24 @@ void LLVMStyle<ELFT>::printSymbolSection(const Elf_Sym *Symbol,
}
template <class ELFT>
-void LLVMStyle<ELFT>::printSymbol(const Elf_Sym *Symbol, unsigned SymIndex,
+void LLVMStyle<ELFT>::printSymbol(const Elf_Sym &Symbol, unsigned SymIndex,
Optional<StringRef> StrTable, bool IsDynamic,
bool /*NonVisibilityBitsUsed*/) {
std::string FullSymbolName =
- this->dumper()->getFullSymbolName(Symbol, SymIndex, StrTable, IsDynamic);
- unsigned char SymbolType = Symbol->getType();
+ this->dumper().getFullSymbolName(Symbol, SymIndex, StrTable, IsDynamic);
+ unsigned char SymbolType = Symbol.getType();
DictScope D(W, "Symbol");
- W.printNumber("Name", FullSymbolName, Symbol->st_name);
- W.printHex("Value", Symbol->st_value);
- W.printNumber("Size", Symbol->st_size);
- W.printEnum("Binding", Symbol->getBinding(), makeArrayRef(ElfSymbolBindings));
+ W.printNumber("Name", FullSymbolName, Symbol.st_name);
+ W.printHex("Value", Symbol.st_value);
+ W.printNumber("Size", Symbol.st_size);
+ W.printEnum("Binding", Symbol.getBinding(), makeArrayRef(ElfSymbolBindings));
if (this->Obj.getHeader().e_machine == ELF::EM_AMDGPU &&
SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS)
W.printEnum("Type", SymbolType, makeArrayRef(AMDGPUSymbolTypes));
else
W.printEnum("Type", SymbolType, makeArrayRef(ElfSymbolTypes));
- if (Symbol->st_other == 0)
+ if (Symbol.st_other == 0)
// Usually st_other flag is zero. Do not pollute the output
// by flags enumeration in that case.
W.printNumber("Other", 0);
@@ -6256,7 +6211,7 @@ void LLVMStyle<ELFT>::printSymbol(const Elf_Sym *Symbol, unsigned SymIndex,
// Someones in their infinite wisdom decided to make STO_MIPS_MIPS16
// flag overlapped with other ST_MIPS_xxx flags. So consider both
// cases separately.
- if ((Symbol->st_other & STO_MIPS_MIPS16) == STO_MIPS_MIPS16)
+ if ((Symbol.st_other & STO_MIPS_MIPS16) == STO_MIPS_MIPS16)
SymOtherFlags.insert(SymOtherFlags.end(),
std::begin(ElfMips16SymOtherFlags),
std::end(ElfMips16SymOtherFlags));
@@ -6265,7 +6220,7 @@ void LLVMStyle<ELFT>::printSymbol(const Elf_Sym *Symbol, unsigned SymIndex,
std::begin(ElfMipsSymOtherFlags),
std::end(ElfMipsSymOtherFlags));
}
- W.printFlags("Other", Symbol->st_other, makeArrayRef(SymOtherFlags), 0x3u);
+ W.printFlags("Other", Symbol.st_other, makeArrayRef(SymOtherFlags), 0x3u);
}
printSymbolSection(Symbol, SymIndex);
}
@@ -6281,16 +6236,16 @@ void LLVMStyle<ELFT>::printSymbols(bool PrintSymbols,
template <class ELFT> void LLVMStyle<ELFT>::printSymbols() {
ListScope Group(W, "Symbols");
- this->dumper()->printSymbolsHelper(false);
+ this->dumper().printSymbolsHelper(false);
}
template <class ELFT> void LLVMStyle<ELFT>::printDynamicSymbols() {
ListScope Group(W, "DynamicSymbols");
- this->dumper()->printSymbolsHelper(true);
+ this->dumper().printSymbolsHelper(true);
}
template <class ELFT> void LLVMStyle<ELFT>::printDynamic() {
- Elf_Dyn_Range Table = this->dumper()->dynamic_table();
+ Elf_Dyn_Range Table = this->dumper().dynamic_table();
if (Table.empty())
return;
@@ -6306,7 +6261,7 @@ template <class ELFT> void LLVMStyle<ELFT>::printDynamic() {
std::string ValueFmt = "%-" + std::to_string(MaxTagSize) + "s ";
for (auto Entry : Table) {
uintX_t Tag = Entry.getTag();
- std::string Value = this->dumper()->getDynamicEntry(Tag, Entry.getVal());
+ std::string Value = this->dumper().getDynamicEntry(Tag, Entry.getVal());
W.startLine() << " " << format_hex(Tag, ELFT::Is64Bits ? 18 : 10, true)
<< " "
<< format(ValueFmt.c_str(),
@@ -6375,7 +6330,7 @@ void LLVMStyle<ELFT>::printVersionSymbolSection(const Elf_Shdr *Sec) {
StringRef StrTable;
ArrayRef<Elf_Sym> Syms;
Expected<ArrayRef<Elf_Versym>> VerTableOrErr =
- this->dumper()->getVersionTable(Sec, &Syms, &StrTable);
+ this->dumper().getVersionTable(*Sec, &Syms, &StrTable);
if (!VerTableOrErr) {
this->reportUniqueWarning(VerTableOrErr.takeError());
return;
@@ -6387,9 +6342,8 @@ void LLVMStyle<ELFT>::printVersionSymbolSection(const Elf_Shdr *Sec) {
for (size_t I = 0, E = Syms.size(); I < E; ++I) {
DictScope S(W, "Symbol");
W.printNumber("Version", (*VerTableOrErr)[I].vs_index & VERSYM_VERSION);
- W.printString("Name",
- this->dumper()->getFullSymbolName(&Syms[I], I, StrTable,
- /*IsDynamic=*/true));
+ W.printString("Name", this->dumper().getFullSymbolName(Syms[I], I, StrTable,
+ /*IsDynamic=*/true));
}
}
@@ -6404,7 +6358,7 @@ void LLVMStyle<ELFT>::printVersionDefinitionSection(const Elf_Shdr *Sec) {
if (!Sec)
return;
- Expected<std::vector<VerDef>> V = this->dumper()->getVersionDefinitions(Sec);
+ Expected<std::vector<VerDef>> V = this->dumper().getVersionDefinitions(*Sec);
if (!V) {
this->reportUniqueWarning(V.takeError());
return;
@@ -6429,8 +6383,7 @@ void LLVMStyle<ELFT>::printVersionDependencySection(const Elf_Shdr *Sec) {
if (!Sec)
return;
- Expected<std::vector<VerNeed>> V =
- this->dumper()->getVersionDependencies(Sec);
+ Expected<std::vector<VerNeed>> V = this->dumper().getVersionDependencies(*Sec);
if (!V) {
this->reportUniqueWarning(V.takeError());
return;
@@ -6459,12 +6412,12 @@ template <class ELFT> void LLVMStyle<ELFT>::printHashHistograms() {
template <class ELFT> void LLVMStyle<ELFT>::printCGProfile() {
ListScope L(W, "CGProfile");
- if (!this->dumper()->getDotCGProfileSec())
+ if (!this->dumper().getDotCGProfileSec())
return;
Expected<ArrayRef<Elf_CGProfile>> CGProfileOrErr =
this->Obj.template getSectionContentsAsArray<Elf_CGProfile>(
- *this->dumper()->getDotCGProfileSec());
+ *this->dumper().getDotCGProfileSec());
if (!CGProfileOrErr) {
this->reportUniqueWarning(
createError("unable to dump the SHT_LLVM_CALL_GRAPH_PROFILE section: " +
@@ -6474,9 +6427,9 @@ template <class ELFT> void LLVMStyle<ELFT>::printCGProfile() {
for (const Elf_CGProfile &CGPE : *CGProfileOrErr) {
DictScope D(W, "CGProfileEntry");
- W.printNumber("From", this->dumper()->getStaticSymbolName(CGPE.cgp_from),
+ W.printNumber("From", this->dumper().getStaticSymbolName(CGPE.cgp_from),
CGPE.cgp_from);
- W.printNumber("To", this->dumper()->getStaticSymbolName(CGPE.cgp_to),
+ W.printNumber("To", this->dumper().getStaticSymbolName(CGPE.cgp_to),
CGPE.cgp_to);
W.printNumber("Weight", CGPE.cgp_weight);
}
@@ -6499,7 +6452,7 @@ static Expected<std::vector<uint64_t>> toULEB128Array(ArrayRef<uint8_t> Data) {
template <class ELFT> void LLVMStyle<ELFT>::printAddrsig() {
ListScope L(W, "Addrsig");
- const Elf_Shdr *Sec = this->dumper()->getDotAddrsigSec();
+ const Elf_Shdr *Sec = this->dumper().getDotAddrsigSec();
if (!Sec)
return;
@@ -6519,7 +6472,7 @@ template <class ELFT> void LLVMStyle<ELFT>::printAddrsig() {
}
for (uint64_t Sym : *SymsOrErr)
- W.printNumber("Sym", this->dumper()->getStaticSymbolName(Sym), Sym);
+ W.printNumber("Sym", this->dumper().getStaticSymbolName(Sym), Sym);
}
template <typename ELFT>
@@ -6547,7 +6500,7 @@ static void printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef<uint8_t> Desc,
break;
case ELF::NT_GNU_PROPERTY_TYPE_0:
ListScope D(W, "Property");
- for (const auto &Property : getGNUPropertyList<ELFT>(Desc))
+ for (const std::string &Property : getGNUPropertyList<ELFT>(Desc))
W.printString(Property);
break;
}
@@ -6769,15 +6722,15 @@ void LLVMStyle<ELFT>::printMipsGOT(const MipsGOTParser<ELFT> &Parser) {
PrintEntry(&E);
- const Elf_Sym *Sym = Parser.getGotSym(&E);
- W.printHex("Value", Sym->st_value);
- W.printEnum("Type", Sym->getType(), makeArrayRef(ElfSymbolTypes));
- printSymbolSection(Sym, Sym - this->dumper()->dynamic_symbols().begin());
+ const Elf_Sym &Sym = *Parser.getGotSym(&E);
+ W.printHex("Value", Sym.st_value);
+ W.printEnum("Type", Sym.getType(), makeArrayRef(ElfSymbolTypes));
+ printSymbolSection(Sym, &Sym - this->dumper().dynamic_symbols().begin());
- std::string SymName = this->dumper()->getFullSymbolName(
- Sym, Sym - &Parser.getGotDynSyms()[0],
- this->dumper()->getDynamicStringTable(), true);
- W.printNumber("Name", SymName, Sym->st_name);
+ std::string SymName = this->dumper().getFullSymbolName(
+ Sym, &Sym - &Parser.getGotDynSyms()[0],
+ this->dumper().getDynamicStringTable(), true);
+ W.printNumber("Name", SymName, Sym.st_name);
}
}
@@ -6814,26 +6767,25 @@ void LLVMStyle<ELFT>::printMipsPLT(const MipsGOTParser<ELFT> &Parser) {
DictScope D(W, "Entry");
PrintEntry(&E);
- const Elf_Sym *Sym = Parser.getPltSym(&E);
- W.printHex("Value", Sym->st_value);
- W.printEnum("Type", Sym->getType(), makeArrayRef(ElfSymbolTypes));
- printSymbolSection(Sym, Sym - this->dumper()->dynamic_symbols().begin());
+ const Elf_Sym &Sym = *Parser.getPltSym(&E);
+ W.printHex("Value", Sym.st_value);
+ W.printEnum("Type", Sym.getType(), makeArrayRef(ElfSymbolTypes));
+ printSymbolSection(Sym, &Sym - this->dumper().dynamic_symbols().begin());
const Elf_Sym *FirstSym =
cantFail(this->Obj.template getEntry<const Elf_Sym>(
*Parser.getPltSymTable(), 0));
- std::string SymName = this->dumper()->getFullSymbolName(
- Sym, Sym - FirstSym, Parser.getPltStrTable(), true);
- W.printNumber("Name", SymName, Sym->st_name);
+ std::string SymName = this->dumper().getFullSymbolName(
+ Sym, &Sym - FirstSym, Parser.getPltStrTable(), true);
+ W.printNumber("Name", SymName, Sym.st_name);
}
}
}
-template <class ELFT>
-void LLVMStyle<ELFT>::printMipsABIFlags(const ELFObjectFile<ELFT> *ObjF) {
+template <class ELFT> void LLVMStyle<ELFT>::printMipsABIFlags() {
const Elf_Mips_ABIFlags<ELFT> *Flags;
if (Expected<const Elf_Mips_ABIFlags<ELFT> *> SecOrErr =
- getMipsAbiFlagsSection(ObjF, *this->dumper())) {
+ getMipsAbiFlagsSection(this->dumper())) {
Flags = *SecOrErr;
if (!Flags) {
W.startLine() << "There is no .MIPS.abiflags section in the file.\n";
diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp
index a1c461a9e639..f46993b4f428 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.cpp
+++ b/llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -37,7 +37,7 @@ static void printAsPrintable(raw_ostream &W, const uint8_t *Start, size_t Len) {
}
static std::vector<object::SectionRef>
-getSectionRefsByNameOrIndex(const object::ObjectFile *Obj,
+getSectionRefsByNameOrIndex(const object::ObjectFile &Obj,
ArrayRef<std::string> Sections) {
std::vector<object::SectionRef> Ret;
std::map<std::string, bool> SecNames;
@@ -50,9 +50,9 @@ getSectionRefsByNameOrIndex(const object::ObjectFile *Obj,
SecNames.emplace(std::string(Section), false);
}
- SecIndex = Obj->isELF() ? 0 : 1;
- for (object::SectionRef SecRef : Obj->sections()) {
- StringRef SecName = unwrapOrError(Obj->getFileName(), SecRef.getName());
+ SecIndex = Obj.isELF() ? 0 : 1;
+ for (object::SectionRef SecRef : Obj.sections()) {
+ StringRef SecName = unwrapOrError(Obj.getFileName(), SecRef.getName());
auto NameIt = SecNames.find(std::string(SecName));
if (NameIt != SecNames.end())
NameIt->second = true;
@@ -68,24 +68,23 @@ getSectionRefsByNameOrIndex(const object::ObjectFile *Obj,
if (!S.second)
reportWarning(
createError(formatv("could not find section '{0}'", S.first).str()),
- Obj->getFileName());
+ Obj.getFileName());
for (std::pair<unsigned, bool> S : SecIndices)
if (!S.second)
reportWarning(
createError(formatv("could not find section {0}", S.first).str()),
- Obj->getFileName());
+ Obj.getFileName());
return Ret;
}
-void ObjDumper::printSectionsAsString(const object::ObjectFile *Obj,
+void ObjDumper::printSectionsAsString(const object::ObjectFile &Obj,
ArrayRef<std::string> Sections) {
bool First = true;
for (object::SectionRef Section :
getSectionRefsByNameOrIndex(Obj, Sections)) {
- StringRef SectionName =
- unwrapOrError(Obj->getFileName(), Section.getName());
+ StringRef SectionName = unwrapOrError(Obj.getFileName(), Section.getName());
if (!First)
W.startLine() << '\n';
@@ -93,7 +92,7 @@ void ObjDumper::printSectionsAsString(const object::ObjectFile *Obj,
W.startLine() << "String dump of section '" << SectionName << "':\n";
StringRef SectionContent =
- unwrapOrError(Obj->getFileName(), Section.getContents());
+ unwrapOrError(Obj.getFileName(), Section.getContents());
const uint8_t *SecContent = SectionContent.bytes_begin();
const uint8_t *CurrentWord = SecContent;
@@ -114,13 +113,12 @@ void ObjDumper::printSectionsAsString(const object::ObjectFile *Obj,
}
}
-void ObjDumper::printSectionsAsHex(const object::ObjectFile *Obj,
+void ObjDumper::printSectionsAsHex(const object::ObjectFile &Obj,
ArrayRef<std::string> Sections) {
bool First = true;
for (object::SectionRef Section :
getSectionRefsByNameOrIndex(Obj, Sections)) {
- StringRef SectionName =
- unwrapOrError(Obj->getFileName(), Section.getName());
+ StringRef SectionName = unwrapOrError(Obj.getFileName(), Section.getName());
if (!First)
W.startLine() << '\n';
@@ -128,7 +126,7 @@ void ObjDumper::printSectionsAsHex(const object::ObjectFile *Obj,
W.startLine() << "Hex dump of section '" << SectionName << "':\n";
StringRef SectionContent =
- unwrapOrError(Obj->getFileName(), Section.getContents());
+ unwrapOrError(Obj.getFileName(), Section.getContents());
const uint8_t *SecContent = SectionContent.bytes_begin();
const uint8_t *SecEnd = SecContent + SectionContent.size();
diff --git a/llvm/tools/llvm-readobj/ObjDumper.h b/llvm/tools/llvm-readobj/ObjDumper.h
index bcde7093a126..9e45062ccda8 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.h
+++ b/llvm/tools/llvm-readobj/ObjDumper.h
@@ -61,7 +61,7 @@ class ObjDumper {
virtual void printNeededLibraries() { }
virtual void printSectionAsHex(StringRef SectionName) {}
virtual void printHashTable() { }
- virtual void printGnuHashTable(const object::ObjectFile *Obj) {}
+ virtual void printGnuHashTable() {}
virtual void printHashSymbols() {}
virtual void printLoadName() {}
virtual void printVersionInfo() {}
@@ -100,9 +100,9 @@ class ObjDumper {
virtual void printStackMap() const = 0;
- void printSectionsAsString(const object::ObjectFile *Obj,
+ void printSectionsAsString(const object::ObjectFile &Obj,
ArrayRef<std::string> Sections);
- void printSectionsAsHex(const object::ObjectFile *Obj,
+ void printSectionsAsHex(const object::ObjectFile &Obj,
ArrayRef<std::string> Sections);
protected:
diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp
index a5849295a16a..173ee3a7f140 100644
--- a/llvm/tools/llvm-readobj/llvm-readobj.cpp
+++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp
@@ -495,13 +495,13 @@ static void dumpObject(const ObjectFile &Obj, ScopedPrinter &Writer,
if (opts::Symbols || opts::DynamicSymbols)
Dumper->printSymbols(opts::Symbols, opts::DynamicSymbols);
if (!opts::StringDump.empty())
- Dumper->printSectionsAsString(&Obj, opts::StringDump);
+ Dumper->printSectionsAsString(Obj, opts::StringDump);
if (!opts::HexDump.empty())
- Dumper->printSectionsAsHex(&Obj, opts::HexDump);
+ Dumper->printSectionsAsHex(Obj, opts::HexDump);
if (opts::HashTable)
Dumper->printHashTable();
if (opts::GnuHashTable)
- Dumper->printGnuHashTable(&Obj);
+ Dumper->printGnuHashTable();
if (opts::VersionInfo)
Dumper->printVersionInfo();
if (Obj.isELF()) {
More information about the llvm-commits
mailing list