summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/MachOObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [MachO] Fix inconsistency between error messages when validating LC_DYSYMTABFrancis Visoiu Mistrih2018-09-041-2/+2
| | | | llvm-svn: 341379
* [MachO] Fix LC_DYSYMTAB validation for external symbolsFrancis Visoiu Mistrih2018-09-041-1/+1
| | | | | | | We were validating the same index (ilocalsym) twice, while iextdefsym was never validated. llvm-svn: 341378
* [llvm-readobj] Add -hex-dump (-x) optionPaul Semel2018-07-111-0/+21
| | | | | | Differential Revision: https://reviews.llvm.org/D48281 llvm-svn: 336782
* [MachO] Add out-of-bounds check to MachOObjectFile.cppSam Clegg2018-06-041-0/+1
| | | | | | | | This is a followup to rL333496. Differential Revision: https://reviews.llvm.org/D47544 llvm-svn: 333929
* MC: Remove redundant substr() callSam Clegg2018-05-301-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D47047 llvm-svn: 333496
* [llvm-objdump] Print "..." instead of random data for virtual sectionsFrancis Visoiu Mistrih2018-04-191-2/+4
| | | | | | | | | | | | | | | | | When disassembling with -D, skip virtual sections by printing "..." for each symbol. This patch also implements `MachOObjectFile::isSectionVirtual`. Test case comes from: ``` .zerofill __DATA,__common,_data64unsigned,472,3 ``` Differential Revision: https://reviews.llvm.org/D45824 llvm-svn: 330342
* For llvm-objdump and Mach-O files, update the printing of some thread statesKevin Enderby2018-03-081-1/+49
| | | | | | | | | | | from core files. I tested this against the couple of core files that were getting errors about unknown thread flavors and it now produce the same output as the Xcode otool-classic(1) tool. Since the core files are huge I didn’t include them as test cases. rdar://38216356 llvm-svn: 327077
* Do not look up symbol names when n_strx == 0Michael Trent2018-01-031-0/+4
| | | | | | | | | | | | | | | | | | | | | | Summary: Historical tools for working with mach-o binaries verify the nlist field n_strx has a non-zero value before using that value to retrieve symbol names. Under some cirumstances, llvm-nm will attempt to display the symbol name at position 0, even though symbol names at that position are not well defined. This change addresses this problem by returning an empty string when n_strx is zero. rdar://problem/35750548 Reviewers: enderby, davide Reviewed By: enderby, davide Subscribers: davide, llvm-commits, JDevlieghere Differential Revision: https://reviews.llvm.org/D41657 llvm-svn: 321773
* Updated llvm-objdump to display local relocations in Mach-O binariesMichael Trent2017-12-151-1/+23
| | | | | | | | | | | | | | | | | | | | | | | Summary: llvm-objdump's Mach-O parser was updated in r306037 to display external relocations for MH_KEXT_BUNDLE file types. This change extends the Macho-O parser to display local relocations for MH_PRELOAD files. When used with the -macho option relocations will be displayed in a historical format. All tests are passing for llvm, clang, and lld. llvm-objdump builds without compiler warnings. rdar://35778019 Reviewers: enderby Reviewed By: enderby Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41199 llvm-svn: 320832
* Fix many -Wsign-compare and -Wtautological-constant-compare warnings.Zachary Turner2017-12-141-1/+1
| | | | | | | | | | | | Most of the -Wsign-compare warnings are due to the fact that enums are signed by default in the MS ABI, while the tautological comparison warnings trigger on x86 builds where sizeof(size_t) is 4 bytes, so N > numeric_limits<unsigned>::max() is always false. Differential Revision: https://reviews.llvm.org/D41256 llvm-svn: 320750
* reverting out -r320532 because a warning is breaking the lld buildMichael Trent2017-12-131-23/+1
| | | | llvm-svn: 320534
* Updated llvm-objdump to display local relocations in Mach-O binariesMichael Trent2017-12-121-1/+23
| | | | | | | | | | | | | | | | | | Summary: llvm-objdump's Mach-O parser was updated in r306037 to display external relocations for MH_KEXT_BUNDLE file types. This change extends the Macho-O parser to display local relocations for MH_PRELOAD files. When used with the -macho option relocations will be displayed in a historical format. rdar://35778019 Reviewers: enderby Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41061 llvm-svn: 320532
* Reverting r320166 to fix test failures.Michael Trent2017-12-081-23/+1
| | | | llvm-svn: 320174
* Updated llvm-objdump to display local relocations in Mach-O binariesMichael Trent2017-12-081-1/+23
| | | | | | | | | | | | | | | | | | | | Summary: llvm-objdump's Mach-O parser was updated in r306037 to display external relocations for MH_KEXT_BUNDLE file types. This change extends the Macho-O parser to display local relocations for MH_PRELOAD files. When used with the -macho option relocations will be displayed in a historical format. rdar://35778019 Reviewers: enderby Reviewed By: enderby Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40867 llvm-svn: 320166
* Untabify.NAKAMURA Takumi2017-10-181-3/+3
| | | | llvm-svn: 316079
* Fix typo in checkTwoLevelHintsCommandJessica Paquette2017-10-171-1/+1
| | | | | | BigSize had a copy/paste typo in it. This fixes that. llvm-svn: 316027
* [dwarfdump] Skip 'stripped' sectionsJonas Devlieghere2017-09-261-0/+6
| | | | | | | | | | | | | | | | | | | When dsymutil generates the companion file, its strips all unnecessary sections by omitting their body and setting the offset in their corresponding load command to zero. One such section is the .eh_frame section, as it contains runtime information rather than debug information and is part of the __TEXT segment. When reading this section, we would just read the number of bytes specified in the load command, starting from offset 0 (i.e. the beginning of the file). Rather than trying to parse this obviously invalid section, dwarfdump now skips this. Differential revision: https://reviews.llvm.org/D38135 llvm-svn: 314208
* [MachO] Prevent heap overflow when load command extends past EOFJonas Devlieghere2017-09-131-1/+4
| | | | | | | | | | | This patch fixes a heap-buffer-overflow when a malformed Mach-O has a load command who's size extends past the end of the binary. Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3225 Differential revision: https://reviews.llvm.org/D37439 llvm-svn: 313145
* Untabify.NAKAMURA Takumi2017-08-281-12/+12
| | | | llvm-svn: 311875
* [MachO] Use Twines more efficiently.Benjamin Kramer2017-08-201-183/+229
| | | | llvm-svn: 311291
* [llvm] Update MachOObjectFile::exports interfaceAlexander Shaposhnikov2017-07-291-3/+2
| | | | | | | | | | This diff removes the second argument of the method MachOObjectFile::exports. In all in-tree uses this argument is equal to "this" and without this argument the interface seems to be cleaner. Test plan: make check-all llvm-svn: 309462
* Small tweak to one check in error handling to the dyld compact exportKevin Enderby2017-07-241-2/+2
| | | | | | | | | | entries in libObject (done in r308690). In the case when the last node has no children setting State.Current = Children + 1; where that would be past Trie.end() is actually ok since the pointer is not used with zero children. rdar://33490512 llvm-svn: 308924
* Add error handling to the dyld compact export entries in libObject.Kevin Enderby2017-07-201-22/+154
| | | | | | | | | | | | | | | | | | | | | lld needs a matching change for this will be my next commit. Expect it to fail build until that matching commit is picked up by the bots. Like the changes in r296527 for dyld bind entires and the changes in r298883 for lazy bind, weak bind and rebase entries the export entries are the last of the dyld compact info to have error handling added. This follows the model of iterators that can fail that Lang Hanes designed when fixing the problem for bad archives r275316 (or r275361). So that iterating through the exports now terminates if there is an error and returns an llvm::Error with an error message in all cases for malformed input. This change provides the plumbing for the error handling, all the needed testing of error conditions and test cases for all of the unique error messages. llvm-svn: 308690
* Updated llvm-objdump symbolic disassembly with x86_64 Mach-O MH_KEXT_BUNDLEKevin Enderby2017-06-221-9/+30
| | | | | | | | | file types so it symbolically disassembles operands using the external relocation entries. rdar://31521343 llvm-svn: 306037
* Move Object format code to lib/BinaryFormat.Zachary Turner2017-06-071-1/+1
| | | | | | | | | | | | This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
* Sort the remaining #include lines in include/... and lib/....Chandler Carruth2017-06-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | I did this a long time ago with a janky python script, but now clang-format has built-in support for this. I fed clang-format every line with a #include and let it re-sort things according to the precise LLVM rules for include ordering baked into clang-format these days. I've reverted a number of files where the results of sorting includes isn't healthy. Either places where we have legacy code relying on particular include ordering (where possible, I'll fix these separately) or where we have particular formatting around #include lines that I didn't want to disturb in this patch. This patch is *entirely* mechanical. If you get merge conflicts or anything, just ignore the changes in this patch and run clang-format over your #include lines in the files. Sorry for any noise here, but it is important to keep these things stable. I was seeing an increasing number of patches with irrelevant re-ordering of #include lines because clang-format was used. This patch at least isolates that churn, makes it easy to skip when resolving conflicts, and gets us to a clean baseline (again). llvm-svn: 304787
* [DWARF] Adding support for the DWARF v5 string offsets table ↵Wolfgang Pieb2017-06-061-0/+6
| | | | | | | | | | (consumer/reader part only). Reviewers: dblaikie, aprantl Differential Revision: https://reviews.llvm.org/D32779 llvm-svn: 304759
* [MachOObject] Fix bind opcode parser error on valid opcode sequenceSteven Wu2017-05-311-1/+1
| | | | | | | BIND_OPCODE_SET_DYLIB_SPECIAL_IMM(0) is a valid way to setp library ordinal. MachOObject should set LibraryOrdinalSet even when IMM is zero. llvm-svn: 304362
* Recommit "[DWARF] - Make collectAddressRanges() return section index in ↵George Rimar2017-05-271-0/+4
| | | | | | | | | | | | | | | | | | | | | | addition to Low/High PC" With fix of uninitialized variable. Original 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: 304078
* 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
OpenPOWER on IntegriCloud