forked from OSchip/llvm-project
[llvm-readobj] - Cleanup implementation LLVMStyle<ELFT>::printAddrsig().
It has following issues: 1) `getStaticSymbolName` returns `std::string`, but the code assigns a result to `Expected<std::string>`. 2) The code uses `unwrapOrError` and never tests the error reported. This patch fixes these issues. Differential revision: https://reviews.llvm.org/D87507
This commit is contained in:
parent
412b417bfa
commit
14e191a0e7
|
@ -31,12 +31,15 @@ Symbols:
|
|||
# RUN: llvm-readobj --all %t1.o | FileCheck %s --check-prefix LLVM
|
||||
# RUN: llvm-readelf --all %t1.o 2>&1 | FileCheck %s --implicit-check-not=warning --implicit-check-not=error
|
||||
|
||||
## Check we report a warning when SHT_LLVM_ADDRSIG is broken (e.g. contains a malformed uleb128).
|
||||
## Check we report a warning when the content of the SHT_LLVM_ADDRSIG section
|
||||
## is broken (e.g. contains a malformed uleb128).
|
||||
|
||||
# RUN: yaml2obj --docnum=2 %s -o %t2.o
|
||||
# RUN: llvm-readobj --addrsig %t2.o 2>&1 | FileCheck %s -DFILE=%t2.o --check-prefix=MALFORMED
|
||||
# RUN: yaml2obj --docnum=2 %s -o %t2.1.o
|
||||
# RUN: llvm-readobj --addrsig %t2.1.o 2>&1 | FileCheck %s -DFILE=%t2.1.o --check-prefix=MALFORMED
|
||||
|
||||
# MALFORMED: warning: '[[FILE]]': malformed uleb128, extends past end
|
||||
# MALFORMED: Addrsig [
|
||||
# MALFORMED-NEXT: warning: '[[FILE]]': unable to decode SHT_LLVM_ADDRSIG section with index 1: malformed uleb128, extends past end
|
||||
# MALFORMED-NEXT: ]
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
|
@ -47,6 +50,16 @@ Sections:
|
|||
- Name: .llvm_addrsig
|
||||
Type: SHT_LLVM_ADDRSIG
|
||||
Content: "FF"
|
||||
ShOffset: [[OFFSET=<none>]]
|
||||
|
||||
## Check we report a warning when the content of the SHT_LLVM_ADDRSIG section can't be read.
|
||||
|
||||
# RUN: yaml2obj --docnum=2 -DOFFSET=0xffffffff %s -o %t2.2.o
|
||||
# RUN: llvm-readobj --addrsig %t2.2.o 2>&1 | FileCheck %s -DFILE=%t2.2.o --check-prefix=BROKEN-SEC
|
||||
|
||||
# BROKEN-SEC: Addrsig [
|
||||
# BROKEN-SEC-NEXT: warning: '[[FILE]]': section [index 1] has a sh_offset (0xffffffff) + sh_size (0x1) that is greater than the file size (0x168)
|
||||
# BROKEN-SEC-NEXT: ]
|
||||
|
||||
## Check we report a warning when SHT_LLVM_ADDRSIG references a symbol that can't be
|
||||
## dumped (e.g. the index value is larger than the number of symbols in .symtab).
|
||||
|
|
|
@ -6489,26 +6489,26 @@ static Expected<std::vector<uint64_t>> toULEB128Array(ArrayRef<uint8_t> Data) {
|
|||
|
||||
template <class ELFT> void LLVMStyle<ELFT>::printAddrsig() {
|
||||
ListScope L(W, "Addrsig");
|
||||
if (!this->dumper()->getDotAddrsigSec())
|
||||
const Elf_Shdr *Sec = this->dumper()->getDotAddrsigSec();
|
||||
if (!Sec)
|
||||
return;
|
||||
ArrayRef<uint8_t> Contents = unwrapOrError(
|
||||
this->FileName,
|
||||
this->Obj.getSectionContents(this->dumper()->getDotAddrsigSec()));
|
||||
Expected<std::vector<uint64_t>> V = toULEB128Array(Contents);
|
||||
if (!V) {
|
||||
reportWarning(V.takeError(), this->FileName);
|
||||
|
||||
Expected<ArrayRef<uint8_t>> ContentsOrErr = this->Obj.getSectionContents(Sec);
|
||||
if (!ContentsOrErr) {
|
||||
this->reportUniqueWarning(ContentsOrErr.takeError());
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint64_t Sym : *V) {
|
||||
Expected<std::string> NameOrErr = this->dumper()->getStaticSymbolName(Sym);
|
||||
if (NameOrErr) {
|
||||
W.printNumber("Sym", *NameOrErr, Sym);
|
||||
continue;
|
||||
}
|
||||
reportWarning(NameOrErr.takeError(), this->FileName);
|
||||
W.printNumber("Sym", "<?>", Sym);
|
||||
Expected<std::vector<uint64_t>> SymsOrErr = toULEB128Array(*ContentsOrErr);
|
||||
if (!SymsOrErr) {
|
||||
this->reportUniqueWarning(createError("unable to decode " +
|
||||
describe(this->Obj, *Sec) + ": " +
|
||||
toString(SymsOrErr.takeError())));
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint64_t Sym : *SymsOrErr)
|
||||
W.printNumber("Sym", this->dumper()->getStaticSymbolName(Sym), Sym);
|
||||
}
|
||||
|
||||
template <typename ELFT>
|
||||
|
|
Loading…
Reference in New Issue