mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-28 05:40:35 +00:00
[llvm-readobj] - Refine error reporting in MipsGOTParser<ELFT> helper.
This is a follow-up for D83225. This does the following: 1) Adds missing tests for existent errors. 2) Stops using `unwrapOrError` to propagate errors to caller. (I am trying to get rid of all `unwrapOrErr` calls in the llvm-readelf code). 3) Improves error messages reported slightly. Differential revision: https://reviews.llvm.org/D83314
This commit is contained in:
parent
89db14b5e3
commit
54223457e2
@ -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: []
|
||||
|
@ -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
|
||||
|
@ -3039,7 +3039,9 @@ Error MipsGOTParser<ELFT>::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<ELFT>::findPLT(Elf_Dyn_Range DynTable) {
|
||||
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()));
|
||||
|
||||
PltSymTable = unwrapOrError(FileName, Obj->getSection(PltRelSec->sh_link));
|
||||
PltStrTable =
|
||||
unwrapOrError(FileName, Obj->getStringTableForSymtab(*PltSymTable));
|
||||
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()));
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user