[PATCH] D64472: [llvm-readobj/llvm-readelf] - Report a warning instead of a error when dumping a broken dynamic section.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 02:36:43 PDT 2019


grimar updated this revision to Diff 208903.
grimar added a comment.

- Improve one of the test cases a bit.


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

https://reviews.llvm.org/D64472

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


Index: tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- tools/llvm-readobj/ELFDumper.cpp
+++ tools/llvm-readobj/ELFDumper.cpp
@@ -134,8 +134,11 @@
     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: This warning needs to be more precise.
+      reportWarning("Invalid entity size");
+      return {Start, Start};
+    }
     return {Start, Start + (Size / EntSize)};
   }
 };
Index: test/tools/llvm-readobj/elf-dynamic-malformed.test
===================================================================
--- test/tools/llvm-readobj/elf-dynamic-malformed.test
+++ test/tools/llvm-readobj/elf-dynamic-malformed.test
@@ -1,9 +1,9 @@
 # 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
+# RUN: llvm-readobj --dynamic-table %t.bad-size 2>&1 | FileCheck %s --implicit-check-not=Dynamic --check-prefix WARN
+# RUN: llvm-readelf --dynamic-table %t.bad-size 2>&1 | FileCheck %s --implicit-check-not=Dynamic --check-prefix WARN
 
-# ERR-SIZE: error: Invalid entity size
+# WARN: warning: Invalid entity size
 
 --- !ELF
 FileHeader:
Index: test/Object/invalid.test
===================================================================
--- test/Object/invalid.test
+++ test/Object/invalid.test
@@ -126,12 +126,12 @@
 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 entity size
 
 --- !ELF
 FileHeader:
@@ -458,22 +458,22 @@
     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 entity size
 
-## 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 entity size
 
 --- !ELF
 FileHeader:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64472.208903.patch
Type: text/x-patch
Size: 3503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190710/659a2064/attachment.bin>


More information about the llvm-commits mailing list