- 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: []
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
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)
return createError("there is no non-empty RELPLT section at 0x" +
Twine::utohexstr(*DtJmpRel));
- ArrayRef<uint8_t> PltContent =
- unwrapOrError(FileName, Obj->getSectionContents(PltSec));
- PltEntries = Entries(reinterpret_cast<const Entry *>(PltContent.data()),
- PltContent.size() / sizeof(Entry));
+ if (Expected<ArrayRef<uint8_t>> PltContentOrErr =
+ Obj->getSectionContents(PltSec))
+ PltEntries =
+ Entries(reinterpret_cast<const Entry *>(PltContentOrErr->data()),
+ PltContentOrErr->size() / sizeof(Entry));
+ else
+ return createError("unable to read PLTGOT section content: " +
+ toString(PltContentOrErr.takeError()));
+
+ if (Expected<const Elf_Shdr *> 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()));
+ }
- PltSymTable = unwrapOrError(FileName, Obj->getSection(PltRelSec->sh_link));
- PltStrTable =
- unwrapOrError(FileName, Obj->getStringTableForSymtab(*PltSymTable));
+ if (Expected<StringRef> 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();
}