summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/MachOObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Object: Make SymbolicFile::symbol_{begin,end}() virtual and remove ↵Peter Collingbourne2016-11-221-2/+2
| | | | | | unnecessary wrappers. llvm-svn: 287611
* Add a checkSymbolTable() method to the MachOObjectFile class.Kevin Enderby2016-11-141-0/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The philosophy of the error checking in libObject for Mach-O files is that the constructor will check the load commands so for their tables the offsets and sizes are properly contained in the file. But there is no checking of the entries of any of the tables. For the contents of the tables themselves the methods accessing the contents of the entries return errors as needed. In some cases this however makes it difficult or cumbersome to produce a good error message which would include the tool name, file name, archive member, and name of the architecture of a slice of a universal file the error occurred in. So idea is that there will be a method to check a table which can be called up front before using it allowing a good error message to be produced before a table is used. And if only verification of the Mach-O file and its tables are wanted a new possible method checkAllTables() could be added to call all of the methods to check all the tables at some time when such methods exist. The checkSymbolTable() is the first of such methods to check one of the Mach-O file tables. This method initially will used in llvm-objdump’s DisassembleMachO() routine before it gets the section and symbol information. As if there are problems with the symbol table currently the error is first encountered by the bool operator() in the SymbolSorter() struct which passed to std::sort(). In this case there is no context as to the file name the symbol which results a poor error message: LLVM ERROR: truncated or malformed object (bad string index: 22 for symbol at index 1) with the added call to the checkSymbolTable() method the error message includes the tool name and file name: llvm-objdump: 'macho-invalid-symbol-strx': truncated or malformed object (bad string table index: 22 past the end of string table, for symbol at index 1) llvm-svn: 286887
* Make the Error class constructor protectedMehdi Amini2016-11-111-1/+1
| | | | | | | | | This is forcing to use Error::success(), which is in a wide majority of cases a lot more readable. Differential Revision: https://reviews.llvm.org/D26481 llvm-svn: 286561
* Add support for the ARM_THREAD_STATE64 andKevin Enderby2016-11-031-0/+19
| | | | | | | | | | | | | in llvm-objdump for Mach-O files add the printing of the ARM_THREAD_STATE64 in the same format as otool-classic(1) on darwin. To do this the 64-bit ARM general tread state needed to be defined in include/llvm/Support/MachO.h . rdar://28985800 llvm-svn: 285967
* Add the rest of the additional error checks for invalid Mach-O files whenKevin Enderby2016-11-021-19/+103
| | | | | | | | | | the offsets and sizes of an element of the Mach-O file overlaps with another element in the Mach-O file. Some other tests for malformed Mach-O files now run into these checks so their tests were also adjusted. llvm-svn: 285860
* More additional error checks for invalid Mach-O files whenKevin Enderby2016-10-311-5/+52
| | | | | | | | | | | the offsets and sizes of an element of the file overlaps with another element in the Mach-O file. This shows the approach to this testing for three elements and contains for tests for their overlap. Checking for all the remain elements will be added next. llvm-svn: 285632
* Another additional error check for invalid Mach-O files for theKevin Enderby2016-10-271-0/+26
| | | | | | | | | | | | | | | | | | | | | | obsolete load commands. Again the philosophy of the error checking in libObject for Mach-O files, the idea behind the checking is that we never will return a Mach-O file out of libObject that contains unknown things the library code can’t operate on. So known obsolete load commands will cause a hard error. Also to make things clear I have added comments to the values and structures in Support/Mach-O.h and Support/MachO.def as to what is obsolete. As noted in a TODO in the code, there may need to be a non-default mode to allow some unknown values for well structured Mach-O files with things like unknown load load commands. So things like using an old lldb on a newer Mach-O file could still provide some limited functionality. llvm-svn: 285342
* nother additional error check for an invalid Mach-O fileKevin Enderby2016-10-241-8/+27
| | | | | | | when contained in a Mach-O universal file and the cputypes in both headers don’t match. llvm-svn: 285026
* Another additional error check for invalid Mach-O files for theKevin Enderby2016-10-201-0/+34
| | | | | | | | | | | | load commands that use the MachO::twolevel_hints_command type which includes only the LC_TWOLEVEL_HINTS load command. This is not used in llvm libObject code or in llvm tool code. But does appear in one of the binary test files. While this load command is obsolete it is easier to add code for it in libObject than edit or change the binary test case. llvm-svn: 284769
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-10-191-0/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | load commands that use the MachO::thread_command type but are not used in llvm libObject code but used in llvm tool code. This includes the LC_UNIXTHREAD and LC_THREAD load commands. A quick note about the philosophy of the error checking in libObject for Mach-O files, the idea behind the checking is that we never will return a Mach-O file out of libObject that contains unknown things in the load commands. To do this the 32-bit ARM and PPC general tread states needed to be defined as two test case binaries contained them. If other thread states for other CPUs need to be added we will do that as needed. Going forward the LC_MAIN load command is used to set the entry point in Mach-O executables these days instead of an LC_UNIXTHREAD as was done in the past. So today only in core files are LC_THREAD load commands and thread states usually found. Other thread states have not yet been defined in include/Support/MachO.h at this time. But that can be added as needed with their corresponding checking also added. llvm-svn: 284668
* One more additional error check for invalid Mach-O files for aKevin Enderby2016-10-181-0/+5
| | | | | | | | | load command that use the MachO:: linkedit_data_command type but is not used in llvm libObject code but used in llvm tool code. This is for the LC_CODE_SIGNATURE load command. llvm-svn: 284529
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-10-181-0/+25
| | | | | | | | | | | load commands that use the MachO::routines_command and and MachO::routines_command_64 types but are not used in llvm libObject code but used in llvm tool code. This includes the LC_ROUTINES and LC_ROUTINES_64 load commands. llvm-svn: 284504
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-10-171-0/+78
| | | | | | | | | | | | load commands that use the MachO::sub_framework_command, MachO::sub_umbrella_command, MachO::sub_library_command and MachO::sub_client_command types but are not used in llvm libObject code but used in llvm tool code. This includes the LC_SUB_FRAMEWORK, LC_SUB_UMBRELLA, LC_SUB_LIBRARY and LC_SUB_CLIENT load commands. llvm-svn: 284431
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-10-111-0/+36
| | | | | | | | | load commands that uses the MachO::linker_option_command type but not used in llvm libObject code but used in llvm tool code. This includes just LC_LINKER_OPTION load command. llvm-svn: 283939
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-10-041-0/+47
| | | | | | | | | | | load commands that uses the MachO::encryption_info_command and MachO::encryption_info_command types but not used in llvm libObject code but used in llvm tool code. This includes just LC_ENCRYPTION_INFO and LC_ENCRYPTION_INFO_64 load commands. llvm-svn: 283250
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-09-291-0/+12
| | | | | | | | | load command that uses the MachO::entry_point_command type but not used in llvm libObject code but used in llvm tool code. This includes just the LC_MAIN load command. llvm-svn: 282766
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-09-291-0/+12
| | | | | | | | | load command that uses the Mach::source_version_command type but not used in llvm libObject code but used in llvm tool code. This includes just the LC_SOURCE_VERSION load command. llvm-svn: 282736
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-09-281-0/+32
| | | | | | | | | load command that uses the Mach::rpath_command type but not used in llvm libObject code but used in llvm tool code. This includes just the LC_RPATH load command. llvm-svn: 282649
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-09-281-0/+32
| | | | | | | | | | other load commands that use the Mach::version_min_command type but not used in llvm libObject code but used in llvm tool code. This includes LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS, LC_VERSION_MIN_TVOS and LC_VERSION_MIN_WATCHOS load commands. llvm-svn: 282635
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-09-271-0/+38
| | | | | | | | | | other load commands that use the MachO::dylinker_command type but not used in llvm libObject code but used in llvm tool code. This includes LC_ID_DYLINKER, LC_LOAD_DYLINKER and LC_DYLD_ENVIRONMENT load commands. llvm-svn: 282553
* Next set of additional error checks for invalid Mach-O files for theKevin Enderby2016-09-261-0/+15
| | | | | | | | | | other load commands that use the Mach::linkedit_data_command type but not used in llvm libObject code but used in llvm tool code. This includes LC_FUNCTION_STARTS, LC_SEGMENT_SPLIT_INFO and LC_DYLIB_CODE_SIGN_DRS load commands. llvm-svn: 282441
* Next set of additional error checks for invalid Mach-O files for bad LC_UUIDKevin Enderby2016-09-211-2/+6
| | | | | | | load commands. Added a missing check and made the check for more than one like other other “more than one” checks. And of course added test cases. llvm-svn: 282104
* Next set of additional error checks for invalid Mach-O files for bad load ↵Kevin Enderby2016-09-201-13/+83
| | | | | | | | | | | | | | | | commands that use the Mach::dylib_command type for the load commands that are currently used in the MachOObjectFile constructor. This contains the missing checks for LC_ID_DYLIB, LC_ID_DYLIB, etc. load commands and the fields for the Mach::dylib_command type. Also checks that only an MH_DYLIB or MH_STUB_DYLIB has an LC_ID_DYLIB load command (and others filetype don’t) and there is not more than one of these load commands. llvm-svn: 282008
* Next set of additional error checks for invalid Mach-O files for bad load ↵Kevin Enderby2016-09-131-7/+82
| | | | | | | | | | | | | commands that use the Mach::dyld_info_command type for the load commands that are currently use in the MachOObjectFile constructor. This contains the missing checks for LC_DYLD_INFO and LC_DYLD_INFO_ONLY load commands and the fields for the Mach::dyld_info_command type. llvm-svn: 281400
* Next set of additional error checks for invalid Mach-O files for bad load ↵Kevin Enderby2016-08-311-12/+36
| | | | | | | | | | | | | | | | | commands that use the Mach::linkedit_data_command type for the load commands that are currently used in the MachOObjectFile constructor. This contains the missing checks for LC_DATA_IN_CODE and LC_LINKER_OPTIMIZATION_HINT load commands and the fields for the Mach::linkedit_data_command type. Checking for other load commands that use this type will be added later. Also fixed a couple of places that was using sizeof(MachOObjectFile::LoadCommandInfo) that should have been using sizeof(MachO::load_command). llvm-svn: 280267
* Next set of additional error checks for invalid Mach-O files for bad ↵Kevin Enderby2016-08-301-6/+99
| | | | | | | | LC_DYSYMTAB’s. This contains the missing checks for LC_DYSYMTAB load command fields. llvm-svn: 280161
* Next set of additional error checks for invalid Mach-O files for bad ↵Kevin Enderby2016-08-261-5/+50
| | | | | | | | LC_SYMTAB’s. This contains the missing checks for LC_SYMTAB load command fields. llvm-svn: 279854
* Reformat.NAKAMURA Takumi2016-08-221-2/+2
| | | | llvm-svn: 279409
* Untabify.NAKAMURA Takumi2016-08-221-15/+14
| | | | llvm-svn: 279408
* Next set of additional error checks for invalid Mach-O files.Kevin Enderby2016-08-121-17/+96
| | | | | | | | | | This contains the two missing checks for LC_SEGMENT load command fields. And checks for the Mach-O sections fields that would make them invalid. With the new checks, some of the existing malformed file checks now trips one of these instead of the issue it was having before so those tests were adjusted. llvm-svn: 278557
* Add the first of what will be a long line of additional error checks for ↵Kevin Enderby2016-08-051-0/+5
| | | | | | | | | | | | | invalid Mach-O files. This is where an LC_SEGMENT load command has a fileoff field that extends past the end of the file. Also fix llvm-nm and llvm-size to remove the errorToErrorCode() call so error messages are printed. And needed to update a few test cases now that they do print the error messages just a bit differently. llvm-svn: 277845
* [Support] Make ErrorAsOutParameter take an Error* rather than an Error&.Lang Hames2016-07-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | This allows ErrorAsOutParameter to work better with "optional" errors. For example, consider a function where for certain input values it is known that the function can't fail. This can now be written as: Result foo(Arg X, Error *Err) { ErrorAsOutParameter EAO(Err); if (<Error Condition>) { if (Err) *Err = <report error>; else llvm_unreachable("Unexpected failure!"); } } Rather than having to construct an ErrorAsOutParameter under every conditional where Err is known to be non-null. llvm-svn: 276430
* Add checks to the MachOObjectFile() constructor to make sure load commands sizesKevin Enderby2016-07-071-0/+19
| | | | | | are the correct multiple. llvm-svn: 274798
* Thread Expected<...> up from libObject’s getSymbolAddress() for symbols to ↵Kevin Enderby2016-06-241-1/+1
| | | | | | | | | | | | | | | | | | | | | allow a good error message to be produced. This is nearly the last libObject interface that used ErrorOr and the last one that appears in llvm/include/llvm/Object/MachO.h . For Mach-O objects this is just a clean up because it’s version of getSymbolAddress() can’t return an error. I will leave it to the experts on COFF and ELF to actually add meaning full error messages in their tests if they wish. And also leave it to these experts to change the last two ErrorOr interfaces in llvm/include/llvm/Object/ObjectFile.h for createCOFFObjectFile() and createELFObjectFile() if they wish. Since there are no test cases for COFF and ELF error cases with respect to getSymbolAddress() in the test suite this is no functional change (NFC). llvm-svn: 273701
* Recommit r270547 ([llvm-dwarfdump] - Teach dwarfdump to decompress debug ↵George Rimar2016-05-241-0/+4
| | | | | | | | | | | | | | | | | | | | | | | sections in zlib style.) Fix was: 1) Had to regenerate dwarfdump-test-zlib.elf-x86-64, dwarfdump-test-zlib-gnu.elf-x86-64 (because llvm-symbolizer-zlib.test uses that inputs for its purposes and failed). 2) Updated llvm-symbolizer-zlib.test (updated used call function address to match new files + added one more check for newly created dwarfdump-test-zlib-gnu.elf-x86-64 binary input). 3) Updated comment in dwarfdump-test-zlib.cc. Original commit message: [llvm-dwarfdump] - Teach dwarfdump to decompress debug sections in zlib style. Before this llvm-dwarfdump only recognized zlib-gnu compression style of headers, this patch adds support for zlib style. It looks reasonable to support both styles for dumping, even if we are not going to suport generating of deprecated gnu one. Differential revision: http://reviews.llvm.org/D20470 llvm-svn: 270557
* Revert r270543 ("Recommit r270540")George Rimar2016-05-241-4/+0
| | | | | | | | Failed build bot in another test. I am sorry for noise. http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_check/23679/testReport/junit/LLVM/DebugInfo/llvm_symbolizer_zlib_test/ llvm-svn: 270547
* Recommit r270540George Rimar2016-05-241-0/+4
| | | | | | | | | | | | | | | | fix: forgot to commit the updated dwarfdump-test-zlib.elf-x86-64 Original commit message: [llvm-dwarfdump] - Teach dwarfdump to decompress debug sections in zlib style. Before this llvm-dwarfdump only recognized zlib-gnu compression style of headers, this patch adds support for zlib style. It looks reasonable to support both styles for dumping, even if we are not going to suport generating of deprecated gnu one. Differential revision: http://reviews.llvm.org/D20470 llvm-svn: 270543
* Revert r270540 "[llvm-dwarfdump] - Teach dwarfdump to decompress debug ↵George Rimar2016-05-241-4/+0
| | | | | | | | | sections in zlib style." it broked bot: http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/5036 llvm-svn: 270541
* [llvm-dwarfdump] - Teach dwarfdump to decompress debug sections in zlib style.George Rimar2016-05-241-0/+4
| | | | | | | | | | | Before this llvm-dwarfdump only recognized zlib-gnu compression style of headers, this patch adds support for zlib style. It looks reasonable to support both styles for dumping, even if we are not going to suport generating of deprecated gnu one. Differential revision: http://reviews.llvm.org/D20470 llvm-svn: 270540
* Change GenericBinaryError to no longer include a FileName, which is then notKevin Enderby2016-05-061-27/+26
| | | | | | | | | | | | | | | | | | part of the error message. As the caller is the one that needs to add the name of where the "object file" comes from to the error message as the object file could be in an archive, or coming from a slice of a Mach-O universal file or a buffer created by a JIT. In the cases of a Mach-O universal file the architecture name may or may not also need to be printed which is up to the tool code. For example if the tool code is only selecting the host architecture slice then that architecture name is never printed. This patch is the change to the libObject code and there will be follow on commits for changes to the code for each tool. llvm-svn: 268789
* Object: Fix two -Wpessimizing-move warnings after r268694Justin Bogner2016-05-051-5/+4
| | | | llvm-svn: 268697
* Fix window bots failures due to r268694 - Cleanup and refactor of ↵Kevin Enderby2016-05-051-1/+1
| | | | | | malformedError() in lib/Object/MachOObjectFile.cpp . llvm-svn: 268696
* Cleanup and refactor of malformedError() in lib/Object/MachOObjectFile.cpp .Kevin Enderby2016-05-051-71/+41
| | | | | | No functional change. llvm-svn: 268694
* Clean up the specific error message for a malformed Mach-O files with bad ↵Kevin Enderby2016-05-051-10/+12
| | | | | | | | | | | | | | | | | | | | | segment load commands. The existing test case in test/Object/macho-invalid.test for macho-invalid-too-small-segment-load-command has a cmdsize of 55, while being too small also it is not a multiple of 4. So when that check is added this test case will produce a different error. So I constructed a new test case that will trigger the intended error. I also changed the error message to be consistent with the other malformed Mach-O file error messages which prints the load command index. I also removed both object_error::macho_load_segment_too_small and object_error::macho_load_segment_too_many_sections from Object/Error.h as they are not needed and can just use object_error::parse_failed and let the error message string distinguish the specific error. llvm-svn: 268652
* Produce another specific error message for a malformed Mach-O file when a loadKevin Enderby2016-05-031-5/+7
| | | | | | | | | | | | | | | | command has a size less than 8 bytes. I think the existing test case in test/Object/macho-invalid.test for macho64-invalid-too-small-load-command was trying to test for this but that test case triggered a different error given how it was constructed. So I constructed a new test case that would trigger this specific error. I also changed the error message to be consistent with the other malformed Mach-O file error messages. I also removed object_error::macho_small_load_command from Object/Error.h as it is not needed and can just use object_error::parse_failed and let the error message string distinguish the error. llvm-svn: 268463
* Produce another specific error message for a malformed Mach-O file when a loadKevin Enderby2016-05-031-2/+10
| | | | | | | | | | | | | | command other than the first one is past the end of the load commands. This is like the test case in test/Object/macho-invalid.test for macho64-invalid-incomplete-load-command but it is the second load command that is past the end of all the load commands instead of the first. The code in the constructor for MachOObjectFile that loops over the load commands used getNextLoadCommandInfo() which was not producing a good error message. So that was fixed and a test case was added. llvm-svn: 268403
* Thread Expected<...> up from libObject’s getType() for symbols to allow ↵Kevin Enderby2016-05-021-7/+8
| | | | | | | | | | | | | | | | | | | | | | llvm-objdump to produce a good error message. Produce another specific error message for a malformed Mach-O file when a symbol’s section index is more than the number of sections. The existing test case in test/Object/macho-invalid.test for macho-invalid-section-index-getSectionRawName now reports the error with the message indicating that a symbol at a specific index has a bad section index and that bad section index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values.  So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: "// TODO: Actually report errors helpfully" and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. llvm-svn: 268298
* MachO: remove weird ARM/Thumb interface from MachOObjectFileTim Northover2016-04-221-58/+6
| | | | | | | | | | | | | | | | Only one consumer (llvm-objdump) actually cared about the fact that there were two triples. Others were actively working around the fact that the Triple returned by getArch might have been invalid. As for llvm-objdump, it needs to be acutely aware of both Triples anyway, so being generic in the exposed API is no benefit. Also rename the version of getArch returning a Triple. Users were having to pass an unwanted nullptr to disambiguate the two, which was nasty. The only functional change here is that armv7m and armv7em object files no longer crash llvm-objdump. llvm-svn: 267249
* Fix a typo in an error message. Caught by Sean Silva!Kevin Enderby2016-04-211-1/+1
| | | | llvm-svn: 267056
* hange the variable name big_size to BigSize. Caught by Rafael Espíndola!Kevin Enderby2016-04-211-14/+14
| | | | llvm-svn: 267043
OpenPOWER on IntegriCloud