[llvm-readobj] - Report unique warnings in printProgramHeaders.
authorGeorgii Rymar <grimar@accesssoftek.com>
Thu, 3 Dec 2020 12:07:28 +0000 (15:07 +0300)
committerGeorgii Rymar <grimar@accesssoftek.com>
Fri, 4 Dec 2020 10:35:44 +0000 (13:35 +0300)
This converts `reportWarning` -> `reportUniqueWarning`

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

llvm/test/tools/llvm-readobj/ELF/program-headers.test
llvm/tools/llvm-readobj/ELFDumper.cpp

index d876a23..3a0fb1e 100644 (file)
@@ -607,16 +607,16 @@ ProgramHeaders:
 
 ## Show the size of the output produced. It is used in the YAML below.
 # RUN: wc -c < %t.err | FileCheck %s --check-prefix=SIZE
-# SIZE: 560
+# SIZE: 616
 
 ## Write the additional 'C', '\0, 'C' bytes to the end.
 # RUN: echo -n -e "C\x00C" >> %t.err
 
 # RUN: llvm-readelf --program-headers %t.err 2>&1 | \
-# RUN:   FileCheck %s -DFILE=%t.err --check-prefix=ERROR-INTERP
+# RUN:   FileCheck %s -DFILE=%t.err --check-prefix=ERROR-INTERP --implicit-check-not=warning:
 
 # ERROR-INTERP:      Type           Offset
-# ERROR-INTERP-NEXT: INTERP         0x000[[#%x,OFFSET:0x230]]
+# ERROR-INTERP-NEXT: INTERP         0x000[[#%x,OFFSET:0x268]]
 # ERROR-INTERP-NEXT:     [Requesting program interpreter: C]
 # ERROR-INTERP-NEXT: INTERP         0x000[[#OFFSET + 1]]
 # ERROR-INTERP-NEXT:     [Requesting program interpreter: ]
@@ -626,6 +626,7 @@ ProgramHeaders:
 # ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0x[[#OFFSET+3]]: it goes past the end of the file (0x[[#OFFSET + 3]])
 # ERROR-INTERP-NEXT: INTERP         0xaabbccddeeff1122
 # ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0xaabbccddeeff1122: it goes past the end of the file (0x[[#OFFSET + 3]])
+# ERROR-INTERP-NEXT: INTERP         0xaabbccddeeff1122
 
 --- !ELF
 FileHeader:
@@ -635,21 +636,25 @@ FileHeader:
 ProgramHeaders:
 ## Case 1: the offset points to the first additional byte.
   - Type:   PT_INTERP
-    Offset: 560
+    Offset: 616
 ## Case 1: the offset points to the second additional byte,
 ##         which is a null byte.
   - Type:   PT_INTERP
-    Offset: 561
+    Offset: 617
 ## Case 3: the offset points to the third additional
 ##         byte, which is the last byte in the file.
   - Type:   PT_INTERP
-    Offset: 562
+    Offset: 618
 ## Case 4: the offset goes 1 byte past the end of the file.
   - Type:   PT_INTERP
-    Offset: 563
+    Offset: 619
 ## Case 5: an arbitrary large offset that goes past the end of the file.
   - Type:   PT_INTERP
     Offset: 0xAABBCCDDEEFF1122
+## Case 6: the same as case 5. Used to demonstrate that we don't report
+##         the same warning twice.
+  - Type:   PT_INTERP
+    Offset: 0xAABBCCDDEEFF1122
 
 ## Check we report a warning when we are unable to read program headers.
 ## Case A: the e_phentsize field is invalid.
index 13d0531..e682581 100644 (file)
@@ -4473,10 +4473,9 @@ template <class ELFT> void GNUStyle<ELFT>::printProgramHeaders() {
     if (Phdr.p_type == ELF::PT_INTERP) {
       OS << "\n";
       auto ReportBadInterp = [&](const Twine &Msg) {
-        reportWarning(
-            createError("unable to read program interpreter name at offset 0x" +
-                        Twine::utohexstr(Phdr.p_offset) + ": " + Msg),
-            this->FileName);
+        this->reportUniqueWarning(
+            "unable to read program interpreter name at offset 0x" +
+            Twine::utohexstr(Phdr.p_offset) + ": " + Msg);
       };
 
       if (Phdr.p_offset >= this->Obj.getBufSize()) {