diff --git a/llvm/test/tools/llvm-readobj/ELF/Inputs/reginfo.obj.elf-mipsel b/llvm/test/tools/llvm-readobj/ELF/Inputs/reginfo.obj.elf-mipsel deleted file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@&1 | \ # RUN: FileCheck %s -DFILE=%t.err1 --check-prefix=NAME-ERR-FOUND --implicit-check-not=warning: # RUN: llvm-readobj -A %t.err1 2>&1 | \ @@ -20,7 +39,7 @@ # NAME-ERR-FOUND: warning: '[[FILE]]': unable to read the name of SHT_PROGBITS section with index 1: a section [index 1] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table # NAME-ERR-FOUND-NEXT: warning: '[[FILE]]': unable to read the name of SHT_PROGBITS section with index 3: a section [index 3] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table -# NAME-ERR-FOUND: The .reginfo section has a wrong size. +# NAME-ERR-FOUND: warning: '[[FILE]]': the .reginfo section has an invalid size (0x0) --- !ELF FileHeader: @@ -38,7 +57,7 @@ ShName: [[NAME=]] ## Check we report a warning when we are unable to find the .reginfo section due to an error. -# RUN: yaml2obj --docnum=1 -DREGINFONAME=0xffff %s -o %t.err2 +# RUN: yaml2obj --docnum=2 -DREGINFONAME=0xffff %s -o %t.err2 # RUN: llvm-readelf -A %t.err2 2>&1 | \ # RUN: FileCheck %s -DFILE=%t.err2 --check-prefix=NAME-ERR-NOTFOUND --implicit-check-not=warning: # RUN: llvm-readobj -A %t.err2 2>&1 | \ 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 @@ -3328,23 +3328,32 @@ } template void ELFDumper::printMipsReginfo() { - const ELFFile *Obj = ObjF->getELFFile(); - const Elf_Shdr *RegInfo = findSectionByName(".reginfo"); - if (!RegInfo) { + const Elf_Shdr *RegInfoSec = findSectionByName(".reginfo"); + if (!RegInfoSec) { W.startLine() << "There is no .reginfo section in the file.\n"; return; } - ArrayRef Sec = unwrapOrError(ObjF->getFileName(), - Obj->getSectionContents(RegInfo)); - if (Sec.size() != sizeof(Elf_Mips_RegInfo)) { - W.startLine() << "The .reginfo section has a wrong size.\n"; + const ELFFile *Obj = ObjF->getELFFile(); + Expected> ContentsOrErr = + Obj->getSectionContents(RegInfoSec); + if (!ContentsOrErr) { + this->reportUniqueWarning(createError( + "unable to read the content of the .reginfo section (" + + describe(*RegInfoSec) + "): " + toString(ContentsOrErr.takeError()))); + return; + } + + if (ContentsOrErr->size() < sizeof(Elf_Mips_RegInfo)) { + this->reportUniqueWarning( + createError("the .reginfo section has an invalid size (0x" + + Twine::utohexstr(ContentsOrErr->size()) + ")")); return; } DictScope GS(W, "MIPS RegInfo"); - auto *Reginfo = reinterpret_cast *>(Sec.data()); - printMipsReginfoData(W, *Reginfo); + printMipsReginfoData(W, *reinterpret_cast *>( + ContentsOrErr->data())); } template