summaryrefslogtreecommitdiff
path: root/llvm/lib/Object/MachOObjectFile.cpp
AgeCommit message (Collapse)Author
2015-06-04[Object, MachO] Cache parsed MachO header in MachOObjectFile. NFC.Alexey Samsonov
Summary: Avoid parsing object file each time MachOObjectFile::getHeader() is called. Instead, cache the header in MachOObjectFile constructor, where it's parsed anyway. In future, we must avoid constructing the object at all if the header can't be parsed. Test Plan: regression test suite. Reviewers: rafael Subscribers: llvm-commits llvm-svn: 239075
2015-06-03[Object, MachO] Introduce MachOObjectFile::load_commands() range iterator.Alexey Samsonov
Summary: Now users don't have to manually deal with getFirstLoadCommandInfo() / getNextLoadCommandInfo(), calculate the number of load segments, etc. No functionality change. Test Plan: regression test suite Reviewers: rafael, lhames, loladiro Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10144 llvm-svn: 238983
2015-06-03Move to llvm-objdump a large amount of code to that is only used there.Rafael Espindola
llvm-svn: 238898
2015-06-01Simplify another function that doesn't fail.Rafael Espindola
llvm-svn: 238703
2015-05-31Simplify interface of function that doesn't fail.Rafael Espindola
llvm-svn: 238700
2015-05-30Add RelocVisitor support for MachOKeno Fischer
This commit adds partial support for MachO relocations to RelocVisitor. A simple test case is added to show that relocations are indeed being applied and that using llvm-dwarfdump on MachO files no longer errors. Correctness is not yet tested, due to an unrelated bug in DebugInfo, which will be fixed with appropriate testcase in a followup commit. Differential Revision: http://reviews.llvm.org/D8148 llvm-svn: 238663
2015-05-22Stop inventing symbol sizes.Rafael Espindola
MachO and COFF quite reasonably only define the size for common symbols. We used to try to figure out the "size" by computing the gap from one symbol to the next. This would not be correct in general, since a part of a section can belong to no visible symbol (padding, private globals). It was also really expensive, since we would walk every symbol to find the size of one. If a caller really wants this, it can sort all the symbols once and get all the gaps ("size") in O(n log n) instead of O(n^2). On MachO this also has the advantage of centralizing all the checks for an invalid n_sect. llvm-svn: 238028
2015-05-22Detect invalid section indexes when we first read them.Rafael Espindola
We still detect the same errors, but now we do it earlier. llvm-svn: 238024
2015-05-21Make it easier to use DwarfContext with MCJITKeno Fischer
Summary: This supersedes http://reviews.llvm.org/D4010, hopefully properly dealing with the JIT case and also adds an actual test case. DwarfContext was basically already usable for the JIT (and back when we were overwriting ELF files it actually worked out of the box by accident), but in order to resolve relocations correctly it needs to know the load address of the section. Rather than trying to get this out of the ObjectFile or requiring the user to create a new ObjectFile just to get some debug info, this adds the capability to pass in that info directly. As part of this I separated out part of the LoadedObjectInfo struct from RuntimeDyld, since it is now required at a higher layer. Reviewers: lhames, echristo Reviewed By: echristo Subscribers: vtjnash, friss, rafael, llvm-commits Differential Revision: http://reviews.llvm.org/D6961 llvm-svn: 237961
2015-03-30Remove more superfluous .str() and replace std::string concatenation with Twine.Yaron Keren
Following r233392, http://llvm.org/viewvc/llvm-project?rev=233392&view=rev. llvm-svn: 233555
2015-01-27dd the option, -link-opt-hints to llvm-objdump used with -macho to print theKevin Enderby
Mach-O AArch64 linker optimization hints for ADRP code optimization. llvm-svn: 227246
2015-01-15Fix edge case when Start overflowed in 32 bit modeFilipe Cabecinhas
llvm-svn: 226229
2015-01-15Report fatal errors instead of segfaulting/asserting on a few invalid ↵Filipe Cabecinhas
accesses while reading MachO files. Summary: Shift an older “invalid file” test to get a consistent naming for these tests. Bugs found by afl-fuzz Reviewers: rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6945 llvm-svn: 226219
2015-01-15[Object] Add SF_Exported flag. This flag will be set on all symbols that wouldLang Hames
be exported from a dylib if their containing object file were linked into one. No test case: No command line tools query this flag, and there are no Object unit tests. llvm-svn: 226217
2015-01-06Don't loop endlessly for MachO files with 0 ncmdsFilipe Cabecinhas
llvm-svn: 225271
2014-12-23Add printing the LC_THREAD load commands with llvm-objdump’s -private-headers.Kevin Enderby
llvm-svn: 224792
2014-12-19Add printing the LC_ROUTINES load commands with llvm-objdump’s ↵Kevin Enderby
-private-headers. llvm-svn: 224627
2014-12-19Add printing the LC_SUB_CLIENT load command with llvm-objdump’s ↵Kevin Enderby
-private-headers. llvm-svn: 224616
2014-12-19Add printing the LC_SUB_LIBRARY load command with llvm-objdump’s ↵Kevin Enderby
-private-headers. llvm-svn: 224607
2014-12-19[Object] Don't crash on empty export lists.Juergen Ributzka
Summary: This fixes the exports iterator if the export list is empty. Reviewers: Bigcheese, kledzik Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6732 llvm-svn: 224563
2014-12-18Add printing the LC_SUB_UMBRELLA load command with llvm-objdump’s ↵Kevin Enderby
-private-headers. llvm-svn: 224548
2014-12-18Add printing the LC_SUB_FRAMEWORK load command with llvm-objdump’s ↵Kevin Enderby
-private-headers. llvm-svn: 224534
2014-12-18Add printing the LC_LINKER_OPTION load command with llvm-objdump’s ↵Kevin Enderby
-private-headers. Also corrected the name of the load command to not end in an ’S’ as well as corrected the name of the MachO::linker_option_command struct and other places that had the word option as plural which did not match the Mac OS X headers. llvm-svn: 224485
2014-12-17Add printing the LC_ENCRYPTION_INFO_64 load command with llvm-objdump’s ↵Kevin Enderby
-private-headers and add tests for the two AArch64 binaries. llvm-svn: 224400
2014-12-16Add printing the LC_ENCRYPTION_INFO load command with llvm-objdump’s ↵Kevin Enderby
-private-headers. llvm-svn: 224390
2014-12-10Move three methods only used by MCJIT to MCJIT.Rafael Espindola
These methods are only used by MCJIT and are very specific to it. In fact, they are also fairly specific to the fact that we have a dynamic linker of relocatable objects. llvm-svn: 223964
2014-12-04Add mach-o LC_RPATH support to llvm-objdumpJean-Daniel Dupas
Summary: Add rpath load command support in Mach-O object and update llvm-objdump to use it. Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6512 llvm-svn: 223343
2014-11-13Object, Mach-O: Refactor and clean code upDavid Majnemer
Don't assert if we can return an error code, reuse existing functionality like is64Bit(). llvm-svn: 221915
2014-11-04Remove the static version of getScatteredRelocationType() now that r221211 addedKevin Enderby
a public version MachOObjectFile::getScatteredRelocationType(). This should fix the build bot for the unused function error. llvm-svn: 221216
2014-11-04Add the code and test cases for 32-bit Intel to llvm-objdump’s Mach-O ↵Kevin Enderby
symbolizer. llvm-svn: 221211
2014-10-27Fix unicode chars into ascii in comment lines.NAKAMURA Takumi
llvm-svn: 220668
2014-10-24[Object] Fix MachO's getUuid to return a pointer into the object instead of ↵Benjamin Kramer
a dangling ArrayRef. This works because uuid's are always little endian so it's not swapped. Fixes use-after-return reported by asan. llvm-svn: 220567
2014-10-23Update llvm-objdump’s Mach-O symbolizer code for Objective-C references.Kevin Enderby
This prints disassembly comments for Objective-C references to CFStrings, Selectors, Classes and method calls. llvm-svn: 220500
2014-10-21[MCJIT] Temporarily revert r220245 - it broke several bots.Lang Hames
(See e.g. http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/17653) llvm-svn: 220249
2014-10-20[MCJIT] Make MCJIT honor symbol visibility settings when populating the globalLang Hames
symbol table. Patch by Anthony Pesch. Thanks Anthony! llvm-svn: 220245
2014-10-18[llvm-objdump] Fix mach-o binding decompression errorNick Kledzik
llvm-svn: 220119
2014-10-15Add MachOObjectFile::getUuid()Alexander Potapenko
This CL introduces MachOObjectFile::getUuid(). This function returns an ArrayRef to the object file's UUID, or an empty ArrayRef if the object file doesn't contain an LC_UUID load command. The new function is gonna be used by llvm-symbolizer. llvm-svn: 219866
2014-10-08Remove bogus std::error_code returns form SectionRef.Rafael Espindola
There are two methods in SectionRef that can fail: * getName: The index into the string table can be invalid. * getContents: The section might point to invalid contents. Every other method will always succeed and returning and std::error_code just complicates the code. For example, a section can have an invalid alignment, but if we are able to get to the section structure at all and create a SectionRef, we will always be able to read that invalid alignment. llvm-svn: 219314
2014-09-17[Object] keep trailing '\0' out of StringRef when parsing mach-o bindingsNick Kledzik
llvm-svn: 217935
2014-09-17[llvm-objdump] properly use c_str() with format("%s"). Improve ↵Nick Kledzik
getLibraryShortNameByIndex() error handling. llvm-svn: 217930
2014-09-16[llvm-objdump] for mach-o add -bind, -lazy-bind, and -weak-bind optionsNick Kledzik
This finishes the ability of llvm-objdump to print out all information from the LC_DYLD_INFO load command. The -bind option prints out symbolic references that dyld must resolve immediately. The -lazy-bind option prints out symbolc reference that are lazily resolved on first use. The -weak-bind option prints out information about symbols which dyld must try to coalesce across images. llvm-svn: 217853
2014-09-12[llvm-objdump] support -rebase option for mach-o to dump rebasing infoNick Kledzik
Similar to my previous -exports-trie option, the -rebase option dumps info from the LC_DYLD_INFO load command. The rebasing info is a list of the the locations that dyld needs to adjust if a mach-o image is not loaded at its preferred address. Since ASLR is now the default, images almost never load at their preferred address, and thus need to be rebased by dyld. llvm-svn: 217709
2014-09-04Adds the next bit of support for llvm-objdump’s -private-headers for ↵Kevin Enderby
executable Mach-O files. This adds the printing of more load commands, so that the normal load commands in a typical X86 Mach-O executable can all be printed. llvm-svn: 217172
2014-09-02Code review tweaksNick Kledzik
llvm-svn: 216931
2014-08-30Fix typo and formattingNick Kledzik
llvm-svn: 216809
2014-08-30Object/llvm-objdump: allow dumping of mach-o exports trieNick Kledzik
MachOObjectFile in lib/Object currently has no support for parsing the rebase, binding, and export information from the LC_DYLD_INFO load command in final linked mach-o images. This patch adds support for parsing the exports trie data structure. It also adds an option to llvm-objdump to dump that export info. I did the exports parsing first because it is the hardest. The information is encoded in a trie structure, but the standard ObjectFile way to inspect content is through iterators. So I needed to make an iterator that would do a non-recursive walk through the trie and maintain the concatenation of edges needed for the current string prefix. I plan to add similar support in MachOObjectFile and llvm-objdump to parse/display the rebasing and binding info too. llvm-svn: 216808
2014-08-27Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or ↵Craig Topper
just letting them be implicitly created. llvm-svn: 216525
2014-08-19Don't own the buffer in object::Binary.Rafael Espindola
Owning the buffer is somewhat inflexible. Some Binaries have sub Binaries (like Archive) and we had to create dummy buffers just to handle that. It is also a bad fit for IRObjectFile where the Module wants to own the buffer too. Keeping this ownership would make supporting IR inside native objects particularly painful. This patch focuses in lib/Object. If something elsewhere used to own an Binary, now it also owns a MemoryBuffer. This patch introduces a few new types. * MemoryBufferRef. This is just a pair of StringRefs for the data and name. This is to MemoryBuffer as StringRef is to std::string. * OwningBinary. A combination of Binary and a MemoryBuffer. This is needed for convenience functions that take a filename and return both the buffer and the Binary using that buffer. The C api now uses OwningBinary to avoid any change in semantics. I will start a new thread to see if we want to change it and how. llvm-svn: 216002
2014-08-18Make llvm-objdump handle both arm and thumb disassembly from the same Mach-OKevin Enderby
file with -macho, the Mach-O specific object file parser option. After some discussion I chose to do this implementation contained in the logic of llvm-objdump’s MachODump.cpp using a second disassembler for thumb when needed and with updates mostly contained in the MachOObjectFile class. llvm-svn: 215931
2014-08-17llvm-objdump: don't print relocations in non-relocatable files.Rafael Espindola
This matches the behavior of GNU objdump. llvm-svn: 215844