1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00
llvm-mirror/lib/Object
Kevin Enderby 9b924af8f7 Fix the code that leads to the incorrect trigger of the report_fatal_error()
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
2016-01-22 22:49:55 +00:00
..
Archive.cpp Reapply r250906 with many suggested updates from Rafael Espindola. 2015-11-05 19:24:56 +00:00
ArchiveWriter.cpp Handle archives with paths in the names. 2015-12-18 16:07:17 +00:00
Binary.cpp
CMakeLists.txt Support for function summary index bitcode sections and files. 2015-10-04 14:33:43 +00:00
COFFObjectFile.cpp COFF: Teach llvm-objdump how to dump DLL forwarder symbols. 2016-01-12 23:28:42 +00:00
COFFYAML.cpp [COFF] Add IMAGE_SCN_TYPE_NOLOAD to SectionCharacteristics 2015-07-30 16:47:56 +00:00
ELF.cpp [WebAssembly] Add a EM_WEBASSEMBLY value, and several bits of code that use it. 2016-01-12 20:56:01 +00:00
ELFObjectFile.cpp
ELFYAML.cpp [llvm-readobj][ELF] Teach llvm-readobj to show arch specific ELF section's flags 2016-01-20 19:15:18 +00:00
Error.cpp Add dynamic_table iterators back to ELF.h. 2015-08-07 15:25:20 +00:00
FunctionIndexObjectFile.cpp Remove "ExportingModule" from ThinLTO Index (NFC) 2015-12-03 02:37:23 +00:00
IRObjectFile.cpp Use diagnostic handler in the LLVMContext 2015-12-14 23:17:03 +00:00
LLVMBuild.txt
MachOObjectFile.cpp Fix the code that leads to the incorrect trigger of the report_fatal_error() 2016-01-22 22:49:55 +00:00
MachOUniversal.cpp Use early return NFC. 2015-08-03 00:10:33 +00:00
Makefile
Object.cpp Convert getSymbolSection to return an ErrorOr. 2015-08-07 23:27:14 +00:00
ObjectFile.cpp Convert getSymbolSection to return an ErrorOr. 2015-08-07 23:27:14 +00:00
RecordStreamer.cpp
RecordStreamer.h Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC) 2015-06-23 09:49:53 +00:00
SymbolicFile.cpp Re-apply r246276 - Object: Teach llvm-ar to create symbol table for COFF short import files 2015-08-28 07:40:30 +00:00
SymbolSize.cpp [SymbolSize] Skip sorting by index, just assign by index. 2015-06-29 16:05:00 +00:00