Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -1269,7 +1269,7 @@ static const typename ELFO::Elf_Shdr * findNotEmptySectionByAddress(const ELFO *Obj, StringRef FileName, uint64_t Addr) { - for (const auto &Shdr : unwrapOrError(FileName, Obj->sections())) + for (const typename ELFO::Elf_Shdr &Shdr : cantFail(Obj->sections())) if (Shdr.sh_addr == Addr && Shdr.sh_size > 0) return &Shdr; return nullptr; @@ -1278,7 +1278,7 @@ template static const typename ELFO::Elf_Shdr * findSectionByName(const ELFO &Obj, StringRef FileName, StringRef Name) { - for (const auto &Shdr : unwrapOrError(FileName, Obj.sections())) + for (const typename ELFO::Elf_Shdr &Shdr : cantFail(Obj.sections())) if (Name == unwrapOrError(FileName, Obj.getSectionName(&Shdr))) return &Shdr; return nullptr; @@ -1899,8 +1899,7 @@ // Try to locate the .dynamic section in the sections header table. const Elf_Shdr *DynamicSec = nullptr; - for (const Elf_Shdr &Sec : - unwrapOrError(ObjF->getFileName(), Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { if (Sec.sh_type != ELF::SHT_DYNAMIC) continue; DynamicSec = &Sec; @@ -2043,8 +2042,7 @@ ELFDumperStyle.reset(new LLVMStyle(Writer, this)); const ELFFile *Obj = ObjF->getELFFile(); - typename ELFT::ShdrRange Sections = - unwrapOrError(ObjF->getFileName(), Obj->sections()); + typename ELFT::ShdrRange Sections = cantFail(Obj->sections()); for (const Elf_Shdr &Sec : Sections) { switch (Sec.sh_type) { case ELF::SHT_SYMTAB: @@ -2882,7 +2880,7 @@ "Attributes not implemented."); DictScope BA(W, "BuildAttributes"); - for (const auto &Sec : unwrapOrError(ObjF->getFileName(), Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { if (Sec.sh_type != ELF::SHT_ARM_ATTRIBUTES && Sec.sh_type != ELF::SHT_RISCV_ATTRIBUTES) continue; @@ -3320,7 +3318,7 @@ template void ELFDumper::printStackMap() const { const ELFFile *Obj = ObjF->getELFFile(); const Elf_Shdr *StackMapSection = nullptr; - for (const auto &Sec : unwrapOrError(ObjF->getFileName(), Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { StringRef Name = unwrapOrError(ObjF->getFileName(), Obj->getSectionName(&Sec)); if (Name == ".llvm_stackmaps") { @@ -3363,7 +3361,7 @@ if (ElfHeader->e_shnum != 0) return to_string(ElfHeader->e_shnum); - ArrayRef Arr = unwrapOrError(FileName, Obj->sections()); + ArrayRef Arr = cantFail(Obj->sections()); if (Arr.empty()) return "0"; return "0 (" + to_string(Arr[0].sh_size) + ")"; @@ -3376,7 +3374,7 @@ if (ElfHeader->e_shstrndx != SHN_XINDEX) return to_string(ElfHeader->e_shstrndx); - ArrayRef Arr = unwrapOrError(FileName, Obj->sections()); + ArrayRef Arr = cantFail(Obj->sections()); if (Arr.empty()) return "65535 (corrupt: out of range)"; return to_string(ElfHeader->e_shstrndx) + " (" + to_string(Arr[0].sh_link) + @@ -3470,7 +3468,7 @@ std::vector Ret; uint64_t I = 0; - for (const Elf_Shdr &Sec : unwrapOrError(FileName, Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { ++I; if (Sec.sh_type != ELF::SHT_GROUP) continue; @@ -3621,7 +3619,7 @@ template void GNUStyle::printRelocations(const ELFO *Obj) { bool HasRelocSections = false; - for (const Elf_Shdr &Sec : unwrapOrError(this->FileName, Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA && Sec.sh_type != ELF::SHT_RELR && Sec.sh_type != ELF::SHT_ANDROID_REL && Sec.sh_type != ELF::SHT_ANDROID_RELA && @@ -3847,7 +3845,7 @@ template void GNUStyle::printSectionHeaders(const ELFO *Obj) { unsigned Bias = ELFT::Is64Bits ? 0 : 8; - ArrayRef Sections = unwrapOrError(this->FileName, Obj->sections()); + ArrayRef Sections = cantFail(Obj->sections()); OS << "There are " << to_string(Sections.size()) << " section headers, starting at offset " << "0x" << to_hexString(Obj->getHeader()->e_shoff, false) << ":\n\n"; @@ -4309,7 +4307,7 @@ std::string Sections; OS << format(" %2.2d ", Phnum++); // Check if each section is in a segment and then print mapping. - for (const Elf_Shdr &Sec : unwrapOrError(this->FileName, Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { if (Sec.sh_type == ELF::SHT_NULL) continue; @@ -4330,7 +4328,7 @@ // Display sections that do not belong to a segment. std::string Sections; - for (const Elf_Shdr &Sec : unwrapOrError(this->FileName, Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { if (BelongsToSegment.find(&Sec) == BelongsToSegment.end()) Sections += unwrapOrError(this->FileName, Obj->getSectionName(&Sec)).str() + ' '; @@ -5407,7 +5405,7 @@ } }; - ArrayRef Sections = unwrapOrError(this->FileName, Obj->sections()); + ArrayRef Sections = cantFail(Obj->sections()); if (Obj->getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) { for (const auto &S : Sections) { if (S.sh_type != SHT_NOTE) @@ -5452,7 +5450,7 @@ }; unsigned I = -1; - for (const Elf_Shdr &Shdr : unwrapOrError(this->FileName, Obj->sections())) { + for (const Elf_Shdr &Shdr : cantFail(Obj->sections())) { ++I; if (Shdr.sh_type != ELF::SHT_LLVM_DEPENDENT_LIBRARIES) continue; @@ -6076,7 +6074,7 @@ ListScope D(W, "Relocations"); int SectionNumber = -1; - for (const Elf_Shdr &Sec : unwrapOrError(this->FileName, Obj->sections())) { + for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { ++SectionNumber; if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA && @@ -6178,10 +6176,9 @@ ListScope SectionsD(W, "Sections"); int SectionIndex = -1; - ArrayRef Sections = unwrapOrError(this->FileName, Obj->sections()); std::vector> FlagsList = getSectionFlagsForTarget(Obj->getHeader()->e_machine); - for (const Elf_Shdr &Sec : Sections) { + for (const Elf_Shdr &Sec : cantFail(Obj->sections())) { StringRef Name = ""; if (Expected SecNameOrErr = Obj->getSectionName(&Sec, this->dumper()->WarningHandler)) @@ -6716,7 +6713,7 @@ } }; - ArrayRef Sections = unwrapOrError(this->FileName, Obj->sections()); + ArrayRef Sections = cantFail(Obj->sections()); if (Obj->getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) { for (const auto &S : Sections) { if (S.sh_type != SHT_NOTE) @@ -6751,7 +6748,7 @@ ListScope L(W, "LinkerOptions"); unsigned I = -1; - for (const Elf_Shdr &Shdr : unwrapOrError(this->FileName, Obj->sections())) { + for (const Elf_Shdr &Shdr : cantFail(Obj->sections())) { ++I; if (Shdr.sh_type != ELF::SHT_LLVM_LINKER_OPTIONS) continue;