Index: llvm/trunk/test/Object/invalid.test =================================================================== --- llvm/trunk/test/Object/invalid.test +++ llvm/trunk/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 section size (48) or entity size (32) --- !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 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: llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test +++ llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test @@ -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 @@ 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 @@ 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 @@ 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 @@ 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: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp +++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp @@ -134,8 +134,12 @@ const Type *Start = reinterpret_cast(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: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp +++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp @@ -377,6 +377,7 @@ } void reportWarning(Twine Msg) { + fouts().flush(); errs() << "\n"; WithColor::warning(errs()) << Msg << "\n"; }