diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index fa821ff6a619..dfcbb00bf234 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -372,10 +372,10 @@ public: }; template -static std::string describe(const ELFFile *Obj, +static std::string describe(const ELFFile &Obj, const typename ELFT::Shdr &Sec) { - unsigned SecNdx = &Sec - &cantFail(Obj->sections()).front(); - return (object::getELFSectionTypeName(Obj->getHeader()->e_machine, + unsigned SecNdx = &Sec - &cantFail(Obj.sections()).front(); + return (object::getELFSectionTypeName(Obj.getHeader()->e_machine, Sec.sh_type) + " section with index " + Twine(SecNdx)) .str(); @@ -383,19 +383,19 @@ static std::string describe(const ELFFile *Obj, template std::string ELFDumper::describe(const Elf_Shdr &Sec) const { - return ::describe(ObjF->getELFFile(), Sec); + return ::describe(*ObjF->getELFFile(), Sec); } template -static Expected getLinkAsStrtab(const ELFFile *Obj, +static Expected getLinkAsStrtab(const ELFFile &Obj, const typename ELFT::Shdr *Sec) { Expected StrTabSecOrErr = - Obj->getSection(Sec->sh_link); + Obj.getSection(Sec->sh_link); if (!StrTabSecOrErr) return createError("invalid section linked to " + describe(Obj, *Sec) + ": " + toString(StrTabSecOrErr.takeError())); - Expected StrTabOrErr = Obj->getStringTable(*StrTabSecOrErr); + Expected StrTabOrErr = Obj.getStringTable(*StrTabSecOrErr); if (!StrTabOrErr) return createError("invalid string table linked to " + describe(Obj, *Sec) + ": " + toString(StrTabOrErr.takeError())); @@ -405,22 +405,22 @@ static Expected getLinkAsStrtab(const ELFFile *Obj, // Returns the linked symbol table and associated string table for a given section. template static Expected> -getLinkAsSymtab(const ELFFile *Obj, const typename ELFT::Shdr *Sec, +getLinkAsSymtab(const ELFFile &Obj, const typename ELFT::Shdr *Sec, unsigned ExpectedType) { Expected SymtabOrErr = - Obj->getSection(Sec->sh_link); + Obj.getSection(Sec->sh_link); if (!SymtabOrErr) 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 " + - object::getELFSectionTypeName(Obj->getHeader()->e_machine, - ExpectedType) + - ", but got " + - object::getELFSectionTypeName(Obj->getHeader()->e_machine, - (*SymtabOrErr)->sh_type)); + return createError("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 StrTabOrErr = getLinkAsStrtab(Obj, *SymtabOrErr); if (!StrTabOrErr) @@ -428,7 +428,7 @@ getLinkAsSymtab(const ELFFile *Obj, const typename ELFT::Shdr *Sec, "can't get a string table for the symbol table linked to " + describe(Obj, *Sec) + ": " + toString(StrTabOrErr.takeError())); - Expected SymsOrErr = Obj->symbols(*SymtabOrErr); + Expected SymsOrErr = Obj.symbols(*SymtabOrErr); if (!SymsOrErr) return createError("unable to read symbols from the " + describe(Obj, *Sec) + ": " + @@ -454,7 +454,7 @@ ELFDumper::getVersionTable(const Elf_Shdr *Sec, ArrayRef *SymTab, toString(VersionsOrErr.takeError())); Expected, StringRef>> SymTabOrErr = - getLinkAsSymtab(Obj, Sec, SHT_DYNSYM); + getLinkAsSymtab(*Obj, Sec, SHT_DYNSYM); if (!SymTabOrErr) { reportUniqueWarning(SymTabOrErr.takeError()); return *VersionsOrErr; @@ -478,7 +478,7 @@ Expected> ELFDumper::getVersionDefinitions(const Elf_Shdr *Sec) const { const ELFFile *Obj = ObjF->getELFFile(); - Expected StrTabOrErr = getLinkAsStrtab(Obj, Sec); + Expected StrTabOrErr = getLinkAsStrtab(*Obj, Sec); if (!StrTabOrErr) return StrTabOrErr.takeError(); @@ -565,7 +565,7 @@ Expected> ELFDumper::getVersionDependencies(const Elf_Shdr *Sec) const { const ELFFile *Obj = ObjF->getELFFile(); StringRef StrTab; - Expected StrTabOrErr = getLinkAsStrtab(Obj, Sec); + Expected StrTabOrErr = getLinkAsStrtab(*Obj, Sec); if (!StrTabOrErr) reportUniqueWarning(StrTabOrErr.takeError()); else @@ -681,10 +681,9 @@ void ELFDumper::printSymbolsHelper(bool IsDynamic) const { return S.st_other & ~0x3; }) != Syms.end(); - ELFDumperStyle->printSymtabMessage(Obj, SymtabSec, Entries, - NonVisibilityBitsUsed); + ELFDumperStyle->printSymtabMessage(SymtabSec, Entries, NonVisibilityBitsUsed); for (const auto &Sym : Syms) - ELFDumperStyle->printSymbol(Obj, &Sym, Syms.begin(), StrTable, IsDynamic, + ELFDumperStyle->printSymbol(&Sym, Syms.begin(), StrTable, IsDynamic, NonVisibilityBitsUsed); } @@ -694,43 +693,37 @@ template class DumpStyle { public: TYPEDEF_ELF_TYPES(ELFT) - DumpStyle(ELFDumper *Dumper) : Dumper(Dumper) { + DumpStyle(ELFDumper *Dumper) + : Obj(*Dumper->getElfObject()->getELFFile()), Dumper(Dumper) { FileName = this->Dumper->getElfObject()->getFileName(); } virtual ~DumpStyle() = default; - virtual void printFileHeaders(const ELFFile *Obj) = 0; - virtual void printGroupSections(const ELFFile *Obj) = 0; - virtual void printRelocations(const ELFFile *Obj) = 0; - virtual void printSectionHeaders(const ELFFile *Obj) = 0; - virtual void printSymbols(const ELFFile *Obj, bool PrintSymbols, - bool PrintDynamicSymbols) = 0; - virtual void printHashSymbols(const ELFFile *Obj) {} - virtual void printDependentLibs(const ELFFile *Obj) = 0; - virtual void printDynamic(const ELFFile *Obj) {} - virtual void printDynamicRelocations(const ELFFile *Obj) = 0; - virtual void printSymtabMessage(const ELFFile *Obj, - const Elf_Shdr *Symtab, size_t Offset, + virtual void printFileHeaders() = 0; + virtual void printGroupSections() = 0; + virtual void printRelocations() = 0; + virtual void printSectionHeaders() = 0; + virtual void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) = 0; + virtual void printHashSymbols() {} + virtual void printDependentLibs() = 0; + virtual void printDynamic() {} + virtual void printDynamicRelocations() = 0; + virtual void printSymtabMessage(const Elf_Shdr *Symtab, size_t Offset, bool NonVisibilityBitsUsed) {} - virtual void printSymbol(const ELFFile *Obj, const Elf_Sym *Symbol, - const Elf_Sym *FirstSym, + virtual void printSymbol(const Elf_Sym *Symbol, const Elf_Sym *FirstSym, Optional StrTable, bool IsDynamic, bool NonVisibilityBitsUsed) = 0; - virtual void printProgramHeaders(const ELFFile *Obj, - bool PrintProgramHeaders, + virtual void printProgramHeaders(bool PrintProgramHeaders, cl::boolOrDefault PrintSectionMapping) = 0; - virtual void printVersionSymbolSection(const ELFFile *Obj, - const Elf_Shdr *Sec) = 0; - virtual void printVersionDefinitionSection(const ELFFile *Obj, - const Elf_Shdr *Sec) = 0; - virtual void printVersionDependencySection(const ELFFile *Obj, - const Elf_Shdr *Sec) = 0; - virtual void printHashHistograms(const ELFFile *Obj) = 0; - virtual void printCGProfile(const ELFFile *Obj) = 0; - virtual void printAddrsig(const ELFFile *Obj) = 0; - virtual void printNotes(const ELFFile *Obj) = 0; - virtual void printELFLinkerOptions(const ELFFile *Obj) = 0; + virtual void printVersionSymbolSection(const Elf_Shdr *Sec) = 0; + virtual void printVersionDefinitionSection(const Elf_Shdr *Sec) = 0; + virtual void printVersionDependencySection(const Elf_Shdr *Sec) = 0; + virtual void printHashHistograms() = 0; + virtual void printCGProfile() = 0; + virtual void printAddrsig() = 0; + virtual void printNotes() = 0; + virtual void printELFLinkerOptions() = 0; virtual void printStackSizes(const ELFObjectFile *Obj) = 0; void printNonRelocatableStackSizes(const ELFObjectFile *Obj, std::function PrintHeader); @@ -752,24 +745,22 @@ public: protected: void printDependentLibsHelper( - const ELFFile *Obj, function_ref OnSectionStart, function_ref OnSectionEntry); - virtual void printRelReloc(const ELFO *Obj, unsigned SecIndex, - const Elf_Shdr *SymTab, const Elf_Rel &R, - unsigned RelIndex) = 0; - virtual void printRelaReloc(const ELFO *Obj, unsigned SecIndex, - const Elf_Shdr *SymTab, const Elf_Rela &R, - unsigned RelIndex) = 0; + virtual void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, + const Elf_Rel &R, unsigned RelIndex) = 0; + virtual void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, + const Elf_Rela &R, unsigned RelIndex) = 0; virtual void printRelrReloc(const Elf_Relr &R) = 0; - void printRelocationsHelper(const ELFFile *Obj, const Elf_Shdr &Sec); + void printRelocationsHelper(const Elf_Shdr &Sec); - StringRef getPrintableSectionName(const ELFFile *Obj, - const Elf_Shdr &Sec) const; + StringRef getPrintableSectionName(const Elf_Shdr &Sec) const; void reportUniqueWarning(Error Err) const; + StringRef FileName; + const ELFFile &Obj; private: const ELFDumper *Dumper; @@ -787,31 +778,27 @@ public: assert (&W.getOStream() == &llvm::fouts()); } - void printFileHeaders(const ELFO *Obj) override; - void printGroupSections(const ELFFile *Obj) override; - void printRelocations(const ELFO *Obj) override; - void printSectionHeaders(const ELFO *Obj) override; - void printSymbols(const ELFO *Obj, bool PrintSymbols, - bool PrintDynamicSymbols) override; - void printHashSymbols(const ELFO *Obj) override; - void printDependentLibs(const ELFFile *Obj) override; - void printDynamic(const ELFFile *Obj) override; - void printDynamicRelocations(const ELFO *Obj) override; - void printSymtabMessage(const ELFO *Obj, const Elf_Shdr *Symtab, - size_t Offset, bool NonVisibilityBitsUsed) override; - void printProgramHeaders(const ELFO *Obj, bool PrintProgramHeaders, + void printFileHeaders() override; + void printGroupSections() override; + void printRelocations() override; + void printSectionHeaders() override; + void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) override; + void printHashSymbols() override; + void printDependentLibs() override; + void printDynamic() override; + void printDynamicRelocations() override; + void printSymtabMessage(const Elf_Shdr *Symtab, size_t Offset, + bool NonVisibilityBitsUsed) override; + void printProgramHeaders(bool PrintProgramHeaders, cl::boolOrDefault PrintSectionMapping) override; - void printVersionSymbolSection(const ELFFile *Obj, - const Elf_Shdr *Sec) override; - void printVersionDefinitionSection(const ELFFile *Obj, - const Elf_Shdr *Sec) override; - void printVersionDependencySection(const ELFFile *Obj, - const Elf_Shdr *Sec) override; - void printHashHistograms(const ELFFile *Obj) override; - void printCGProfile(const ELFFile *Obj) override; - void printAddrsig(const ELFFile *Obj) override; - void printNotes(const ELFFile *Obj) override; - void printELFLinkerOptions(const ELFFile *Obj) override; + void printVersionSymbolSection(const Elf_Shdr *Sec) override; + void printVersionDefinitionSection(const Elf_Shdr *Sec) override; + void printVersionDependencySection(const Elf_Shdr *Sec) override; + void printHashHistograms() override; + void printCGProfile() override; + void printAddrsig() override; + void printNotes() override; + void printELFLinkerOptions() override; void printStackSizes(const ELFObjectFile *Obj) override; void printStackSizeEntry(uint64_t Size, StringRef FuncName) override; void printMipsGOT(const MipsGOTParser &Parser) override; @@ -822,9 +809,8 @@ private: void printHashHistogram(const Elf_Hash &HashTable); void printGnuHashHistogram(const Elf_GnuHash &GnuHashTable); - void printHashTableSymbols(const ELFO *Obj, const Elf_Hash &HashTable); - void printGnuHashTableSymbols(const ELFO *Obj, - const Elf_GnuHash &GnuHashTable); + void printHashTableSymbols(const Elf_Hash &HashTable); + void printGnuHashTableSymbols(const Elf_GnuHash &GnuHashTable); struct Field { std::string Str; @@ -876,35 +862,31 @@ private: OS.flush(); return OS; } - void printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, uint32_t Sym, + void printHashedSymbol(const Elf_Sym *FirstSym, uint32_t Sym, StringRef StrTable, uint32_t Bucket); void printRelocHeader(unsigned SType); - void printRelReloc(const ELFO *Obj, unsigned SecIndex, const Elf_Shdr *SymTab, + void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, const Elf_Rel &R, unsigned RelIndex) override; - void printRelaReloc(const ELFO *Obj, unsigned SecIndex, - const Elf_Shdr *SymTab, const Elf_Rela &R, - unsigned RelIndex) override; + void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, + const Elf_Rela &R, unsigned RelIndex) override; void printRelrReloc(const Elf_Relr &R) override; template - void printRelRelaReloc(const ELFO *Obj, unsigned SecIndex, - const Elf_Shdr *SymTab, const RelTy &R, - unsigned RelIndex); + void printRelRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, + const RelTy &R, unsigned RelIndex); template - void printRelRelaReloc(const ELFO *Obj, const Elf_Sym *Sym, - StringRef SymbolName, const RelTy &R); - void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First, + void printRelRelaReloc(const Elf_Sym *Sym, StringRef SymbolName, + const RelTy &R); + void printSymbol(const Elf_Sym *Symbol, const Elf_Sym *First, Optional StrTable, bool IsDynamic, bool NonVisibilityBitsUsed) override; - std::string getSymbolSectionNdx(const ELFO *Obj, const Elf_Sym *Symbol, + std::string getSymbolSectionNdx(const Elf_Sym *Symbol, const Elf_Sym *FirstSym); - template - void printDynamicRelocation(const ELFO *Obj, const RelTy &R); - void printProgramHeaders(const ELFO *Obj); - void printSectionMapping(const ELFO *Obj); - void printGNUVersionSectionProlog(const ELFFile *Obj, - const typename ELFT::Shdr *Sec, + template void printDynamicRelocation(const RelTy &R); + void printProgramHeaders(); + void printSectionMapping(); + void printGNUVersionSectionProlog(const typename ELFT::Shdr *Sec, const Twine &Label, unsigned EntriesNum); }; @@ -928,28 +910,24 @@ public: LLVMStyle(ScopedPrinter &W, ELFDumper *Dumper) : DumpStyle(Dumper), W(W) {} - void printFileHeaders(const ELFO *Obj) override; - void printGroupSections(const ELFFile *Obj) override; - void printRelocations(const ELFO *Obj) override; - void printSectionHeaders(const ELFO *Obj) override; - void printSymbols(const ELFO *Obj, bool PrintSymbols, - bool PrintDynamicSymbols) override; - void printDependentLibs(const ELFFile *Obj) override; - void printDynamic(const ELFFile *Obj) override; - void printDynamicRelocations(const ELFO *Obj) override; - void printProgramHeaders(const ELFO *Obj, bool PrintProgramHeaders, + void printFileHeaders() override; + void printGroupSections() override; + void printRelocations() override; + void printSectionHeaders() override; + void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) override; + void printDependentLibs() override; + void printDynamic() override; + void printDynamicRelocations() override; + void printProgramHeaders(bool PrintProgramHeaders, cl::boolOrDefault PrintSectionMapping) override; - void printVersionSymbolSection(const ELFFile *Obj, - const Elf_Shdr *Sec) override; - void printVersionDefinitionSection(const ELFFile *Obj, - const Elf_Shdr *Sec) override; - void printVersionDependencySection(const ELFFile *Obj, - const Elf_Shdr *Sec) override; - void printHashHistograms(const ELFFile *Obj) override; - void printCGProfile(const ELFFile *Obj) override; - void printAddrsig(const ELFFile *Obj) override; - void printNotes(const ELFFile *Obj) override; - void printELFLinkerOptions(const ELFFile *Obj) override; + void printVersionSymbolSection(const Elf_Shdr *Sec) override; + void printVersionDefinitionSection(const Elf_Shdr *Sec) override; + void printVersionDependencySection(const Elf_Shdr *Sec) override; + void printHashHistograms() override; + void printCGProfile() override; + void printAddrsig() override; + void printNotes() override; + void printELFLinkerOptions() override; void printStackSizes(const ELFObjectFile *Obj) override; void printStackSizeEntry(uint64_t Size, StringRef FuncName) override; void printMipsGOT(const MipsGOTParser &Parser) override; @@ -957,26 +935,24 @@ public: void printMipsABIFlags(const ELFObjectFile *Obj) override; private: - void printRelReloc(const ELFO *Obj, unsigned SecIndex, const Elf_Shdr *SymTab, + void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, const Elf_Rel &R, unsigned RelIndex) override; - void printRelaReloc(const ELFO *Obj, unsigned SecIndex, - const Elf_Shdr *SymTab, const Elf_Rela &R, - unsigned RelIndex) override; + void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, + const Elf_Rela &R, unsigned RelIndex) override; void printRelrReloc(const Elf_Relr &R) override; template - void printRelRelaReloc(const ELFO *Obj, unsigned SecIndex, const RelTy &Rel, - unsigned RelIndex, const Elf_Shdr *SymTab); - template - void printDynamicRelocation(const ELFO *Obj, const RelTy& Rel); + void printRelRelaReloc(unsigned SecIndex, const RelTy &Rel, unsigned RelIndex, + const Elf_Shdr *SymTab); + template void printDynamicRelocation(const RelTy &Rel); - void printSymbols(const ELFO *Obj); - void printDynamicSymbols(const ELFO *Obj); + void printSymbols(); + void printDynamicSymbols(); void printSymbolSection(const Elf_Sym *Symbol, const Elf_Sym *First); - void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First, + void printSymbol(const Elf_Sym *Symbol, const Elf_Sym *First, Optional StrTable, bool IsDynamic, bool /*NonVisibilityBitsUsed*/) override; - void printProgramHeaders(const ELFO *Obj); - void printSectionMapping(const ELFO *Obj) {} + void printProgramHeaders(); + void printSectionMapping() {} ScopedPrinter &W; }; @@ -2273,71 +2249,66 @@ typename ELFDumper::Elf_Relr_Range ELFDumper::dyn_relrs() const { } template void ELFDumper::printFileHeaders() { - ELFDumperStyle->printFileHeaders(ObjF->getELFFile()); + ELFDumperStyle->printFileHeaders(); } template void ELFDumper::printSectionHeaders() { - ELFDumperStyle->printSectionHeaders(ObjF->getELFFile()); + ELFDumperStyle->printSectionHeaders(); } template void ELFDumper::printRelocations() { - ELFDumperStyle->printRelocations(ObjF->getELFFile()); + ELFDumperStyle->printRelocations(); } template void ELFDumper::printProgramHeaders( bool PrintProgramHeaders, cl::boolOrDefault PrintSectionMapping) { - ELFDumperStyle->printProgramHeaders(ObjF->getELFFile(), PrintProgramHeaders, - PrintSectionMapping); + ELFDumperStyle->printProgramHeaders(PrintProgramHeaders, PrintSectionMapping); } template void ELFDumper::printVersionInfo() { // Dump version symbol section. - ELFDumperStyle->printVersionSymbolSection(ObjF->getELFFile(), - SymbolVersionSection); + ELFDumperStyle->printVersionSymbolSection(SymbolVersionSection); // Dump version definition section. - ELFDumperStyle->printVersionDefinitionSection(ObjF->getELFFile(), - SymbolVersionDefSection); + ELFDumperStyle->printVersionDefinitionSection(SymbolVersionDefSection); // Dump version dependency section. - ELFDumperStyle->printVersionDependencySection(ObjF->getELFFile(), - SymbolVersionNeedSection); + ELFDumperStyle->printVersionDependencySection(SymbolVersionNeedSection); } template void ELFDumper::printDependentLibs() { - ELFDumperStyle->printDependentLibs(ObjF->getELFFile()); + ELFDumperStyle->printDependentLibs(); } template void ELFDumper::printDynamicRelocations() { - ELFDumperStyle->printDynamicRelocations(ObjF->getELFFile()); + ELFDumperStyle->printDynamicRelocations(); } template void ELFDumper::printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) { - ELFDumperStyle->printSymbols(ObjF->getELFFile(), PrintSymbols, - PrintDynamicSymbols); + ELFDumperStyle->printSymbols(PrintSymbols, PrintDynamicSymbols); } template void ELFDumper::printHashSymbols() { - ELFDumperStyle->printHashSymbols(ObjF->getELFFile()); + ELFDumperStyle->printHashSymbols(); } template void ELFDumper::printHashHistograms() { - ELFDumperStyle->printHashHistograms(ObjF->getELFFile()); + ELFDumperStyle->printHashHistograms(); } template void ELFDumper::printCGProfile() { - ELFDumperStyle->printCGProfile(ObjF->getELFFile()); + ELFDumperStyle->printCGProfile(); } template void ELFDumper::printNotes() { - ELFDumperStyle->printNotes(ObjF->getELFFile()); + ELFDumperStyle->printNotes(); } template void ELFDumper::printELFLinkerOptions() { - ELFDumperStyle->printELFLinkerOptions(ObjF->getELFFile()); + ELFDumperStyle->printELFLinkerOptions(); } template void ELFDumper::printStackSizes() { @@ -2673,7 +2644,7 @@ template <> void ELFDumper::printUnwindInfo() { } // end anonymous namespace template void ELFDumper::printDynamicTable() { - ELFDumperStyle->printDynamic(ObjF->getELFFile()); + ELFDumperStyle->printDynamic(); } template void ELFDumper::printNeededLibraries() { @@ -2691,26 +2662,26 @@ template void ELFDumper::printNeededLibraries() { } template -static Error checkHashTable(const ELFFile *Obj, +static Error checkHashTable(const ELFFile &Obj, const typename ELFT::Hash *H, bool *IsHeaderValid = nullptr) { auto MakeError = [&](uint64_t Off, const Twine &Msg = "") { return createError("the hash table at offset 0x" + Twine::utohexstr(Off) + " goes past the end of the file (0x" + - Twine::utohexstr(Obj->getBufSize()) + ")" + Msg); + Twine::utohexstr(Obj.getBufSize()) + ")" + Msg); }; // Each SHT_HASH section starts from two 32-bit fields: nbucket and nchain. const unsigned HeaderSize = 2 * sizeof(typename ELFT::Word); - const uint64_t SecOffset = (const uint8_t *)H - Obj->base(); + const uint64_t SecOffset = (const uint8_t *)H - Obj.base(); if (IsHeaderValid) - *IsHeaderValid = Obj->getBufSize() - SecOffset >= HeaderSize; + *IsHeaderValid = Obj.getBufSize() - SecOffset >= HeaderSize; - if (Obj->getBufSize() - SecOffset < HeaderSize) + if (Obj.getBufSize() - SecOffset < HeaderSize) return MakeError(SecOffset); - if (Obj->getBufSize() - SecOffset - HeaderSize < + if (Obj.getBufSize() - SecOffset - HeaderSize < ((uint64_t)H->nbucket + H->nchain) * sizeof(typename ELFT::Word)) return MakeError(SecOffset, ", nbucket = " + Twine(H->nbucket) + ", nchain = " + Twine(H->nchain)); @@ -2718,20 +2689,19 @@ static Error checkHashTable(const ELFFile *Obj, } template -static Error checkGNUHashTable(const ELFFile *Obj, +static Error checkGNUHashTable(const ELFFile &Obj, const typename ELFT::GnuHash *GnuHashTable, bool *IsHeaderValid = nullptr) { const uint8_t *TableData = reinterpret_cast(GnuHashTable); - assert(TableData >= Obj->base() && - TableData < Obj->base() + Obj->getBufSize() && + assert(TableData >= Obj.base() && TableData < Obj.base() + Obj.getBufSize() && "GnuHashTable must always point to a location inside the file"); - uint64_t TableOffset = TableData - Obj->base(); + uint64_t TableOffset = TableData - Obj.base(); if (IsHeaderValid) - *IsHeaderValid = TableOffset + /*Header size:*/ 16 < Obj->getBufSize(); + *IsHeaderValid = TableOffset + /*Header size:*/ 16 < Obj.getBufSize(); if (TableOffset + 16 + (uint64_t)GnuHashTable->nbuckets * 4 + (uint64_t)GnuHashTable->maskwords * sizeof(typename ELFT::Off) >= - Obj->getBufSize()) + Obj.getBufSize()) return createError("unable to dump the SHT_GNU_HASH " "section at 0x" + Twine::utohexstr(TableOffset) + @@ -2745,7 +2715,7 @@ template void ELFDumper::printHashTable() { return; bool IsHeaderValid; - Error Err = checkHashTable(ObjF->getELFFile(), HashTable, &IsHeaderValid); + Error Err = checkHashTable(*ObjF->getELFFile(), HashTable, &IsHeaderValid); if (IsHeaderValid) { W.printNumber("Num Buckets", HashTable->nbucket); W.printNumber("Num Chains", HashTable->nchain); @@ -2801,8 +2771,8 @@ void ELFDumper::printGnuHashTable(const object::ObjectFile *Obj) { return; bool IsHeaderValid; - Error Err = - checkGNUHashTable(ObjF->getELFFile(), GnuHashTable, &IsHeaderValid); + Error Err = checkGNUHashTable(*ObjF->getELFFile(), GnuHashTable, + &IsHeaderValid); if (IsHeaderValid) { W.printNumber("Num Buckets", GnuHashTable->nbuckets); W.printNumber("First Hashed Symbol Index", GnuHashTable->symndx); @@ -3093,7 +3063,7 @@ Error MipsGOTParser::findPLT(Elf_Dyn_Range DynTable) { 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 StrTabOrErr = @@ -3101,7 +3071,7 @@ Error MipsGOTParser::findPLT(Elf_Dyn_Range DynTable) { 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(); @@ -3431,11 +3401,11 @@ template void ELFDumper::printStackMap() const { } template void ELFDumper::printGroupSections() { - ELFDumperStyle->printGroupSections(ObjF->getELFFile()); + ELFDumperStyle->printGroupSections(); } template void ELFDumper::printAddrsig() { - ELFDumperStyle->printAddrsig(ObjF->getELFFile()); + ELFDumperStyle->printAddrsig(); } static inline void printFields(formatted_raw_ostream &OS, StringRef Str1, @@ -3448,34 +3418,34 @@ static inline void printFields(formatted_raw_ostream &OS, StringRef Str1, } template -static std::string getSectionHeadersNumString(const ELFFile *Obj, +static std::string getSectionHeadersNumString(const ELFFile &Obj, StringRef FileName) { - const typename ELFT::Ehdr *ElfHeader = Obj->getHeader(); + const typename ELFT::Ehdr *ElfHeader = Obj.getHeader(); if (ElfHeader->e_shnum != 0) return to_string(ElfHeader->e_shnum); - ArrayRef Arr = cantFail(Obj->sections()); + ArrayRef Arr = cantFail(Obj.sections()); if (Arr.empty()) return "0"; return "0 (" + to_string(Arr[0].sh_size) + ")"; } template -static std::string getSectionHeaderTableIndexString(const ELFFile *Obj, +static std::string getSectionHeaderTableIndexString(const ELFFile &Obj, StringRef FileName) { - const typename ELFT::Ehdr *ElfHeader = Obj->getHeader(); + const typename ELFT::Ehdr *ElfHeader = Obj.getHeader(); if (ElfHeader->e_shstrndx != SHN_XINDEX) return to_string(ElfHeader->e_shstrndx); - ArrayRef Arr = cantFail(Obj->sections()); + ArrayRef Arr = cantFail(Obj.sections()); if (Arr.empty()) return "65535 (corrupt: out of range)"; return to_string(ElfHeader->e_shstrndx) + " (" + to_string(Arr[0].sh_link) + ")"; } -template void GNUStyle::printFileHeaders(const ELFO *Obj) { - const Elf_Ehdr *e = Obj->getHeader(); +template void GNUStyle::printFileHeaders() { + const Elf_Ehdr *e = this->Obj.getHeader(); OS << "ELF Header:\n"; OS << " Magic: "; std::string Str; @@ -3529,9 +3499,9 @@ template void GNUStyle::printFileHeaders(const ELFO *Obj) { printFields(OS, "Number of program headers:", Str); Str = to_string(e->e_shentsize) + " (bytes)"; printFields(OS, "Size of section headers:", Str); - Str = getSectionHeadersNumString(Obj, this->FileName); + Str = getSectionHeadersNumString(this->Obj, this->FileName); printFields(OS, "Number of section headers:", Str); - Str = getSectionHeaderTableIndexString(Obj, this->FileName); + Str = getSectionHeaderTableIndexString(this->Obj, this->FileName); printFields(OS, "Section header string table index:", Str); } @@ -3553,7 +3523,7 @@ struct GroupSection { }; template -std::vector getGroups(const ELFFile *Obj, +std::vector getGroups(const ELFFile &Obj, StringRef FileName) { using Elf_Shdr = typename ELFT::Shdr; using Elf_Sym = typename ELFT::Sym; @@ -3561,21 +3531,21 @@ std::vector getGroups(const ELFFile *Obj, std::vector Ret; uint64_t I = 0; - for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(Obj.sections())) { ++I; if (Sec.sh_type != ELF::SHT_GROUP) continue; const Elf_Shdr *Symtab = - unwrapOrError(FileName, Obj->getSection(Sec.sh_link)); + unwrapOrError(FileName, Obj.getSection(Sec.sh_link)); StringRef StrTable = - unwrapOrError(FileName, Obj->getStringTableForSymtab(*Symtab)); + unwrapOrError(FileName, Obj.getStringTableForSymtab(*Symtab)); const Elf_Sym *Sym = unwrapOrError( - FileName, Obj->template getEntry(Symtab, Sec.sh_info)); + FileName, Obj.template getEntry(Symtab, Sec.sh_info)); auto Data = unwrapOrError( - FileName, Obj->template getSectionContentsAsArray(&Sec)); + FileName, Obj.template getSectionContentsAsArray(&Sec)); - StringRef Name = unwrapOrError(FileName, Obj->getSectionName(&Sec)); + StringRef Name = unwrapOrError(FileName, Obj.getSectionName(&Sec)); StringRef Signature = StrTable.data() + Sym->st_name; Ret.push_back({Name, maybeDemangle(Signature), @@ -3588,8 +3558,8 @@ std::vector getGroups(const ELFFile *Obj, std::vector &GM = Ret.back().Members; for (uint32_t Ndx : Data.slice(1)) { - auto Sec = unwrapOrError(FileName, Obj->getSection(Ndx)); - const StringRef Name = unwrapOrError(FileName, Obj->getSectionName(Sec)); + auto Sec = unwrapOrError(FileName, Obj.getSection(Ndx)); + const StringRef Name = unwrapOrError(FileName, Obj.getSectionName(Sec)); GM.push_back({Name, Ndx}); } } @@ -3607,8 +3577,8 @@ mapSectionsToGroups(ArrayRef Groups) { } // namespace -template void GNUStyle::printGroupSections(const ELFO *Obj) { - std::vector V = getGroups(Obj, this->FileName); +template void GNUStyle::printGroupSections() { + std::vector V = getGroups(this->Obj, this->FileName); DenseMap Map = mapSectionsToGroups(V); for (const GroupSection &G : V) { OS << "\n" @@ -3634,17 +3604,15 @@ template void GNUStyle::printGroupSections(const ELFO *Obj) { } template -void GNUStyle::printRelReloc(const ELFO *Obj, unsigned SecIndex, - const Elf_Shdr *SymTab, const Elf_Rel &R, - unsigned RelIndex) { - printRelRelaReloc(Obj, SecIndex, SymTab, R, RelIndex); +void GNUStyle::printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, + const Elf_Rel &R, unsigned RelIndex) { + printRelRelaReloc(SecIndex, SymTab, R, RelIndex); } template -void GNUStyle::printRelaReloc(const ELFO *Obj, unsigned SecIndex, - const Elf_Shdr *SymTab, const Elf_Rela &R, - unsigned RelIndex) { - printRelRelaReloc(Obj, SecIndex, SymTab, R, RelIndex); +void GNUStyle::printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, + const Elf_Rela &R, unsigned RelIndex) { + printRelRelaReloc(SecIndex, SymTab, R, RelIndex); } template void GNUStyle::printRelrReloc(const Elf_Relr &R) { @@ -3653,7 +3621,7 @@ template void GNUStyle::printRelrReloc(const Elf_Relr &R) { template template -void GNUStyle::printRelRelaReloc(const ELFO *Obj, unsigned SecIndex, +void GNUStyle::printRelRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, const RelTy &R, unsigned RelIndex) { Expected> Target = @@ -3663,7 +3631,7 @@ void GNUStyle::printRelRelaReloc(const ELFO *Obj, unsigned SecIndex, "unable to print relocation " + Twine(RelIndex) + " in section " + Twine(SecIndex) + ": " + toString(Target.takeError()))); else - printRelRelaReloc(Obj, /*Sym=*/Target->first, /*Name=*/Target->second, R); + printRelRelaReloc(/*Sym=*/Target->first, /*Name=*/Target->second, R); } template @@ -3678,8 +3646,8 @@ static Optional getAddend(const typename ELFT::Rel &) { template template -void GNUStyle::printRelRelaReloc(const ELFO *Obj, const Elf_Sym *Sym, - StringRef SymbolName, const RelTy &R) { +void GNUStyle::printRelRelaReloc(const Elf_Sym *Sym, StringRef SymbolName, + const RelTy &R) { // First two fields are bit width dependent. The rest of them are fixed width. unsigned Bias = ELFT::Is64Bits ? 8 : 0; Field Fields[5] = {0, 10 + Bias, 19 + 2 * Bias, 42 + 2 * Bias, 53 + 2 * Bias}; @@ -3689,7 +3657,7 @@ void GNUStyle::printRelRelaReloc(const ELFO *Obj, const Elf_Sym *Sym, Fields[1].Str = to_string(format_hex_no_prefix(R.r_info, Width)); SmallString<32> RelocName; - Obj->getRelocationTypeName(R.getType(Obj->isMips64EL()), RelocName); + this->Obj.getRelocationTypeName(R.getType(this->Obj.isMips64EL()), RelocName); Fields[2].Str = RelocName.c_str(); if (Sym) @@ -3744,14 +3712,14 @@ static bool isRelocationSec(const typename ELFT::Shdr &Sec) { Sec.sh_type == ELF::SHT_ANDROID_RELR; } -template void GNUStyle::printRelocations(const ELFO *Obj) { +template void GNUStyle::printRelocations() { auto GetEntriesNum = [&](const Elf_Shdr &Sec) -> Expected { // Android's packed relocation section needs to be unpacked first // to get the actual number of entries. if (Sec.sh_type == ELF::SHT_ANDROID_REL || Sec.sh_type == ELF::SHT_ANDROID_RELA) { Expected> RelasOrErr = - Obj->android_relas(&Sec); + this->Obj.android_relas(&Sec); if (!RelasOrErr) return RelasOrErr.takeError(); return RelasOrErr->size(); @@ -3759,17 +3727,17 @@ template void GNUStyle::printRelocations(const ELFO *Obj) { if (!opts::RawRelr && (Sec.sh_type == ELF::SHT_RELR || Sec.sh_type == ELF::SHT_ANDROID_RELR)) { - Expected RelrsOrErr = Obj->relrs(&Sec); + Expected RelrsOrErr = this->Obj.relrs(&Sec); if (!RelrsOrErr) return RelrsOrErr.takeError(); - return Obj->decode_relrs(*RelrsOrErr).size(); + return this->Obj.decode_relrs(*RelrsOrErr).size(); } return Sec.getEntityCount(); }; bool HasRelocSections = false; - for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(this->Obj.sections())) { if (!isRelocationSec(Sec)) continue; HasRelocSections = true; @@ -3779,16 +3747,16 @@ template void GNUStyle::printRelocations(const ELFO *Obj) { EntriesNum = std::to_string(*NumOrErr); else this->reportUniqueWarning(createError( - "unable to get the number of relocations in " + describe(Obj, Sec) + - ": " + toString(NumOrErr.takeError()))); + "unable to get the number of relocations in " + + describe(this->Obj, Sec) + ": " + toString(NumOrErr.takeError()))); uintX_t Offset = Sec.sh_offset; - StringRef Name = this->getPrintableSectionName(Obj, Sec); + StringRef Name = this->getPrintableSectionName(Sec); OS << "\nRelocation section '" << Name << "' at offset 0x" << to_hexString(Offset, false) << " contains " << EntriesNum << " entries:\n"; printRelocHeader(Sec.sh_type); - this->printRelocationsHelper(Obj, Sec); + this->printRelocationsHelper(Sec); } if (!HasRelocSections) OS << "\nThere are no relocations in this file.\n"; @@ -3846,13 +3814,12 @@ static void printSectionDescription(formatted_raw_ostream &OS, OS << "p (processor specific)\n"; } -template -void GNUStyle::printSectionHeaders(const ELFO *Obj) { +template void GNUStyle::printSectionHeaders() { unsigned Bias = ELFT::Is64Bits ? 0 : 8; - ArrayRef Sections = cantFail(Obj->sections()); + ArrayRef Sections = cantFail(this->Obj.sections()); OS << "There are " << to_string(Sections.size()) << " section headers, starting at offset " - << "0x" << to_hexString(Obj->getHeader()->e_shoff, false) << ":\n\n"; + << "0x" << to_hexString(this->Obj.getHeader()->e_shoff, false) << ":\n\n"; OS << "Section Headers:\n"; Field Fields[11] = { {"[Nr]", 2}, {"Name", 7}, {"Type", 25}, @@ -3864,8 +3831,8 @@ void GNUStyle::printSectionHeaders(const ELFO *Obj) { OS << "\n"; StringRef SecStrTable; - if (Expected SecStrTableOrErr = - Obj->getSectionStringTable(Sections, this->dumper()->WarningHandler)) + if (Expected SecStrTableOrErr = this->Obj.getSectionStringTable( + Sections, this->dumper()->WarningHandler)) SecStrTable = *SecStrTableOrErr; else this->reportUniqueWarning(SecStrTableOrErr.takeError()); @@ -3877,15 +3844,15 @@ void GNUStyle::printSectionHeaders(const ELFO *Obj) { Fields[1].Str = ""; else Fields[1].Str = std::string(unwrapOrError( - this->FileName, Obj->getSectionName(&Sec, SecStrTable))); + this->FileName, this->Obj.getSectionName(&Sec, SecStrTable))); Fields[2].Str = - getSectionTypeString(Obj->getHeader()->e_machine, Sec.sh_type); + getSectionTypeString(this->Obj.getHeader()->e_machine, Sec.sh_type); Fields[3].Str = to_string(format_hex_no_prefix(Sec.sh_addr, ELFT::Is64Bits ? 16 : 8)); Fields[4].Str = to_string(format_hex_no_prefix(Sec.sh_offset, 6)); Fields[5].Str = to_string(format_hex_no_prefix(Sec.sh_size, 6)); Fields[6].Str = to_string(format_hex_no_prefix(Sec.sh_entsize, 2)); - Fields[7].Str = getGNUFlags(Obj->getHeader()->e_machine, Sec.sh_flags); + Fields[7].Str = getGNUFlags(this->Obj.getHeader()->e_machine, Sec.sh_flags); Fields[8].Str = to_string(Sec.sh_link); Fields[9].Str = to_string(Sec.sh_info); Fields[10].Str = to_string(Sec.sh_addralign); @@ -3905,16 +3872,15 @@ void GNUStyle::printSectionHeaders(const ELFO *Obj) { OS << "\n"; ++SectionIndex; } - printSectionDescription(OS, Obj->getHeader()->e_machine); + printSectionDescription(OS, this->Obj.getHeader()->e_machine); } template -void GNUStyle::printSymtabMessage(const ELFO *Obj, const Elf_Shdr *Symtab, - size_t Entries, +void GNUStyle::printSymtabMessage(const Elf_Shdr *Symtab, size_t Entries, bool NonVisibilityBitsUsed) { StringRef Name; if (Symtab) - Name = this->getPrintableSectionName(Obj, *Symtab); + Name = this->getPrintableSectionName(*Symtab); if (!Name.empty()) OS << "\nSymbol table '" << Name << "'"; else @@ -3932,8 +3898,7 @@ void GNUStyle::printSymtabMessage(const ELFO *Obj, const Elf_Shdr *Symtab, } template -std::string GNUStyle::getSymbolSectionNdx(const ELFO *Obj, - const Elf_Sym *Symbol, +std::string GNUStyle::getSymbolSectionNdx(const Elf_Sym *Symbol, const Elf_Sym *FirstSym) { unsigned SectionIndex = Symbol->st_shndx; switch (SectionIndex) { @@ -3976,8 +3941,7 @@ std::string GNUStyle::getSymbolSectionNdx(const ELFO *Obj, } template -void GNUStyle::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, - const Elf_Sym *FirstSym, +void GNUStyle::printSymbol(const Elf_Sym *Symbol, const Elf_Sym *FirstSym, Optional StrTable, bool IsDynamic, bool NonVisibilityBitsUsed) { unsigned Bias = ELFT::Is64Bits ? 8 : 0; @@ -3989,7 +3953,7 @@ void GNUStyle::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, Fields[2].Str = to_string(format_decimal(Symbol->st_size, 5)); unsigned char SymbolType = Symbol->getType(); - if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU && + if (this->Obj.getHeader()->e_machine == ELF::EM_AMDGPU && SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS) Fields[3].Str = printEnum(SymbolType, makeArrayRef(AMDGPUSymbolTypes)); else @@ -4004,7 +3968,7 @@ void GNUStyle::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, " [st_other, 2)) + ">]"; Fields[6].Column += NonVisibilityBitsUsed ? 13 : 0; - Fields[6].Str = getSymbolSectionNdx(Obj, Symbol, FirstSym); + Fields[6].Str = getSymbolSectionNdx(Symbol, FirstSym); Fields[7].Str = this->dumper()->getFullSymbolName(Symbol, StrTable, IsDynamic); @@ -4014,9 +3978,8 @@ void GNUStyle::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, } template -void GNUStyle::printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, - uint32_t Sym, StringRef StrTable, - uint32_t Bucket) { +void GNUStyle::printHashedSymbol(const Elf_Sym *FirstSym, uint32_t Sym, + StringRef StrTable, uint32_t Bucket) { unsigned Bias = ELFT::Is64Bits ? 8 : 0; Field Fields[9] = {0, 6, 11, 20 + Bias, 25 + Bias, 34 + Bias, 41 + Bias, 49 + Bias, 53 + Bias}; @@ -4029,7 +3992,7 @@ void GNUStyle::printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, Fields[3].Str = to_string(format_decimal(Symbol->st_size, 5)); unsigned char SymbolType = Symbol->getType(); - if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU && + if (this->Obj.getHeader()->e_machine == ELF::EM_AMDGPU && SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS) Fields[4].Str = printEnum(SymbolType, makeArrayRef(AMDGPUSymbolTypes)); else @@ -4039,7 +4002,7 @@ void GNUStyle::printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, printEnum(Symbol->getBinding(), makeArrayRef(ElfSymbolBindings)); Fields[6].Str = printEnum(Symbol->getVisibility(), makeArrayRef(ElfSymbolVisibilities)); - Fields[7].Str = getSymbolSectionNdx(Obj, Symbol, FirstSym); + Fields[7].Str = getSymbolSectionNdx(Symbol, FirstSym); Fields[8].Str = this->dumper()->getFullSymbolName(Symbol, StrTable, true); for (auto &Entry : Fields) @@ -4048,8 +4011,7 @@ void GNUStyle::printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, } template -void GNUStyle::printSymbols(const ELFO *Obj, bool PrintSymbols, - bool PrintDynamicSymbols) { +void GNUStyle::printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) { if (!PrintSymbols && !PrintDynamicSymbols) return; // GNU readelf prints both the .dynsym and .symtab with --symbols. @@ -4059,8 +4021,7 @@ void GNUStyle::printSymbols(const ELFO *Obj, bool PrintSymbols, } template -void GNUStyle::printHashTableSymbols(const ELFO *Obj, - const Elf_Hash &SysVHash) { +void GNUStyle::printHashTableSymbols(const Elf_Hash &SysVHash) { StringRef StringTable = this->dumper()->getDynamicStringTable(); if (StringTable.empty()) return; @@ -4100,15 +4061,14 @@ void GNUStyle::printHashTableSymbols(const ELFO *Obj, break; } - printHashedSymbol(Obj, FirstSym, Ch, StringTable, Buc); + printHashedSymbol(FirstSym, Ch, StringTable, Buc); Visited[Ch] = true; } } } template -void GNUStyle::printGnuHashTableSymbols(const ELFO *Obj, - const Elf_GnuHash &GnuHash) { +void GNUStyle::printGnuHashTableSymbols(const Elf_GnuHash &GnuHash) { StringRef StringTable = this->dumper()->getDynamicStringTable(); if (StringTable.empty()) return; @@ -4132,7 +4092,7 @@ void GNUStyle::printGnuHashTableSymbols(const ELFO *Obj, uint32_t GnuHashable = Index - GnuHash.symndx; // Print whole chain while (true) { - printHashedSymbol(Obj, FirstSym, Index++, StringTable, Buc); + printHashedSymbol(FirstSym, Index++, StringTable, Buc); // Chain ends at symbol with stopper bit if ((GnuHash.values(DynSyms.size())[GnuHashable++] & 1) == 1) break; @@ -4140,13 +4100,13 @@ void GNUStyle::printGnuHashTableSymbols(const ELFO *Obj, } } -template void GNUStyle::printHashSymbols(const ELFO *Obj) { +template void GNUStyle::printHashSymbols() { if (const Elf_Hash *SysVHash = this->dumper()->getHashTable()) { OS << "\n Symbol table of .hash for image:\n"; - if (Error E = checkHashTable(Obj, SysVHash)) + if (Error E = checkHashTable(this->Obj, SysVHash)) this->reportUniqueWarning(std::move(E)); else - printHashTableSymbols(Obj, *SysVHash); + printHashTableSymbols(*SysVHash); } // Try printing the .gnu.hash table. @@ -4158,10 +4118,10 @@ template void GNUStyle::printHashSymbols(const ELFO *Obj) { OS << " Num Buc: Value Size Type Bind Vis Ndx Name"; OS << "\n"; - if (Error E = checkGNUHashTable(Obj, GnuHash)) + if (Error E = checkGNUHashTable(this->Obj, GnuHash)) this->reportUniqueWarning(std::move(E)); else - printGnuHashTableSymbols(Obj, *GnuHash); + printGnuHashTableSymbols(*GnuHash); } } @@ -4247,21 +4207,19 @@ static bool checkPTDynamic(const typename ELFT::Phdr &Phdr, template void GNUStyle::printProgramHeaders( - const ELFO *Obj, bool PrintProgramHeaders, - cl::boolOrDefault PrintSectionMapping) { + bool PrintProgramHeaders, cl::boolOrDefault PrintSectionMapping) { if (PrintProgramHeaders) - printProgramHeaders(Obj); + printProgramHeaders(); // Display the section mapping along with the program headers, unless // -section-mapping is explicitly set to false. if (PrintSectionMapping != cl::BOU_FALSE) - printSectionMapping(Obj); + printSectionMapping(); } -template -void GNUStyle::printProgramHeaders(const ELFO *Obj) { +template void GNUStyle::printProgramHeaders() { unsigned Bias = ELFT::Is64Bits ? 8 : 0; - const Elf_Ehdr *Header = Obj->getHeader(); + const Elf_Ehdr *Header = this->Obj.getHeader(); Field Fields[8] = {2, 17, 26, 37 + Bias, 48 + Bias, 56 + Bias, 64 + Bias, 68 + Bias}; OS << "\nElf file type is " @@ -4280,7 +4238,7 @@ void GNUStyle::printProgramHeaders(const ELFO *Obj) { unsigned Width = ELFT::Is64Bits ? 18 : 10; unsigned SizeWidth = ELFT::Is64Bits ? 8 : 7; - Expected> PhdrsOrErr = Obj->program_headers(); + Expected> PhdrsOrErr = this->Obj.program_headers(); if (!PhdrsOrErr) { this->reportUniqueWarning(createError("unable to dump program headers: " + toString(PhdrsOrErr.takeError()))); @@ -4307,15 +4265,15 @@ void GNUStyle::printProgramHeaders(const ELFO *Obj) { this->FileName); }; - if (Phdr.p_offset >= Obj->getBufSize()) { + if (Phdr.p_offset >= this->Obj.getBufSize()) { ReportBadInterp("it goes past the end of the file (0x" + - Twine::utohexstr(Obj->getBufSize()) + ")"); + Twine::utohexstr(this->Obj.getBufSize()) + ")"); continue; } const char *Data = - reinterpret_cast(Obj->base()) + Phdr.p_offset; - size_t MaxSize = Obj->getBufSize() - Phdr.p_offset; + reinterpret_cast(this->Obj.base()) + Phdr.p_offset; + size_t MaxSize = this->Obj.getBufSize() - Phdr.p_offset; size_t Len = strnlen(Data, MaxSize); if (Len == MaxSize) { ReportBadInterp("it is not null-terminated"); @@ -4329,13 +4287,12 @@ void GNUStyle::printProgramHeaders(const ELFO *Obj) { } } -template -void GNUStyle::printSectionMapping(const ELFO *Obj) { +template void GNUStyle::printSectionMapping() { OS << "\n Section to Segment mapping:\n Segment Sections...\n"; DenseSet BelongsToSegment; int Phnum = 0; - Expected> PhdrsOrErr = Obj->program_headers(); + Expected> PhdrsOrErr = this->Obj.program_headers(); if (!PhdrsOrErr) { this->reportUniqueWarning(createError( "can't read program headers to build section to segment mapping: " + @@ -4347,7 +4304,7 @@ void GNUStyle::printSectionMapping(const ELFO *Obj) { std::string Sections; OS << format(" %2.2d ", Phnum++); // Check if each section is in a segment and then print mapping. - for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(this->Obj.sections())) { if (Sec.sh_type == ELF::SHT_NULL) continue; @@ -4357,7 +4314,8 @@ void GNUStyle::printSectionMapping(const ELFO *Obj) { if (checkTLSSections(Phdr, Sec) && checkOffsets(Phdr, Sec) && checkVMA(Phdr, Sec) && checkPTDynamic(Phdr, Sec)) { Sections += - unwrapOrError(this->FileName, Obj->getSectionName(&Sec)).str() + + unwrapOrError(this->FileName, this->Obj.getSectionName(&Sec)) + .str() + " "; BelongsToSegment.insert(&Sec); } @@ -4368,10 +4326,11 @@ void GNUStyle::printSectionMapping(const ELFO *Obj) { // Display sections that do not belong to a segment. std::string Sections; - for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(this->Obj.sections())) { if (BelongsToSegment.find(&Sec) == BelongsToSegment.end()) Sections += - unwrapOrError(this->FileName, Obj->getSectionName(&Sec)).str() + ' '; + unwrapOrError(this->FileName, this->Obj.getSectionName(&Sec)).str() + + ' '; } if (!Sections.empty()) { OS << " None " << Sections << '\n'; @@ -4386,10 +4345,10 @@ template struct RelSymbol { }; template -RelSymbol getSymbolForReloc(const ELFFile *Obj, StringRef FileName, +RelSymbol getSymbolForReloc(const ELFFile &Obj, StringRef FileName, const ELFDumper *Dumper, const RelTy &Reloc) { - uint32_t SymIndex = Reloc.getSymbol(Obj->isMips64EL()); + uint32_t SymIndex = Reloc.getSymbol(Obj.isMips64EL()); auto WarnAndReturn = [&](const typename ELFT::Sym *Sym, const Twine &Reason) -> RelSymbol { reportWarning( @@ -4424,21 +4383,22 @@ RelSymbol getSymbolForReloc(const ELFFile *Obj, StringRef FileName, template template -void GNUStyle::printDynamicRelocation(const ELFO *Obj, const RelTy &R) { - RelSymbol S = getSymbolForReloc(Obj, this->FileName, this->dumper(), R); - printRelRelaReloc(Obj, S.Sym, S.Name, R); +void GNUStyle::printDynamicRelocation(const RelTy &R) { + RelSymbol S = + getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R); + printRelRelaReloc(S.Sym, S.Name, R); } template -static size_t getMaxDynamicTagSize(const ELFFile *Obj, +static size_t getMaxDynamicTagSize(const ELFFile &Obj, typename ELFT::DynRange Tags) { size_t Max = 0; for (const typename ELFT::Dyn &Dyn : Tags) - Max = std::max(Max, Obj->getDynamicTagAsString(Dyn.d_tag).size()); + Max = std::max(Max, Obj.getDynamicTagAsString(Dyn.d_tag).size()); return Max; } -template void GNUStyle::printDynamic(const ELFO *Obj) { +template void GNUStyle::printDynamic() { Elf_Dyn_Range Table = this->dumper()->dynamic_table(); if (Table.empty()) return; @@ -4448,12 +4408,12 @@ template void GNUStyle::printDynamic(const ELFO *Obj) { OS << "Dynamic section at offset " << format_hex(reinterpret_cast(DynamicTableRegion.Addr) - - Obj->base(), + this->Obj.base(), 1) << " contains " << Table.size() << " entries:\n"; // The type name is surrounded with round brackets, hence add 2. - size_t MaxTagSize = getMaxDynamicTagSize(Obj, Table) + 2; + size_t MaxTagSize = getMaxDynamicTagSize(this->Obj, Table) + 2; // The "Name/Value" column should be indented from the "Type" column by N // spaces, where N = MaxTagSize - length of "Type" (4) + trailing // space (1) = 3. @@ -4464,15 +4424,14 @@ template void GNUStyle::printDynamic(const ELFO *Obj) { for (auto Entry : Table) { uintX_t Tag = Entry.getTag(); std::string Type = - std::string("(") + Obj->getDynamicTagAsString(Tag).c_str() + ")"; + std::string("(") + this->Obj.getDynamicTagAsString(Tag).c_str() + ")"; 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"; } } -template -void GNUStyle::printDynamicRelocations(const ELFO *Obj) { +template void GNUStyle::printDynamicRelocations() { const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion(); const DynRegionInfo &DynRelaRegion = this->dumper()->getDynRelaRegion(); const DynRegionInfo &DynRelrRegion = this->dumper()->getDynRelrRegion(); @@ -4480,70 +4439,70 @@ void GNUStyle::printDynamicRelocations(const ELFO *Obj) { if (DynRelaRegion.Size > 0) { OS << "\n'RELA' relocation section at offset " << format_hex(reinterpret_cast(DynRelaRegion.Addr) - - Obj->base(), + this->Obj.base(), 1) << " contains " << DynRelaRegion.Size << " bytes:\n"; printRelocHeader(ELF::SHT_RELA); for (const Elf_Rela &Rela : this->dumper()->dyn_relas()) - printDynamicRelocation(Obj, Rela); + printDynamicRelocation(Rela); } if (DynRelRegion.Size > 0) { OS << "\n'REL' relocation section at offset " << format_hex(reinterpret_cast(DynRelRegion.Addr) - - Obj->base(), + this->Obj.base(), 1) << " contains " << DynRelRegion.Size << " bytes:\n"; printRelocHeader(ELF::SHT_REL); for (const Elf_Rel &Rel : this->dumper()->dyn_rels()) - printDynamicRelocation(Obj, Rel); + printDynamicRelocation(Rel); } if (DynRelrRegion.Size > 0) { OS << "\n'RELR' relocation section at offset " << format_hex(reinterpret_cast(DynRelrRegion.Addr) - - Obj->base(), + this->Obj.base(), 1) << " contains " << DynRelrRegion.Size << " bytes:\n"; printRelocHeader(ELF::SHT_REL); Elf_Relr_Range Relrs = this->dumper()->dyn_relrs(); - for (const Elf_Rel &R : Obj->decode_relrs(Relrs)) - printDynamicRelocation(Obj, R); + for (const Elf_Rel &R : this->Obj.decode_relrs(Relrs)) + printDynamicRelocation(R); } if (DynPLTRelRegion.Size) { OS << "\n'PLT' relocation section at offset " << format_hex(reinterpret_cast(DynPLTRelRegion.Addr) - - Obj->base(), + this->Obj.base(), 1) << " contains " << DynPLTRelRegion.Size << " bytes:\n"; if (DynPLTRelRegion.EntSize == sizeof(Elf_Rela)) { printRelocHeader(ELF::SHT_RELA); for (const Elf_Rela &Rela : DynPLTRelRegion.getAsArrayRef()) - printDynamicRelocation(Obj, Rela); + printDynamicRelocation(Rela); } else { printRelocHeader(ELF::SHT_REL); for (const Elf_Rel &Rel : DynPLTRelRegion.getAsArrayRef()) - printDynamicRelocation(Obj, Rel); + printDynamicRelocation(Rel); } } } template void GNUStyle::printGNUVersionSectionProlog( - const ELFFile *Obj, const typename ELFT::Shdr *Sec, - const Twine &Label, unsigned EntriesNum) { - StringRef SecName = unwrapOrError(this->FileName, Obj->getSectionName(Sec)); + const typename ELFT::Shdr *Sec, const Twine &Label, unsigned EntriesNum) { + StringRef SecName = + unwrapOrError(this->FileName, this->Obj.getSectionName(Sec)); OS << Label << " section '" << SecName << "' " << "contains " << EntriesNum << " entries:\n"; StringRef SymTabName = ""; Expected SymTabOrErr = - Obj->getSection(Sec->sh_link); + this->Obj.getSection(Sec->sh_link); if (SymTabOrErr) SymTabName = - unwrapOrError(this->FileName, Obj->getSectionName(*SymTabOrErr)); + unwrapOrError(this->FileName, this->Obj.getSectionName(*SymTabOrErr)); else this->reportUniqueWarning(createError("invalid section linked to " + - describe(Obj, *Sec) + ": " + + describe(this->Obj, *Sec) + ": " + toString(SymTabOrErr.takeError()))); OS << " Addr: " << format_hex_no_prefix(Sec->sh_addr, 16) @@ -4552,16 +4511,15 @@ void GNUStyle::printGNUVersionSectionProlog( } template -void GNUStyle::printVersionSymbolSection(const ELFFile *Obj, - const Elf_Shdr *Sec) { +void GNUStyle::printVersionSymbolSection(const Elf_Shdr *Sec) { if (!Sec) return; - printGNUVersionSectionProlog(Obj, Sec, "Version symbols", + printGNUVersionSectionProlog(Sec, "Version symbols", Sec->sh_size / sizeof(Elf_Versym)); Expected> VerTableOrErr = this->dumper()->getVersionTable(Sec, /*SymTab=*/nullptr, - /*StrTab=*/nullptr); + /*StrTab=*/nullptr); if (!VerTableOrErr) { this->reportUniqueWarning(VerTableOrErr.takeError()); return; @@ -4581,9 +4539,10 @@ void GNUStyle::printVersionSymbolSection(const ELFFile *Obj, this->dumper()->getSymbolVersionByIndex(Ndx, IsDefault); if (!NameOrErr) { if (!NameOrErr) - this->reportUniqueWarning(createError( - "unable to get a version for entry " + Twine(I) + " of " + - describe(Obj, *Sec) + ": " + toString(NameOrErr.takeError()))); + this->reportUniqueWarning( + createError("unable to get a version for entry " + Twine(I) + + " of " + describe(this->Obj, *Sec) + ": " + + toString(NameOrErr.takeError()))); Versions.emplace_back(""); continue; } @@ -4627,12 +4586,11 @@ static std::string versionFlagToString(unsigned Flags) { } template -void GNUStyle::printVersionDefinitionSection(const ELFFile *Obj, - const Elf_Shdr *Sec) { +void GNUStyle::printVersionDefinitionSection(const Elf_Shdr *Sec) { if (!Sec) return; - printGNUVersionSectionProlog(Obj, Sec, "Version definition", Sec->sh_info); + printGNUVersionSectionProlog(Sec, "Version definition", Sec->sh_info); Expected> V = this->dumper()->getVersionDefinitions(Sec); if (!V) { @@ -4655,13 +4613,12 @@ void GNUStyle::printVersionDefinitionSection(const ELFFile *Obj, } template -void GNUStyle::printVersionDependencySection(const ELFFile *Obj, - const Elf_Shdr *Sec) { +void GNUStyle::printVersionDependencySection(const Elf_Shdr *Sec) { if (!Sec) return; unsigned VerneedNum = Sec->sh_info; - printGNUVersionSectionProlog(Obj, Sec, "Version needs", VerneedNum); + printGNUVersionSectionProlog(Sec, "Version needs", VerneedNum); Expected> V = this->dumper()->getVersionDependencies(Sec); @@ -4796,11 +4753,10 @@ void GNUStyle::printGnuHashHistogram(const Elf_GnuHash &GnuHashTable) { // dynamic symbol table. The table shows the number of hash buckets for // different lengths of chains as an absolute number and percentage of the total // buckets, and the cumulative coverage of symbols for each set of buckets. -template -void GNUStyle::printHashHistograms(const ELFFile *Obj) { +template void GNUStyle::printHashHistograms() { // Print histogram for the .hash section. if (const Elf_Hash *HashTable = this->dumper()->getHashTable()) { - if (Error E = checkHashTable(Obj, HashTable)) + if (Error E = checkHashTable(this->Obj, HashTable)) this->reportUniqueWarning(std::move(E)); else printHashHistogram(*HashTable); @@ -4808,20 +4764,18 @@ void GNUStyle::printHashHistograms(const ELFFile *Obj) { // Print histogram for the .gnu.hash section. if (const Elf_GnuHash *GnuHashTable = this->dumper()->getGnuHashTable()) { - if (Error E = checkGNUHashTable(Obj, GnuHashTable)) + if (Error E = checkGNUHashTable(this->Obj, GnuHashTable)) this->reportUniqueWarning(std::move(E)); else printGnuHashHistogram(*GnuHashTable); } } -template -void GNUStyle::printCGProfile(const ELFFile *Obj) { +template void GNUStyle::printCGProfile() { OS << "GNUStyle::printCGProfile not implemented\n"; } -template -void GNUStyle::printAddrsig(const ELFFile *Obj) { +template void GNUStyle::printAddrsig() { reportError(createError("--addrsig: not implemented"), this->FileName); } @@ -5352,8 +5306,7 @@ static void printCoreNote(raw_ostream &OS, const CoreNote &Note) { } } -template -void GNUStyle::printNotes(const ELFFile *Obj) { +template void GNUStyle::printNotes() { auto PrintHeader = [&](Optional SecName, const typename ELFT::Off Offset, const typename ELFT::Addr Size) { @@ -5385,7 +5338,7 @@ void GNUStyle::printNotes(const ELFFile *Obj) { } else if (Name == "AMDGPU") { OS << getAMDGPUNoteTypeName(Type) << '\n'; } else { - StringRef NoteType = Obj->getHeader()->e_type == ELF::ET_CORE + StringRef NoteType = this->Obj.getHeader()->e_type == ELF::ET_CORE ? getCoreNoteTypeName(Type) : getGenericNoteTypeName(Type); if (!NoteType.empty()) @@ -5425,21 +5378,21 @@ void GNUStyle::printNotes(const ELFFile *Obj) { } }; - ArrayRef Sections = cantFail(Obj->sections()); - if (Obj->getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) { + ArrayRef Sections = cantFail(this->Obj.sections()); + if (this->Obj.getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) { for (const auto &S : Sections) { if (S.sh_type != SHT_NOTE) continue; - PrintHeader(expectedToOptional(Obj->getSectionName(&S)), S.sh_offset, + PrintHeader(expectedToOptional(this->Obj.getSectionName(&S)), S.sh_offset, S.sh_size); Error Err = Error::success(); - for (auto Note : Obj->notes(S, Err)) + for (auto Note : this->Obj.notes(S, Err)) ProcessNote(Note); if (Err) reportError(std::move(Err), this->FileName); } } else { - Expected> PhdrsOrErr = Obj->program_headers(); + Expected> PhdrsOrErr = this->Obj.program_headers(); if (!PhdrsOrErr) { this->reportUniqueWarning(createError( "unable to read program headers to locate the PT_NOTE segment: " + @@ -5452,7 +5405,7 @@ void GNUStyle::printNotes(const ELFFile *Obj) { continue; PrintHeader(/*SecName=*/None, P.p_offset, P.p_filesz); Error Err = Error::success(); - for (auto Note : Obj->notes(P, Err)) + for (auto Note : this->Obj.notes(P, Err)) ProcessNote(Note); if (Err) reportError(std::move(Err), this->FileName); @@ -5460,14 +5413,12 @@ void GNUStyle::printNotes(const ELFFile *Obj) { } } -template -void GNUStyle::printELFLinkerOptions(const ELFFile *Obj) { +template void GNUStyle::printELFLinkerOptions() { OS << "printELFLinkerOptions not implemented!\n"; } template void DumpStyle::printDependentLibsHelper( - const ELFFile *Obj, function_ref OnSectionStart, function_ref OnLibEntry) { auto Warn = [this](unsigned SecNdx, StringRef Msg) { @@ -5477,14 +5428,14 @@ void DumpStyle::printDependentLibsHelper( }; unsigned I = -1; - for (const Elf_Shdr &Shdr : cantFail(Obj->sections())) { + for (const Elf_Shdr &Shdr : cantFail(Obj.sections())) { ++I; if (Shdr.sh_type != ELF::SHT_LLVM_DEPENDENT_LIBRARIES) continue; OnSectionStart(Shdr); - Expected> ContentsOrErr = Obj->getSectionContents(&Shdr); + Expected> ContentsOrErr = Obj.getSectionContents(&Shdr); if (!ContentsOrErr) { Warn(I, toString(ContentsOrErr.takeError())); continue; @@ -5505,8 +5456,7 @@ void DumpStyle::printDependentLibsHelper( } template -void DumpStyle::printRelocationsHelper(const ELFFile *Obj, - const Elf_Shdr &Sec) { +void DumpStyle::printRelocationsHelper(const Elf_Shdr &Sec) { auto Warn = [&](Error &&E, const Twine &Prefix = "unable to read relocations from") { this->reportUniqueWarning(createError(Prefix + " " + describe(Obj, Sec) + @@ -5518,7 +5468,7 @@ void DumpStyle::printRelocationsHelper(const ELFFile *Obj, // a symbol table. const Elf_Shdr *SymTab; if (Sec.sh_type != ELF::SHT_RELR && Sec.sh_type != ELF::SHT_ANDROID_RELR) { - Expected SymTabOrErr = Obj->getSection(Sec.sh_link); + Expected SymTabOrErr = Obj.getSection(Sec.sh_link); if (!SymTabOrErr) { Warn(SymTabOrErr.takeError(), "unable to locate a symbol table for"); return; @@ -5526,28 +5476,28 @@ void DumpStyle::printRelocationsHelper(const ELFFile *Obj, SymTab = *SymTabOrErr; } - unsigned SecNdx = &Sec - &cantFail(Obj->sections()).front(); + unsigned SecNdx = &Sec - &cantFail(Obj.sections()).front(); unsigned RelNdx = 0; switch (Sec.sh_type) { case ELF::SHT_REL: - if (Expected RangeOrErr = Obj->rels(&Sec)) { + if (Expected RangeOrErr = Obj.rels(&Sec)) { for (const Elf_Rel &R : *RangeOrErr) - printRelReloc(Obj, SecNdx, SymTab, R, ++RelNdx); + printRelReloc(SecNdx, SymTab, R, ++RelNdx); } else { Warn(RangeOrErr.takeError()); } break; case ELF::SHT_RELA: - if (Expected RangeOrErr = Obj->relas(&Sec)) { + if (Expected RangeOrErr = Obj.relas(&Sec)) { for (const Elf_Rela &R : *RangeOrErr) - printRelaReloc(Obj, SecNdx, SymTab, R, ++RelNdx); + printRelaReloc(SecNdx, SymTab, R, ++RelNdx); } else { Warn(RangeOrErr.takeError()); } break; case ELF::SHT_RELR: case ELF::SHT_ANDROID_RELR: { - Expected RangeOrErr = Obj->relrs(&Sec); + Expected RangeOrErr = Obj.relrs(&Sec); if (!RangeOrErr) { Warn(RangeOrErr.takeError()); break; @@ -5558,15 +5508,15 @@ void DumpStyle::printRelocationsHelper(const ELFFile *Obj, break; } - for (const Elf_Rel &R : Obj->decode_relrs(*RangeOrErr)) - printRelReloc(Obj, SecNdx, /*SymTab=*/nullptr, R, ++RelNdx); + for (const Elf_Rel &R : Obj.decode_relrs(*RangeOrErr)) + printRelReloc(SecNdx, /*SymTab=*/nullptr, R, ++RelNdx); break; } case ELF::SHT_ANDROID_REL: case ELF::SHT_ANDROID_RELA: - if (Expected> RelasOrErr = Obj->android_relas(&Sec)) { + if (Expected> RelasOrErr = Obj.android_relas(&Sec)) { for (const Elf_Rela &R : *RelasOrErr) - printRelaReloc(Obj, SecNdx, SymTab, R, ++RelNdx); + printRelaReloc(SecNdx, SymTab, R, ++RelNdx); } else { Warn(RelasOrErr.takeError()); } @@ -5575,11 +5525,10 @@ void DumpStyle::printRelocationsHelper(const ELFFile *Obj, } template -StringRef DumpStyle::getPrintableSectionName(const ELFFile *Obj, - const Elf_Shdr &Sec) const { +StringRef DumpStyle::getPrintableSectionName(const Elf_Shdr &Sec) const { StringRef Name = ""; if (Expected 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 " + @@ -5588,8 +5537,7 @@ StringRef DumpStyle::getPrintableSectionName(const ELFFile *Obj, return Name; } -template -void GNUStyle::printDependentLibs(const ELFFile *Obj) { +template void GNUStyle::printDependentLibs() { bool SectionStarted = false; struct NameOffset { StringRef Name; @@ -5613,13 +5561,13 @@ void GNUStyle::printDependentLibs(const ELFFile *Obj) { PrintSection(); SectionStarted = true; Current.Offset = Shdr.sh_offset; - Current.Name = this->getPrintableSectionName(Obj, Shdr); + Current.Name = this->getPrintableSectionName(Shdr); }; auto OnLibEntry = [&](StringRef Lib, uint64_t Offset) { SecEntries.push_back(NameOffset{Lib, Offset}); }; - this->printDependentLibsHelper(Obj, OnSectionStart, OnLibEntry); + this->printDependentLibsHelper(OnSectionStart, OnLibEntry); if (SectionStarted) PrintSection(); } @@ -5788,7 +5736,7 @@ void DumpStyle::printNonRelocatableStackSizes( if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(Elf_Addr) + 1)) { reportUniqueWarning(createStringError( object_error::parse_failed, - describe(EF, *ElfSec) + + describe(*EF, *ElfSec) + " ended while trying to extract a stack size entry")); break; } @@ -5835,7 +5783,7 @@ void DumpStyle::printRelocatableStackSizes( if (!RelSecOrErr) { reportUniqueWarning( createStringError(object_error::parse_failed, - describe(Obj->getELFFile(), *ElfSec) + + describe(*Obj->getELFFile(), *ElfSec) + ": failed to get a relocated section: " + toString(RelSecOrErr.takeError()))); continue; @@ -5891,7 +5839,7 @@ void DumpStyle::printRelocatableStackSizes( Obj->getSection(RelocSec.getRawDataRefImpl()); reportUniqueWarning(createStringError( object_error::parse_failed, - describe(EF, *RelocSecShdr) + + describe(*EF, *RelocSecShdr) + " contains an unsupported relocation with index " + Twine(I) + ": " + EF->getRelocationTypeName(Reloc.getType()))); continue; @@ -5989,8 +5937,7 @@ void GNUStyle::printMipsGOT(const MipsGOTParser &Parser) { OS.PadToColumn(40 + 3 * Bias); OS << printEnum(Sym->getType(), makeArrayRef(ElfSymbolTypes)); OS.PadToColumn(48 + 3 * Bias); - OS << getSymbolSectionNdx(Parser.Obj, Sym, - this->dumper()->dynamic_symbols().begin()); + OS << getSymbolSectionNdx(Sym, this->dumper()->dynamic_symbols().begin()); OS.PadToColumn(52 + 3 * Bias); OS << SymName << "\n"; } @@ -6039,8 +5986,7 @@ void GNUStyle::printMipsPLT(const MipsGOTParser &Parser) { OS.PadToColumn(29 + 3 * Bias); OS << printEnum(Sym->getType(), makeArrayRef(ElfSymbolTypes)); OS.PadToColumn(37 + 3 * Bias); - OS << getSymbolSectionNdx(Parser.Obj, Sym, - this->dumper()->dynamic_symbols().begin()); + OS << getSymbolSectionNdx(Sym, this->dumper()->dynamic_symbols().begin()); OS.PadToColumn(41 + 3 * Bias); OS << SymName << "\n"; } @@ -6101,8 +6047,8 @@ void GNUStyle::printMipsABIFlags(const ELFObjectFile *ObjF) { OS << "\n"; } -template void LLVMStyle::printFileHeaders(const ELFO *Obj) { - const Elf_Ehdr *E = Obj->getHeader(); +template void LLVMStyle::printFileHeaders() { + const Elf_Ehdr *E = this->Obj.getHeader(); { DictScope D(W, "ElfHeader"); { @@ -6155,16 +6101,15 @@ template void LLVMStyle::printFileHeaders(const ELFO *Obj) { W.printNumber("ProgramHeaderCount", E->e_phnum); W.printNumber("SectionHeaderEntrySize", E->e_shentsize); W.printString("SectionHeaderCount", - getSectionHeadersNumString(Obj, this->FileName)); + getSectionHeadersNumString(this->Obj, this->FileName)); W.printString("StringTableSectionIndex", - getSectionHeaderTableIndexString(Obj, this->FileName)); + getSectionHeaderTableIndexString(this->Obj, this->FileName)); } } -template -void LLVMStyle::printGroupSections(const ELFO *Obj) { +template void LLVMStyle::printGroupSections() { DictScope Lists(W, "Groups"); - std::vector V = getGroups(Obj, this->FileName); + std::vector V = getGroups(this->Obj, this->FileName); DenseMap Map = mapSectionsToGroups(V); for (const GroupSection &G : V) { DictScope D(W, "Group"); @@ -6193,35 +6138,33 @@ void LLVMStyle::printGroupSections(const ELFO *Obj) { W.startLine() << "There are no group sections in the file.\n"; } -template void LLVMStyle::printRelocations(const ELFO *Obj) { +template void LLVMStyle::printRelocations() { ListScope D(W, "Relocations"); - for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(this->Obj.sections())) { if (!isRelocationSec(Sec)) continue; - StringRef Name = this->getPrintableSectionName(Obj, Sec); - unsigned SecNdx = &Sec - &cantFail(Obj->sections()).front(); + StringRef Name = this->getPrintableSectionName(Sec); + unsigned SecNdx = &Sec - &cantFail(this->Obj.sections()).front(); W.startLine() << "Section (" << SecNdx << ") " << Name << " {\n"; W.indent(); - this->printRelocationsHelper(Obj, Sec); + this->printRelocationsHelper(Sec); W.unindent(); W.startLine() << "}\n"; } } template -void LLVMStyle::printRelReloc(const ELFO *Obj, unsigned SecIndex, - const Elf_Shdr *SymTab, const Elf_Rel &R, - unsigned RelIndex) { - printRelRelaReloc(Obj, SecIndex, R, RelIndex, SymTab); +void LLVMStyle::printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, + const Elf_Rel &R, unsigned RelIndex) { + printRelRelaReloc(SecIndex, R, RelIndex, SymTab); } template -void LLVMStyle::printRelaReloc(const ELFO *Obj, unsigned SecIndex, - const Elf_Shdr *SymTab, const Elf_Rela &R, - unsigned RelIndex) { - printRelRelaReloc(Obj, SecIndex, R, RelIndex, SymTab); +void LLVMStyle::printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, + const Elf_Rela &R, unsigned RelIndex) { + printRelRelaReloc(SecIndex, R, RelIndex, SymTab); } template void LLVMStyle::printRelrReloc(const Elf_Relr &R) { @@ -6230,8 +6173,8 @@ template void LLVMStyle::printRelrReloc(const Elf_Relr &R) { template template -void LLVMStyle::printRelRelaReloc(const ELFO *Obj, unsigned SecIndex, - const RelTy &Rel, unsigned RelIndex, +void LLVMStyle::printRelRelaReloc(unsigned SecIndex, const RelTy &Rel, + unsigned RelIndex, const Elf_Shdr *SymTab) { Expected> Target = this->dumper()->getRelocationTarget(SymTab, Rel); @@ -6244,15 +6187,16 @@ void LLVMStyle::printRelRelaReloc(const ELFO *Obj, unsigned SecIndex, std::string TargetName = Target->second; SmallString<32> RelocName; - Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); + this->Obj.getRelocationTypeName(Rel.getType(this->Obj.isMips64EL()), + RelocName); uintX_t Addend = getAddend(Rel).getValueOr(0); if (opts::ExpandRelocs) { DictScope Group(W, "Relocation"); W.printHex("Offset", Rel.r_offset); - W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL())); + W.printNumber("Type", RelocName, (int)Rel.getType(this->Obj.isMips64EL())); W.printNumber("Symbol", !TargetName.empty() ? TargetName : "-", - Rel.getSymbol(Obj->isMips64EL())); + Rel.getSymbol(this->Obj.isMips64EL())); W.printHex("Addend", Addend); } else { raw_ostream &OS = W.startLine(); @@ -6262,21 +6206,20 @@ void LLVMStyle::printRelRelaReloc(const ELFO *Obj, unsigned SecIndex, } } -template -void LLVMStyle::printSectionHeaders(const ELFO *Obj) { +template void LLVMStyle::printSectionHeaders() { ListScope SectionsD(W, "Sections"); int SectionIndex = -1; std::vector> FlagsList = - getSectionFlagsForTarget(Obj->getHeader()->e_machine); - for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { + getSectionFlagsForTarget(this->Obj.getHeader()->e_machine); + for (const Elf_Shdr &Sec : cantFail(this->Obj.sections())) { DictScope SectionD(W, "Section"); W.printNumber("Index", ++SectionIndex); - W.printNumber("Name", this->getPrintableSectionName(Obj, Sec), Sec.sh_name); - W.printHex( - "Type", - object::getELFSectionTypeName(Obj->getHeader()->e_machine, Sec.sh_type), - Sec.sh_type); + W.printNumber("Name", this->getPrintableSectionName(Sec), Sec.sh_name); + W.printHex("Type", + object::getELFSectionTypeName(this->Obj.getHeader()->e_machine, + Sec.sh_type), + Sec.sh_type); W.printFlags("Flags", Sec.sh_flags, makeArrayRef(FlagsList)); W.printHex("Address", Sec.sh_addr); W.printHex("Offset", Sec.sh_offset); @@ -6288,32 +6231,33 @@ void LLVMStyle::printSectionHeaders(const ELFO *Obj) { if (opts::SectionRelocations) { ListScope D(W, "Relocations"); - this->printRelocationsHelper(Obj, Sec); + this->printRelocationsHelper(Sec); } if (opts::SectionSymbols) { ListScope D(W, "Symbols"); if (const Elf_Shdr *Symtab = this->dumper()->getDotSymtabSec()) { StringRef StrTable = unwrapOrError( - this->FileName, Obj->getStringTableForSymtab(*Symtab)); + this->FileName, this->Obj.getStringTableForSymtab(*Symtab)); for (const Elf_Sym &Sym : - unwrapOrError(this->FileName, Obj->symbols(Symtab))) { - const Elf_Shdr *SymSec = unwrapOrError( - this->FileName, - Obj->getSection(&Sym, Symtab, this->dumper()->getShndxTable())); + unwrapOrError(this->FileName, this->Obj.symbols(Symtab))) { + const Elf_Shdr *SymSec = + unwrapOrError(this->FileName, + this->Obj.getSection( + &Sym, Symtab, this->dumper()->getShndxTable())); if (SymSec == &Sec) - printSymbol( - Obj, &Sym, - unwrapOrError(this->FileName, Obj->symbols(Symtab)).begin(), - StrTable, false, false); + printSymbol(&Sym, + unwrapOrError(this->FileName, this->Obj.symbols(Symtab)) + .begin(), + StrTable, false, false); } } } if (opts::SectionData && Sec.sh_type != ELF::SHT_NOBITS) { ArrayRef Data = - unwrapOrError(this->FileName, Obj->getSectionContents(&Sec)); + unwrapOrError(this->FileName, this->Obj.getSectionContents(&Sec)); W.printBinaryBlock( "SectionData", StringRef(reinterpret_cast(Data.data()), Data.size())); @@ -6351,8 +6295,7 @@ void LLVMStyle::printSymbolSection(const Elf_Sym *Symbol, } template -void LLVMStyle::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, - const Elf_Sym *First, +void LLVMStyle::printSymbol(const Elf_Sym *Symbol, const Elf_Sym *First, Optional StrTable, bool IsDynamic, bool /*NonVisibilityBitsUsed*/) { std::string FullSymbolName = @@ -6364,7 +6307,7 @@ void LLVMStyle::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, W.printHex("Value", Symbol->st_value); W.printNumber("Size", Symbol->st_size); W.printEnum("Binding", Symbol->getBinding(), makeArrayRef(ElfSymbolBindings)); - if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU && + if (this->Obj.getHeader()->e_machine == ELF::EM_AMDGPU && SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS) W.printEnum("Type", SymbolType, makeArrayRef(AMDGPUSymbolTypes)); else @@ -6376,7 +6319,7 @@ void LLVMStyle::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, else { std::vector> SymOtherFlags(std::begin(ElfSymOtherFlags), std::end(ElfSymOtherFlags)); - if (Obj->getHeader()->e_machine == EM_MIPS) { + if (this->Obj.getHeader()->e_machine == EM_MIPS) { // Someones in their infinite wisdom decided to make STO_MIPS_MIPS16 // flag overlapped with other ST_MIPS_xxx flags. So consider both // cases separately. @@ -6395,33 +6338,32 @@ void LLVMStyle::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, } template -void LLVMStyle::printSymbols(const ELFO *Obj, bool PrintSymbols, +void LLVMStyle::printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) { if (PrintSymbols) - printSymbols(Obj); + printSymbols(); if (PrintDynamicSymbols) - printDynamicSymbols(Obj); + printDynamicSymbols(); } -template void LLVMStyle::printSymbols(const ELFO *Obj) { +template void LLVMStyle::printSymbols() { ListScope Group(W, "Symbols"); this->dumper()->printSymbolsHelper(false); } -template -void LLVMStyle::printDynamicSymbols(const ELFO *Obj) { +template void LLVMStyle::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); this->dumper()->printSymbolsHelper(true); } -template void LLVMStyle::printDynamic(const ELFFile *Obj) { +template void LLVMStyle::printDynamic() { Elf_Dyn_Range Table = this->dumper()->dynamic_table(); if (Table.empty()) return; W.startLine() << "DynamicSection [ (" << Table.size() << " entries)\n"; - size_t MaxTagSize = getMaxDynamicTagSize(Obj, Table); + size_t MaxTagSize = getMaxDynamicTagSize(this->Obj, Table); // The "Name/Value" column should be indented from the "Type" column by N // spaces, where N = MaxTagSize - length of "Type" (4) + trailing // space (1) = -3. @@ -6435,14 +6377,13 @@ template void LLVMStyle::printDynamic(const ELFFile *Ob W.startLine() << " " << format_hex(Tag, ELFT::Is64Bits ? 18 : 10, true) << " " << format(ValueFmt.c_str(), - Obj->getDynamicTagAsString(Tag).c_str()) + this->Obj.getDynamicTagAsString(Tag).c_str()) << Value << "\n"; } W.startLine() << "]\n"; } -template -void LLVMStyle::printDynamicRelocations(const ELFO *Obj) { +template void LLVMStyle::printDynamicRelocations() { const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion(); const DynRegionInfo &DynRelaRegion = this->dumper()->getDynRelaRegion(); const DynRegionInfo &DynRelrRegion = this->dumper()->getDynRelrRegion(); @@ -6452,42 +6393,43 @@ void LLVMStyle::printDynamicRelocations(const ELFO *Obj) { W.indent(); if (DynRelaRegion.Size > 0) { for (const Elf_Rela &Rela : this->dumper()->dyn_relas()) - printDynamicRelocation(Obj, Rela); + printDynamicRelocation(Rela); } if (DynRelRegion.Size > 0) { for (const Elf_Rel &Rel : this->dumper()->dyn_rels()) - printDynamicRelocation(Obj, Rel); + printDynamicRelocation(Rel); } if (DynRelrRegion.Size > 0) { Elf_Relr_Range Relrs = this->dumper()->dyn_relrs(); - for (const Elf_Rel &R : Obj->decode_relrs(Relrs)) - printDynamicRelocation(Obj, R); + for (const Elf_Rel &R : this->Obj.decode_relrs(Relrs)) + printDynamicRelocation(R); } if (DynPLTRelRegion.EntSize == sizeof(Elf_Rela)) for (const Elf_Rela &Rela : DynPLTRelRegion.getAsArrayRef()) - printDynamicRelocation(Obj, Rela); + printDynamicRelocation(Rela); else for (const Elf_Rel &Rel : DynPLTRelRegion.getAsArrayRef()) - printDynamicRelocation(Obj, Rel); + printDynamicRelocation(Rel); W.unindent(); W.startLine() << "}\n"; } template - template -void LLVMStyle::printDynamicRelocation(const ELFO *Obj, const RelTy& Rel) { +template +void LLVMStyle::printDynamicRelocation(const RelTy &Rel) { SmallString<32> RelocName; - Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); + this->Obj.getRelocationTypeName(Rel.getType(this->Obj.isMips64EL()), + RelocName); std::string SymbolName = - getSymbolForReloc(Obj, this->FileName, this->dumper(), Rel).Name; + getSymbolForReloc(this->Obj, this->FileName, this->dumper(), Rel).Name; uintX_t Addend = getAddend(Rel).getValueOr(0); if (opts::ExpandRelocs) { DictScope Group(W, "Relocation"); W.printHex("Offset", Rel.r_offset); - W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL())); + W.printNumber("Type", RelocName, (int)Rel.getType(this->Obj.isMips64EL())); W.printString("Symbol", !SymbolName.empty() ? SymbolName : "-"); W.printHex("Addend", Addend); } else { @@ -6500,19 +6442,17 @@ void LLVMStyle::printDynamicRelocation(const ELFO *Obj, const RelTy& Rel) template void LLVMStyle::printProgramHeaders( - const ELFO *Obj, bool PrintProgramHeaders, - cl::boolOrDefault PrintSectionMapping) { + bool PrintProgramHeaders, cl::boolOrDefault PrintSectionMapping) { if (PrintProgramHeaders) - printProgramHeaders(Obj); + printProgramHeaders(); if (PrintSectionMapping == cl::BOU_TRUE) - printSectionMapping(Obj); + printSectionMapping(); } -template -void LLVMStyle::printProgramHeaders(const ELFO *Obj) { +template void LLVMStyle::printProgramHeaders() { ListScope L(W, "ProgramHeaders"); - Expected> PhdrsOrErr = Obj->program_headers(); + Expected> PhdrsOrErr = this->Obj.program_headers(); if (!PhdrsOrErr) { this->reportUniqueWarning(createError("unable to dump program headers: " + toString(PhdrsOrErr.takeError()))); @@ -6522,7 +6462,7 @@ void LLVMStyle::printProgramHeaders(const ELFO *Obj) { for (const Elf_Phdr &Phdr : *PhdrsOrErr) { DictScope P(W, "ProgramHeader"); StringRef Type = - segmentTypeToString(Obj->getHeader()->e_machine, Phdr.p_type); + segmentTypeToString(this->Obj.getHeader()->e_machine, Phdr.p_type); W.printHex("Type", Type.empty() ? "Unknown" : Type, Phdr.p_type); W.printHex("Offset", Phdr.p_offset); @@ -6536,8 +6476,7 @@ void LLVMStyle::printProgramHeaders(const ELFO *Obj) { } template -void LLVMStyle::printVersionSymbolSection(const ELFFile *Obj, - const Elf_Shdr *Sec) { +void LLVMStyle::printVersionSymbolSection(const Elf_Shdr *Sec) { ListScope SS(W, "VersionSymbols"); if (!Sec) return; @@ -6557,8 +6496,8 @@ void LLVMStyle::printVersionSymbolSection(const ELFFile *Obj, 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], StrTable, /*IsDynamic=*/true)); + W.printString("Name", this->dumper()->getFullSymbolName(&Syms[I], StrTable, + /*IsDynamic=*/true)); } } @@ -6568,8 +6507,7 @@ static const EnumEntry SymVersionFlags[] = { {"Info", "INFO", VER_FLG_INFO}}; template -void LLVMStyle::printVersionDefinitionSection(const ELFFile *Obj, - const Elf_Shdr *Sec) { +void LLVMStyle::printVersionDefinitionSection(const Elf_Shdr *Sec) { ListScope SD(W, "VersionDefinitions"); if (!Sec) return; @@ -6594,8 +6532,7 @@ void LLVMStyle::printVersionDefinitionSection(const ELFFile *Obj, } template -void LLVMStyle::printVersionDependencySection(const ELFFile *Obj, - const Elf_Shdr *Sec) { +void LLVMStyle::printVersionDependencySection(const Elf_Shdr *Sec) { ListScope SD(W, "VersionRequirements"); if (!Sec) return; @@ -6624,19 +6561,17 @@ void LLVMStyle::printVersionDependencySection(const ELFFile *Obj, } } -template -void LLVMStyle::printHashHistograms(const ELFFile *Obj) { +template void LLVMStyle::printHashHistograms() { W.startLine() << "Hash Histogram not implemented!\n"; } -template -void LLVMStyle::printCGProfile(const ELFFile *Obj) { +template void LLVMStyle::printCGProfile() { ListScope L(W, "CGProfile"); if (!this->dumper()->getDotCGProfileSec()) return; Expected> CGProfileOrErr = - Obj->template getSectionContentsAsArray( + this->Obj.template getSectionContentsAsArray( this->dumper()->getDotCGProfileSec()); if (!CGProfileOrErr) { this->reportUniqueWarning( @@ -6670,14 +6605,13 @@ static Expected> toULEB128Array(ArrayRef Data) { return Ret; } -template -void LLVMStyle::printAddrsig(const ELFFile *Obj) { +template void LLVMStyle::printAddrsig() { ListScope L(W, "Addrsig"); if (!this->dumper()->getDotAddrsigSec()) return; ArrayRef Contents = unwrapOrError( this->FileName, - Obj->getSectionContents(this->dumper()->getDotAddrsigSec())); + this->Obj.getSectionContents(this->dumper()->getDotAddrsigSec())); Expected> V = toULEB128Array(Contents); if (!V) { reportWarning(V.takeError(), this->FileName); @@ -6737,8 +6671,7 @@ static void printCoreNoteLLVMStyle(const CoreNote &Note, ScopedPrinter &W) { } } -template -void LLVMStyle::printNotes(const ELFFile *Obj) { +template void LLVMStyle::printNotes() { ListScope L(W, "Notes"); auto PrintHeader = [&](Optional SecName, @@ -6767,7 +6700,7 @@ void LLVMStyle::printNotes(const ELFFile *Obj) { } else if (Name == "AMDGPU") { W.printString("Type", getAMDGPUNoteTypeName(Type)); } else { - StringRef NoteType = Obj->getHeader()->e_type == ELF::ET_CORE + StringRef NoteType = this->Obj.getHeader()->e_type == ELF::ET_CORE ? getCoreNoteTypeName(Type) : getGenericNoteTypeName(Type); if (!NoteType.empty()) @@ -6805,22 +6738,22 @@ void LLVMStyle::printNotes(const ELFFile *Obj) { } }; - ArrayRef Sections = cantFail(Obj->sections()); - if (Obj->getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) { + ArrayRef Sections = cantFail(this->Obj.sections()); + if (this->Obj.getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) { for (const auto &S : Sections) { if (S.sh_type != SHT_NOTE) continue; DictScope D(W, "NoteSection"); - PrintHeader(expectedToOptional(Obj->getSectionName(&S)), S.sh_offset, + PrintHeader(expectedToOptional(this->Obj.getSectionName(&S)), S.sh_offset, S.sh_size); Error Err = Error::success(); - for (auto Note : Obj->notes(S, Err)) + for (auto Note : this->Obj.notes(S, Err)) ProcessNote(Note); if (Err) reportError(std::move(Err), this->FileName); } } else { - Expected> PhdrsOrErr = Obj->program_headers(); + Expected> PhdrsOrErr = this->Obj.program_headers(); if (!PhdrsOrErr) { this->reportUniqueWarning(createError( "unable to read program headers to locate the PT_NOTE segment: " + @@ -6834,7 +6767,7 @@ void LLVMStyle::printNotes(const ELFFile *Obj) { DictScope D(W, "NoteSection"); PrintHeader(/*SecName=*/None, P.p_offset, P.p_filesz); Error Err = Error::success(); - for (auto Note : Obj->notes(P, Err)) + for (auto Note : this->Obj.notes(P, Err)) ProcessNote(Note); if (Err) reportError(std::move(Err), this->FileName); @@ -6842,17 +6775,17 @@ void LLVMStyle::printNotes(const ELFFile *Obj) { } } -template -void LLVMStyle::printELFLinkerOptions(const ELFFile *Obj) { +template void LLVMStyle::printELFLinkerOptions() { ListScope L(W, "LinkerOptions"); unsigned I = -1; - for (const Elf_Shdr &Shdr : cantFail(Obj->sections())) { + for (const Elf_Shdr &Shdr : cantFail(this->Obj.sections())) { ++I; if (Shdr.sh_type != ELF::SHT_LLVM_LINKER_OPTIONS) continue; - Expected> ContentsOrErr = Obj->getSectionContents(&Shdr); + Expected> ContentsOrErr = + this->Obj.getSectionContents(&Shdr); if (!ContentsOrErr) { this->reportUniqueWarning( createError("unable to read the content of the " @@ -6887,11 +6820,10 @@ void LLVMStyle::printELFLinkerOptions(const ELFFile *Obj) { } } -template -void LLVMStyle::printDependentLibs(const ELFFile *Obj) { +template void LLVMStyle::printDependentLibs() { ListScope L(W, "DependentLibs"); this->printDependentLibsHelper( - Obj, [](const Elf_Shdr &) {}, + [](const Elf_Shdr &) {}, [this](StringRef Lib, uint64_t) { W.printString(Lib); }); }