diff --git a/test/tools/llvm-readobj/ELF/mips-got.test b/test/tools/llvm-readobj/ELF/mips-got.test index 54b321bcaae..cfbf1c4f37a 100644 --- a/test/tools/llvm-readobj/ELF/mips-got.test +++ b/test/tools/llvm-readobj/ELF/mips-got.test @@ -519,3 +519,31 @@ Sections: - Tag: DT_NULL Value: 0 DynamicSymbols: [] + +# RUN: yaml2obj --docnum=2 -DVAL1=0xffff %s -o %t.err4.o +# RUN: not llvm-readobj -A %t.err4.o 2>&1 | FileCheck %s -DFILE=%t.err4.o -check-prefix=ERR4 + +# ERR4: error: '[[FILE]]': DT_MIPS_GOTSYM value (65535) exceeds the number of dynamic symbols (1) + +# RUN: yaml2obj --docnum=2 -DVAL2=0xffff %s -o %t.err5.o +# RUN: not llvm-readobj -A %t.err5.o 2>&1 | FileCheck %s -DFILE=%t.err5.o -check-prefix=ERR5 + +# ERR5: error: '[[FILE]]': there is no non-empty GOT section at 0xffff + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_MIPS +Sections: + - Name: .dynamic + Type: SHT_DYNAMIC + Entries: + - Tag: DT_MIPS_LOCAL_GOTNO + Value: 0 + - Tag: DT_MIPS_GOTSYM + Value: [[VAL1=0]] + - Tag: DT_PLTGOT + Value: [[VAL2=0]] +DynamicSymbols: [] diff --git a/test/tools/llvm-readobj/ELF/mips-plt.test b/test/tools/llvm-readobj/ELF/mips-plt.test index fa62aa98251..4959d8892ac 100644 --- a/test/tools/llvm-readobj/ELF/mips-plt.test +++ b/test/tools/llvm-readobj/ELF/mips-plt.test @@ -117,4 +117,26 @@ Sections: Value: [[VAL2=0]] - Tag: DT_NULL Value: 0 + - Name: .foo + Type: SHT_PROGBITS + Address: 0x100 + ShSize: 0xffffffff + Link: [[LINK=0x1]] DynamicSymbols: [] + +## Check we report errors when we are unable to dump PLTGOT properly. + +# RUN: yaml2obj --docnum=2 -DVAL1=0x100 %s -o %t.err5.o +# RUN: not llvm-readobj -A %t.err5.o 2>&1 | FileCheck %s -DFILE=%t.err5.o -check-prefix ERR5 + +# ERR5: error: '[[FILE]]': unable to read PLTGOT section content: section [index 2] has a sh_offset (0x70) + sh_size (0xffffffff) that is greater than the file size (0x280) + +# RUN: yaml2obj --docnum=2 -DVAL2=0x100 -DLINK=0xaaaaaaaa %s -o %t.err6.o +# RUN: not llvm-readobj -A %t.err6.o 2>&1 | FileCheck %s -DFILE=%t.err6.o -check-prefix ERR6 + +# ERR6: error: '[[FILE]]': unable to get a symbol table linked to the RELPLT section with index 2: invalid section index: 2863311530 + +# RUN: yaml2obj --docnum=2 -DVAL2=0x100 %s -o %t.err7.o +# RUN: not llvm-readobj -A %t.err7.o 2>&1 | FileCheck %s -DFILE=%t.err7.o -check-prefix ERR7 + +# ERR7: error: '[[FILE]]': unable to get a string table for the symbol table with index 1: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index cd3c79d208e..b8a5de27cb6 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -3039,7 +3039,9 @@ Error MipsGOTParser::findGOT(Elf_Dyn_Range DynTable, size_t DynSymTotal = DynSyms.size(); if (*DtGotSym > DynSymTotal) - return createError("MIPS_GOTSYM exceeds a number of dynamic symbols"); + return createError("DT_MIPS_GOTSYM value (" + Twine(*DtGotSym) + + ") exceeds the number of dynamic symbols (" + + Twine(DynSymTotal) + ")"); GotSec = findNotEmptySectionByAddress(Obj, FileName, *DtPltGot); if (!GotSec) @@ -3093,14 +3095,35 @@ Error MipsGOTParser::findPLT(Elf_Dyn_Range DynTable) { return createError("there is no non-empty RELPLT section at 0x" + Twine::utohexstr(*DtJmpRel)); - ArrayRef PltContent = - unwrapOrError(FileName, Obj->getSectionContents(PltSec)); - PltEntries = Entries(reinterpret_cast(PltContent.data()), - PltContent.size() / sizeof(Entry)); + if (Expected> PltContentOrErr = + Obj->getSectionContents(PltSec)) + PltEntries = + Entries(reinterpret_cast(PltContentOrErr->data()), + PltContentOrErr->size() / sizeof(Entry)); + else + return createError("unable to read PLTGOT section content: " + + toString(PltContentOrErr.takeError())); - PltSymTable = unwrapOrError(FileName, Obj->getSection(PltRelSec->sh_link)); - PltStrTable = - unwrapOrError(FileName, Obj->getStringTableForSymtab(*PltSymTable)); + if (Expected PltSymTableOrErr = + Obj->getSection(PltRelSec->sh_link)) { + PltSymTable = *PltSymTableOrErr; + } else { + unsigned SecNdx = PltRelSec - &cantFail(Obj->sections()).front(); + return createError("unable to get a symbol table linked to the RELPLT " + "section with index " + + Twine(SecNdx) + ": " + + toString(PltSymTableOrErr.takeError())); + } + + if (Expected StrTabOrErr = + Obj->getStringTableForSymtab(*PltSymTable)) { + PltStrTable = *StrTabOrErr; + } else { + unsigned SecNdx = PltSymTable - &cantFail(Obj->sections()).front(); + return createError( + "unable to get a string table for the symbol table with index " + + Twine(SecNdx) + ": " + toString(StrTabOrErr.takeError())); + } return Error::success(); }