mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:43:36 +01:00
9b924af8f7
in MachOObjectFile::getSymbolByIndex() when a Mach-O file has a symbol table load command but the number of symbols are zero. The code in MachOObjectFile::symbol_begin_impl() should not be assuming there is a symbol at index 0, in cases there is no symbol table load command or the count of symbol is zero. So I also fixed that. And needed to fix MachOObjectFile::symbol_end_impl() to also do the same thing for no symbol table or one with zero entries. The code in MachOObjectFile::getSymbolByIndex() should trigger the report_fatal_error() for programmatic errors for any index when there is no symbol table load command and not return the end iterator. So also fixed that. Note there is no test case as this is a programmatic error. The test case using the file macho-invalid-bad-symbol-index has a symbol table load command with its number of symbols (nsyms) is zero. Which was incorrectly testing the bad triggering of the report_fatal_error() in in MachOObjectFile::getSymbolByIndex(). This test case is an invalid Mach-O file but not for that reason. It appears this Mach-O file use to have an nsyms value of 11, and what makes this Mach-O file invalid is the counts and indexes into the symbol table of the dynamic load command are now invalid because the number of symbol table entries (nsyms) is now zero. Which can be seen with the existing llvm-obdump: % llvm-objdump -private-headers macho-invalid-bad-symbol-index … Load command 4 cmd LC_SYMTAB cmdsize 24 symoff 4216 nsyms 0 stroff 4392 strsize 144 Load command 5 cmd LC_DYSYMTAB cmdsize 80 ilocalsym 0 nlocalsym 8 (past the end of the symbol table) iextdefsym 8 (greater than the number of symbols) nextdefsym 2 (past the end of the symbol table) iundefsym 10 (greater than the number of symbols) nundefsym 1 (past the end of the symbol table) ... And the native darwin tools generates an error for this file: % nm macho-invalid-bad-symbol-index nm: object: macho-invalid-bad-symbol-index truncated or malformed object (ilocalsym plus nlocalsym in LC_DYSYMTAB load command extends past the end of the symbol table) I added new checks for the indexes and sizes for these in the constructor of MachOObjectFile. And added comments for what would be a proper diagnostic messages. And changed the test case using macho-invalid-bad-symbol-index to test for the new error now produced. Also added a test with a valid Mach-O file with a symbol table load command where the number of symbols is zero that shows the report_fatal_error() is not called. llvm-svn: 258576
59 lines
3.5 KiB
Plaintext
59 lines
3.5 KiB
Plaintext
// No crash, might not be totally invalid
|
|
RUN: llvm-objdump -private-headers %p/Inputs/macho-invalid-zero-ncmds
|
|
|
|
RUN: not llvm-objdump -private-headers %p/Inputs/macho64-invalid-incomplete-load-command 2>&1 \
|
|
RUN: | FileCheck -check-prefix INCOMPLETE-LOADC %s
|
|
INCOMPLETE-LOADC: Invalid data was encountered while parsing the file.
|
|
|
|
RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-too-small-load-command 2>&1 \
|
|
RUN: | FileCheck -check-prefix SMALL-LOADC-SIZE %s
|
|
RUN: not llvm-objdump -private-headers %p/Inputs/macho64-invalid-too-small-load-command 2>&1 \
|
|
RUN: | FileCheck -check-prefix SMALL-LOADC-SIZE %s
|
|
SMALL-LOADC-SIZE: Mach-O load command with size < 8 bytes
|
|
|
|
RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-too-small-segment-load-command 2>&1 \
|
|
RUN: | FileCheck -check-prefix SMALL-SEGLOADC-SIZE %s
|
|
RUN: not llvm-objdump -private-headers %p/Inputs/macho64-invalid-too-small-segment-load-command 2>&1 \
|
|
RUN: | FileCheck -check-prefix SMALL-SEGLOADC-SIZE %s
|
|
SMALL-SEGLOADC-SIZE: Mach-O segment load command size is too small
|
|
|
|
RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-no-size-for-sections 2>&1 \
|
|
RUN: | FileCheck -check-prefix TOO-MANY-SECTS %s
|
|
RUN: not llvm-objdump -private-headers %p/Inputs/macho64-invalid-no-size-for-sections 2>&1 \
|
|
RUN: | FileCheck -check-prefix TOO-MANY-SECTS %s
|
|
TOO-MANY-SECTS: Mach-O segment load command contains too many sections
|
|
|
|
RUN: not llvm-objdump -t %p/Inputs/macho-invalid-bad-symbol-index 2>&1 \
|
|
RUN: | FileCheck -check-prefix BAD-SYMBOL %s
|
|
BAD-SYMBOL: Invalid data was encountered while parsing the file.
|
|
RUN: llvm-objdump -t %p/Inputs/macho-valid-0-nsyms 2>&1 \
|
|
RUN: | FileCheck -check-prefix ZERO-NSYMS %s
|
|
ZERO-NSYMS: SYMBOL TABLE
|
|
ZERO-NSYMS-NOT: Requested symbol index is out of range
|
|
|
|
RUN: not llvm-objdump -t %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
|
|
RUN: | FileCheck -check-prefix NAME-PAST-EOF %s
|
|
NAME-PAST-EOF: error reading file: Invalid data was encountered while parsing the file.
|
|
RUN: llvm-nm -pa %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
|
|
RUN: | FileCheck -check-prefix NAME-PAST-EOF-nm-pa %s
|
|
NAME-PAST-EOF-nm-pa: 0000000000000000 - 00 0000 SO bad string index
|
|
RUN: llvm-nm -pax %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
|
|
RUN: | FileCheck -check-prefix NAME-PAST-EOF-nm-pax %s
|
|
NAME-PAST-EOF-nm-pax: 0000000000000000 64 00 0000 fe000002 bad string index
|
|
|
|
RUN: llvm-nm %p/Inputs/macho-invalid-section-index-getSectionRawName 2>&1 \
|
|
RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SYMBOL-SEC %s
|
|
INVALID-SECTION-IDX-SYMBOL-SEC: 0000000100000000 S __mh_execute_header
|
|
RUN: llvm-nm -m %p/Inputs/macho-invalid-section-index-getSectionRawName 2>&1 \
|
|
RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SYMBOL-SEC-m %s
|
|
INVALID-SECTION-IDX-SYMBOL-SEC-m: 0000000100000000 (?,?) [referenced dynamically] external __mh_execute_header
|
|
RUN: llvm-nm -pax %p/Inputs/macho-invalid-section-index-getSectionRawName 2>&1 \
|
|
RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SYMBOL-SEC-pax %s
|
|
INVALID-SECTION-IDX-SYMBOL-SEC-pax: 0000000100000000 0f 42 0010 00000065 __mh_execute_header
|
|
|
|
RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-header 2>&1 | FileCheck -check-prefix INVALID-HEADER %s
|
|
INVALID-HEADER: Invalid data was encountered while parsing the file
|
|
|
|
RUN: not llvm-objdump -private-headers %p/Inputs/macho64-invalid-incomplete-segment-load-command 2>&1 | FileCheck -check-prefix INCOMPLETE-SEGMENT-LOADC %s
|
|
INCOMPLETE-SEGMENT-LOADC: Invalid data was encountered while parsing the file
|