Index: llvm/test/tools/llvm-readobj/ELF/mips-reginfo.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/mips-reginfo.test +++ llvm/test/tools/llvm-readobj/ELF/mips-reginfo.test @@ -1,18 +1,37 @@ ## Check that we are able to dump the SHT_MIPS_REGINFO section using -A properly. -# RUN: llvm-readobj -A %p/Inputs/reginfo.obj.elf-mipsel | FileCheck %s +# RUN: yaml2obj --docnum=1 %s -o %t1 +# RUN: llvm-readobj -A %t1 | FileCheck %s --check-prefix=OPTIONS +# RUN: llvm-readelf -A %t1 | FileCheck %s --check-prefix=OPTIONS -# CHECK: MIPS RegInfo { -# CHECK-NEXT: GP: 0x7FEF -# CHECK-NEXT: General Mask: 0xB00001F6 -# CHECK-NEXT: Co-Proc Mask0: 0x0 -# CHECK-NEXT: Co-Proc Mask1: 0x0 -# CHECK-NEXT: Co-Proc Mask2: 0x0 -# CHECK-NEXT: Co-Proc Mask3: 0x0 -# CHECK-NEXT: } +# OPTIONS: MIPS RegInfo { +# OPTIONS-NEXT: GP: 0x807060504030201 +# OPTIONS-NEXT: General Mask: 0xD0C0B0A +# OPTIONS-NEXT: Co-Proc Mask0: 0x88776655 +# OPTIONS-NEXT: Co-Proc Mask1: 0xCCBBAA99 +# OPTIONS-NEXT: Co-Proc Mask2: 0x1EFFEEDD +# OPTIONS-NEXT: Co-Proc Mask3: 0x5E4E3E2E +# OPTIONS-NEXT: } + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS +Sections: + - Name: .reginfo + Type: SHT_MIPS_REGINFO + ContentArray: [ 0xA, 0xB, 0xC, 0xD, ## Bit-mask of used general registers. + 0x11, 0x22, 0x33, 0x44, ## Unused padding field. + 0x55, 0x66, 0x77, 0x88, ## Bit-mask of used co-processor registers (0). + 0x99, 0xAA, 0xBB, 0xCC, ## Bit-mask of used co-processor registers (1). + 0xDD, 0xEE, 0xFF, 0x1E, ## Bit-mask of used co-processor registers (2). + 0x2E, 0x3E, 0x4E, 0x5E, ## Bit-mask of used co-processor registers (3). + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 ] ## GP register value. ## Check that we try to dump the .reginfo section when we are able to locate it by name. -# RUN: yaml2obj --docnum=1 -DNAME=0xffff %s -o %t.err1 +# RUN: yaml2obj --docnum=2 -DNAME=0xffff %s -o %t.err1 # RUN: llvm-readelf -A %t.err1 2>&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 | \ Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ 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