Index: llvm/include/llvm/Object/ELFObjectFile.h =================================================================== --- llvm/include/llvm/Object/ELFObjectFile.h +++ llvm/include/llvm/Object/ELFObjectFile.h @@ -441,7 +441,7 @@ unsigned getPlatformFlags() const override { return EF.getHeader().e_flags; } - const ELFFile *getELFFile() const { return &EF; } + const ELFFile &getELFFile() const { return EF; } bool isDyldType() const { return isDyldELFObject; } static bool classof(const Binary *v) { Index: llvm/lib/DebugInfo/Symbolize/Symbolize.cpp =================================================================== --- llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -287,10 +287,8 @@ } template -Optional> getBuildID(const ELFFile *Obj) { - if (!Obj) - return {}; - auto PhdrsOrErr = Obj->program_headers(); +Optional> getBuildID(const ELFFile &Obj) { + auto PhdrsOrErr = Obj.program_headers(); if (!PhdrsOrErr) { consumeError(PhdrsOrErr.takeError()); return {}; @@ -299,7 +297,7 @@ if (P.p_type != ELF::PT_NOTE) continue; Error Err = Error::success(); - for (auto N : Obj->notes(P, Err)) + for (auto N : Obj.notes(P, Err)) if (N.getType() == ELF::NT_GNU_BUILD_ID && N.getName() == ELF::ELF_NOTE_GNU) return N.getDesc(); consumeError(std::move(Err)); Index: llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp =================================================================== --- llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp @@ -626,7 +626,7 @@ auto &ELFObjFile = cast>(**ELFObj); std::string fileName(ELFObj->get()->getFileName()); return ELFLinkGraphBuilder_x86_64(std::move(fileName), - *ELFObjFile.getELFFile()) + ELFObjFile.getELFFile()) .buildGraph(); } Index: llvm/lib/InterfaceStub/ELFObjHandler.cpp =================================================================== --- llvm/lib/InterfaceStub/ELFObjHandler.cpp +++ llvm/lib/InterfaceStub/ELFObjHandler.cpp @@ -585,15 +585,15 @@ using Elf_Sym_Range = typename ELFT::SymRange; using Elf_Sym = typename ELFT::Sym; std::unique_ptr DestStub = std::make_unique(); - const ELFFile *ElfFile = ElfObj.getELFFile(); + const ELFFile &ElfFile = ElfObj.getELFFile(); // Fetch .dynamic table. - Expected DynTable = ElfFile->dynamicEntries(); + Expected DynTable = ElfFile.dynamicEntries(); if (!DynTable) { return DynTable.takeError(); } // Fetch program headers. - Expected PHdrs = ElfFile->program_headers(); + Expected PHdrs = ElfFile.program_headers(); if (!PHdrs) { return PHdrs.takeError(); } @@ -604,8 +604,7 @@ return std::move(Err); // Get pointer to in-memory location of .dynstr section. - Expected DynStrPtr = - ElfFile->toMappedAddr(DynEnt.StrTabAddr); + Expected DynStrPtr = ElfFile.toMappedAddr(DynEnt.StrTabAddr); if (!DynStrPtr) return appendToError(DynStrPtr.takeError(), "when locating .dynstr section contents"); @@ -614,7 +613,7 @@ DynEnt.StrSize); // Populate Arch from ELF header. - DestStub->Arch = ElfFile->getHeader().e_machine; + DestStub->Arch = ElfFile.getHeader().e_machine; // Populate SoName from .dynamic entries and dynamic string table. if (DynEnt.SONameOffset.hasValue()) { @@ -637,13 +636,13 @@ } // Populate Symbols from .dynsym table and dynamic string table. - Expected SymCount = getNumSyms(DynEnt, *ElfFile); + Expected SymCount = getNumSyms(DynEnt, ElfFile); if (!SymCount) return SymCount.takeError(); if (*SymCount > 0) { // Get pointer to in-memory location of .dynsym section. Expected DynSymPtr = - ElfFile->toMappedAddr(DynEnt.DynSymAddr); + ElfFile.toMappedAddr(DynEnt.DynSymAddr); if (!DynSymPtr) return appendToError(DynSymPtr.takeError(), "when locating .dynsym section contents"); Index: llvm/lib/XRay/InstrumentationMap.cpp =================================================================== --- llvm/lib/XRay/InstrumentationMap.cpp +++ llvm/lib/XRay/InstrumentationMap.cpp @@ -95,16 +95,16 @@ if (ObjFile.getBinary()->isELF()) { uint32_t RelativeRelocation = [](object::ObjectFile *ObjFile) { if (const auto *ELFObj = dyn_cast(ObjFile)) - return ELFObj->getELFFile()->getRelativeRelocationType(); + return ELFObj->getELFFile().getRelativeRelocationType(); else if (const auto *ELFObj = dyn_cast(ObjFile)) - return ELFObj->getELFFile()->getRelativeRelocationType(); + return ELFObj->getELFFile().getRelativeRelocationType(); else if (const auto *ELFObj = dyn_cast(ObjFile)) - return ELFObj->getELFFile()->getRelativeRelocationType(); + return ELFObj->getELFFile().getRelativeRelocationType(); else if (const auto *ELFObj = dyn_cast(ObjFile)) - return ELFObj->getELFFile()->getRelativeRelocationType(); + return ELFObj->getELFFile().getRelativeRelocationType(); else return static_cast(0); }(ObjFile.getBinary()); Index: llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp =================================================================== --- llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp +++ llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp @@ -207,8 +207,8 @@ /// \returns A valid image base address if we are able to extract one. template static llvm::Optional -getImageBaseAddress(const object::ELFFile *ELFFile) { - auto PhdrRangeOrErr = ELFFile->program_headers(); +getImageBaseAddress(const object::ELFFile &ELFFile) { + auto PhdrRangeOrErr = ELFFile.program_headers(); if (!PhdrRangeOrErr) { consumeError(PhdrRangeOrErr.takeError()); return llvm::None; Index: llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp =================================================================== --- llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp +++ llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp @@ -192,13 +192,13 @@ static Expected> findBuildID(const CopyConfig &Config, const object::ELFObjectFileBase &In) { if (auto *O = dyn_cast>(&In)) - return findBuildID(Config, *O->getELFFile()); + return findBuildID(Config, O->getELFFile()); else if (auto *O = dyn_cast>(&In)) - return findBuildID(Config, *O->getELFFile()); + return findBuildID(Config, O->getELFFile()); else if (auto *O = dyn_cast>(&In)) - return findBuildID(Config, *O->getELFFile()); + return findBuildID(Config, O->getELFFile()); else if (auto *O = dyn_cast>(&In)) - return findBuildID(Config, *O->getELFFile()); + return findBuildID(Config, O->getELFFile()); llvm_unreachable("Bad file format"); } Index: llvm/tools/llvm-objcopy/ELF/Object.h =================================================================== --- llvm/tools/llvm-objcopy/ELF/Object.h +++ llvm/tools/llvm-objcopy/ELF/Object.h @@ -957,7 +957,7 @@ public: ELFBuilder(const ELFObjectFile &ElfObj, Object &Obj, Optional ExtractPartition) - : ElfFile(*ElfObj.getELFFile()), Obj(Obj), + : ElfFile(ElfObj.getELFFile()), Obj(Obj), ExtractPartition(ExtractPartition) {} Error build(bool EnsureSymtab); Index: llvm/tools/llvm-objdump/ELFDump.cpp =================================================================== --- llvm/tools/llvm-objdump/ELFDump.cpp +++ llvm/tools/llvm-objdump/ELFDump.cpp @@ -25,14 +25,14 @@ using namespace llvm::objdump; template -static Expected getDynamicStrTab(const ELFFile *Elf) { - auto DynamicEntriesOrError = Elf->dynamicEntries(); +static Expected getDynamicStrTab(const ELFFile &Elf) { + auto DynamicEntriesOrError = Elf.dynamicEntries(); if (!DynamicEntriesOrError) return DynamicEntriesOrError.takeError(); for (const typename ELFT::Dyn &Dyn : *DynamicEntriesOrError) { if (Dyn.d_tag == ELF::DT_STRTAB) { - auto MappedAddrOrError = Elf->toMappedAddr(Dyn.getPtr()); + auto MappedAddrOrError = Elf.toMappedAddr(Dyn.getPtr()); if (!MappedAddrOrError) consumeError(MappedAddrOrError.takeError()); return StringRef(reinterpret_cast(*MappedAddrOrError)); @@ -40,13 +40,13 @@ } // If the dynamic segment is not present, we fall back on the sections. - auto SectionsOrError = Elf->sections(); + auto SectionsOrError = Elf.sections(); if (!SectionsOrError) return SectionsOrError.takeError(); for (const typename ELFT::Shdr &Sec : *SectionsOrError) { if (Sec.sh_type == ELF::SHT_DYNSYM) - return Elf->getStringTableForSymtab(Sec); + return Elf.getStringTableForSymtab(Sec); } return createError("dynamic string table not found"); @@ -56,7 +56,7 @@ static Error getRelocationValueString(const ELFObjectFile *Obj, const RelocationRef &RelRef, SmallVectorImpl &Result) { - const ELFFile &EF = *Obj->getELFFile(); + const ELFFile &EF = Obj->getELFFile(); DataRefImpl Rel = RelRef.getRawDataRefImpl(); auto SecOrErr = EF.getSection(Rel.d.a); if (!SecOrErr) @@ -133,9 +133,9 @@ } template -static uint64_t getSectionLMA(const ELFFile *Obj, +static uint64_t getSectionLMA(const ELFFile &Obj, const object::ELFSectionRef &Sec) { - auto PhdrRangeOrErr = Obj->program_headers(); + auto PhdrRangeOrErr = Obj.program_headers(); if (!PhdrRangeOrErr) report_fatal_error(toString(PhdrRangeOrErr.takeError())); @@ -162,14 +162,14 @@ } template -static void printDynamicSection(const ELFFile *Elf, StringRef Filename) { +static void printDynamicSection(const ELFFile &Elf, StringRef Filename) { ArrayRef DynamicEntries = - unwrapOrError(Elf->dynamicEntries(), Filename); + unwrapOrError(Elf.dynamicEntries(), Filename); // Find the maximum tag name length to format the value column properly. size_t MaxLen = 0; for (const typename ELFT::Dyn &Dyn : DynamicEntries) - MaxLen = std::max(MaxLen, Elf->getDynamicTagAsString(Dyn.d_tag).size()); + MaxLen = std::max(MaxLen, Elf.getDynamicTagAsString(Dyn.d_tag).size()); std::string TagFmt = " %-" + std::to_string(MaxLen) + "s "; outs() << "Dynamic Section:\n"; @@ -177,7 +177,7 @@ if (Dyn.d_tag == ELF::DT_NULL) continue; - std::string Str = Elf->getDynamicTagAsString(Dyn.d_tag); + std::string Str = Elf.getDynamicTagAsString(Dyn.d_tag); outs() << format(TagFmt.c_str(), Str.c_str()); const char *Fmt = @@ -199,9 +199,9 @@ } template -static void printProgramHeaders(const ELFFile *Obj, StringRef FileName) { +static void printProgramHeaders(const ELFFile &Obj, StringRef FileName) { outs() << "Program Header:\n"; - auto ProgramHeaderOrError = Obj->program_headers(); + auto ProgramHeaderOrError = Obj.program_headers(); if (!ProgramHeaderOrError) { reportWarning("unable to read program headers: " + toString(ProgramHeaderOrError.takeError()), @@ -328,20 +328,20 @@ } template -static void printSymbolVersionInfo(const ELFFile *Elf, +static void printSymbolVersionInfo(const ELFFile &Elf, StringRef FileName) { ArrayRef Sections = - unwrapOrError(Elf->sections(), FileName); + unwrapOrError(Elf.sections(), FileName); for (const typename ELFT::Shdr &Shdr : Sections) { if (Shdr.sh_type != ELF::SHT_GNU_verneed && Shdr.sh_type != ELF::SHT_GNU_verdef) continue; ArrayRef Contents = - unwrapOrError(Elf->getSectionContents(Shdr), FileName); + unwrapOrError(Elf.getSectionContents(Shdr), FileName); const typename ELFT::Shdr *StrTabSec = - unwrapOrError(Elf->getSection(Shdr.sh_link), FileName); - StringRef StrTab = unwrapOrError(Elf->getStringTable(*StrTabSec), FileName); + unwrapOrError(Elf.getSection(Shdr.sh_link), FileName); + StringRef StrTab = unwrapOrError(Elf.getStringTable(*StrTabSec), FileName); if (Shdr.sh_type == ELF::SHT_GNU_verneed) printSymbolVersionDependency(Contents, StrTab); Index: llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h =================================================================== --- llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h +++ llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h @@ -49,7 +49,7 @@ static const typename ELFT::Shdr * findSectionByAddress(const object::ELFObjectFile &ObjF, uint64_t Addr) { Expected SectionsOrErr = - ObjF.getELFFile()->sections(); + ObjF.getELFFile().sections(); if (!SectionsOrErr) reportError(SectionsOrErr.takeError(), ObjF.getFileName()); @@ -61,7 +61,7 @@ template void PrinterContext::printUnwindInformation() const { - const object::ELFFile &Obj = *ObjF.getELFFile(); + const object::ELFFile &Obj = ObjF.getELFFile(); Expected PhdrsOrErr = Obj.program_headers(); if (!PhdrsOrErr) @@ -100,7 +100,7 @@ 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 &Obj = *ObjF.getELFFile(); + const object::ELFFile &Obj = ObjF.getELFFile(); if (const Elf_Shdr *EHFrameHdr = findSectionByAddress(ObjF, EHFramePHdr->p_vaddr)) { Expected NameOrErr = Obj.getSectionName(*EHFrameHdr); @@ -180,7 +180,7 @@ W.indent(); Expected> DataOrErr = - ObjF.getELFFile()->getSectionContents(*EHFrameShdr); + ObjF.getELFFile().getSectionContents(*EHFrameShdr); if (!DataOrErr) reportError(DataOrErr.takeError(), ObjF.getFileName()); Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -751,7 +751,7 @@ TYPEDEF_ELF_TYPES(ELFT) DumpStyle(const ELFDumper &Dumper) - : Obj(*Dumper.getElfObject().getELFFile()), ElfObj(Dumper.getElfObject()), + : Obj(Dumper.getElfObject().getELFFile()), ElfObj(Dumper.getElfObject()), Dumper(Dumper) { FileName = ElfObj.getFileName(); } @@ -2012,7 +2012,7 @@ template ELFDumper::ELFDumper(const object::ELFObjectFile &O, ScopedPrinter &Writer) - : ObjDumper(Writer, O.getFileName()), ObjF(O), Obj(*O.getELFFile()), + : ObjDumper(Writer, O.getFileName()), ObjF(O), Obj(O.getELFFile()), DynRelRegion(O, *this), DynRelaRegion(O, *this), DynRelrRegion(O, *this), DynPLTRelRegion(O, *this), DynamicTable(O, *this) { if (opts::Output == opts::GNU) @@ -2695,7 +2695,7 @@ static Error checkHashTable(const ELFDumper &Dumper, const typename ELFT::Hash *H, bool *IsHeaderValid = nullptr) { - const ELFFile &Obj = *Dumper.getElfObject().getELFFile(); + const ELFFile &Obj = Dumper.getElfObject().getELFFile(); const uint64_t SecOffset = (const uint8_t *)H - Obj.base(); if (Dumper.getHashTableEntSize() == 8) { auto It = llvm::find_if(ElfMachineType, [&](const EnumEntry &E) { @@ -2986,7 +2986,7 @@ template MipsGOTParser::MipsGOTParser(const ELFDumper &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()) {} @@ -5528,7 +5528,7 @@ StartNotesFn, llvm::function_ref ProcessNoteFn, llvm::function_ref FinishNotesFn) { - const ELFFile &Obj = *Dumper.getElfObject().getELFFile(); + const ELFFile &Obj = Dumper.getElfObject().getELFFile(); ArrayRef Sections = cantFail(Obj.sections()); if (Obj.getHeader().e_type != ELF::ET_CORE && !Sections.empty()) { @@ -6210,7 +6210,7 @@ constexpr StringRef ErrPrefix = "unable to read the .MIPS.abiflags section: "; Expected> DataOrErr = - Dumper.getElfObject().getELFFile()->getSectionContents(*Sec); + Dumper.getElfObject().getELFFile().getSectionContents(*Sec); if (!DataOrErr) return createError(ErrPrefix + toString(DataOrErr.takeError())); Index: llvm/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/elf2yaml.cpp +++ llvm/tools/obj2yaml/elf2yaml.cpp @@ -1566,16 +1566,16 @@ Error elf2yaml(raw_ostream &Out, const object::ObjectFile &Obj) { std::unique_ptr DWARFCtx = DWARFContext::create(Obj); if (const auto *ELFObj = dyn_cast(&Obj)) - return elf2yaml(Out, *ELFObj->getELFFile(), std::move(DWARFCtx)); + return elf2yaml(Out, ELFObj->getELFFile(), std::move(DWARFCtx)); if (const auto *ELFObj = dyn_cast(&Obj)) - return elf2yaml(Out, *ELFObj->getELFFile(), std::move(DWARFCtx)); + return elf2yaml(Out, ELFObj->getELFFile(), std::move(DWARFCtx)); if (const auto *ELFObj = dyn_cast(&Obj)) - return elf2yaml(Out, *ELFObj->getELFFile(), std::move(DWARFCtx)); + return elf2yaml(Out, ELFObj->getELFFile(), std::move(DWARFCtx)); if (const auto *ELFObj = dyn_cast(&Obj)) - return elf2yaml(Out, *ELFObj->getELFFile(), std::move(DWARFCtx)); + return elf2yaml(Out, ELFObj->getELFFile(), std::move(DWARFCtx)); llvm_unreachable("unknown ELF file format"); }