[PATCH] D83131: [llvm-readobj] - Refine the error reporting in LLVMStyle<ELFT>::printELFLinkerOptions.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 6 12:53:35 PDT 2020


grimar updated this revision to Diff 275632.
grimar marked an inline comment as done.
grimar added a comment.

- Addressed review comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83131/new/

https://reviews.llvm.org/D83131

Files:
  llvm/test/tools/llvm-readobj/ELF/linker-options.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
@@ -6753,30 +6753,33 @@
     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;
     }
 
Index: llvm/test/tools/llvm-readobj/ELF/linker-options.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/linker-options.test
+++ 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 @@
   - 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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83131.275632.patch
Type: text/x-patch
Size: 4074 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200706/d238d158/attachment-0001.bin>


More information about the llvm-commits mailing list