summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/MachOObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Revert r304002 "[DWARF] - Make collectAddressRanges() return section index ↵George Rimar2017-05-261-4/+0
| | | | | | | | in addition to Low/High PC" Revert it again. Now another bot unhappy: http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/8750 llvm-svn: 304011
* [DWARF] - Make collectAddressRanges() return section index in addition to ↵George Rimar2017-05-261-0/+4
| | | | | | | | | | | | | | | | | | Low/High PC This change is intended to use for LLD in D33183. Problem we have in LLD when building .gdb_index is that we need to know section which address range belongs to. Previously it was solved on LLD side by providing fake section addresses with use of llvm::LoadedObjectInfo interface. We assigned file offsets as addressed. Then after obtaining ranges lists, for each range we had to find section ID's. That not only was slow, but also complicated implementation and was the reason of incorrect behavior when sections share the same offsets, like D33176 shows. This patch makes DWARF parsers to return section index as well. That solves problem mentioned above. Differential revision: https://reviews.llvm.org/D33184 llvm-svn: 304002
* Revert "[DWARF] - Make collectAddressRanges() return section index in ↵George Rimar2017-05-261-4/+0
| | | | | | | | | | | | addition to Low/High PC" Broked BB again: TEST 'LLVM :: DebugInfo/X86/dbg-value-regmask-clobber.ll' FAILED ... LLVM ERROR: Section was outside of section table. llvm-svn: 303984
* Recommit r303978 "[DWARF] - Make collectAddressRanges() return section index ↵George Rimar2017-05-261-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | in addition to Low/High PC" With fix of test compilation. Initial commit message: This change is intended to use for LLD in D33183. Problem we have in LLD when building .gdb_index is that we need to know section which address range belongs to. Previously it was solved on LLD side by providing fake section addresses with use of llvm::LoadedObjectInfo interface. We assigned file offsets as addressed. Then after obtaining ranges lists, for each range we had to find section ID's. That not only was slow, but also complicated implementation and was the reason of incorrect behavior when sections share the same offsets, like D33176 shows. This patch makes DWARF parsers to return section index as well. That solves problem mentioned above. Differential revision: https://reviews.llvm.org/D33184 llvm-svn: 303983
* Revert r303978 "[DWARF] - Make collectAddressRanges() return section index ↵George Rimar2017-05-261-4/+0
| | | | | | | | in addition to Low/High PC" It failed BB. llvm-svn: 303981
* [DWARF] - Make collectAddressRanges() return section index in addition to ↵George Rimar2017-05-261-0/+4
| | | | | | | | | | | | | | | | | | | | | | Low/High PC This change is intended to use for LLD in D33183. Problem we have in LLD when building .gdb_index is that we need to know section which address range belongs to. Previously it was solved on LLD side by providing fake section addresses with use of llvm::LoadedObjectInfo interface. We assigned file offsets as addressed. Then after obtaining ranges lists, for each range we had to find section ID's. That not only was slow, but also complicated implementation and was the reason of incorrect behavior when sections share the same offsets, like D33176 shows. This patch makes DWARF parsers to return section index as well. That solves problem mentioned above. Differential revision: https://reviews.llvm.org/D33184 llvm-svn: 303978
* [Object] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko2017-04-211-103/+112
| | | | | | other minor fixes (NFC). llvm-svn: 301049
* Remove unused functions. Remove static qualifier from functions in header ↵Vassil Vassilev2017-04-111-7/+0
| | | | | | files. NFC. llvm-svn: 299947
* [Object] Remove check for BIND_OPCODE_DONE/REBASE_OPCODE_DONE.Juergen Ributzka2017-03-301-12/+8
| | | | | | | | | | BIND_OPCODE_DONE/REBASE_OPCODE_DONE may appear at the end of the opcode array, but they are not required to. The linker only adds them as padding to align the opcodes to pointer size. This fixes rdar://problem/31285560. llvm-svn: 299104
* Add the error handling for Mach-O dyld compact lazy bind, weak bind andKevin Enderby2017-03-271-46/+274
| | | | | | | | | | | | | | | | | | | | | rebase entry errors and test cases for each of the error checks. Also verified with Nick Kledzik that a BIND_OPCODE_SET_ADDEND_SLEB opcode is legal in a lazy bind table, so code that had that as an error check was removed. With MachORebaseEntry and MachOBindEntry classes now returning an llvm::Error in all cases for malformed input the variables Malformed and logic to set use them is no longer needed and has been removed from those classes. Also in a few places, removed the redundant Done assignment to true when also calling moveToEnd() as it does that assignment. This only leaves the dyld compact export entries left to have error handling yet to be added for the dyld compact info. llvm-svn: 298883
* Add the rest of the error checking for Mach-O dyld compact bind entry errorsKevin Enderby2017-03-201-29/+406
| | | | | | | | | | | | | | | | | | | | | | | | | and test cases for each of the error checks. To do this more plumbing was needed so that the segment indexes and segment offsets can be checked. Basically what was done was the SegInfo from llvm-objdump’s MachODump.cpp was moved into libObject for Mach-O objects as BindRebaseSegInfo and it is only created when an iterator for bind or rebase entries are created. This commit really only adds the error checking and test cases for the bind table entires and the checking for the lazy bind and weak bind entries are still to be fully done as well as the rebase entires. Though some of the plumbing for those are added with this commit. Those other error checks and test cases will be added in follow on commits. Note, the two llvm_unreachable() calls should now actually be unreachable with the error checks in place and would take a logic bug in the error checking code to be reached if the segment indexes and segment offsets are used from a checked bind entry. Comments have been added to the methods that require the arguments to have been checked prior to calling. llvm-svn: 298292
* Actually add error handling to unpacking the dyld compact bind andKevin Enderby2017-02-281-11/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | other tables. Providing a helpful error message to what the error is and where the error occurred based on which opcode it was associated with. There have been handful of bug fixes dealing with bad bind info in object files, r294021 and r249845, which only put a band aid on the problem after a bad bind table was created after unpacking from its compact info. In these cases a bind table should have never been created and an error should have simply been generated. This change puts in place the plumbing to allow checking and returning of an error when the compact info is unpacked. This follows the model of iterators that can fail that Lang Hanes designed when fixing the problem for bad archives r275316 (or r275361). This change uses one of the existing test cases that now causes an error instead of printing <<bad library ordinal>> after a bad bind table is created. The error uses the offset into the opcode table as shown with the macOS dyldinfo(1) tool to indicate where the error is and which opcode and which parameter is in error. For example the exiting test case has this lazy binding opcode table: % dyldinfo -opcodes test/tools/llvm-objdump/Inputs/bad-ordinal.macho-x86_64 … lazy binding opcodes: 0x0000 BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB(0x02, 0x00000010) 0x0002 BIND_OPCODE_SET_DYLIB_ORDINAL_IMM(2) In the test case the binary only has one library so setting the library ordinal to the value of 2 in the BIND_OPCODE_SET_DYLIB_ORDINAL_IMM opcode at 0x0002 above is an error. This now produces this error message: % llvm-objdump -lazy-bind bad-ordinal.macho-x86_64 … llvm-objdump: 'bad-ordinal.macho-x86_64': truncated or malformed object (for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB bad library ordinal: 2 (max 1) for opcode at: 0x2) This change provides the plumbing for the error handling and one example of an error message. Other error checks and test cases will be added in follow on commits. llvm-svn: 296527
* Yet another fix llvm-objdump so it picks a good CPU based for Mach-O files,Kevin Enderby2017-02-101-0/+2
| | | | | | | | | | | in this case for CPU_SUBTYPE_ARM64_ALL. For this cpusubtype it should default to a cyclone CPU to give proper disassembly without a -mcpu= flag. rdar://27767188 llvm-svn: 294771
* Fix a typo in an error message for a check of invalid Mach-O files whereKevin Enderby2017-02-071-1/+1
| | | | | | | | | | | | it was printing the field name fileoff instead of filesize. The original check was added in r278557. This was found in tracking down the problem that lead to the fix in r293842 - [dsymutil] Fix __LINKEDIT vmsize in dsymutil upgrade path rdar://30386075 llvm-svn: 294354
* Fix llvm-objdump so it picks a good CPU based for Mach-O filesKevin Enderby2017-01-241-0/+4
| | | | | | | | | | | for CPU_SUBTYPE_ARM_V7S and CPU_SUBTYPE_ARM_V7K. For these two cpusubtypes they should default to a cortex-a7 CPU to give proper disassembly without a -mcpu= flag. rdar://27431703 llvm-svn: 292993
* Add support for the x86_thread_state32_t andKevin Enderby2017-01-231-1/+20
| | | | | | | | | | | | | in llvm-objdump for Mach-O files add the printing of the x86_thread_state32_t in the same format as otool-classic(1) on darwin. To do this the 32-bit x86 general tread state needed to be defined in include/llvm/Support/MachO.h . rdar://30110111 llvm-svn: 292829
* Add LC_BUILD_VERSION load commandSteven Wu2017-01-231-0/+34
| | | | | | | | | | | | | | | | | | | Summary: Add a new load command LC_BUILD_VERSION. It is a generic version of LC_*_VERSION_MIN load_command used on Apple platforms. Instead of having a seperate load command for each platform, LC_BUILD_VERSION is recording platform info as an enum. It also records SDK version, min_os, and tools that used to build the binary. rdar://problem/29781291 Reviewers: enderby Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29044 llvm-svn: 292824
* Add support for the new LC_NOTE load command.Kevin Enderby2017-01-191-0/+33
| | | | | | | | | | It describes a region of arbitrary data included in a Mach-O file. Its initial use is to record extra data in MH_CORE files. rdar://30001545 rdar://30001731 llvm-svn: 292500
* llvm-objdump: speed up -objc-meta-dataSaleem Abdulrasool2017-01-081-0/+8
| | | | | | | | | | | | | | | | | | Running a Debug build of objdump -objc-meta-data with a large Mach-O file is currently unnecessarily slow. With some local test input, this change reduces the run time from 75-85s down to 15-20s. The two changes are: Assert on pointer equality not array equality Replace vector<pair<address, symbol>> with DenseMap<address, symbol> Additionally, use a std::unique_ptr rather than handling the memory manually. Patch by Dave Lee! llvm-svn: 291398
* Fix a bugs with using some Mach-O command line flags like "-arch armv7m".Kevin Enderby2016-12-161-1/+36
| | | | | | | | | | | | | | | | | | The Mach-O command line flag like "-arch armv7m" does not match the arch name part of its llvm Triple which is "thumbv7m-apple-darwin”. I think the best way to fix this is to have llvm::object::MachOObjectFile::getArchTriple() optionally return the name of the Mach-O arch flag that would be used with -arch that matches the CPUType and CPUSubType. Then change llvm::object::MachOUniversalBinary::ObjectForArch::getArchTypeName() to use that and change it to getArchFlagName() as the type name is really part of the Triple and the -arch flag name is a Mach-O thing for a specific Triple with a specific Mcpu value. rdar://29663637 llvm-svn: 290001
* [Object][MachO] Reference-ify some helper function arguments. NFC.Lang Hames2016-12-041-201/+200
| | | | | | | Changes all static helper functions in MachOObjectFile.cpp that expect a non-null MachOObjectFile pointer to take a reference instead. llvm-svn: 288608
* 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
OpenPOWER on IntegriCloud