]> granicus.if.org Git - llvm/commitdiff
[llvm-readobj/llvm-readelf] - Report a warning instead of a error when dumping a...
authorGeorge Rimar <grimar@accesssoftek.com>
Thu, 11 Jul 2019 12:26:48 +0000 (12:26 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Thu, 11 Jul 2019 12:26:48 +0000 (12:26 +0000)
It does not make sence to stop dumping the object if the broken
dynamic section was found. In this patch I changed the behavior from
"report an error" to "report a warning". This matches GNU.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365762 91177308-0d34-0410-b5e6-96231b3b80d8

test/Object/invalid.test
test/tools/llvm-readobj/elf-dynamic-malformed.test
tools/llvm-readobj/ELFDumper.cpp
tools/llvm-readobj/llvm-readobj.cpp

index cd855c14b0e43386ddf7587b82c35ef761dcc42e..97ebb9f8573931d7258a07f809e3fccc6de3bd23 100644 (file)
@@ -126,12 +126,12 @@ Sections:
 Symbols:
   - Name: foo
 
-## Check that llvm-readobj reports an error if .dynsym has an invalid sh_entsize.
+## Check that llvm-readobj reports a warning if .dynsym has an invalid sh_entsize.
 
 # RUN: yaml2obj %s --docnum=7 -o %t7
-# RUN: not llvm-readobj --dyn-symbols %t7 2>&1 | FileCheck --check-prefix=INVALID-DYNSYM-SIZE %s
+# RUN: llvm-readobj --dyn-symbols %t7 2>&1 | FileCheck --check-prefix=INVALID-DYNSYM-SIZE %s
 
-# INVALID-DYNSYM-SIZE: error: Invalid entity size
+# INVALID-DYNSYM-SIZE: warning: invalid section size (48) or entity size (32)
 
 --- !ELF
 FileHeader:
@@ -458,22 +458,22 @@ ProgramHeaders:
     Sections:
       - Section: .dynamic
 
-## Check that llvm-readobj reports an error when a dynamic relocation section
+## Check that llvm-readobj reports a warning when a dynamic relocation section
 ## has sh_entsize field with size != sizeof(Elf_Rela).
 
-# RUN: not llvm-readobj --dyn-relocations \
+# RUN: llvm-readobj --dyn-relocations \
 # RUN:   %p/Inputs/corrupt-invalid-relocation-size.elf.x86-64 2>&1 \
 # RUN:    | FileCheck --check-prefix=RELOC-BROKEN-ENTSIZE %s
 
-# RELOC-BROKEN-ENTSIZE: error: Invalid entity size
+# RELOC-BROKEN-ENTSIZE: warning: invalid section size (24) or entity size (25)
 
-## Check that llvm-readobj reports an error when .dynamic section has an invalid
+## Check that llvm-readobj reports a warning when .dynamic section has an invalid
 ## size, which isn't a multiple of the dynamic entry size. 
 
 # RUN: yaml2obj %s --docnum=22 -o %t22
-# RUN: not llvm-readobj --dyn-relocations %t22 2>&1 | FileCheck --check-prefix=DYN-TABLE-SIZE %s
+# RUN: llvm-readobj --dyn-relocations %t22 2>&1 | FileCheck --check-prefix=DYN-TABLE-SIZE %s
 
-# DYN-TABLE-SIZE: error: Invalid entity size
+# DYN-TABLE-SIZE: warning: invalid section size (1) or entity size (16)
 
 --- !ELF
 FileHeader:
index b860aa4b3b5b01f672161f0307bc83307f1d7058..c8aa8d58eec92f9513e730076a41579bdb2c3e42 100644 (file)
@@ -1,9 +1,32 @@
-# Test handling of a dynamic section size which is not a multiple of its entry size.
-# RUN: yaml2obj %s --docnum=1 -o %t.bad-size
-# RUN: not llvm-readobj --dynamic-table %t.bad-size 2>&1 | FileCheck %s --check-prefix ERR-SIZE
-# RUN: not llvm-readelf --dynamic-table %t.bad-size 2>&1 | FileCheck %s --check-prefix ERR-SIZE
+## Test handling of a dynamic section size which is not a multiple of its entry size.
+## Test the full output to demonstrate how we print the warnings.
 
-# ERR-SIZE: error: Invalid entity size
+# RUN: yaml2obj %s --docnum=1 -o %t.bad-size
+# RUN: llvm-readobj --all %t.bad-size 2>&1 \
+# RUN:   | FileCheck %s --implicit-check-not=warning --check-prefix WARN
+# RUN: llvm-readelf --all %t.bad-size 2>&1 \
+# RUN:   | FileCheck %s --implicit-check-not=warning --check-prefix WARN-GNU
+
+# WARN-NOT: warning
+# WARN: warning: invalid section size (4) or entity size (16)
+# WARN-EMPTY:
+# WARN-NEXT: File:
+# WARN:      Symbols [
+# WARN:      ]
+# WARN-EMPTY:
+## A warning is printed at the place where a normal dynamic table should be. 
+# WARN-NEXT: warning: invalid section size (4) or entity size (16)
+# WARN-NEXT: ProgramHeaders [
+
+# WARN-GNU-NOT:  warning
+# WARN-GNU:      warning: invalid section size (4) or entity size (16)
+# WARN-GNU-NEXT: ELF Header:
+# WARN-GNU:      Symbol table '.symtab' contains 1 entries:
+# WARN-GNU:        0:
+# WARN-GNU-EMPTY:
+## A warning is printed at the place where a normal dynamic table should be. 
+# WARN-GNU:      warning: invalid section size (4) or entity size (16)
+# WARN-GNU-EMPTY:
 
 --- !ELF
 FileHeader:
@@ -26,7 +49,7 @@ ProgramHeaders:
     Sections:
       - Section: .dynamic
 
-# Test handling of a .dynamic section with an invalid entsize (i.e. not 2 * sizeof(Elf_Dyn)).
+## Test handling of a .dynamic section with an invalid entsize (i.e. not 2 * sizeof(Elf_Dyn)).
 # RUN: yaml2obj %s --docnum=2 -o %t.bad-entsize
 # RUN: llvm-readobj --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE-LLVM
 # RUN: llvm-readelf --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE-GNU
@@ -68,7 +91,7 @@ ProgramHeaders:
     Sections:
       - Section: .dynamic
 
-# Test handling of string references pointing past the end of the dynamic string table.
+## Test handling of string references pointing past the end of the dynamic string table.
 # RUN: yaml2obj %s --docnum=3 -o %t.bad-string
 # RUN: llvm-readobj --dynamic-table %t.bad-string | FileCheck %s --check-prefix BAD-STRING-LLVM
 # RUN: llvm-readelf --dynamic-table %t.bad-string | FileCheck %s --check-prefix BAD-STRING-GNU
@@ -136,7 +159,7 @@ ProgramHeaders:
     Sections:
       - Section: .dynamic
 
-# Test handling of DT_STRTAB pointing outside the file's address space.
+## Test handling of DT_STRTAB pointing outside the file's address space.
 # RUN: yaml2obj %s --docnum=4 -o %t.bad-strtab
 
 # RUN: llvm-readobj --dynamic-table %t.bad-strtab 2>&1 >/dev/null | FileCheck %s --check-prefix BAD-STRTAB-ERR
@@ -181,7 +204,7 @@ ProgramHeaders:
     Sections:
       - Section: .dynamic
 
-# Test handling of other d_ptr tags pointing outside the file's address space.
+## Test handling of other d_ptr tags pointing outside the file's address space.
 # RUN: yaml2obj %s --docnum=5 -o %t.bad-rela
 # RUN: llvm-readobj --dynamic-table %t.bad-rela 2>&1 | FileCheck %s --check-prefixes=CHECK,BAD-RELA
 # RUN: llvm-readelf --dynamic-table %t.bad-rela 2>&1 | FileCheck %s --check-prefixes=CHECK,BAD-RELA-GNU
index b70f69c2a8b79b6d3c9c8762ce68b654fa81e1ad..589199c009f63fca0d76baa6cb0aeaa24a39319c 100644 (file)
@@ -134,8 +134,12 @@ struct DynRegionInfo {
     const Type *Start = reinterpret_cast<const Type *>(Addr);
     if (!Start)
       return {Start, Start};
-    if (EntSize != sizeof(Type) || Size % EntSize)
-      reportError("Invalid entity size");
+    if (EntSize != sizeof(Type) || Size % EntSize) {
+      // TODO: Add a section index to this warning.
+      reportWarning("invalid section size (" + Twine(Size) +
+                    ") or entity size (" + Twine(EntSize) + ")");
+      return {Start, Start};
+    }
     return {Start, Start + (Size / EntSize)};
   }
 };
index 31e8bbe1a627aca0404cf0b7fca91398886e77d2..f00d94ee5c42c90660570d66eeb89b797657c160 100644 (file)
@@ -377,6 +377,7 @@ LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) {
 }
 
 void reportWarning(Twine Msg) {
+  fouts().flush();
   errs() << "\n";
   WithColor::warning(errs()) << Msg << "\n";
 }