diff options
author | Georgii Rymar <grimar@accesssoftek.com> | 2020-07-03 17:24:09 +0300 |
---|---|---|
committer | Georgii Rymar <grimar@accesssoftek.com> | 2020-07-07 14:04:17 +0300 |
commit | 0d656cb25dc760cdfe0adfdd7256651b7bd0bcab (patch) | |
tree | 3ff0e9b61970aea54f13455d712220597ae2ccb2 /llvm | |
parent | 8f0f7dbcea34e2e89fb0946067af3488c20c4532 (diff) | |
download | llvm-0d656cb25dc760cdfe0adfdd7256651b7bd0bcab.zip llvm-0d656cb25dc760cdfe0adfdd7256651b7bd0bcab.tar.gz llvm-0d656cb25dc760cdfe0adfdd7256651b7bd0bcab.tar.bz2 |
[llvm-readobj] - Refine the error reporting in LLVMStyle<ELFT>::printELFLinkerOptions.
It is possible to:
1) Avoid using the `unwrapOrError` calls and hence allow to continue dumping even when
something is not OK with one of SHT_LLVM_LINKER_OPTIONS sections.
2) replace `reportWarning` with `reportUniqueWarning` calls. In this method it is no-op,
because it is not possible to have a duplicated warnings anyways, but since we probably
want to switch to `reportUniqueWarning` globally, this is a good thing to do.
This patch addresses both these points.
Differential revision: https://reviews.llvm.org/D83131
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/test/tools/llvm-readobj/ELF/linker-options.test | 13 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 37 |
2 files changed, 31 insertions, 19 deletions
diff --git a/llvm/test/tools/llvm-readobj/ELF/linker-options.test b/llvm/test/tools/llvm-readobj/ELF/linker-options.test index 3fad6b6..8e66547 100644 --- a/llvm/test/tools/llvm-readobj/ELF/linker-options.test +++ b/llvm/test/tools/llvm-readobj/ELF/linker-options.test @@ -2,13 +2,14 @@ ## to dump SHT_LLVM_LINKER_OPTIONS sections. # RUN: yaml2obj --docnum=1 %s -o %t1 -# RUN: llvm-readobj --elf-linker-options %t1 2>&1 | FileCheck %s --check-prefix=CHECK -DFILE=%t1 +# RUN: llvm-readobj --elf-linker-options %t1 2>&1 | FileCheck %s -DFILE=%t1 # CHECK: LinkerOptions [ # CHECK: option 0: value 0 # CHECK: option 1: value 1 # CHECK-NEXT: warning: '[[FILE]]': SHT_LLVM_LINKER_OPTIONS section at index 2 is broken: an incomplete key-value pair was found. The last possible key was: "c" # CHECK-NEXT: warning: '[[FILE]]': SHT_LLVM_LINKER_OPTIONS section at index 4 is broken: the content is not null-terminated +# CHECK-NEXT: warning: '[[FILE]]': unable to read the content of the SHT_LLVM_LINKER_OPTIONS section: section [index 5] has a sh_offset (0xffffffff) + sh_size (0x8) that is greater than the file size (0x370) # CHECK-NEXT: option 3: value 3 # CHECK-NEXT: ] @@ -44,7 +45,15 @@ Sections: - Name: .linker-options.nonul Type: SHT_LLVM_LINKER_OPTIONS Content: "61" -## Case 5: another correct case to show we do not stop dumping after reporting a warning. +## Case 5: check we report a warning when it is not possible to read +## the content of the SHT_LLVM_LINKER_OPTIONS section. + - Name: .linker-options.broken.content + Type: SHT_LLVM_LINKER_OPTIONS + ShOffset: 0xffffffff + Options: + - Name: foo + Value: bar +## Case 6: another correct case to show we do not stop dumping after reporting a warning. - Name: .linker-options.valid2 Type: SHT_LLVM_LINKER_OPTIONS Options: diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index bbdae75..247dfd9 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -6794,30 +6794,33 @@ void LLVMStyle<ELFT>::printELFLinkerOptions(const ELFFile<ELFT> *Obj) { if (Shdr.sh_type != ELF::SHT_LLVM_LINKER_OPTIONS) continue; - ArrayRef<uint8_t> Contents = - unwrapOrError(this->FileName, Obj->getSectionContents(&Shdr)); - if (Contents.empty()) + Expected<ArrayRef<uint8_t>> ContentsOrErr = Obj->getSectionContents(&Shdr); + if (!ContentsOrErr) { + this->reportUniqueWarning( + createError("unable to read the content of the " + "SHT_LLVM_LINKER_OPTIONS section: " + + toString(ContentsOrErr.takeError()))); + continue; + } + if (ContentsOrErr->empty()) continue; - if (Contents.back() != 0) { - reportWarning(createError("SHT_LLVM_LINKER_OPTIONS section at index " + - Twine(I) + - " is broken: the " - "content is not null-terminated"), - this->FileName); + if (ContentsOrErr->back() != 0) { + this->reportUniqueWarning( + createError("SHT_LLVM_LINKER_OPTIONS section at index " + Twine(I) + + " is broken: the " + "content is not null-terminated")); continue; } SmallVector<StringRef, 16> Strings; - toStringRef(Contents.drop_back()).split(Strings, '\0'); + toStringRef(ContentsOrErr->drop_back()).split(Strings, '\0'); if (Strings.size() % 2 != 0) { - reportWarning( - createError( - "SHT_LLVM_LINKER_OPTIONS section at index " + Twine(I) + - " is broken: an incomplete " - "key-value pair was found. The last possible key was: \"" + - Strings.back() + "\""), - this->FileName); + this->reportUniqueWarning(createError( + "SHT_LLVM_LINKER_OPTIONS section at index " + Twine(I) + + " is broken: an incomplete " + "key-value pair was found. The last possible key was: \"" + + Strings.back() + "\"")); continue; } |