diff --git a/lld/ELF/Arch/AMDGPU.cpp b/lld/ELF/Arch/AMDGPU.cpp --- a/lld/ELF/Arch/AMDGPU.cpp +++ b/lld/ELF/Arch/AMDGPU.cpp @@ -41,7 +41,7 @@ } static uint32_t getEFlags(InputFile *file) { - return cast>(file)->getObj().getHeader()->e_flags; + return cast>(file)->getObj().getHeader().e_flags; } uint32_t AMDGPU::calcEFlags() const { diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp --- a/lld/ELF/Arch/Hexagon.cpp +++ b/lld/ELF/Arch/Hexagon.cpp @@ -66,7 +66,7 @@ // greatest revision in the list of inputs. uint32_t ret = 0; for (InputFile *f : objectFiles) { - uint32_t eflags = cast>(f)->getObj().getHeader()->e_flags; + uint32_t eflags = cast>(f)->getObj().getHeader().e_flags; if (eflags > ret) ret = eflags; } diff --git a/lld/ELF/Arch/Mips.cpp b/lld/ELF/Arch/Mips.cpp --- a/lld/ELF/Arch/Mips.cpp +++ b/lld/ELF/Arch/Mips.cpp @@ -372,7 +372,7 @@ if (!f) return false; // If current file has PIC code, LA25 stub is not required. - if (f->getObj().getHeader()->e_flags & EF_MIPS_PIC) + if (f->getObj().getHeader().e_flags & EF_MIPS_PIC) return false; auto *d = dyn_cast(&s); // LA25 is required if target file has PIC code @@ -749,7 +749,7 @@ if (!file) return false; - return file->getObj().getHeader()->e_flags & EF_MIPS_PIC; + return file->getObj().getHeader().e_flags & EF_MIPS_PIC; } template TargetInfo *elf::getMipsTargetInfo() { diff --git a/lld/ELF/Arch/MipsArchTree.cpp b/lld/ELF/Arch/MipsArchTree.cpp --- a/lld/ELF/Arch/MipsArchTree.cpp +++ b/lld/ELF/Arch/MipsArchTree.cpp @@ -297,7 +297,7 @@ template uint32_t elf::calcMipsEFlags() { std::vector v; for (InputFile *f : objectFiles) - v.push_back({f, cast>(f)->getObj().getHeader()->e_flags}); + v.push_back({f, cast>(f)->getObj().getHeader().e_flags}); if (v.empty()) { // If we don't have any input files, we'll have to rely on the information // we can derive from emulation information, since this at least gets us @@ -363,7 +363,7 @@ template static bool isN32Abi(const InputFile *f) { if (auto *ef = dyn_cast(f)) - return ef->template getObj().getHeader()->e_flags & EF_MIPS_ABI2; + return ef->template getObj().getHeader().e_flags & EF_MIPS_ABI2; return false; } diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp --- a/lld/ELF/Arch/PPC64.cpp +++ b/lld/ELF/Arch/PPC64.cpp @@ -620,8 +620,8 @@ static uint32_t getEFlags(InputFile *file) { if (config->ekind == ELF64BEKind) - return cast>(file)->getObj().getHeader()->e_flags; - return cast>(file)->getObj().getHeader()->e_flags; + return cast>(file)->getObj().getHeader().e_flags; + return cast>(file)->getObj().getHeader().e_flags; } // This file implements v2 ABI. This function makes sure that all diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp --- a/lld/ELF/Arch/RISCV.cpp +++ b/lld/ELF/Arch/RISCV.cpp @@ -104,8 +104,8 @@ static uint32_t getEFlags(InputFile *f) { if (config->is64) - return cast>(f)->getObj().getHeader()->e_flags; - return cast>(f)->getObj().getHeader()->e_flags; + return cast>(f)->getObj().getHeader().e_flags; + return cast>(f)->getObj().getHeader().e_flags; } uint32_t RISCV::calcEFlags() const { diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1719,7 +1719,7 @@ ArrayRef syms = obj->getSymbols(); if (obj->addrsigSec) { ArrayRef contents = - check(obj->getObj().getSectionContents(obj->addrsigSec)); + check(obj->getObj().getSectionContents(*obj->addrsigSec)); const uint8_t *cur = contents.begin(); while (cur != contents.end()) { unsigned size; diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -348,9 +348,9 @@ // Initialize trivial attributes. const ELFFile &obj = getObj(); - emachine = obj.getHeader()->e_machine; - osabi = obj.getHeader()->e_ident[llvm::ELF::EI_OSABI]; - abiVersion = obj.getHeader()->e_ident[llvm::ELF::EI_ABIVERSION]; + emachine = obj.getHeader().e_machine; + osabi = obj.getHeader().e_ident[llvm::ELF::EI_OSABI]; + abiVersion = obj.getHeader().e_ident[llvm::ELF::EI_ABIVERSION]; ArrayRef sections = CHECK(obj.sections(), this); @@ -378,7 +378,7 @@ template uint32_t ObjFile::getSectionIndex(const Elf_Sym &sym) const { return CHECK( - this->getObj().getSectionIndex(&sym, getELFSyms(), shndxTable), + this->getObj().getSectionIndex(sym, getELFSyms(), shndxTable), this); } @@ -566,7 +566,7 @@ if (sec.sh_type == ELF::SHT_LLVM_CALL_GRAPH_PROFILE) cgProfile = - check(obj.template getSectionContentsAsArray(&sec)); + check(obj.template getSectionContentsAsArray(sec)); // SHF_EXCLUDE'ed sections are discarded by the linker. However, // if -r is given, we'll let the final link discard such sections. @@ -595,7 +595,7 @@ ArrayRef entries = - CHECK(obj.template getSectionContentsAsArray(&sec), this); + CHECK(obj.template getSectionContentsAsArray(sec), this); if (entries.empty()) fatal(toString(this) + ": empty SHT_GROUP"); @@ -870,7 +870,7 @@ if (config->emachine == EM_ARM && sec.sh_type == SHT_ARM_ATTRIBUTES) { ARMAttributeParser attributes; - ArrayRef contents = check(this->getObj().getSectionContents(&sec)); + ArrayRef contents = check(this->getObj().getSectionContents(sec)); if (Error e = attributes.parse(contents, config->ekind == ELF32LEKind ? support::little : support::big)) { @@ -894,7 +894,7 @@ if (config->emachine == EM_RISCV && sec.sh_type == SHT_RISCV_ATTRIBUTES) { RISCVAttributeParser attributes; - ArrayRef contents = check(this->getObj().getSectionContents(&sec)); + ArrayRef contents = check(this->getObj().getSectionContents(sec)); if (Error e = attributes.parse(contents, support::little)) { auto *isec = make(*this, sec, name); warn(toString(isec) + ": " + llvm::toString(std::move(e))); @@ -919,7 +919,7 @@ if (config->relocatable) break; ArrayRef data = - CHECK(this->getObj().template getSectionContentsAsArray(&sec), this); + CHECK(this->getObj().template getSectionContentsAsArray(sec), this); if (!data.empty() && data.back() != '\0') { error(toString(this) + ": corrupted dependent libraries section (unterminated string): " + @@ -959,12 +959,12 @@ ": multiple relocation sections to one section are not supported"); if (sec.sh_type == SHT_RELA) { - ArrayRef rels = CHECK(getObj().relas(&sec), this); + ArrayRef rels = CHECK(getObj().relas(sec), this); target->firstRelocation = rels.begin(); target->numRelocations = rels.size(); target->areRelocsRela = true; } else { - ArrayRef rels = CHECK(getObj().rels(&sec), this); + ArrayRef rels = CHECK(getObj().rels(sec), this); target->firstRelocation = rels.begin(); target->numRelocations = rels.size(); target->areRelocsRela = false; @@ -1065,7 +1065,7 @@ template StringRef ObjFile::getSectionName(const Elf_Shdr &sec) { - return CHECK(getObj().getSectionName(&sec, sectionStringTable), this); + return CHECK(getObj().getSectionName(sec, sectionStringTable), this); } // Initialize this->Symbols. this->Symbols is a parallel array as @@ -1279,7 +1279,7 @@ if (!sec) return {}; std::vector verneeds; - ArrayRef data = CHECK(obj.getSectionContents(sec), this); + ArrayRef data = CHECK(obj.getSectionContents(*sec), this); const uint8_t *verneedBuf = data.begin(); for (unsigned i = 0; i != sec->sh_info; ++i) { if (verneedBuf + sizeof(typename ELFT::Verneed) > data.end()) @@ -1355,7 +1355,7 @@ continue; case SHT_DYNAMIC: dynamicTags = - CHECK(obj.template getSectionContentsAsArray(&sec), this); + CHECK(obj.template getSectionContentsAsArray(sec), this); break; case SHT_GNU_versym: versymSec = &sec; @@ -1414,7 +1414,7 @@ std::vector versyms(size, VER_NDX_GLOBAL); if (versymSec) { ArrayRef versym = - CHECK(obj.template getSectionContentsAsArray(versymSec), + CHECK(obj.template getSectionContentsAsArray(*versymSec), this) .slice(firstGlobal); for (size_t i = 0; i < size; ++i) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -53,7 +53,7 @@ const typename ELFT::Shdr &hdr) { if (hdr.sh_type == SHT_NOBITS) return makeArrayRef(nullptr, hdr.sh_size); - return check(file.getObj().getSectionContents(&hdr)); + return check(file.getObj().getSectionContents(hdr)); } InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags, @@ -456,7 +456,7 @@ Elf_Shdr_Impl sec = CHECK(file->getObj().sections(), file)[secIdx]; warn("relocation refers to a discarded section: " + - CHECK(file->getObj().getSectionName(&sec), file) + + CHECK(file->getObj().getSectionName(sec), file) + "\n>>> referenced by " + getObjMsg(p->r_offset)); } p->setSymbolAndType(0, 0, false); diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -692,7 +692,7 @@ if (sym.type == ELF::STT_SECTION) { msg = "relocation refers to a discarded section: "; msg += CHECK( - file->getObj().getSectionName(&objSections[sym.discardedSecIdx]), file); + file->getObj().getSectionName(objSections[sym.discardedSecIdx]), file); } else { msg = "relocation refers to a symbol in a discarded section: " + toString(sym); diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h --- a/llvm/include/llvm/Object/ELF.h +++ b/llvm/include/llvm/Object/ELF.h @@ -58,11 +58,11 @@ template class ELFFile; template -std::string getSecIndexForError(const ELFFile *Obj, - const typename ELFT::Shdr *Sec) { - auto TableOrErr = Obj->sections(); +std::string getSecIndexForError(const ELFFile &Obj, + const typename ELFT::Shdr &Sec) { + auto TableOrErr = Obj.sections(); if (TableOrErr) - return "[index " + std::to_string(Sec - &TableOrErr->front()) + "]"; + return "[index " + std::to_string(&Sec - &TableOrErr->front()) + "]"; // To make this helper be more convenient for error reporting purposes we // drop the error. But really it should never be triggered. Before this point, // our code should have called 'sections()' and reported a proper error on @@ -72,11 +72,11 @@ } template -std::string getPhdrIndexForError(const ELFFile *Obj, - const typename ELFT::Phdr *Phdr) { - auto Headers = Obj->program_headers(); +std::string getPhdrIndexForError(const ELFFile &Obj, + const typename ELFT::Phdr &Phdr) { + auto Headers = Obj.program_headers(); if (Headers) - return ("[index " + Twine(Phdr - &Headers->front()) + "]").str(); + return ("[index " + Twine(&Phdr - &Headers->front()) + "]").str(); // See comment in the getSecIndexForError() above. llvm::consumeError(Headers.takeError()); return "[unknown index]"; @@ -134,17 +134,17 @@ ELFFile(StringRef Object); public: - const Elf_Ehdr *getHeader() const { - return reinterpret_cast(base()); + const Elf_Ehdr &getHeader() const { + return *reinterpret_cast(base()); } template Expected getEntry(uint32_t Section, uint32_t Entry) const; template - Expected getEntry(const Elf_Shdr *Section, uint32_t Entry) const; + Expected getEntry(const Elf_Shdr &Section, uint32_t Entry) const; Expected - getStringTable(const Elf_Shdr *Section, + getStringTable(const Elf_Shdr &Section, WarningHandler WarnHandler = &defaultWarningHandler) const; Expected getStringTableForSymtab(const Elf_Shdr &Section) const; Expected getStringTableForSymtab(const Elf_Shdr &Section, @@ -163,18 +163,18 @@ std::string getDynamicTagAsString(uint64_t Type) const; /// Get the symbol for a given relocation. - Expected getRelocationSymbol(const Elf_Rel *Rel, + Expected getRelocationSymbol(const Elf_Rel &Rel, const Elf_Shdr *SymTab) const; static Expected create(StringRef Object); bool isLE() const { - return getHeader()->getDataEncoding() == ELF::ELFDATA2LSB; + return getHeader().getDataEncoding() == ELF::ELFDATA2LSB; } bool isMipsELF64() const { - return getHeader()->e_machine == ELF::EM_MIPS && - getHeader()->getFileClass() == ELF::ELFCLASS64; + return getHeader().e_machine == ELF::EM_MIPS && + getHeader().getFileClass() == ELF::ELFCLASS64; } bool isMips64EL() const { return isMipsELF64() && isLE(); } @@ -188,43 +188,43 @@ Expected symbols(const Elf_Shdr *Sec) const { if (!Sec) return makeArrayRef(nullptr, nullptr); - return getSectionContentsAsArray(Sec); + return getSectionContentsAsArray(*Sec); } - Expected relas(const Elf_Shdr *Sec) const { + Expected relas(const Elf_Shdr &Sec) const { return getSectionContentsAsArray(Sec); } - Expected rels(const Elf_Shdr *Sec) const { + Expected rels(const Elf_Shdr &Sec) const { return getSectionContentsAsArray(Sec); } - Expected relrs(const Elf_Shdr *Sec) const { + Expected relrs(const Elf_Shdr &Sec) const { return getSectionContentsAsArray(Sec); } std::vector decode_relrs(Elf_Relr_Range relrs) const; - Expected> android_relas(const Elf_Shdr *Sec) const; + Expected> android_relas(const Elf_Shdr &Sec) const; /// Iterate over program header table. Expected program_headers() const { - if (getHeader()->e_phnum && getHeader()->e_phentsize != sizeof(Elf_Phdr)) + if (getHeader().e_phnum && getHeader().e_phentsize != sizeof(Elf_Phdr)) return createError("invalid e_phentsize: " + - Twine(getHeader()->e_phentsize)); + Twine(getHeader().e_phentsize)); uint64_t HeadersSize = - (uint64_t)getHeader()->e_phnum * getHeader()->e_phentsize; - uint64_t PhOff = getHeader()->e_phoff; + (uint64_t)getHeader().e_phnum * getHeader().e_phentsize; + uint64_t PhOff = getHeader().e_phoff; if (PhOff + HeadersSize < PhOff || PhOff + HeadersSize > getBufSize()) return createError("program headers are longer than binary of size " + Twine(getBufSize()) + ": e_phoff = 0x" + - Twine::utohexstr(getHeader()->e_phoff) + - ", e_phnum = " + Twine(getHeader()->e_phnum) + - ", e_phentsize = " + Twine(getHeader()->e_phentsize)); + Twine::utohexstr(getHeader().e_phoff) + + ", e_phnum = " + Twine(getHeader().e_phnum) + + ", e_phentsize = " + Twine(getHeader().e_phentsize)); auto *Begin = reinterpret_cast(base() + PhOff); - return makeArrayRef(Begin, Begin + getHeader()->e_phnum); + return makeArrayRef(Begin, Begin + getHeader().e_phnum); } /// Get an iterator over notes in a program header. @@ -257,7 +257,7 @@ assert(Shdr.sh_type == ELF::SHT_NOTE && "Shdr is not of type SHT_NOTE"); ErrorAsOutParameter ErrAsOutParam(&Err); if (Shdr.sh_offset + Shdr.sh_size > getBufSize()) { - Err = createError("SHT_NOTE section " + getSecIndexForError(this, &Shdr) + + Err = createError("SHT_NOTE section " + getSecIndexForError(*this, Shdr) + " has invalid offset (0x" + Twine::utohexstr(Shdr.sh_offset) + ") or size (0x" + Twine::utohexstr(Shdr.sh_size) + ")"); @@ -298,12 +298,12 @@ Expected getSectionStringTable( Elf_Shdr_Range Sections, WarningHandler WarnHandler = &defaultWarningHandler) const; - Expected getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms, + Expected getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms, ArrayRef ShndxTable) const; - Expected getSection(const Elf_Sym *Sym, + Expected getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, ArrayRef ShndxTable) const; - Expected getSection(const Elf_Sym *Sym, + Expected getSection(const Elf_Sym &Sym, Elf_Sym_Range Symtab, ArrayRef ShndxTable) const; Expected getSection(uint32_t Index) const; @@ -312,14 +312,14 @@ uint32_t Index) const; Expected - getSectionName(const Elf_Shdr *Section, + getSectionName(const Elf_Shdr &Section, WarningHandler WarnHandler = &defaultWarningHandler) const; - Expected getSectionName(const Elf_Shdr *Section, + Expected getSectionName(const Elf_Shdr &Section, StringRef DotShstrtab) const; template - Expected> getSectionContentsAsArray(const Elf_Shdr *Sec) const; - Expected> getSectionContents(const Elf_Shdr *Sec) const; - Expected> getSegmentContents(const Elf_Phdr *Phdr) const; + Expected> getSectionContentsAsArray(const Elf_Shdr &Sec) const; + Expected> getSectionContents(const Elf_Shdr &Sec) const; + Expected> getSegmentContents(const Elf_Phdr &Phdr) const; }; using ELF32LEFile = ELFFile; @@ -337,11 +337,11 @@ template inline Expected -getExtendedSymbolTableIndex(const typename ELFT::Sym *Sym, - const typename ELFT::Sym *FirstSym, +getExtendedSymbolTableIndex(const typename ELFT::Sym &Sym, + const typename ELFT::Sym &FirstSym, ArrayRef ShndxTable) { - assert(Sym->st_shndx == ELF::SHN_XINDEX); - unsigned Index = Sym - FirstSym; + assert(Sym.st_shndx == ELF::SHN_XINDEX); + unsigned Index = &Sym - &FirstSym; if (Index >= ShndxTable.size()) return createError( "extended symbol index (" + Twine(Index) + @@ -354,12 +354,12 @@ template Expected -ELFFile::getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms, +ELFFile::getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms, ArrayRef ShndxTable) const { - uint32_t Index = Sym->st_shndx; + uint32_t Index = Sym.st_shndx; if (Index == ELF::SHN_XINDEX) { - auto ErrorOrIndex = getExtendedSymbolTableIndex( - Sym, Syms.begin(), ShndxTable); + Expected ErrorOrIndex = + getExtendedSymbolTableIndex(Sym, *Syms.begin(), ShndxTable); if (!ErrorOrIndex) return ErrorOrIndex.takeError(); return *ErrorOrIndex; @@ -371,7 +371,7 @@ template Expected -ELFFile::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab, +ELFFile::getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, ArrayRef ShndxTable) const { auto SymsOrErr = symbols(SymTab); if (!SymsOrErr) @@ -381,7 +381,7 @@ template Expected -ELFFile::getSection(const Elf_Sym *Sym, Elf_Sym_Range Symbols, +ELFFile::getSection(const Elf_Sym &Sym, Elf_Sym_Range Symbols, ArrayRef ShndxTable) const { auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable); if (!IndexOrErr) @@ -402,7 +402,7 @@ Elf_Sym_Range Symbols = *SymsOrErr; if (Index >= Symbols.size()) return createError("unable to get symbol from section " + - getSecIndexForError(this, Sec) + + getSecIndexForError(*this, *Sec) + ": invalid symbol index (" + Twine(Index) + ")"); return &Symbols[Index]; } @@ -410,26 +410,26 @@ template template Expected> -ELFFile::getSectionContentsAsArray(const Elf_Shdr *Sec) const { - if (Sec->sh_entsize != sizeof(T) && sizeof(T) != 1) - return createError("section " + getSecIndexForError(this, Sec) + - " has an invalid sh_entsize: " + Twine(Sec->sh_entsize)); +ELFFile::getSectionContentsAsArray(const Elf_Shdr &Sec) const { + if (Sec.sh_entsize != sizeof(T) && sizeof(T) != 1) + return createError("section " + getSecIndexForError(*this, Sec) + + " has an invalid sh_entsize: " + Twine(Sec.sh_entsize)); - uintX_t Offset = Sec->sh_offset; - uintX_t Size = Sec->sh_size; + uintX_t Offset = Sec.sh_offset; + uintX_t Size = Sec.sh_size; if (Size % sizeof(T)) - return createError("section " + getSecIndexForError(this, Sec) + + return createError("section " + getSecIndexForError(*this, Sec) + " has an invalid sh_size (" + Twine(Size) + ") which is not a multiple of its sh_entsize (" + - Twine(Sec->sh_entsize) + ")"); + Twine(Sec.sh_entsize) + ")"); if (std::numeric_limits::max() - Offset < Size) - return createError("section " + getSecIndexForError(this, Sec) + + return createError("section " + getSecIndexForError(*this, Sec) + " has a sh_offset (0x" + Twine::utohexstr(Offset) + ") + sh_size (0x" + Twine::utohexstr(Size) + ") that cannot be represented"); if (Offset + Size > Buf.size()) - return createError("section " + getSecIndexForError(this, Sec) + + return createError("section " + getSecIndexForError(*this, Sec) + " has a sh_offset (0x" + Twine::utohexstr(Offset) + ") + sh_size (0x" + Twine::utohexstr(Size) + ") that is greater than the file size (0x" + @@ -445,17 +445,17 @@ template Expected> -ELFFile::getSegmentContents(const Elf_Phdr *Phdr) const { - uintX_t Offset = Phdr->p_offset; - uintX_t Size = Phdr->p_filesz; +ELFFile::getSegmentContents(const Elf_Phdr &Phdr) const { + uintX_t Offset = Phdr.p_offset; + uintX_t Size = Phdr.p_filesz; if (std::numeric_limits::max() - Offset < Size) - return createError("program header " + getPhdrIndexForError(this, Phdr) + + return createError("program header " + getPhdrIndexForError(*this, Phdr) + " has a p_offset (0x" + Twine::utohexstr(Offset) + ") + p_filesz (0x" + Twine::utohexstr(Size) + ") that cannot be represented"); if (Offset + Size > Buf.size()) - return createError("program header " + getPhdrIndexForError(this, Phdr) + + return createError("program header " + getPhdrIndexForError(*this, Phdr) + " has a p_offset (0x" + Twine::utohexstr(Offset) + ") + p_filesz (0x" + Twine::utohexstr(Size) + ") that is greater than the file size (0x" + @@ -465,13 +465,13 @@ template Expected> -ELFFile::getSectionContents(const Elf_Shdr *Sec) const { +ELFFile::getSectionContents(const Elf_Shdr &Sec) const { return getSectionContentsAsArray(Sec); } template StringRef ELFFile::getRelocationTypeName(uint32_t Type) const { - return getELFRelocationTypeName(getHeader()->e_machine, Type); + return getELFRelocationTypeName(getHeader().e_machine, Type); } template @@ -507,24 +507,24 @@ template uint32_t ELFFile::getRelativeRelocationType() const { - return getELFRelativeRelocationType(getHeader()->e_machine); + return getELFRelativeRelocationType(getHeader().e_machine); } template Expected -ELFFile::getRelocationSymbol(const Elf_Rel *Rel, +ELFFile::getRelocationSymbol(const Elf_Rel &Rel, const Elf_Shdr *SymTab) const { - uint32_t Index = Rel->getSymbol(isMips64EL()); + uint32_t Index = Rel.getSymbol(isMips64EL()); if (Index == 0) return nullptr; - return getEntry(SymTab, Index); + return getEntry(*SymTab, Index); } template Expected ELFFile::getSectionStringTable(Elf_Shdr_Range Sections, WarningHandler WarnHandler) const { - uint32_t Index = getHeader()->e_shstrndx; + uint32_t Index = getHeader().e_shstrndx; if (Index == ELF::SHN_XINDEX) { // If the section name string table section index is greater than // or equal to SHN_LORESERVE, then the actual index of the section name @@ -542,7 +542,7 @@ if (Index >= Sections.size()) return createError("section header string table index " + Twine(Index) + " does not exist"); - return getStringTable(&Sections[Index], WarnHandler); + return getStringTable(Sections[Index], WarnHandler); } template ELFFile::ELFFile(StringRef Object) : Buf(Object) {} @@ -558,13 +558,13 @@ template Expected ELFFile::sections() const { - const uintX_t SectionTableOffset = getHeader()->e_shoff; + const uintX_t SectionTableOffset = getHeader().e_shoff; if (SectionTableOffset == 0) return ArrayRef(); - if (getHeader()->e_shentsize != sizeof(Elf_Shdr)) + if (getHeader().e_shentsize != sizeof(Elf_Shdr)) return createError("invalid e_shentsize in ELF header: " + - Twine(getHeader()->e_shentsize)); + Twine(getHeader().e_shentsize)); const uint64_t FileSize = Buf.size(); if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize || @@ -581,7 +581,7 @@ const Elf_Shdr *First = reinterpret_cast(base() + SectionTableOffset); - uintX_t NumSections = getHeader()->e_shnum; + uintX_t NumSections = getHeader().e_shnum; if (NumSections == 0) NumSections = First->sh_size; @@ -612,21 +612,21 @@ auto SecOrErr = getSection(Section); if (!SecOrErr) return SecOrErr.takeError(); - return getEntry(*SecOrErr, Entry); + return getEntry(**SecOrErr, Entry); } template template -Expected ELFFile::getEntry(const Elf_Shdr *Section, +Expected ELFFile::getEntry(const Elf_Shdr &Section, uint32_t Entry) const { - if (sizeof(T) != Section->sh_entsize) - return createError("section " + getSecIndexForError(this, Section) + + if (sizeof(T) != Section.sh_entsize) + return createError("section " + getSecIndexForError(*this, Section) + " has invalid sh_entsize: expected " + Twine(sizeof(T)) + - ", but got " + Twine(Section->sh_entsize)); - uint64_t Pos = Section->sh_offset + (uint64_t)Entry * sizeof(T); + ", but got " + Twine(Section.sh_entsize)); + uint64_t Pos = Section.sh_offset + (uint64_t)Entry * sizeof(T); if (Pos + sizeof(T) > Buf.size()) return createError("unable to access section " + - getSecIndexForError(this, Section) + " data at 0x" + + getSecIndexForError(*this, Section) + " data at 0x" + Twine::utohexstr(Pos) + ": offset goes past the end of file"); return reinterpret_cast(base() + Pos); @@ -643,14 +643,14 @@ template Expected -ELFFile::getStringTable(const Elf_Shdr *Section, +ELFFile::getStringTable(const Elf_Shdr &Section, WarningHandler WarnHandler) const { - if (Section->sh_type != ELF::SHT_STRTAB) + if (Section.sh_type != ELF::SHT_STRTAB) if (Error E = WarnHandler("invalid sh_type for string table section " + - getSecIndexForError(this, Section) + + getSecIndexForError(*this, Section) + ": expected SHT_STRTAB, but got " + object::getELFSectionTypeName( - getHeader()->e_machine, Section->sh_type))) + getHeader().e_machine, Section.sh_type))) return std::move(E); auto V = getSectionContentsAsArray(Section); @@ -659,10 +659,10 @@ ArrayRef Data = *V; if (Data.empty()) return createError("SHT_STRTAB string table section " + - getSecIndexForError(this, Section) + " is empty"); + getSecIndexForError(*this, Section) + " is empty"); if (Data.back() != '\0') return createError("SHT_STRTAB string table section " + - getSecIndexForError(this, Section) + + getSecIndexForError(*this, Section) + " is non-null terminated"); return StringRef(Data.begin(), Data.size()); } @@ -681,7 +681,7 @@ ELFFile::getSHNDXTable(const Elf_Shdr &Section, Elf_Shdr_Range Sections) const { assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX); - auto VOrErr = getSectionContentsAsArray(&Section); + auto VOrErr = getSectionContentsAsArray(Section); if (!VOrErr) return VOrErr.takeError(); ArrayRef V = *VOrErr; @@ -691,10 +691,10 @@ const Elf_Shdr &SymTable = **SymTableOrErr; if (SymTable.sh_type != ELF::SHT_SYMTAB && SymTable.sh_type != ELF::SHT_DYNSYM) - return createError("SHT_SYMTAB_SHNDX section is linked with " + - object::getELFSectionTypeName(getHeader()->e_machine, - SymTable.sh_type) + - " section (expected SHT_SYMTAB/SHT_DYNSYM)"); + return createError( + "SHT_SYMTAB_SHNDX section is linked with " + + object::getELFSectionTypeName(getHeader().e_machine, SymTable.sh_type) + + " section (expected SHT_SYMTAB/SHT_DYNSYM)"); uint64_t Syms = SymTable.sh_size / sizeof(Elf_Sym); if (V.size() != Syms) @@ -722,15 +722,16 @@ if (Sec.sh_type != ELF::SHT_SYMTAB && Sec.sh_type != ELF::SHT_DYNSYM) return createError( "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM"); - auto SectionOrErr = object::getSection(Sections, Sec.sh_link); + Expected SectionOrErr = + object::getSection(Sections, Sec.sh_link); if (!SectionOrErr) return SectionOrErr.takeError(); - return getStringTable(*SectionOrErr); + return getStringTable(**SectionOrErr); } template Expected -ELFFile::getSectionName(const Elf_Shdr *Section, +ELFFile::getSectionName(const Elf_Shdr &Section, WarningHandler WarnHandler) const { auto SectionsOrErr = sections(); if (!SectionsOrErr) @@ -742,13 +743,13 @@ } template -Expected ELFFile::getSectionName(const Elf_Shdr *Section, +Expected ELFFile::getSectionName(const Elf_Shdr &Section, StringRef DotShstrtab) const { - uint32_t Offset = Section->sh_name; + uint32_t Offset = Section.sh_name; if (Offset == 0) return StringRef(); if (Offset >= DotShstrtab.size()) - return createError("a section " + getSecIndexForError(this, Section) + + return createError("a section " + getSecIndexForError(*this, Section) + " has an invalid sh_name (0x" + Twine::utohexstr(Offset) + ") offset which goes past the end of the " diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h --- a/llvm/include/llvm/Object/ELFObjectFile.h +++ b/llvm/include/llvm/Object/ELFObjectFile.h @@ -377,7 +377,7 @@ for (const Elf_Shdr &Sec : *SectionsOrErr) { if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES || Sec.sh_type == ELF::SHT_RISCV_ATTRIBUTES) { - auto ErrorOrContents = EF.getSectionContents(&Sec); + auto ErrorOrContents = EF.getSectionContents(Sec); if (!ErrorOrContents) return ErrorOrContents.takeError(); @@ -432,7 +432,7 @@ Triple::ArchType getArch() const override; Expected getStartAddress() const override; - unsigned getPlatformFlags() const override { return EF.getHeader()->e_flags; } + unsigned getPlatformFlags() const override { return EF.getHeader().e_flags; } const ELFFile *getELFFile() const { return &EF; } @@ -468,7 +468,7 @@ if (!StrTabOrErr) return StrTabOrErr.takeError(); const Elf_Shdr *StringTableSec = *StrTabOrErr; - auto SymStrTabOrErr = EF.getStringTable(StringTableSec); + auto SymStrTabOrErr = EF.getStringTable(*StringTableSec); if (!SymStrTabOrErr) return SymStrTabOrErr.takeError(); Expected Name = ESym->getName(*SymStrTabOrErr); @@ -507,9 +507,9 @@ if (ESym->st_shndx == ELF::SHN_ABS) return Ret; - const Elf_Ehdr *Header = EF.getHeader(); + const Elf_Ehdr &Header = EF.getHeader(); // Clear the ARM/Thumb or microMIPS indicator flag. - if ((Header->e_machine == ELF::EM_ARM || Header->e_machine == ELF::EM_MIPS) && + if ((Header.e_machine == ELF::EM_ARM || Header.e_machine == ELF::EM_MIPS) && ESym->getType() == ELF::STT_FUNC) Ret &= ~1; @@ -533,14 +533,13 @@ return Result; } - const Elf_Ehdr *Header = EF.getHeader(); auto SymTabOrErr = EF.getSection(Symb.d.a); if (!SymTabOrErr) return SymTabOrErr.takeError(); - const Elf_Shdr *SymTab = *SymTabOrErr; - if (Header->e_type == ELF::ET_REL) { - auto SectionOrErr = EF.getSection(ESym, SymTab, ShndxTable); + if (EF.getHeader().e_type == ELF::ET_REL) { + Expected SectionOrErr = + EF.getSection(*ESym, *SymTabOrErr, ShndxTable); if (!SectionOrErr) return SectionOrErr.takeError(); const Elf_Shdr *Section = *SectionOrErr; @@ -561,11 +560,11 @@ template uint16_t ELFObjectFile::getEMachine() const { - return EF.getHeader()->e_machine; + return EF.getHeader().e_machine; } template uint16_t ELFObjectFile::getEType() const { - return EF.getHeader()->e_type; + return EF.getHeader().e_type; } template @@ -652,7 +651,7 @@ // TODO: Test this error. return SymbolsOrErr.takeError(); - if (EF.getHeader()->e_machine == ELF::EM_ARM) { + if (EF.getHeader().e_machine == ELF::EM_ARM) { if (Expected NameOrErr = getSymbolName(Sym)) { StringRef Name = *NameOrErr; if (Name.startswith("$d") || Name.startswith("$t") || @@ -685,7 +684,7 @@ Expected ELFObjectFile::getSymbolSection(const Elf_Sym *ESym, const Elf_Shdr *SymTab) const { - auto ESecOrErr = EF.getSection(ESym, SymTab, ShndxTable); + auto ESecOrErr = EF.getSection(*ESym, SymTab, ShndxTable); if (!ESecOrErr) return ESecOrErr.takeError(); @@ -717,7 +716,7 @@ template Expected ELFObjectFile::getSectionName(DataRefImpl Sec) const { - return EF.getSectionName(&*getSection(Sec)); + return EF.getSectionName(*getSection(Sec)); } template @@ -847,7 +846,7 @@ if (!SectionsOrErr) return relocation_iterator(RelocationRef()); uintptr_t SHT = reinterpret_cast((*SectionsOrErr).begin()); - RelData.d.a = (Sec.p - SHT) / EF.getHeader()->e_shentsize; + RelData.d.a = (Sec.p - SHT) / EF.getHeader().e_shentsize; RelData.d.b = 0; return relocation_iterator(RelocationRef(RelData, this)); } @@ -874,7 +873,7 @@ template Expected ELFObjectFile::getRelocatedSection(DataRefImpl Sec) const { - if (EF.getHeader()->e_type != ELF::ET_REL) + if (EF.getHeader().e_type != ELF::ET_REL) return section_end(); const Elf_Shdr *EShdr = getSection(Sec); @@ -933,7 +932,7 @@ template StringRef ELFObjectFile::getRelocationTypeName(uint32_t Type) const { - return getELFRelocationTypeName(EF.getHeader()->e_machine, Type); + return getELFRelocationTypeName(EF.getHeader().e_machine, Type); } template @@ -1087,9 +1086,9 @@ template StringRef ELFObjectFile::getFileFormatName() const { bool IsLittleEndian = ELFT::TargetEndianness == support::little; - switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) { + switch (EF.getHeader().e_ident[ELF::EI_CLASS]) { case ELF::ELFCLASS32: - switch (EF.getHeader()->e_machine) { + switch (EF.getHeader().e_machine) { case ELF::EM_386: return "elf32-i386"; case ELF::EM_IAMCU: @@ -1123,7 +1122,7 @@ return "elf32-unknown"; } case ELF::ELFCLASS64: - switch (EF.getHeader()->e_machine) { + switch (EF.getHeader().e_machine) { case ELF::EM_386: return "elf64-i386"; case ELF::EM_X86_64: @@ -1157,7 +1156,7 @@ template Triple::ArchType ELFObjectFile::getArch() const { bool IsLittleEndian = ELFT::TargetEndianness == support::little; - switch (EF.getHeader()->e_machine) { + switch (EF.getHeader().e_machine) { case ELF::EM_386: case ELF::EM_IAMCU: return Triple::x86; @@ -1174,7 +1173,7 @@ case ELF::EM_LANAI: return Triple::lanai; case ELF::EM_MIPS: - switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) { + switch (EF.getHeader().e_ident[ELF::EI_CLASS]) { case ELF::ELFCLASS32: return IsLittleEndian ? Triple::mipsel : Triple::mips; case ELF::ELFCLASS64: @@ -1189,7 +1188,7 @@ case ELF::EM_PPC64: return IsLittleEndian ? Triple::ppc64le : Triple::ppc64; case ELF::EM_RISCV: - switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) { + switch (EF.getHeader().e_ident[ELF::EI_CLASS]) { case ELF::ELFCLASS32: return Triple::riscv32; case ELF::ELFCLASS64: @@ -1210,7 +1209,7 @@ if (!IsLittleEndian) return Triple::UnknownArch; - unsigned MACH = EF.getHeader()->e_flags & ELF::EF_AMDGPU_MACH; + unsigned MACH = EF.getHeader().e_flags & ELF::EF_AMDGPU_MACH; if (MACH >= ELF::EF_AMDGPU_MACH_R600_FIRST && MACH <= ELF::EF_AMDGPU_MACH_R600_LAST) return Triple::r600; @@ -1235,7 +1234,7 @@ template Expected ELFObjectFile::getStartAddress() const { - return EF.getHeader()->e_entry; + return EF.getHeader().e_entry; } template @@ -1245,7 +1244,7 @@ } template bool ELFObjectFile::isRelocatableObject() const { - return EF.getHeader()->e_type == ELF::ET_REL; + return EF.getHeader().e_type == ELF::ET_REL; } } // end namespace object diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp @@ -244,7 +244,7 @@ object::ELFFile::Elf_Shdr_Range sections; SymbolTable SymTab; - bool isRelocatable() { return Obj.getHeader()->e_type == llvm::ELF::ET_REL; } + bool isRelocatable() { return Obj.getHeader().e_type == llvm::ELF::ET_REL; } support::endianness getEndianness(const object::ELFFile &Obj) { @@ -253,7 +253,7 @@ // This could also just become part of a template unsigned getPointerSize(const object::ELFFile &Obj) { - return Obj.getHeader()->getFileClass() == ELF::ELFCLASS64 ? 8 : 4; + return Obj.getHeader().getFileClass() == ELF::ELFCLASS64 ? 8 : 4; } // We don't technically need this right now @@ -277,7 +277,7 @@ auto StrTabSec = Obj.getSection(SecRef.sh_link); if (!StrTabSec) return StrTabSec.takeError(); - auto StringTable = Obj.getStringTable(*StrTabSec); + auto StringTable = Obj.getStringTable(**StrTabSec); if (!StringTable) return StringTable.takeError(); @@ -310,7 +310,7 @@ Error createNormalizedSections() { LLVM_DEBUG(dbgs() << "Creating normalized sections...\n"); for (auto &SecRef : sections) { - auto Name = Obj.getSectionName(&SecRef); + auto Name = Obj.getSectionName(SecRef); if (!Name) return Name.takeError(); sys::Memory::ProtectionFlags Prot; @@ -343,7 +343,7 @@ if (SecRef.sh_type != ELF::SHT_NOBITS) { // .sections() already checks that the data is not beyond the end of // file - auto contents = Obj.getSectionContentsAsArray(&SecRef); + auto contents = Obj.getSectionContentsAsArray(SecRef); if (!contents) return contents.takeError(); @@ -375,7 +375,7 @@ return make_error("Shouldn't have REL in x64", llvm::inconvertibleErrorCode()); - auto RelSectName = Obj.getSectionName(&SecRef); + auto RelSectName = Obj.getSectionName(SecRef); if (!RelSectName) return RelSectName.takeError(); // Deal with .eh_frame later @@ -386,7 +386,7 @@ if (!UpdateSection) return UpdateSection.takeError(); - auto UpdateSectionName = Obj.getSectionName(*UpdateSection); + auto UpdateSectionName = Obj.getSectionName(**UpdateSection); if (!UpdateSectionName) return UpdateSectionName.takeError(); @@ -397,7 +397,7 @@ *UpdateSectionName, llvm::inconvertibleErrorCode()); - auto Relocations = Obj.relas(&SecRef); + auto Relocations = Obj.relas(SecRef); if (!Relocations) return Relocations.takeError(); @@ -409,7 +409,7 @@ << "Name: " << Obj.getRelocationTypeName(Type) << "\n"; }); auto SymbolIndex = Rela.getSymbol(false); - auto Symbol = Obj.getRelocationSymbol(&Rela, &SymTab); + auto Symbol = Obj.getRelocationSymbol(Rela, &SymTab); if (!Symbol) return Symbol.takeError(); @@ -472,10 +472,10 @@ auto StrTabSec = Obj.getSection(SecRef.sh_link); if (!StrTabSec) return StrTabSec.takeError(); - auto StringTable = Obj.getStringTable(*StrTabSec); + auto StringTable = Obj.getStringTable(**StrTabSec); if (!StringTable) return StringTable.takeError(); - auto Name = Obj.getSectionName(&SecRef); + auto Name = Obj.getSectionName(SecRef); if (!Name) return Name.takeError(); auto Section = G->findSectionByName(*Name); @@ -520,7 +520,7 @@ auto DefinedSection = Obj.getSection(SymRef.st_shndx); if (!DefinedSection) return DefinedSection.takeError(); - auto sectName = Obj.getSectionName(*DefinedSection); + auto sectName = Obj.getSectionName(**DefinedSection); if (!sectName) return Name.takeError(); diff --git a/llvm/lib/InterfaceStub/ELFObjHandler.cpp b/llvm/lib/InterfaceStub/ELFObjHandler.cpp --- a/llvm/lib/InterfaceStub/ELFObjHandler.cpp +++ b/llvm/lib/InterfaceStub/ELFObjHandler.cpp @@ -320,7 +320,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()) { diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -366,7 +366,7 @@ template Expected> -ELFFile::android_relas(const Elf_Shdr *Sec) const { +ELFFile::android_relas(const Elf_Shdr &Sec) const { // This function reads relocations in Android's packed relocation format, // which is based on SLEB128 and delta encoding. Expected> ContentsOrErr = getSectionContents(Sec); @@ -511,7 +511,7 @@ template std::string ELFFile::getDynamicTagAsString(uint64_t Type) const { - return getDynamicTagAsString(getHeader()->e_machine, Type); + return getDynamicTagAsString(getHeader().e_machine, Type); } template @@ -541,7 +541,7 @@ for (const Elf_Shdr &Sec : *SectionsOrError) { if (Sec.sh_type == ELF::SHT_DYNAMIC) { Expected> DynOrError = - getSectionContentsAsArray(&Sec); + getSectionContentsAsArray(Sec); if (!DynOrError) return DynOrError.takeError(); Dyn = *DynOrError; diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp --- a/llvm/tools/llvm-objcopy/ELF/Object.cpp +++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp @@ -1320,7 +1320,7 @@ ElfHdr.Index = Index++; ElfHdr.OriginalOffset = ElfHdr.Offset = EhdrOffset; - const auto &Ehdr = *HeadersFile.getHeader(); + const typename ELFT::Ehdr &Ehdr = HeadersFile.getHeader(); auto &PrHdr = Obj.ProgramHdrSegment; PrHdr.Type = PT_PHDR; PrHdr.Flags = 0; @@ -1398,7 +1398,7 @@ const Elf_Shdr &ShndxSec = *unwrapOrError(ElfFile.getSection(SymTab->getShndxTable()->Index)); ShndxData = unwrapOrError( - ElfFile.template getSectionContentsAsArray(&ShndxSec)); + ElfFile.template getSectionContentsAsArray(ShndxSec)); if (ShndxData.size() != Symbols.size()) error("symbol section index table does not have the same number of " "entries as the symbol table"); @@ -1476,7 +1476,7 @@ case SHT_REL: case SHT_RELA: if (Shdr.sh_flags & SHF_ALLOC) { - Data = unwrapOrError(ElfFile.getSectionContents(&Shdr)); + Data = unwrapOrError(ElfFile.getSectionContents(Shdr)); return Obj.addSection(Data); } return Obj.addSection(); @@ -1485,7 +1485,7 @@ // mean altering the memory image. There are no special link types or // anything so we can just use a Section. if (Shdr.sh_flags & SHF_ALLOC) { - Data = unwrapOrError(ElfFile.getSectionContents(&Shdr)); + Data = unwrapOrError(ElfFile.getSectionContents(Shdr)); return Obj.addSection
(Data); } return Obj.addSection(); @@ -1493,16 +1493,16 @@ case SHT_GNU_HASH: // Hash tables should refer to SHT_DYNSYM which we're not going to change. // Because of this we don't need to mess with the hash tables either. - Data = unwrapOrError(ElfFile.getSectionContents(&Shdr)); + Data = unwrapOrError(ElfFile.getSectionContents(Shdr)); return Obj.addSection
(Data); case SHT_GROUP: - Data = unwrapOrError(ElfFile.getSectionContents(&Shdr)); + Data = unwrapOrError(ElfFile.getSectionContents(Shdr)); return Obj.addSection(Data); case SHT_DYNSYM: - Data = unwrapOrError(ElfFile.getSectionContents(&Shdr)); + Data = unwrapOrError(ElfFile.getSectionContents(Shdr)); return Obj.addSection(Data); case SHT_DYNAMIC: - Data = unwrapOrError(ElfFile.getSectionContents(&Shdr)); + Data = unwrapOrError(ElfFile.getSectionContents(Shdr)); return Obj.addSection(Data); case SHT_SYMTAB: { auto &SymTab = Obj.addSection(); @@ -1517,9 +1517,9 @@ case SHT_NOBITS: return Obj.addSection
(Data); default: { - Data = unwrapOrError(ElfFile.getSectionContents(&Shdr)); + Data = unwrapOrError(ElfFile.getSectionContents(Shdr)); - StringRef Name = unwrapOrError(ElfFile.getSectionName(&Shdr)); + StringRef Name = unwrapOrError(ElfFile.getSectionName(Shdr)); if (Name.startswith(".zdebug") || (Shdr.sh_flags & ELF::SHF_COMPRESSED)) { uint64_t DecompressedSize, DecompressedAlign; std::tie(DecompressedSize, DecompressedAlign) = @@ -1541,7 +1541,7 @@ continue; } auto &Sec = makeSection(Shdr); - Sec.Name = std::string(unwrapOrError(ElfFile.getSectionName(&Shdr))); + Sec.Name = std::string(unwrapOrError(ElfFile.getSectionName(Shdr))); Sec.Type = Sec.OriginalType = Shdr.sh_type; Sec.Flags = Sec.OriginalFlags = Shdr.sh_flags; Sec.Addr = Shdr.sh_addr; @@ -1560,7 +1560,7 @@ } template void ELFBuilder::readSections(bool EnsureSymtab) { - uint32_t ShstrIndex = ElfFile.getHeader()->e_shstrndx; + uint32_t ShstrIndex = ElfFile.getHeader().e_shstrndx; if (ShstrIndex == SHN_XINDEX) ShstrIndex = unwrapOrError(ElfFile.getSection(0))->sh_link; @@ -1602,10 +1602,10 @@ auto Shdr = unwrapOrError(ElfFile.sections()).begin() + RelSec->Index; if (RelSec->Type == SHT_REL) initRelocations(RelSec, Obj.SymbolTable, - unwrapOrError(ElfFile.rels(Shdr))); + unwrapOrError(ElfFile.rels(*Shdr))); else initRelocations(RelSec, Obj.SymbolTable, - unwrapOrError(ElfFile.relas(Shdr))); + unwrapOrError(ElfFile.relas(*Shdr))); } else if (auto GroupSec = dyn_cast(&Sec)) { initGroupSection(GroupSec); } @@ -1622,7 +1622,7 @@ ELFFile HeadersFile = unwrapOrError(ELFFile::create(toStringRef( {ElfFile.base() + EhdrOffset, ElfFile.getBufSize() - EhdrOffset}))); - auto &Ehdr = *HeadersFile.getHeader(); + auto &Ehdr = HeadersFile.getHeader(); Obj.OSABI = Ehdr.e_ident[EI_OSABI]; Obj.ABIVersion = Ehdr.e_ident[EI_ABIVERSION]; Obj.Type = Ehdr.e_type; diff --git a/llvm/tools/llvm-objdump/ELFDump.cpp b/llvm/tools/llvm-objdump/ELFDump.cpp --- a/llvm/tools/llvm-objdump/ELFDump.cpp +++ b/llvm/tools/llvm-objdump/ELFDump.cpp @@ -92,7 +92,7 @@ return SymSI.takeError(); const typename ELFT::Shdr *SymSec = Obj->getSection((*SymSI)->getRawDataRefImpl()); - auto SecName = EF.getSectionName(SymSec); + auto SecName = EF.getSectionName(*SymSec); if (!SecName) return SecName.takeError(); Fmt << *SecName; @@ -338,10 +338,10 @@ 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); + StringRef StrTab = unwrapOrError(Elf->getStringTable(*StrTabSec), FileName); if (Shdr.sh_type == ELF::SHT_GNU_verneed) printSymbolVersionDependency(Contents, StrTab); diff --git a/llvm/tools/llvm-readobj/ARMEHABIPrinter.h b/llvm/tools/llvm-readobj/ARMEHABIPrinter.h --- a/llvm/tools/llvm-readobj/ARMEHABIPrinter.h +++ b/llvm/tools/llvm-readobj/ARMEHABIPrinter.h @@ -407,7 +407,7 @@ reportError(SymTabOrErr.takeError(), FileName); const Elf_Shdr *SymTab = *SymTabOrErr; - for (const Elf_Rel &R : unwrapOrError(FileName, ELF->rels(&Sec))) { + for (const Elf_Rel &R : unwrapOrError(FileName, ELF->rels(Sec))) { if (R.r_offset != static_cast(IndexTableOffset)) continue; @@ -417,9 +417,9 @@ RelA.r_addend = 0; const Elf_Sym *Symbol = - unwrapOrError(FileName, ELF->getRelocationSymbol(&RelA, SymTab)); + unwrapOrError(FileName, ELF->getRelocationSymbol(RelA, SymTab)); - auto Ret = ELF->getSection(Symbol, SymTab, ShndxTable); + auto Ret = ELF->getSection(*Symbol, SymTab, ShndxTable); if (!Ret) report_fatal_error(errorToErrorCode(Ret.takeError()).message()); return *Ret; @@ -432,7 +432,7 @@ void PrinterContext::PrintExceptionTable(const Elf_Shdr *IT, const Elf_Shdr *EHT, uint64_t TableEntryOffset) const { - Expected> Contents = ELF->getSectionContents(EHT); + Expected> Contents = ELF->getSectionContents(*EHT); if (!Contents) return; @@ -499,7 +499,7 @@ template void PrinterContext::PrintIndexTable(unsigned SectionIndex, const Elf_Shdr *IT) const { - Expected> Contents = ELF->getSectionContents(IT); + Expected> Contents = ELF->getSectionContents(*IT); if (!Contents) return; @@ -553,7 +553,7 @@ FindExceptionTable(SectionIndex, Entry * IndexTableEntrySize + 4); if (EHT) - if (auto Name = ELF->getSectionName(EHT)) + if (auto Name = ELF->getSectionName(*EHT)) SW.printString("ExceptionHandlingTable", *Name); uint64_t TableEntryOffset = PREL31(Word1, IT->sh_addr); @@ -575,7 +575,7 @@ DictScope UIT(SW, "UnwindIndexTable"); SW.printNumber("SectionIndex", SectionIndex); - if (auto SectionName = ELF->getSectionName(&Sec)) + if (auto SectionName = ELF->getSectionName(Sec)) SW.printString("SectionName", *SectionName); SW.printHex("SectionOffset", Sec.sh_offset); diff --git a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h --- a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h +++ b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h @@ -85,7 +85,7 @@ reportError(SectionsOrErr.takeError(), ObjF->getFileName()); for (const Elf_Shdr &Shdr : *SectionsOrErr) { - Expected NameOrErr = Obj->getSectionName(&Shdr); + Expected NameOrErr = Obj->getSectionName(Shdr); if (!NameOrErr) reportError(NameOrErr.takeError(), ObjF->getFileName()); if (*NameOrErr == ".eh_frame") @@ -104,13 +104,13 @@ const object::ELFFile *Obj = ObjF->getELFFile(); if (const Elf_Shdr *EHFrameHdr = findSectionByAddress(ObjF, EHFramePHdr->p_vaddr)) { - Expected NameOrErr = Obj->getSectionName(EHFrameHdr); + Expected NameOrErr = Obj->getSectionName(*EHFrameHdr); if (!NameOrErr) reportError(NameOrErr.takeError(), ObjF->getFileName()); W.printString("Corresponding Section", *NameOrErr); } - Expected> Content = Obj->getSegmentContents(EHFramePHdr); + Expected> Content = Obj->getSegmentContents(*EHFramePHdr); if (!Content) reportError(Content.takeError(), ObjF->getFileName()); @@ -181,7 +181,7 @@ W.indent(); Expected> DataOrErr = - ObjF->getELFFile()->getSectionContents(EHFrameShdr); + ObjF->getELFFile()->getSectionContents(*EHFrameShdr); if (!DataOrErr) reportError(DataOrErr.takeError(), ObjF->getFileName()); diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -404,7 +404,7 @@ 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, + return (object::getELFSectionTypeName(Obj.getHeader().e_machine, Sec.sh_type) + " section with index " + Twine(SecNdx)) .str(); @@ -424,7 +424,7 @@ 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())); @@ -443,13 +443,12 @@ ": " + 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) @@ -477,7 +476,7 @@ return createError("the " + describe(*Sec) + " is misaligned"); Expected> VersionsOrErr = - Obj->template getSectionContentsAsArray(Sec); + Obj->template getSectionContentsAsArray(*Sec); if (!VersionsOrErr) return createError("cannot read content of " + describe(*Sec) + ": " + toString(VersionsOrErr.takeError())); @@ -511,7 +510,7 @@ if (!StrTabOrErr) return StrTabOrErr.takeError(); - Expected> ContentsOrErr = Obj->getSectionContents(Sec); + Expected> ContentsOrErr = Obj->getSectionContents(*Sec); if (!ContentsOrErr) return createError("cannot read content of " + describe(*Sec) + ": " + toString(ContentsOrErr.takeError())); @@ -600,7 +599,7 @@ else StrTab = *StrTabOrErr; - Expected> ContentsOrErr = Obj->getSectionContents(Sec); + Expected> ContentsOrErr = Obj->getSectionContents(*Sec); if (!ContentsOrErr) return createError("cannot read content of " + describe(*Sec) + ": " + toString(ContentsOrErr.takeError())); @@ -1069,7 +1068,7 @@ // Get the corresponding version index entry. if (Expected EntryOrErr = ObjF->getELFFile()->template getEntry( - SymbolVersionSection, EntryIndex)) + *SymbolVersionSection, EntryIndex)) return this->getSymbolVersionByIndex((*EntryOrErr)->vs_index, IsDefault); else return EntryOrErr.takeError(); @@ -1084,7 +1083,7 @@ const ELFFile &Obj = *ObjF->getELFFile(); Expected SymOrErr = - Obj.template getEntry(SymTab, R.Symbol); + Obj.template getEntry(*SymTab, R.Symbol); if (!SymOrErr) return SymOrErr.takeError(); const Elf_Sym *Sym = *SymOrErr; @@ -1095,14 +1094,14 @@ // This code block returns the section name. if (Sym->getType() == ELF::STT_SECTION) { Expected SecOrErr = - Obj.getSection(Sym, SymTab, ShndxTable); + Obj.getSection(*Sym, SymTab, ShndxTable); if (!SecOrErr) return SecOrErr.takeError(); // A section symbol describes the section at index 0. if (*SecOrErr == nullptr) return RelSymbol(Sym, ""); - Expected NameOrErr = Obj.getSectionName(*SecOrErr); + Expected NameOrErr = Obj.getSectionName(**SecOrErr); if (!NameOrErr) return NameOrErr.takeError(); return RelSymbol(Sym, NameOrErr->str()); @@ -1227,7 +1226,7 @@ ELFDumper::getSymbolSectionIndex(const Elf_Sym *Symbol, const Elf_Sym *FirstSym) const { return Symbol->st_shndx == SHN_XINDEX - ? object::getExtendedSymbolTableIndex(Symbol, FirstSym, + ? object::getExtendedSymbolTableIndex(*Symbol, *FirstSym, ShndxTable) : Symbol->st_shndx; } @@ -1259,7 +1258,7 @@ Obj->getSection(SectionIndex); if (!SecOrErr) return SecOrErr.takeError(); - return Obj->getSectionName(*SecOrErr); + return Obj->getSectionName(**SecOrErr); } template @@ -2423,7 +2422,7 @@ ELFDumper::findSectionByName(StringRef Name) const { const ELFFile *Obj = ObjF->getELFFile(); for (const Elf_Shdr &Shdr : cantFail(Obj->sections())) { - if (Expected NameOrErr = Obj->getSectionName(&Shdr)) { + if (Expected NameOrErr = Obj->getSectionName(Shdr)) { if (*NameOrErr == Name) return &Shdr; } else { @@ -2456,7 +2455,7 @@ }; // Handle custom printing of architecture specific tags - switch (ObjF->getELFFile()->getHeader()->e_machine) { + switch (ObjF->getELFFile()->getHeader().e_machine) { case EM_AARCH64: switch (Type) { case DT_AARCH64_BTI_PLT: @@ -2653,7 +2652,7 @@ template <> void ELFDumper::printUnwindInfo() { const ELFFile *Obj = ObjF->getELFFile(); - const unsigned Machine = Obj->getHeader()->e_machine; + const unsigned Machine = Obj->getHeader().e_machine; if (Machine == EM_ARM) { ARM::EHABI::PrinterContext Ctx(W, Obj, ObjF->getFileName(), DotSymtabSec); @@ -2832,7 +2831,7 @@ template void ELFDumper::printArchSpecificInfo() { const ELFFile *Obj = ObjF->getELFFile(); - switch (Obj->getHeader()->e_machine) { + switch (Obj->getHeader().e_machine) { case EM_ARM: case EM_RISCV: printAttributes(); @@ -2867,7 +2866,7 @@ return; } - const unsigned Machine = Obj->getHeader()->e_machine; + const unsigned Machine = Obj->getHeader().e_machine; assert((Machine == EM_ARM || Machine == EM_RISCV) && "Attributes not implemented."); @@ -2878,7 +2877,7 @@ continue; ArrayRef Contents = - unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(&Sec)); + unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(Sec)); if (Contents[0] != ELFAttrs::Format_Version) { reportWarning(createError(Twine("unrecognised FormatVersion: 0x") + Twine::utohexstr(Contents[0])), @@ -2978,7 +2977,7 @@ return Error::success(); ArrayRef Content = - unwrapOrError(FileName, Obj->getSectionContents(GotSec)); + unwrapOrError(FileName, Obj->getSectionContents(*GotSec)); GotEntries = Entries(reinterpret_cast(Content.data()), Content.size() / sizeof(Entry)); LocalNum = GotEntries.size(); @@ -3028,7 +3027,7 @@ GlobalNum = DynSymTotal - *DtGotSym; ArrayRef Content = - unwrapOrError(FileName, Obj->getSectionContents(GotSec)); + unwrapOrError(FileName, Obj->getSectionContents(*GotSec)); GotEntries = Entries(reinterpret_cast(Content.data()), Content.size() / sizeof(Entry)); GotDynSyms = DynSyms.drop_front(*DtGotSym); @@ -3072,7 +3071,7 @@ Twine::utohexstr(*DtJmpRel)); if (Expected> PltContentOrErr = - Obj->getSectionContents(PltSec)) + Obj->getSectionContents(*PltSec)) PltEntries = Entries(reinterpret_cast(PltContentOrErr->data()), PltContentOrErr->size() / sizeof(Entry)); @@ -3196,13 +3195,13 @@ MipsGOTParser::getPltSym(const Entry *E) const { int64_t Offset = std::distance(getPltEntries().data(), E); if (PltRelSec->sh_type == ELF::SHT_REL) { - Elf_Rel_Range Rels = unwrapOrError(FileName, Obj->rels(PltRelSec)); + Elf_Rel_Range Rels = unwrapOrError(FileName, Obj->rels(*PltRelSec)); return unwrapOrError(FileName, - Obj->getRelocationSymbol(&Rels[Offset], PltSymTable)); + Obj->getRelocationSymbol(Rels[Offset], PltSymTable)); } else { - Elf_Rela_Range Rels = unwrapOrError(FileName, Obj->relas(PltRelSec)); + Elf_Rela_Range Rels = unwrapOrError(FileName, Obj->relas(*PltRelSec)); return unwrapOrError(FileName, - Obj->getRelocationSymbol(&Rels[Offset], PltSymTable)); + Obj->getRelocationSymbol(Rels[Offset], PltSymTable)); } } @@ -3299,7 +3298,7 @@ const ELFFile *Obj = ObjF->getELFFile(); Expected> ContentsOrErr = - Obj->getSectionContents(RegInfoSec); + Obj->getSectionContents(*RegInfoSec); if (!ContentsOrErr) { this->reportUniqueWarning(createError( "unable to read the content of the .reginfo section (" + @@ -3367,7 +3366,7 @@ DictScope GS(W, "MIPS Options"); ArrayRef Data = - unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(MipsOpts)); + unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(*MipsOpts)); const uint8_t *const SecBegin = Data.begin(); while (!Data.empty()) { bool IsSupported; @@ -3407,7 +3406,7 @@ }; Expected> ContentOrErr = - Obj->getSectionContents(StackMapSection); + Obj->getSectionContents(*StackMapSection); if (!ContentOrErr) { Warn(ContentOrErr.takeError()); return; @@ -3442,9 +3441,9 @@ template static std::string getSectionHeadersNumString(const ELFFile &Obj, StringRef FileName) { - const typename ELFT::Ehdr *ElfHeader = Obj.getHeader(); - if (ElfHeader->e_shnum != 0) - return to_string(ElfHeader->e_shnum); + const typename ELFT::Ehdr &ElfHeader = Obj.getHeader(); + if (ElfHeader.e_shnum != 0) + return to_string(ElfHeader.e_shnum); ArrayRef Arr = cantFail(Obj.sections()); if (Arr.empty()) @@ -3455,71 +3454,71 @@ template static std::string getSectionHeaderTableIndexString(const ELFFile &Obj, StringRef FileName) { - const typename ELFT::Ehdr *ElfHeader = Obj.getHeader(); - if (ElfHeader->e_shstrndx != SHN_XINDEX) - return to_string(ElfHeader->e_shstrndx); + const typename ELFT::Ehdr &ElfHeader = Obj.getHeader(); + if (ElfHeader.e_shstrndx != SHN_XINDEX) + return to_string(ElfHeader.e_shstrndx); 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) + + return to_string(ElfHeader.e_shstrndx) + " (" + to_string(Arr[0].sh_link) + ")"; } template void GNUStyle::printFileHeaders() { - const Elf_Ehdr *e = this->Obj.getHeader(); + const Elf_Ehdr &e = this->Obj.getHeader(); OS << "ELF Header:\n"; OS << " Magic: "; std::string Str; for (int i = 0; i < ELF::EI_NIDENT; i++) - OS << format(" %02x", static_cast(e->e_ident[i])); + OS << format(" %02x", static_cast(e.e_ident[i])); OS << "\n"; - Str = printEnum(e->e_ident[ELF::EI_CLASS], makeArrayRef(ElfClass)); + Str = printEnum(e.e_ident[ELF::EI_CLASS], makeArrayRef(ElfClass)); printFields(OS, "Class:", Str); - Str = printEnum(e->e_ident[ELF::EI_DATA], makeArrayRef(ElfDataEncoding)); + Str = printEnum(e.e_ident[ELF::EI_DATA], makeArrayRef(ElfDataEncoding)); printFields(OS, "Data:", Str); OS.PadToColumn(2u); OS << "Version:"; OS.PadToColumn(37u); - OS << to_hexString(e->e_ident[ELF::EI_VERSION]); - if (e->e_version == ELF::EV_CURRENT) + OS << to_hexString(e.e_ident[ELF::EI_VERSION]); + if (e.e_version == ELF::EV_CURRENT) OS << " (current)"; OS << "\n"; - Str = printEnum(e->e_ident[ELF::EI_OSABI], makeArrayRef(ElfOSABI)); + Str = printEnum(e.e_ident[ELF::EI_OSABI], makeArrayRef(ElfOSABI)); printFields(OS, "OS/ABI:", Str); printFields(OS, - "ABI Version:", std::to_string(e->e_ident[ELF::EI_ABIVERSION])); - Str = printEnum(e->e_type, makeArrayRef(ElfObjectFileType)); + "ABI Version:", std::to_string(e.e_ident[ELF::EI_ABIVERSION])); + Str = printEnum(e.e_type, makeArrayRef(ElfObjectFileType)); printFields(OS, "Type:", Str); - Str = printEnum(e->e_machine, makeArrayRef(ElfMachineType)); + Str = printEnum(e.e_machine, makeArrayRef(ElfMachineType)); printFields(OS, "Machine:", Str); - Str = "0x" + to_hexString(e->e_version); + Str = "0x" + to_hexString(e.e_version); printFields(OS, "Version:", Str); - Str = "0x" + to_hexString(e->e_entry); + Str = "0x" + to_hexString(e.e_entry); printFields(OS, "Entry point address:", Str); - Str = to_string(e->e_phoff) + " (bytes into file)"; + Str = to_string(e.e_phoff) + " (bytes into file)"; printFields(OS, "Start of program headers:", Str); - Str = to_string(e->e_shoff) + " (bytes into file)"; + Str = to_string(e.e_shoff) + " (bytes into file)"; printFields(OS, "Start of section headers:", Str); std::string ElfFlags; - if (e->e_machine == EM_MIPS) + if (e.e_machine == EM_MIPS) ElfFlags = - printFlags(e->e_flags, makeArrayRef(ElfHeaderMipsFlags), + printFlags(e.e_flags, makeArrayRef(ElfHeaderMipsFlags), unsigned(ELF::EF_MIPS_ARCH), unsigned(ELF::EF_MIPS_ABI), unsigned(ELF::EF_MIPS_MACH)); - else if (e->e_machine == EM_RISCV) - ElfFlags = printFlags(e->e_flags, makeArrayRef(ElfHeaderRISCVFlags)); - Str = "0x" + to_hexString(e->e_flags); + else if (e.e_machine == EM_RISCV) + ElfFlags = printFlags(e.e_flags, makeArrayRef(ElfHeaderRISCVFlags)); + Str = "0x" + to_hexString(e.e_flags); if (!ElfFlags.empty()) Str = Str + ", " + ElfFlags; printFields(OS, "Flags:", Str); - Str = to_string(e->e_ehsize) + " (bytes)"; + Str = to_string(e.e_ehsize) + " (bytes)"; printFields(OS, "Size of this header:", Str); - Str = to_string(e->e_phentsize) + " (bytes)"; + Str = to_string(e.e_phentsize) + " (bytes)"; printFields(OS, "Size of program headers:", Str); - Str = to_string(e->e_phnum); + Str = to_string(e.e_phnum); printFields(OS, "Number of program headers:", Str); - Str = to_string(e->e_shentsize) + " (bytes)"; + Str = to_string(e.e_shentsize) + " (bytes)"; printFields(OS, "Size of section headers:", Str); Str = getSectionHeadersNumString(this->Obj, this->FileName); printFields(OS, "Number of section headers:", Str); @@ -3563,11 +3562,11 @@ StringRef StrTable = 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), @@ -3580,7 +3579,7 @@ std::vector &GM = Ret.back().Members; for (uint32_t Ndx : Data.slice(1)) { - auto Sec = unwrapOrError(FileName, Obj.getSection(Ndx)); + const Elf_Shdr &Sec = *unwrapOrError(FileName, Obj.getSection(Ndx)); const StringRef Name = unwrapOrError(FileName, Obj.getSectionName(Sec)); GM.push_back({Name, Ndx}); } @@ -3727,7 +3726,7 @@ if (Sec.sh_type == ELF::SHT_ANDROID_REL || Sec.sh_type == ELF::SHT_ANDROID_RELA) { Expected> RelasOrErr = - this->Obj.android_relas(&Sec); + this->Obj.android_relas(Sec); if (!RelasOrErr) return RelasOrErr.takeError(); return RelasOrErr->size(); @@ -3735,7 +3734,7 @@ if (!opts::RawRelr && (Sec.sh_type == ELF::SHT_RELR || Sec.sh_type == ELF::SHT_ANDROID_RELR)) { - Expected RelrsOrErr = this->Obj.relrs(&Sec); + Expected RelrsOrErr = this->Obj.relrs(Sec); if (!RelrsOrErr) return RelrsOrErr.takeError(); return this->Obj.decode_relrs(*RelrsOrErr).size(); @@ -3827,7 +3826,7 @@ ArrayRef Sections = cantFail(this->Obj.sections()); OS << "There are " << to_string(Sections.size()) << " section headers, starting at offset " - << "0x" << to_hexString(this->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}, @@ -3852,15 +3851,15 @@ Fields[1].Str = ""; else Fields[1].Str = std::string(unwrapOrError( - this->FileName, this->Obj.getSectionName(&Sec, SecStrTable))); + this->FileName, this->Obj.getSectionName(Sec, SecStrTable))); Fields[2].Str = - getSectionTypeString(this->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(this->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); @@ -3880,7 +3879,7 @@ OS << "\n"; ++SectionIndex; } - printSectionDescription(OS, this->Obj.getHeader()->e_machine); + printSectionDescription(OS, this->Obj.getHeader().e_machine); } template @@ -3918,7 +3917,7 @@ return "COM"; case ELF::SHN_XINDEX: { Expected IndexOrErr = object::getExtendedSymbolTableIndex( - Symbol, FirstSym, this->dumper()->getShndxTable()); + *Symbol, *FirstSym, this->dumper()->getShndxTable()); if (!IndexOrErr) { assert(Symbol->st_shndx == SHN_XINDEX && "getSymbolSectionIndex should only fail due to an invalid " @@ -3961,7 +3960,7 @@ Fields[2].Str = to_string(format_decimal(Symbol->st_size, 5)); unsigned char SymbolType = Symbol->getType(); - if (this->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 @@ -4000,7 +3999,7 @@ Fields[3].Str = to_string(format_decimal(Symbol->st_size, 5)); unsigned char SymbolType = Symbol->getType(); - if (this->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 @@ -4227,14 +4226,14 @@ template void GNUStyle::printProgramHeaders() { unsigned Bias = ELFT::Is64Bits ? 8 : 0; - const Elf_Ehdr *Header = this->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 " - << printEnum(Header->e_type, makeArrayRef(ElfObjectFileType)) << "\n" - << "Entry point " << format_hex(Header->e_entry, 3) << "\n" - << "There are " << Header->e_phnum << " program headers," - << " starting at offset " << Header->e_phoff << "\n\n" + << printEnum(Header.e_type, makeArrayRef(ElfObjectFileType)) << "\n" + << "Entry point " << format_hex(Header.e_entry, 3) << "\n" + << "There are " << Header.e_phnum << " program headers," + << " starting at offset " << Header.e_phoff << "\n\n" << "Program Headers:\n"; if (ELFT::Is64Bits) OS << " Type Offset VirtAddr PhysAddr " @@ -4254,7 +4253,7 @@ } for (const Elf_Phdr &Phdr : *PhdrsOrErr) { - Fields[0].Str = getGNUPtType(Header->e_machine, Phdr.p_type); + Fields[0].Str = getGNUPtType(Header.e_machine, Phdr.p_type); Fields[1].Str = to_string(format_hex(Phdr.p_offset, 8)); Fields[2].Str = to_string(format_hex(Phdr.p_vaddr, Width)); Fields[3].Str = to_string(format_hex(Phdr.p_paddr, Width)); @@ -4322,8 +4321,7 @@ if (checkTLSSections(Phdr, Sec) && checkOffsets(Phdr, Sec) && checkVMA(Phdr, Sec) && checkPTDynamic(Phdr, Sec)) { Sections += - unwrapOrError(this->FileName, this->Obj.getSectionName(&Sec)) - .str() + + unwrapOrError(this->FileName, this->Obj.getSectionName(Sec)).str() + " "; BelongsToSegment.insert(&Sec); } @@ -4337,7 +4335,7 @@ for (const Elf_Shdr &Sec : cantFail(this->Obj.sections())) { if (BelongsToSegment.find(&Sec) == BelongsToSegment.end()) Sections += - unwrapOrError(this->FileName, this->Obj.getSectionName(&Sec)).str() + + unwrapOrError(this->FileName, this->Obj.getSectionName(Sec)).str() + ' '; } if (!Sections.empty()) { @@ -4478,7 +4476,7 @@ void GNUStyle::printGNUVersionSectionProlog( const typename ELFT::Shdr *Sec, const Twine &Label, unsigned EntriesNum) { StringRef SecName = - unwrapOrError(this->FileName, this->Obj.getSectionName(Sec)); + unwrapOrError(this->FileName, this->Obj.getSectionName(*Sec)); OS << Label << " section '" << SecName << "' " << "contains " << EntriesNum << " entries:\n"; @@ -4487,7 +4485,7 @@ this->Obj.getSection(Sec->sh_link); if (SymTabOrErr) SymTabName = - unwrapOrError(this->FileName, this->Obj.getSectionName(*SymTabOrErr)); + unwrapOrError(this->FileName, this->Obj.getSectionName(**SymTabOrErr)); else this->reportUniqueWarning(createError("invalid section linked to " + describe(this->Obj, *Sec) + ": " + @@ -5273,7 +5271,7 @@ << format_hex(Descriptor.size(), 10) << '\t'; StringRef NoteType = - getNoteTypeName(Note, this->Obj.getHeader()->e_type); + getNoteTypeName(Note, this->Obj.getHeader().e_type); if (!NoteType.empty()) OS << NoteType << '\n'; else @@ -5311,11 +5309,11 @@ }; ArrayRef Sections = cantFail(this->Obj.sections()); - if (this->Obj.getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) { - for (const auto &S : Sections) { + if (this->Obj.getHeader().e_type != ELF::ET_CORE && !Sections.empty()) { + for (const Elf_Shdr &S : Sections) { if (S.sh_type != SHT_NOTE) continue; - PrintHeader(expectedToOptional(this->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 : this->Obj.notes(S, Err)) @@ -5367,7 +5365,7 @@ OnSectionStart(Shdr); - Expected> ContentsOrErr = Obj.getSectionContents(&Shdr); + Expected> ContentsOrErr = Obj.getSectionContents(Shdr); if (!ContentsOrErr) { Warn(I, toString(ContentsOrErr.takeError())); continue; @@ -5412,7 +5410,7 @@ const bool IsMips64EL = this->Obj.isMips64EL(); 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) printReloc(Relocation(R, IsMips64EL), ++RelNdx, Sec, SymTab); } else { @@ -5420,7 +5418,7 @@ } break; case ELF::SHT_RELA: - if (Expected RangeOrErr = Obj.relas(&Sec)) { + if (Expected RangeOrErr = Obj.relas(Sec)) { for (const Elf_Rela &R : *RangeOrErr) printReloc(Relocation(R, IsMips64EL), ++RelNdx, Sec, SymTab); } else { @@ -5429,7 +5427,7 @@ 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; @@ -5447,7 +5445,7 @@ } 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) printReloc(Relocation(R, IsMips64EL), ++RelNdx, Sec, SymTab); } else { @@ -5461,7 +5459,7 @@ 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 " + @@ -5659,7 +5657,7 @@ PrintHeader(); const Elf_Shdr *ElfSec = Obj->getSection(Sec.getRawDataRefImpl()); ArrayRef Contents = - unwrapOrError(this->FileName, EF->getSectionContents(ElfSec)); + unwrapOrError(this->FileName, EF->getSectionContents(*ElfSec)); DataExtractor Data(Contents, Obj->isLittleEndian(), sizeof(Elf_Addr)); uint64_t Offset = 0; while (Offset < Contents.size()) { @@ -5724,7 +5722,7 @@ const Elf_Shdr *ContentsSec = Obj->getSection((*RelSecOrErr)->getRawDataRefImpl()); Expected ContentsSectionNameOrErr = - EF->getSectionName(ContentsSec); + EF->getSectionName(*ContentsSec); if (!ContentsSectionNameOrErr) { consumeError(ContentsSectionNameOrErr.takeError()); continue; @@ -5936,7 +5934,7 @@ const ELFFile *Obj = ObjF->getELFFile(); constexpr StringRef ErrPrefix = "unable to read the .MIPS.abiflags section: "; - Expected> DataOrErr = Obj->getSectionContents(Sec); + Expected> DataOrErr = Obj->getSectionContents(*Sec); if (!DataOrErr) return createError(ErrPrefix + toString(DataOrErr.takeError())); @@ -5981,21 +5979,21 @@ } template void LLVMStyle::printFileHeaders() { - const Elf_Ehdr *E = this->Obj.getHeader(); + const Elf_Ehdr &E = this->Obj.getHeader(); { DictScope D(W, "ElfHeader"); { DictScope D(W, "Ident"); - W.printBinary("Magic", makeArrayRef(E->e_ident).slice(ELF::EI_MAG0, 4)); - W.printEnum("Class", E->e_ident[ELF::EI_CLASS], makeArrayRef(ElfClass)); - W.printEnum("DataEncoding", E->e_ident[ELF::EI_DATA], + W.printBinary("Magic", makeArrayRef(E.e_ident).slice(ELF::EI_MAG0, 4)); + W.printEnum("Class", E.e_ident[ELF::EI_CLASS], makeArrayRef(ElfClass)); + W.printEnum("DataEncoding", E.e_ident[ELF::EI_DATA], makeArrayRef(ElfDataEncoding)); - W.printNumber("FileVersion", E->e_ident[ELF::EI_VERSION]); + W.printNumber("FileVersion", E.e_ident[ELF::EI_VERSION]); auto OSABI = makeArrayRef(ElfOSABI); - if (E->e_ident[ELF::EI_OSABI] >= ELF::ELFOSABI_FIRST_ARCH && - E->e_ident[ELF::EI_OSABI] <= ELF::ELFOSABI_LAST_ARCH) { - switch (E->e_machine) { + if (E.e_ident[ELF::EI_OSABI] >= ELF::ELFOSABI_FIRST_ARCH && + E.e_ident[ELF::EI_OSABI] <= ELF::ELFOSABI_LAST_ARCH) { + switch (E.e_machine) { case ELF::EM_AMDGPU: OSABI = makeArrayRef(AMDGPUElfOSABI); break; @@ -6007,32 +6005,32 @@ break; } } - W.printEnum("OS/ABI", E->e_ident[ELF::EI_OSABI], OSABI); - W.printNumber("ABIVersion", E->e_ident[ELF::EI_ABIVERSION]); - W.printBinary("Unused", makeArrayRef(E->e_ident).slice(ELF::EI_PAD)); + W.printEnum("OS/ABI", E.e_ident[ELF::EI_OSABI], OSABI); + W.printNumber("ABIVersion", E.e_ident[ELF::EI_ABIVERSION]); + W.printBinary("Unused", makeArrayRef(E.e_ident).slice(ELF::EI_PAD)); } - W.printEnum("Type", E->e_type, makeArrayRef(ElfObjectFileType)); - W.printEnum("Machine", E->e_machine, makeArrayRef(ElfMachineType)); - W.printNumber("Version", E->e_version); - W.printHex("Entry", E->e_entry); - W.printHex("ProgramHeaderOffset", E->e_phoff); - W.printHex("SectionHeaderOffset", E->e_shoff); - if (E->e_machine == EM_MIPS) - W.printFlags("Flags", E->e_flags, makeArrayRef(ElfHeaderMipsFlags), + W.printEnum("Type", E.e_type, makeArrayRef(ElfObjectFileType)); + W.printEnum("Machine", E.e_machine, makeArrayRef(ElfMachineType)); + W.printNumber("Version", E.e_version); + W.printHex("Entry", E.e_entry); + W.printHex("ProgramHeaderOffset", E.e_phoff); + W.printHex("SectionHeaderOffset", E.e_shoff); + if (E.e_machine == EM_MIPS) + W.printFlags("Flags", E.e_flags, makeArrayRef(ElfHeaderMipsFlags), unsigned(ELF::EF_MIPS_ARCH), unsigned(ELF::EF_MIPS_ABI), unsigned(ELF::EF_MIPS_MACH)); - else if (E->e_machine == EM_AMDGPU) - W.printFlags("Flags", E->e_flags, makeArrayRef(ElfHeaderAMDGPUFlags), + else if (E.e_machine == EM_AMDGPU) + W.printFlags("Flags", E.e_flags, makeArrayRef(ElfHeaderAMDGPUFlags), unsigned(ELF::EF_AMDGPU_MACH)); - else if (E->e_machine == EM_RISCV) - W.printFlags("Flags", E->e_flags, makeArrayRef(ElfHeaderRISCVFlags)); + else if (E.e_machine == EM_RISCV) + W.printFlags("Flags", E.e_flags, makeArrayRef(ElfHeaderRISCVFlags)); else - W.printFlags("Flags", E->e_flags); - W.printNumber("HeaderSize", E->e_ehsize); - W.printNumber("ProgramHeaderEntrySize", E->e_phentsize); - W.printNumber("ProgramHeaderCount", E->e_phnum); - W.printNumber("SectionHeaderEntrySize", E->e_shentsize); + W.printFlags("Flags", E.e_flags); + W.printNumber("HeaderSize", E.e_ehsize); + W.printNumber("ProgramHeaderEntrySize", E.e_phentsize); + W.printNumber("ProgramHeaderCount", E.e_phnum); + W.printNumber("SectionHeaderEntrySize", E.e_shentsize); W.printString("SectionHeaderCount", getSectionHeadersNumString(this->Obj, this->FileName)); W.printString("StringTableSectionIndex", @@ -6133,13 +6131,13 @@ int SectionIndex = -1; std::vector> FlagsList = - getSectionFlagsForTarget(this->Obj.getHeader()->e_machine); + 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(Sec), Sec.sh_name); W.printHex("Type", - object::getELFSectionTypeName(this->Obj.getHeader()->e_machine, + object::getELFSectionTypeName(this->Obj.getHeader().e_machine, Sec.sh_type), Sec.sh_type); W.printFlags("Flags", Sec.sh_flags, makeArrayRef(FlagsList)); @@ -6167,7 +6165,7 @@ const Elf_Shdr *SymSec = unwrapOrError(this->FileName, this->Obj.getSection( - &Sym, Symtab, this->dumper()->getShndxTable())); + Sym, Symtab, this->dumper()->getShndxTable())); if (SymSec == &Sec) printSymbol(&Sym, unwrapOrError(this->FileName, this->Obj.symbols(Symtab)) @@ -6179,7 +6177,7 @@ if (opts::SectionData && Sec.sh_type != ELF::SHT_NOBITS) { ArrayRef Data = - unwrapOrError(this->FileName, this->Obj.getSectionContents(&Sec)); + unwrapOrError(this->FileName, this->Obj.getSectionContents(Sec)); W.printBinaryBlock( "SectionData", StringRef(reinterpret_cast(Data.data()), Data.size())); @@ -6229,7 +6227,7 @@ W.printHex("Value", Symbol->st_value); W.printNumber("Size", Symbol->st_size); W.printEnum("Binding", Symbol->getBinding(), makeArrayRef(ElfSymbolBindings)); - if (this->Obj.getHeader()->e_machine == ELF::EM_AMDGPU && + if (this->Obj.getHeader().e_machine == ELF::EM_AMDGPU && SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS) W.printEnum("Type", SymbolType, makeArrayRef(AMDGPUSymbolTypes)); else @@ -6241,7 +6239,7 @@ else { std::vector> SymOtherFlags(std::begin(ElfSymOtherFlags), std::end(ElfSymOtherFlags)); - if (this->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. @@ -6342,7 +6340,7 @@ for (const Elf_Phdr &Phdr : *PhdrsOrErr) { DictScope P(W, "ProgramHeader"); StringRef Type = - segmentTypeToString(this->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); @@ -6452,7 +6450,7 @@ Expected> CGProfileOrErr = this->Obj.template getSectionContentsAsArray( - this->dumper()->getDotCGProfileSec()); + *this->dumper()->getDotCGProfileSec()); if (!CGProfileOrErr) { this->reportUniqueWarning( createError("unable to dump the SHT_LLVM_CALL_GRAPH_PROFILE section: " + @@ -6491,7 +6489,8 @@ if (!Sec) return; - Expected> ContentsOrErr = this->Obj.getSectionContents(Sec); + Expected> ContentsOrErr = + this->Obj.getSectionContents(*Sec); if (!ContentsOrErr) { this->reportUniqueWarning(ContentsOrErr.takeError()); return; @@ -6573,7 +6572,7 @@ W.printHex("Data size", Descriptor.size()); StringRef NoteType = - getNoteTypeName(Note, this->Obj.getHeader()->e_type); + getNoteTypeName(Note, this->Obj.getHeader().e_type); if (!NoteType.empty()) W.printString("Type", NoteType); else @@ -6609,12 +6608,12 @@ }; ArrayRef Sections = cantFail(this->Obj.sections()); - if (this->Obj.getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) { - for (const auto &S : Sections) { + if (this->Obj.getHeader().e_type != ELF::ET_CORE && !Sections.empty()) { + for (const Elf_Shdr &S : Sections) { if (S.sh_type != SHT_NOTE) continue; DictScope D(W, "NoteSection"); - PrintHeader(expectedToOptional(this->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 : this->Obj.notes(S, Err)) @@ -6655,7 +6654,7 @@ continue; Expected> ContentsOrErr = - this->Obj.getSectionContents(&Shdr); + this->Obj.getSectionContents(Shdr); if (!ContentsOrErr) { this->reportUniqueWarning( createError("unable to read the content of the " diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -124,7 +124,7 @@ if (!SectionNames[SecIndex].empty()) return SectionNames[SecIndex]; - auto NameOrErr = Obj.getSectionName(Sec); + auto NameOrErr = Obj.getSectionName(*Sec); if (!NameOrErr) return NameOrErr; StringRef Name = *NameOrErr; @@ -153,7 +153,7 @@ return SymbolNameOrErr; StringRef Name = *SymbolNameOrErr; if (Name.empty() && Sym->getType() == ELF::STT_SECTION) { - auto ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable); + auto ShdrOrErr = Obj.getSection(*Sym, SymTab, ShndxTable); if (!ShdrOrErr) return ShdrOrErr.takeError(); return getUniquedSectionName(*ShdrOrErr); @@ -235,14 +235,14 @@ // Dump header. We do not dump EPh* and ESh* fields. When not explicitly set, // the values are set by yaml2obj automatically and there is no need to dump // them here. - Y->Header.Class = ELFYAML::ELF_ELFCLASS(Obj.getHeader()->getFileClass()); - Y->Header.Data = ELFYAML::ELF_ELFDATA(Obj.getHeader()->getDataEncoding()); - Y->Header.OSABI = Obj.getHeader()->e_ident[ELF::EI_OSABI]; - Y->Header.ABIVersion = Obj.getHeader()->e_ident[ELF::EI_ABIVERSION]; - Y->Header.Type = Obj.getHeader()->e_type; - Y->Header.Machine = ELFYAML::ELF_EM(Obj.getHeader()->e_machine); - Y->Header.Flags = Obj.getHeader()->e_flags; - Y->Header.Entry = Obj.getHeader()->e_entry; + Y->Header.Class = ELFYAML::ELF_ELFCLASS(Obj.getHeader().getFileClass()); + Y->Header.Data = ELFYAML::ELF_ELFDATA(Obj.getHeader().getDataEncoding()); + Y->Header.OSABI = Obj.getHeader().e_ident[ELF::EI_OSABI]; + Y->Header.ABIVersion = Obj.getHeader().e_ident[ELF::EI_ABIVERSION]; + Y->Header.Type = Obj.getHeader().e_type; + Y->Header.Machine = ELFYAML::ELF_EM(Obj.getHeader().e_machine); + Y->Header.Flags = Obj.getHeader().e_flags; + Y->Header.Entry = Obj.getHeader().e_entry; // Dump sections auto SectionsOrErr = Obj.sections(); @@ -588,7 +588,7 @@ return Error::success(); } - auto ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable); + auto ShdrOrErr = Obj.getSection(*Sym, SymTab, ShndxTable); if (!ShdrOrErr) return ShdrOrErr.takeError(); const Elf_Shdr *Shdr = *ShdrOrErr; @@ -611,7 +611,7 @@ R.Offset = Rel->r_offset; R.Addend = 0; - auto SymOrErr = Obj.getRelocationSymbol(Rel, SymTab); + auto SymOrErr = Obj.getRelocationSymbol(*Rel, SymTab); if (!SymOrErr) return SymOrErr.takeError(); @@ -624,7 +624,7 @@ auto StrTabSec = Obj.getSection(SymTab->sh_link); if (!StrTabSec) return StrTabSec.takeError(); - auto StrTabOrErr = Obj.getStringTable(*StrTabSec); + auto StrTabOrErr = Obj.getStringTable(**StrTabSec); if (!StrTabOrErr) return StrTabOrErr.takeError(); @@ -725,7 +725,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - auto ContentOrErr = Obj.getSectionContents(Shdr); + auto ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError(); @@ -758,7 +758,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - auto ContentOrErr = Obj.getSectionContents(Shdr); + auto ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError(); @@ -799,7 +799,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - auto ContentOrErr = Obj.getSectionContents(Shdr); + auto ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError(); @@ -830,7 +830,7 @@ if (Error E = dumpCommonSection(Shdr, *DL)) return std::move(E); - Expected> ContentOrErr = Obj.getSectionContents(Shdr); + Expected> ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError(); @@ -857,7 +857,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - Expected> ContentOrErr = Obj.getSectionContents(Shdr); + Expected> ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError(); ArrayRef Content = *ContentOrErr; @@ -913,7 +913,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - auto DynTagsOrErr = Obj.template getSectionContentsAsArray(Shdr); + auto DynTagsOrErr = Obj.template getSectionContentsAsArray(*Shdr); if (!DynTagsOrErr) return DynTagsOrErr.takeError(); @@ -936,7 +936,7 @@ const Elf_Shdr *SymTab = *SymTabOrErr; if (Shdr->sh_type == ELF::SHT_REL) { - auto Rels = Obj.rels(Shdr); + auto Rels = Obj.rels(*Shdr); if (!Rels) return Rels.takeError(); for (const Elf_Rel &Rel : *Rels) { @@ -946,7 +946,7 @@ S->Relocations.push_back(R); } } else { - auto Rels = Obj.relas(Shdr); + auto Rels = Obj.relas(*Shdr); if (!Rels) return Rels.takeError(); for (const Elf_Rela &Rel : *Rels) { @@ -968,7 +968,7 @@ if (auto E = dumpCommonSection(Shdr, *S)) return std::move(E); - if (Expected> Relrs = Obj.relrs(Shdr)) { + if (Expected> Relrs = Obj.relrs(*Shdr)) { S->Entries.emplace(); for (Elf_Relr Rel : *Relrs) S->Entries->emplace_back(Rel); @@ -978,7 +978,7 @@ consumeError(Relrs.takeError()); } - Expected> ContentOrErr = Obj.getSectionContents(Shdr); + Expected> ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError(); S->Content = *ContentOrErr; @@ -994,7 +994,7 @@ unsigned SecIndex = Shdr - &Sections[0]; if (SecIndex != 0 || Shdr->sh_type != ELF::SHT_NULL) { - auto ContentOrErr = Obj.getSectionContents(Shdr); + auto ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError(); ArrayRef Content = *ContentOrErr; @@ -1016,7 +1016,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - auto EntriesOrErr = Obj.template getSectionContentsAsArray(Shdr); + auto EntriesOrErr = Obj.template getSectionContentsAsArray(*Shdr); if (!EntriesOrErr) return EntriesOrErr.takeError(); for (const Elf_Word &E : *EntriesOrErr) @@ -1042,7 +1042,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - auto ContentOrErr = Obj.getSectionContents(Shdr); + auto ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError(); @@ -1078,7 +1078,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - auto ContentOrErr = Obj.getSectionContents(Shdr); + auto ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError(); @@ -1119,7 +1119,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - auto ContentOrErr = Obj.getSectionContents(Shdr); + auto ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError(); @@ -1179,11 +1179,11 @@ if (!StringTableShdrOrErr) return StringTableShdrOrErr.takeError(); - auto StringTableOrErr = Obj.getStringTable(*StringTableShdrOrErr); + auto StringTableOrErr = Obj.getStringTable(**StringTableShdrOrErr); if (!StringTableOrErr) return StringTableOrErr.takeError(); - auto Contents = Obj.getSectionContents(Shdr); + auto Contents = Obj.getSectionContents(*Shdr); if (!Contents) return Contents.takeError(); @@ -1224,7 +1224,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - auto VersionsOrErr = Obj.template getSectionContentsAsArray(Shdr); + auto VersionsOrErr = Obj.template getSectionContentsAsArray(*Shdr); if (!VersionsOrErr) return VersionsOrErr.takeError(); for (const Elf_Half &E : *VersionsOrErr) @@ -1245,7 +1245,7 @@ S->Info = Shdr->sh_info; - auto Contents = Obj.getSectionContents(Shdr); + auto Contents = Obj.getSectionContents(*Shdr); if (!Contents) return Contents.takeError(); @@ -1253,7 +1253,7 @@ if (!StringTableShdrOrErr) return StringTableShdrOrErr.takeError(); - auto StringTableOrErr = Obj.getStringTable(*StringTableShdrOrErr); + auto StringTableOrErr = Obj.getStringTable(**StringTableShdrOrErr); if (!StringTableOrErr) return StringTableOrErr.takeError(); @@ -1322,7 +1322,7 @@ return SymbolName.takeError(); S->Signature = *SymbolName; - auto MembersOrErr = Obj.template getSectionContentsAsArray(Shdr); + auto MembersOrErr = Obj.template getSectionContentsAsArray(*Shdr); if (!MembersOrErr) return MembersOrErr.takeError(); @@ -1352,7 +1352,7 @@ if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - auto ContentOrErr = Obj.getSectionContents(Shdr); + auto ContentOrErr = Obj.getSectionContents(*Shdr); if (!ContentOrErr) return ContentOrErr.takeError();