[llvm-branch-commits] [llvm] ce322fb - [llvm-readelf/obj] - Stop using `reportError` when dumping notes.

Georgii Rymar via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 25 04:36:15 PST 2020


Author: Georgii Rymar
Date: 2020-11-25T15:22:56+03:00
New Revision: ce322fb0b8973134f9e0f8f38e99f7051d24acb8

URL: https://github.com/llvm/llvm-project/commit/ce322fb0b8973134f9e0f8f38e99f7051d24acb8
DIFF: https://github.com/llvm/llvm-project/commit/ce322fb0b8973134f9e0f8f38e99f7051d24acb8.diff

LOG: [llvm-readelf/obj] - Stop using `reportError` when dumping notes.

This starts using `reportUniqueWarnings` instead of `reportError`
in the code that is responsible for dumping notes.

Differential revision: https://reviews.llvm.org/D92021

Added: 
    

Modified: 
    llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
    llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test b/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
index 530a4a87293b..4a5cb1a38473 100644
--- a/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
+++ b/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
@@ -113,10 +113,22 @@ ProgramHeaders:
 ## that goes past the end of file.
 
 # RUN: yaml2obj --docnum=2 -DSHOFFSET=0xffff0000 %s -o %t2.so
-# RUN: not llvm-readelf --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
-# RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
-
-# ERR1: error: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0xffff0000) or size (0x0)
+# RUN: llvm-readelf --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1-GNU
+# RUN: llvm-readobj --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1-LLVM
+
+# ERR1-GNU:      Displaying notes found in: .note
+# ERR1-GNU-NEXT:   Owner                Data size        Description
+# ERR1-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0xffff0000) or size (0x0)
+# ERR1-GNU-NOT: {{.}}
+
+# ERR1-LLVM:      Notes [
+# ERR1-LLVM-NEXT:   NoteSection {
+# ERR1-LLVM-NEXT:     Name:   .note
+# ERR1-LLVM-NEXT:     Offset: 0xFFFF0000
+# ERR1-LLVM-NEXT:     Size:   0x0
+# ERR1-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0xffff0000) or size (0x0)
+# ERR1-LLVM-NEXT:   }
+# ERR1-LLVM-NEXT: ]
 
 --- !ELF
 FileHeader:
@@ -134,19 +146,43 @@ Sections:
 ## that goes past the end of file.
 
 # RUN: yaml2obj --docnum=2 -DSHSIZE=0xffff0000 %s -o %t3.so
-# RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
-# RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
-
-# ERR2: error: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0x40) or size (0xffff0000)
+# RUN: llvm-readelf --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2-GNU
+# RUN: llvm-readobj --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2-LLVM
+
+# ERR2-GNU:      Displaying notes found in: .note
+# ERR2-GNU-NEXT:   Owner                Data size        Description
+# ERR2-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0x40) or size (0xffff0000)
+# ERR2-GNU-NOT: {{.}}
+
+# ERR2-LLVM:      Notes [
+# ERR2-LLVM-NEXT:   NoteSection {
+# ERR2-LLVM-NEXT:     Name: .note
+# ERR2-LLVM-NEXT:     Offset: 0x40
+# ERR2-LLVM-NEXT:     Size: 0xFFFF0000
+# ERR2-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0x40) or size (0xffff0000)
+# ERR2-LLVM-NEXT:   }
+# ERR2-LLVM-NEXT: ]
 
 ## Test tools report an error if a note program header has an invalid offset that
 ## goes past the end of file.
 
 # RUN: yaml2obj --docnum=3 -DPHOFFSET=0xffff0000 %s -o %t4.so
-# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
-# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
-
-# ERR3: error: '[[FILE]]': unable to read notes from the PT_NOTE segment: invalid offset (0xffff0000) or size (0x0)
+# RUN: llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3-GNU
+# RUN: llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3-LLVM
+
+# ERR3-GNU:      Displaying notes found at file offset 0xffff0000 with length 0x00000000:
+# ERR3-GNU-NEXT:   Owner                Data size        Description
+# ERR3-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 1: invalid offset (0xffff0000) or size (0x0)
+# ERR3-GNU-NOT: {{.}}
+
+# ERR3-LLVM:      Notes [
+# ERR3-LLVM-NEXT:   NoteSection {
+# ERR3-LLVM-NEXT:     Name: <?>
+# ERR3-LLVM-NEXT:     Offset: 0xFFFF0000
+# ERR3-LLVM-NEXT:     Size: 0x0
+# ERR3-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 1: invalid offset (0xffff0000) or size (0x0)
+# ERR3-LLVM-NEXT:   }
+# ERR3-LLVM-NEXT: ]
 
 --- !ELF
 FileHeader:
@@ -162,10 +198,22 @@ ProgramHeaders:
 ## goes past the end of file.
 
 # RUN: yaml2obj --docnum=3 -DPHFILESIZE=0xffff0000 %s -o %t5.so
-# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so  %s --check-prefix=ERR4
-# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4
-
-# ERR4: error: '[[FILE]]': unable to read notes from the PT_NOTE segment: invalid offset (0x0) or size (0xffff0000)
+# RUN: llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4-GNU
+# RUN: llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4-LLVM
+
+# ERR4-GNU:      Displaying notes found at file offset 0x00000000 with length 0xffff0000:
+# ERR4-GNU-NEXT:   Owner                Data size        Description
+# ERR4-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 1: invalid offset (0x0) or size (0xffff0000)
+# ERR4-GNU-NOT: {{.}}
+
+# ERR4-LLVM:      Notes [
+# ERR4-LLVM-NEXT:   NoteSection {
+# ERR4-LLVM-NEXT:     Name: <?>
+# ERR4-LLVM-NEXT:     Offset: 0x0
+# ERR4-LLVM-NEXT:     Size: 0xFFFF0000
+# ERR4-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 1: invalid offset (0x0) or size (0xffff0000)
+# ERR4-LLVM-NEXT:   }
+# ERR4-LLVM-NEXT: ]
 
 ## Check we report a warning when we are unable to locate the PT_NOTE
 ## segment because of broken program headers.

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index e80e2c3db95d..2fac1c970fb3 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -5562,10 +5562,9 @@ static void printNotesHelper(
       for (const typename ELFT::Note &Note : Obj.notes(S, Err))
         ProcessNoteFn(Note);
       if (Err)
-        reportError(createError("unable to read notes from the " +
-                                describe(Obj, S) + ": " +
-                                toString(std::move(Err))),
-                    Dumper.getElfObject().getFileName());
+        Dumper.reportUniqueWarning(
+            createError("unable to read notes from the " + describe(Obj, S) +
+                        ": " + toString(std::move(Err))));
       FinishNotesFn();
     }
     return;
@@ -5579,7 +5578,9 @@ static void printNotesHelper(
     return;
   }
 
+  size_t I = 0;
   for (const typename ELFT::Phdr &P : *PhdrsOrErr) {
+    ++I;
     if (P.p_type != PT_NOTE)
       continue;
     StartNotesFn(/*SecName=*/None, P.p_offset, P.p_filesz);
@@ -5587,10 +5588,9 @@ static void printNotesHelper(
     for (const typename ELFT::Note Note : Obj.notes(P, Err))
       ProcessNoteFn(Note);
     if (Err)
-      reportError(
-          createError("unable to read notes from the PT_NOTE segment: " +
-                      toString(std::move(Err))),
-          Dumper.getElfObject().getFileName());
+      Dumper.reportUniqueWarning(createError(
+          "unable to read notes from the PT_NOTE segment with index " +
+          Twine(I) + ": " + toString(std::move(Err))));
     FinishNotesFn();
   }
 }


        


More information about the llvm-branch-commits mailing list