Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -353,7 +353,7 @@ void printSymbolsHelper(bool IsDynamic) const; std::string getDynamicEntry(uint64_t Type, uint64_t Value) const; - Expected findSectionByName(StringRef Name) const; + const Elf_Shdr *findSectionByName(StringRef Name) const; const Elf_Shdr *getDotSymtabSec() const { return DotSymtabSec; } const Elf_Shdr *getDotCGProfileSec() const { return DotCGProfileSec; } @@ -2454,7 +2454,7 @@ } template -Expected +const typename ELFT::Shdr * ELFDumper::findSectionByName(StringRef Name) const { const ELFFile *Obj = ObjF->getELFFile(); for (const Elf_Shdr &Shdr : cantFail(Obj->sections())) { @@ -3009,12 +3009,7 @@ // Find static GOT secton. if (IsStatic) { - Expected GotOrErr = Dumper.findSectionByName(".got"); - if (!GotOrErr) - return GotOrErr.takeError(); - else - GotSec = *GotOrErr; - + GotSec = Dumper.findSectionByName(".got"); if (!GotSec) return Error::success(); @@ -3333,19 +3328,14 @@ template void ELFDumper::printMipsReginfo() { const ELFFile *Obj = ObjF->getELFFile(); - Expected RegInfoOrErr = findSectionByName(".reginfo"); - if (!RegInfoOrErr) { - reportUniqueWarning(RegInfoOrErr.takeError()); - return; - } - - if ((*RegInfoOrErr) == nullptr) { + const Elf_Shdr *RegInfo = findSectionByName(".reginfo"); + if (!RegInfo) { W.startLine() << "There is no .reginfo section in the file.\n"; return; } ArrayRef Sec = unwrapOrError(ObjF->getFileName(), - Obj->getSectionContents(*RegInfoOrErr)); + Obj->getSectionContents(RegInfo)); if (Sec.size() != sizeof(Elf_Mips_RegInfo)) { W.startLine() << "The .reginfo section has a wrong size.\n"; return; @@ -3358,21 +3348,16 @@ template void ELFDumper::printMipsOptions() { const ELFFile *Obj = ObjF->getELFFile(); - Expected MipsOptOrErr = findSectionByName(".MIPS.options"); - if (!MipsOptOrErr) { - reportUniqueWarning(MipsOptOrErr.takeError()); - return; - } - - if ((*MipsOptOrErr) == nullptr) { + const Elf_Shdr *MipsOpts = findSectionByName(".MIPS.options"); + if (!MipsOpts) { W.startLine() << "There is no .MIPS.options section in the file.\n"; return; } DictScope GS(W, "MIPS Options"); - ArrayRef Sec = unwrapOrError(ObjF->getFileName(), - Obj->getSectionContents(*MipsOptOrErr)); + ArrayRef Sec = + unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(MipsOpts)); while (!Sec.empty()) { if (Sec.size() < sizeof(Elf_Mips_Options)) { W.startLine() << "The .MIPS.options section has a wrong size.\n"; @@ -5982,16 +5967,13 @@ Expected *> getMipsAbiFlagsSection(const ELFObjectFile *ObjF, const ELFDumper &Dumper) { - Expected SecOrErr = - Dumper.findSectionByName(".MIPS.abiflags"); - if (!SecOrErr) - return SecOrErr.takeError(); - if (*SecOrErr == nullptr) + const typename ELFT::Shdr *Sec = Dumper.findSectionByName(".MIPS.abiflags"); + if (Sec == nullptr) return nullptr; const ELFFile *Obj = ObjF->getELFFile(); constexpr StringRef ErrPrefix = "unable to read the .MIPS.abiflags section: "; - Expected> DataOrErr = Obj->getSectionContents(*SecOrErr); + Expected> DataOrErr = Obj->getSectionContents(Sec); if (!DataOrErr) return createError(ErrPrefix + toString(DataOrErr.takeError()));