1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00

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

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

llvm-svn: 365762
This commit is contained in:
George Rimar 2019-07-11 12:26:48 +00:00
parent e67c5ce969
commit 44f982eeb2
4 changed files with 48 additions and 20 deletions

View 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:

View 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

View 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)};
}
};

View 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";
}