[llvm] 3d811c5 - [llvm-readelf/obj] - Stop calling `reportError` in `printArchSpecificInfo()`.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 26 23:42:47 PST 2020


Author: Georgii Rymar
Date: 2020-11-27T10:27:00+03:00
New Revision: 3d811c57aa1a26fb2ba737dfc6f922fd98c96622

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

LOG: [llvm-readelf/obj] - Stop calling `reportError` in `printArchSpecificInfo()`.

This is related to MIPS. Currently we might report an error and exit,
though there is no problem to report a warning and try to continue dumping
an object. The code uses `MipsGOTParser<ELFT> Parser`, which is isolated
in this method.

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

Added: 
    

Modified: 
    llvm/test/tools/llvm-readobj/ELF/mips-got.test
    llvm/test/tools/llvm-readobj/ELF/mips-plt.test
    llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-readobj/ELF/mips-got.test b/llvm/test/tools/llvm-readobj/ELF/mips-got.test
index 1615ce0b0e1b..01bff1b914f8 100644
--- a/llvm/test/tools/llvm-readobj/ELF/mips-got.test
+++ b/llvm/test/tools/llvm-readobj/ELF/mips-got.test
@@ -368,19 +368,13 @@ DynamicSymbols: []
 ## Check we report errors when dynamic tags, needed for dumping GOT, are missing.
 
 # RUN: yaml2obj --docnum=4 -DTAG1=DT_MIPS_LOCAL_GOTNO -DTAG2=DT_MIPS_GOTSYM %s -o %t.err1.o
-# RUN: not llvm-readobj -A %t.err1.o 2>&1 | FileCheck %s -DFILE=%t.err1.o -check-prefix ERR1
-
-# ERR1: error: '[[FILE]]': cannot find PLTGOT dynamic tag
+# RUN: llvm-readobj -A %t.err1.o 2>&1 | FileCheck %s -DFILE=%t.err1.o -check-prefixes=NO-OUTPUT,ERR1
 
 # RUN: yaml2obj --docnum=4 -DTAG1=DT_PLTGOT -DTAG2=DT_MIPS_GOTSYM %s -o %t.err2.o
-# RUN: not llvm-readobj -A %t.err2.o 2>&1 | FileCheck %s -DFILE=%t.err2.o -check-prefix ERR2
-
-# ERR2: error: '[[FILE]]': cannot find MIPS_LOCAL_GOTNO dynamic tag
+# RUN: llvm-readobj -A %t.err2.o 2>&1 | FileCheck %s -DFILE=%t.err2.o -check-prefixes=NO-OUTPUT,ERR2
 
 # RUN: yaml2obj --docnum=4 -DTAG1=DT_PLTGOT -DTAG2=DT_MIPS_LOCAL_GOTNO %s -o %t.err3.o
-# RUN: not llvm-readobj -A %t.err3.o 2>&1 | FileCheck %s -DFILE=%t.err3.o -check-prefix ERR3
-
-# ERR3: error: '[[FILE]]': cannot find MIPS_GOTSYM dynamic tag
+# RUN: llvm-readobj -A %t.err3.o 2>&1 | FileCheck %s -DFILE=%t.err3.o -check-prefixes=NO-OUTPUT,ERR3
 
 --- !ELF
 FileHeader:
@@ -401,14 +395,10 @@ Sections:
 DynamicSymbols: []
 
 # RUN: yaml2obj --docnum=5 -DVAL1=0xffff %s -o %t.err4.o
-# RUN: not llvm-readobj -A %t.err4.o 2>&1 | FileCheck %s -DFILE=%t.err4.o -check-prefix=ERR4
-
-# ERR4: error: '[[FILE]]': DT_MIPS_GOTSYM value (65535) exceeds the number of dynamic symbols (1)
+# RUN: llvm-readobj -A %t.err4.o 2>&1 | FileCheck %s -DFILE=%t.err4.o -check-prefixes=NO-OUTPUT,ERR4
 
 # RUN: yaml2obj --docnum=5 -DVAL2=0xffff %s -o %t.err5.o
-# RUN: not llvm-readobj -A %t.err5.o 2>&1 | FileCheck %s -DFILE=%t.err5.o -check-prefix=ERR5
-
-# ERR5: error: '[[FILE]]': there is no non-empty GOT section at 0xffff
+# RUN: llvm-readobj -A %t.err5.o 2>&1 | FileCheck %s -DFILE=%t.err5.o -check-prefixes=NO-OUTPUT,ERR5
 
 --- !ELF
 FileHeader:
@@ -428,6 +418,20 @@ Sections:
         Value: [[VAL2=0]]
 DynamicSymbols: []
 
+# NO-OUTPUT:      LoadName: <Not found>
+# NO-OUTPUT-NEXT: There is no .MIPS.abiflags section in the file.
+# NO-OUTPUT-NEXT: There is no .MIPS.options section in the file.
+# NO-OUTPUT-NEXT: There is no .reginfo section in the file.
+
+# ERR1-NEXT: warning: '[[FILE]]': cannot find PLTGOT dynamic tag
+# ERR2-NEXT: warning: '[[FILE]]': cannot find MIPS_LOCAL_GOTNO dynamic tag
+# ERR3-NEXT: warning: '[[FILE]]': cannot find MIPS_GOTSYM dynamic tag
+# ERR4-NEXT: warning: '[[FILE]]': DT_MIPS_GOTSYM value (65535) exceeds the number of dynamic symbols (1)
+# ERR5-NEXT: warning: '[[FILE]]': there is no non-empty GOT section at 0xffff
+
+# NO-OUTPUT-EMPTY:
+# NO-OUTPUT-NOT: {{.}}
+
 ## Check that we do not report a warning about the .got section when we are able to locate it by name.
 # RUN: yaml2obj --docnum=6 -DNAME=0xffff %s -o %t.err6.o
 # RUN: llvm-readobj -A %t.err6.o 2>&1 | \

diff  --git a/llvm/test/tools/llvm-readobj/ELF/mips-plt.test b/llvm/test/tools/llvm-readobj/ELF/mips-plt.test
index 3f57a39988e8..607388cb852b 100644
--- a/llvm/test/tools/llvm-readobj/ELF/mips-plt.test
+++ b/llvm/test/tools/llvm-readobj/ELF/mips-plt.test
@@ -89,14 +89,10 @@ DynamicSymbols:
 ## Check we report errors when dynamic tags, needed for dumping PLT, are missing.
 
 # RUN: yaml2obj --docnum=2 -DTAG=DT_MIPS_PLTGOT %s -o %t.err1.o
-# RUN: not llvm-readobj -A %t.err1.o 2>&1 | FileCheck %s -DFILE=%t.err1.o --check-prefix=ERR1
-
-# ERR1: error: '[[FILE]]': cannot find JMPREL dynamic tag
+# RUN: llvm-readobj -A %t.err1.o 2>&1 | FileCheck %s -DFILE=%t.err1.o --check-prefixes=NO-OUTPUT,ERR1
 
 # RUN: yaml2obj --docnum=2 -DTAG=DT_JMPREL %s -o %t.err2.o
-# RUN: not llvm-readobj -A %t.err2.o 2>&1 | FileCheck %s -DFILE=%t.err2.o --check-prefix=ERR2
-
-# ERR2: error: '[[FILE]]': cannot find MIPS_PLTGOT dynamic tag
+# RUN: llvm-readobj -A %t.err2.o 2>&1 | FileCheck %s -DFILE=%t.err2.o --check-prefixes=NO-OUTPUT,ERR2
 
 --- !ELF
 FileHeader:
@@ -115,14 +111,10 @@ Sections:
 
 ## Check we report errors when we are unable to find PLTGOT/JMPREL sections.
 # RUN: yaml2obj --docnum=3 %s -DVAL1=0xffff -o %t.err3.o
-# RUN: not llvm-readobj -A %t.err3.o 2>&1 | FileCheck %s -DFILE=%t.err3.o -check-prefix ERR3
-
-# ERR3: error: '[[FILE]]': there is no non-empty PLTGOT section at 0xffff
+# RUN: llvm-readobj -A %t.err3.o 2>&1 | FileCheck %s -DFILE=%t.err3.o -check-prefixes=NO-OUTPUT,ERR3
 
 # RUN: yaml2obj --docnum=3 %s -DVAL2=0xffff -o %t.err4.o
-# RUN: not llvm-readobj -A %t.err4.o 2>&1 | FileCheck %s -DFILE=%t.err4.o -check-prefix ERR4
-
-# ERR4: error: '[[FILE]]': there is no non-empty RELPLT section at 0xffff
+# RUN: llvm-readobj -A %t.err4.o 2>&1 | FileCheck %s -DFILE=%t.err4.o -check-prefixes=NO-OUTPUT,ERR4
 
 --- !ELF
 FileHeader:
@@ -150,19 +142,29 @@ DynamicSymbols: []
 ## Check we report errors when we are unable to dump PLTGOT properly.
 
 # RUN: yaml2obj --docnum=3 -DVAL1=0x100 %s -o %t.err5.o
-# RUN: not llvm-readobj -A %t.err5.o 2>&1 | FileCheck %s -DFILE=%t.err5.o -check-prefix ERR5
-
-# ERR5: error: '[[FILE]]': unable to read PLTGOT section content: section [index 2] has a sh_offset (0x70) + sh_size (0xffffffff) that is greater than the file size (0x280)
+# RUN: llvm-readobj -A %t.err5.o 2>&1 | FileCheck %s -DFILE=%t.err5.o -check-prefixes=NO-OUTPUT,ERR5
 
 # RUN: yaml2obj --docnum=3 -DVAL2=0x100 -DLINK=0xaaaaaaaa %s -o %t.err6.o
-# RUN: not llvm-readobj -A %t.err6.o 2>&1 | FileCheck %s -DFILE=%t.err6.o -check-prefix ERR6
-
-# ERR6: error: '[[FILE]]': unable to get a symbol table linked to the SHT_PROGBITS section with index 2: invalid section index: 2863311530
+# RUN: llvm-readobj -A %t.err6.o 2>&1 | FileCheck %s -DFILE=%t.err6.o -check-prefixes=NO-OUTPUT,ERR6
 
 # RUN: yaml2obj --docnum=3 -DVAL2=0x100 %s -o %t.err7.o
-# RUN: not llvm-readobj -A %t.err7.o 2>&1 | FileCheck %s -DFILE=%t.err7.o -check-prefix ERR7
-
-# ERR7: error: '[[FILE]]': unable to get a string table for the SHT_DYNAMIC section with index 1: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
+# RUN: llvm-readobj -A %t.err7.o 2>&1 | FileCheck %s -DFILE=%t.err7.o -check-prefixes=NO-OUTPUT,ERR7
+
+# NO-OUTPUT:      LoadName: <Not found>
+# NO-OUTPUT-NEXT: There is no .MIPS.abiflags section in the file.
+# NO-OUTPUT-NEXT: There is no .MIPS.options section in the file.
+# NO-OUTPUT-NEXT: There is no .reginfo section in the file.
+
+# ERR1-NEXT: warning: '[[FILE]]': cannot find JMPREL dynamic tag
+# ERR2-NEXT: warning: '[[FILE]]': cannot find MIPS_PLTGOT dynamic tag
+# ERR3-NEXT: warning: '[[FILE]]': there is no non-empty PLTGOT section at 0xffff
+# ERR4-NEXT: warning: '[[FILE]]': there is no non-empty RELPLT section at 0xffff
+# ERR5-NEXT: warning: '[[FILE]]': unable to read PLTGOT section content: section [index 2] has a sh_offset (0x70) + sh_size (0xffffffff) that is greater than the file size (0x280)
+# ERR6-NEXT: warning: '[[FILE]]': unable to get a symbol table linked to the SHT_PROGBITS section with index 2: invalid section index: 2863311530
+# ERR7-NEXT: warning: '[[FILE]]': unable to get a string table for the SHT_DYNAMIC section with index 1: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
+
+# NO-OUTPUT-EMPTY:
+# NO-OUTPUT-NOT: {{.}}
 
 ## Check how we print PLT entries when they are unnamed section symbols.
 # RUN: yaml2obj --docnum=4 %s -o %t3

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index c546be25a951..890bb2a21e82 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -2886,12 +2886,12 @@ template <class ELFT> void ELFDumper<ELFT>::printArchSpecificInfo() {
     printMipsReginfo();
     MipsGOTParser<ELFT> Parser(*this);
     if (Error E = Parser.findGOT(dynamic_table(), dynamic_symbols()))
-      reportError(std::move(E), ObjF.getFileName());
+      reportUniqueWarning(std::move(E));
     else if (!Parser.isGotEmpty())
       ELFDumperStyle->printMipsGOT(Parser);
 
     if (Error E = Parser.findPLT(dynamic_table()))
-      reportError(std::move(E), ObjF.getFileName());
+      reportUniqueWarning(std::move(E));
     else if (!Parser.isPltEmpty())
       ELFDumperStyle->printMipsPLT(Parser);
     break;


        


More information about the llvm-commits mailing list