aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/MachODump.cpp
AgeCommit message (Collapse)AuthorFilesLines
2017-10-06[llvm-objdump] Add RAII for xar apisFrancis Ricci1-15/+33
Summary: xar_open and xar_iter_new require manual calls to close/free functions to deallocate resources. This makes it easy to introduce memory leaks, so add RAII struct wrappers for these resources. Reviewers: enderby, rafael, compnerd, lhames, dblaikie Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38598 llvm-svn: 315069
2017-09-23[Support] Rename tool_output_file to ToolOutputFile, NFCReid Kleckner1-1/+1
This class isn't similar to anything from the STL, so it shouldn't use the STL naming conventions. llvm-svn: 314050
2017-09-21Fix a bug in llvm-objdump when disassembling using the wrong default CPUKevin Enderby1-3/+7
in the second slice of a Mach-O universal file. The code in llvm-objdump in in DisassembleMachO() was getting the default CPU then incorrectly setting into the global variable used for the -mcpu option if that was not set. This caused a second call to DisassembleMachO() to use the wrong default CPU when disassembling the next slice in a Mach-O universal file. And would result in bad disassembly and an error message about an recognized processor for the target: % llvm-objdump -d -m -arch all fat.macho-armv7s-arm64 fat.macho-armv7s-arm64 (architecture armv7s): (__TEXT,__text) section armv7: 0: 60 47 bx r12 fat.macho-armv7s-arm64 (architecture arm64): 'cortex-a7' is not a recognized processor for this target (ignoring processor) 'cortex-a7' is not a recognized processor for this target (ignoring processor) (__TEXT,__text) section ___multc3: 0: .long 0x1e620810 rdar://34439149 llvm-svn: 313921
2017-09-18[dwarfdump] Make .eh_frame an alias for .debug_frameJonas Devlieghere1-3/+2
This patch makes the `.eh_frame` extension an alias for `.debug_frame`. Up till now it was only possible to dump the section using objdump, but not with dwarfdump. Since the two are essentially interchangeable, we dump whichever of the two is present. As a workaround, this patch also adds parsing for 3 currently unimplemented CFA instructions: `DW_CFA_def_cfa_expression`, `DW_CFA_expression`, and `DW_CFA_val_expression`. Because I lack the required knowledge, I just parse the fields without actually creating the instructions. Finally, this also fixes the typo in the `.debug_frame` section name which incorrectly contained a trailing `s`. Differential revision: https://reviews.llvm.org/D37852 llvm-svn: 313530
2017-09-13[llvm-objdump] Fix memory leaks in macho dumpFrancis Ricci1-2/+5
Summary: Detected by LeakSanitizer for Darwin Reviewers: enderby, rafael Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D37750 llvm-svn: 313146
2017-08-28Untabify.NAKAMURA Takumi1-31/+31
llvm-svn: 311875
2017-07-29[llvm] Update MachOObjectFile::exports interfaceAlexander Shaposhnikov1-1/+1
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
2017-07-20Add error handling to the dyld compact export entries in libObject.Kevin Enderby1-1/+4
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
2017-07-19Use delegation instead of inheritance.Rafael Espindola1-2/+2
This changes DwarfContext to delegate to DwarfObject instead of having pure virtual methods. With this DwarfContextInMemory is replaced with an implementation of DwarfObject that is local to a .cpp file. llvm-svn: 308543
2017-06-22Updated llvm-objdump for arm64 Mach-O MH_KEXT_BUNDLE file types soKevin Enderby1-2/+7
it symbolically disassembles the __text section from the __TEXT_EXEC segment not the usual __TEXT segment by default. rdar://30590208 llvm-svn: 306046
2017-06-22Updated llvm-objdump symbolic disassembly with x86_64 Mach-O MH_KEXT_BUNDLEKevin Enderby1-4/+38
file types so it symbolically disassembles operands using the external relocation entries. rdar://31521343 llvm-svn: 306037
2017-06-20Updated llvm-objdump with Mach-O files and the -objc-meta-data option soKevin Enderby1-0/+6
that it symbolically prints the superclass when it has dyld bind info for it. rdar://7638823 llvm-svn: 305866
2017-06-20Change llvm-objdump with Mach-O files and the -info-plist option with theKevin Enderby1-1/+2
-no-leading-headers option so that it does not print the leading header. rdar://27378808 llvm-svn: 305849
2017-06-19Fix a FIXME in llvm-objdump for the -exports-trie option that was not addingKevin Enderby1-1/+17
in the base address. Without this Mach-O files, like 64-bit executables, don’t have the correct addresses printed for their exports. As the default is to link at address 0x100000000 not zero. llvm-svn: 305744
2017-06-19Change llvm-nm for Mach-O files to use dyld info in some cases when printing ↵Kevin Enderby1-0/+4
symbols. In order to reduce swift binary sizes, Apple is now stripping swift symbols from the nlist symbol table. llvm-nm currently only looks at the nlist symbol table and misses symbols that are present in dyld info. This makes it hard to know the set of symbols for a binary using just llvm-nm. Unless you know to run llvm-objdump -exports-trie that can output the exported symbols in the dyld info from the export trie, which does so but in a different format. Also moving forward the time may come a when a fully linked Mach-O file that uses dyld will no longer have an nlist symbol table to avoid duplicating the symbol information. This change adds three flags to llvm-nm, -add-dyldinfo, -no-dyldinfo, and -dyldinfo-only. The first, -add-dyldinfo, has the same effect as when the new bit in the Mach-O header, MH_NLIST_OUTOFSYNC_WITH_DYLDINFO, appears in a binary. In that it looks through the dyld info from the export trie and adds symbols to be printed that are not already in its internal SymbolList variable. The -no-dyldinfo option turns this behavior off. The -dyldinfo-only option only looks at the dyld information and recreates the symbol table from the dyld info from the export trie and binding information. As if it the Mach-O file had no nlist symbol table. Also fixed a few bugs with Mach-O N_INDR symbols not correctly printing the indirect name, or in the same format as the old nm-classic program. rdar://32021551 llvm-svn: 305733
2017-06-07Move Object format code to lib/BinaryFormat.Zachary Turner1-3/+4
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
2017-06-01[DWARF] Introduce Dump OptionsAdrian Prantl1-1/+4
This commit introduces a structure that holds all the flags that control the pretty printing of dwarf output. Patch by Spyridoula Gravani! Differential Revision: https://reviews.llvm.org/D33749 llvm-svn: 304446
2017-03-20Add the rest of the error checking for Mach-O dyld compact bind entry errorsKevin Enderby1-139/+21
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
2017-02-28Actually add error handling to unpacking the dyld compact bind andKevin Enderby1-5/+20
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
2017-02-09Tweak the implementation of llvm-objdump’s -objc-meta-data option soKevin Enderby1-63/+91
that it works when the ObjC metadata sections end up in the __DATA_CONST or __DATA_DIRTY segments. rdar://26315238 llvm-svn: 294599
2017-02-08llvm-objdump: make NoLeadingAddr work on more than just MachOSaleem Abdulrasool1-3/+0
Support printing the disassembly without the address on all formats rather than making it MachO specific. Patch by Jeff Muizelaar! llvm-svn: 294495
2017-02-06Fix a bug in llvm-obdump(1) with the -macho and -info-plist optionsKevin Enderby1-1/+1
which caused it to print more than the (__TEXT,__info_plist) if that section did not end with a null. rdar://27378808 llvm-svn: 294236
2017-02-06Fix a bug in llvm-obdump(1) with the -macho and -disassemble optionsKevin Enderby1-1/+28
which caused it to not disassemble the bytes a the start of the section if the section had symbols and the first symbol was not at the start of the section. rdar://30143243 llvm-svn: 294212
2017-02-03Fix a bug in llvm-obdump(1) with the -objc-meta-data flag with -machoKevin Enderby1-1/+1
which caused a hang on a malformed binary with bad bind info. rdar://29672108 llvm-svn: 294021
2017-01-31Fix a bug in llvm-obdump(1) with the -macho flag disassembling an objectKevin Enderby1-2/+5
without symbols that makes calls through a symbol stub which were not correctly being annotated with “## symbol stub for: _foo”. Just adds the same parameters for getting the annotations from DisAsm->getInstruction() and passing them to IP->printInst() from the code above when boolean variable symbolTableWorked was true. rdar://29791952 llvm-svn: 293662
2017-01-30Change the llvm-obdump(1) behavior with the -macho flag and inappropriate ↵Kevin Enderby1-2/+7
file types. To better match the old darwin otool(1) behavior, when llvm-obdump(1) is used with the -macho option and the input file is not an object file simply print the file name and this message: foo: is not an object file and continue on to process other input files. Also in this case don’t exit non-zero. This should help in some OSS projects' with autoconf scripts that are expecting the old darwin otool(1) behavior. rdar://26828015 llvm-svn: 293547
2017-01-23Add support for the x86_thread_state32_t andKevin Enderby1-1/+98
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
2017-01-23Add LC_BUILD_VERSION load commandSteven Wu1-0/+36
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
2017-01-19Add support for the new LC_NOTE load command.Kevin Enderby1-0/+16
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
2017-01-08llvm-objdump: speed up -objc-meta-dataSaleem Abdulrasool1-26/+5
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
2016-12-16Fix a bugs with using some Mach-O command line flags like "-arch armv7m".Kevin Enderby1-11/+15
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
2016-11-29Add to llvm-objdump the -no-leading-headers option with the use of the ↵Kevin Enderby1-6/+11
-macho option. In some cases the leading headers of the file name, archive member and architecture slice name in the output of lvm-objdump is not wanted so the tool’s output can be directly used by scripts. This matches the -X option of the Apple otool(1) program. rdar://28491674 llvm-svn: 288199
2016-11-20Fix spelling mistakes in Tools/Tests comments. NFC.Simon Pilgrim1-1/+1
Identified by Pedro Giffuni in PR27636. llvm-svn: 287489
2016-11-15General clean up of Mach-O error handling in llvm-objdump.Kevin Enderby1-173/+72
To get a good error message for all files that could contain Mach-O files the code in llvm-objdump needs to use the archive member name and name of the architecture of a slice of a universal file in those cases where the error come from a Mach-O file in an archive or a universal file. Most of this is fixed by moving the call to checkSymbolTable() into ProcessMachO() and calling it when the operation needs the symbol table. And then calling the form of report_error() that has the ArchiveName and ArchitectureName arguments. One other place needed to call this form of report_error() also with these arguments. Also changed the code in MachODump.cpp to not use report_fatal_error() and use report_error() instead to make the code smaller and cleaner. All cases of this are for errors with the symbol table which should now never be tripped since checkSymbolTable() should be called first to get a good error message in these cases. llvm-svn: 287050
2016-11-15llvm-objdump: deal with unexpected object files more gracefully.Tim Northover1-8/+18
Specifically, we don't want to segfault on release builds, so print the problem instead. llvm-svn: 287022
2016-11-14Add a checkSymbolTable() method to the MachOObjectFile class.Kevin Enderby1-0/+3
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
2016-11-11Make the Error class constructor protectedMehdi Amini1-5/+6
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
2016-11-04Remove dead code trying to handle when the amount of data read isChandler Carruth1-12/+2
insufficient to populate the expected struct. Prior to this we already bailed out of the routine when this situation comes up, so none of this code had any effect. If someone wants to bring it back to handle these cases, fixing the earlier conditions and adding the necessary test cases that actually exercises it, they can always revert this and go from there. Both of these were noticed by PVS-Studio due to the identical (dead) condition. llvm-svn: 285989
2016-11-03Add support for the ARM_THREAD_STATE64 andKevin Enderby1-0/+84
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
2016-10-31Fix an unconditional break in checkMachOAndArchFlagsDavid Majnemer1-24/+20
Found by PVS-Studio. llvm-svn: 285598
2016-10-21For llvm-objdump for Mach-O files add printing ofKevin Enderby1-2/+69
the ARM_THREAD_STATE in the same format as otool-classic(1) on darwin. Also remove an extra space in printing the initprot to make the output match otool-classic(1) on darwin. rdar://28851457 llvm-svn: 284852
2016-10-01Use StringRef instead of raw pointers in MCAsmInfo/MCInstrInfo APIs (NFC)Mehdi Amini1-1/+1
llvm-svn: 283018
2016-09-08llvm-objdump: add missing ) in help output, NFCSaleem Abdulrasool1-1/+1
Add a missing ')' in the help output. NFC. llvm-svn: 281000
2016-09-06Add an c++ itanium demangler to llvm.Rafael Espindola1-16/+5
This adds a copy of the demangler in libcxxabi. The code also has no dependencies on anything else in LLVM. To enforce that I added it as another library. That way a BUILD_SHARED_LIBS will fail if anyone adds an use of StringRef for example. The no llvm dependency combined with the fact that this has to build on linux, OS X and Windows required a few changes to the code. In particular: No constexpr. No alignas On OS X at least this library has only one global symbol: __ZN4llvm16itanium_demangleEPKcPcPmPi My current plan is: Commit something like this Change lld to use it Change lldb to use it as the fallback Add a few #ifdefs so that exactly the same file can be used in libcxxabi to export abi::__cxa_demangle. Once the fast demangler in lldb can handle any names this implementation can be replaced with it and we will have the one true demangler. llvm-svn: 280732
2016-08-12Use the range variant of find/find_if instead of unpacking begin/endDavid Majnemer1-3/+3
If the result of the find is only used to compare against end(), just use is_contained instead. No functionality change is intended. llvm-svn: 278469
2016-08-12Use the range variant of find_if instead of unpacking begin/endDavid Majnemer1-15/+11
No functionality change is intended. llvm-svn: 278443
2016-08-03Reapply "More fixes to get good error messages for bad archives."Vedant Kumar1-4/+14
This reverts commit the revert commit r277627. The build errors mentioned in r277627 were likely caused by an unclean build directory. Sorry for the noise. llvm-svn: 277630
2016-08-03Revert "More fixes to get good error messages for bad archives."Vedant Kumar1-14/+4
This reverts commit r277540. It breaks the build with: ../lib/Object/Archive.cpp:264:41: error: return type of out-of-line definition of 'llvm::object::ArchiveMemberHeader::getUID' differs from that in the declaration Expected<unsigned> ArchiveMemberHeader::getUID() const { ~~~~~~~~~~~~~~~~~~ ^ include/llvm/Object/Archive.h:53:12: note: previous declaration is here unsigned getUID() const; ~~~~~~~~ ^ llvm-svn: 277627
2016-08-02More fixes to get good error messages for bad archives.Kevin Enderby1-4/+14
Fixed the last incorrect uses of llvm_unreachable() in the code which were actually just cases of errors in the input Archives. llvm-svn: 277540
2016-07-29The next step along the way to getting good error messages for bad archives.Kevin Enderby1-4/+11
As mentioned in commit log for r276686 this next step is adding a new method in the ArchiveMemberHeader class to get the full name that does proper error checking, and can be use for error messages. To do this the name of ArchiveMemberHeader::getName() is changed to ArchiveMemberHeader::getRawName() to be consistent with Archive::Child::getRawName(). Then the “new” method is the addition of a new implementation of ArchiveMemberHeader::getName() which gets the full name and provides proper error checking. Which is mostly a rewrite of what was Archive::Child::getName() and cleaning up incorrect uses of llvm_unreachable() in the code which were actually just cases of errors in the input Archives. Then Archive::Child::getName() is changed to return Expected<> and use the new implementation of ArchiveMemberHeader::getName() . Also needed to change Archive::getMemoryBufferRef() with these changes to return Expected<> as well to propagate Errors up. As well as changing Archive::isThinMember() to return Expected<> . llvm-svn: 277177