[PATCH] D87507: [llvm-readobj] - Cleanup implementation LLVMStyle<ELFT>::printAddrsig().
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 04:44:50 PDT 2020
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
grimar requested review of this revision.
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.
https://reviews.llvm.org/D87507
Files:
llvm/test/tools/llvm-readobj/ELF/addrsig.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -6540,26 +6540,26 @@
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>
Index: llvm/test/tools/llvm-readobj/ELF/addrsig.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/addrsig.test
+++ llvm/test/tools/llvm-readobj/ELF/addrsig.test
@@ -31,12 +31,15 @@
# 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:
@@ -44,9 +47,19 @@
Data: ELFDATA2LSB
Type: ET_DYN
Sections:
- - Name: .llvm_addrsig
- Type: SHT_LLVM_ADDRSIG
- Content: "FF"
+ - 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).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87507.291185.patch
Type: text/x-patch
Size: 3782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200911/3d121c53/attachment.bin>
More information about the llvm-commits
mailing list