aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/MachODump.cpp
AgeCommit message (Collapse)AuthorFilesLines
2015-10-21Backing out commit r250906 as it broke lld.Kevin Enderby1-28/+9
llvm-svn: 250908
2015-10-21This removes the eating of the error in Archive::Child::getSize() when the ↵Kevin Enderby1-9/+28
characters in the size field in the archive header for the member is not a number. To do this we have all of the needed methods return ErrorOr to push them up until we get out of lib. Then the tools and can handle the error in whatever way is appropriate for that tool. So the solution is to plumb all the ErrorOr stuff through everything that touches archives. This include its iterators as one can create an Archive object but the first or any other Child object may fail to be created due to a bad size field in its header. Thanks to Lang Hames on the changes making child_iterator contain an ErrorOr<Child> instead of a Child and the needed changes to ErrorOr.h to add operator overloading for * and -> . We don’t want to use llvm_unreachable() as it calls abort() and is produces a “crash” and using report_fatal_error() to move the error checking will cause the program to stop, neither of which are really correct in library code. There are still some uses of these that should be cleaned up in this library code for other than the size field. Also corrected the code where the size gets us to the “at the end of the archive” which is OK but past the end of the archive will return object_error::parse_failed now. The test cases use archives with text files so one can see the non-digit character, in this case a ‘%’, in the size field. llvm-svn: 250906
2015-10-10Fix a bugs in the Mach-O disassembler when disassembling from aKevin Enderby1-57/+66
malformed Mach-O file that caused a crash. This was because of an assert where the code was incorrectly attempting to parse relocation entries off of the sections and the filetype was not an MH_OBJECT. rdar://22983603 llvm-svn: 249921
2015-10-09Fix use of uninitialized bool, found by ubsan in portion ofRichard Smith1-6/+10
test/tools/llvm-objdump/malformed-machos.test added in r249845. llvm-svn: 249909
2015-10-09Fixed two bugs in llvm-objdump’s printing of Objective-C meta dataKevin Enderby1-0/+20
from malformed Mach-O files that caused crashes. The first because the offset in a dyld bind table entry was out of range. The second because their was no image info section and the routine printing it did not have the need check to see the section did not exist. rdar://22983603 llvm-svn: 249845
2015-10-08Fix a bug in llvm-objdump’s printing of Objective-C meta dataKevin Enderby1-0/+2
from malformed Mach-O files that caused a crash because of a section header had a size that extended past the end of the file. rdar://22983603 llvm-svn: 249768
2015-10-08Fix a bug in llvm-objdump’s printing of Objective-C meta dataKevin Enderby1-3/+9
from malformed Mach-O files that caused a crash because of loops in the class meta data. llvm-svn: 249700
2015-10-06Fix two bugs in llvm-objdump’s printing of Objective-C meta dataKevin Enderby1-2/+4
from malformed Mach-O files that caused crashes. We recently got about 700 malformed Mach-O files which we have been using the improve the robustness of tools that deal with reading data from object files. These resulted in about 20 small bug fixes to the darwin based tools. The goal here is to also improve the robustness of llvm-objdump and this is the first two fixes. In talking with Tim Northover the approach we thought might be best is to: 1) Only include tests for the malformed Mach-O files that cause crashes (not all 700+ tests). 2) The test should only contain the command line option that caused the crash and not all the others that don’t matter. 3) There should be only one line for the FileCheck that is past the point of the crash if possible and if possible indicates the malformation. Again the goal is to fix crashes and not so much care about how the printing of malformed data comes out. Tim also suggested if we really wanted to add test cases for all 700+ malformed Mach-O files putting them in the regression tests might be an option. But many of these do not cause crashes. llvm-svn: 249479
2015-09-29Fix Clang-tidy modernize-use-nullptr warnings in examples and include ↵Hans Wennborg1-4/+5
directories; other minor cleanups. Patch by Eugene Zelenko! Differential Revision: http://reviews.llvm.org/D13172 llvm-svn: 248811
2015-09-21Use makeArrayRef or None to avoid unnecessarily mentioning the ArrayRef type ↵Craig Topper1-8/+8
extra times. NFC llvm-svn: 248140
2015-09-15Revert r247692: Replace Triple with a new TargetTuple in MCTargetDesc/* and ↵Daniel Sanders1-4/+3
related. NFC. Eric has replied and has demanded the patch be reverted. llvm-svn: 247702
2015-09-15Re-commit r247683: Replace Triple with a new TargetTuple in MCTargetDesc/* ↵Daniel Sanders1-3/+4
and related. NFC. Summary: This is the first patch in the series to migrate Triple's (which are ambiguous) to TargetTuple's (which aren't). For the moment, TargetTuple simply passes all requests to the Triple object it holds. Once it has replaced Triple, it will start to implement the interface in a more suitable way. This change makes some changes to the public C++ API. In particular, InitMCSubtargetInfo(), createMCRelocationInfo(), and createMCSymbolizer() now take TargetTuples instead of Triples. The other public C++ API's have been left as-is for the moment to reduce patch size. This commit also contains a trivial patch to clang to account for the C++ API change. Thanks go to Pavel Labath for fixing LLDB for me. Reviewers: rengolin Subscribers: jyknight, dschuff, arsenm, rampitec, danalbert, srhines, javed.absar, dsanders, echristo, emaste, jholewinski, tberghammer, ted, jfb, llvm-commits, rengolin Differential Revision: http://reviews.llvm.org/D10969 llvm-svn: 247692
2015-09-15Revert r247684 - Replace Triple with a new TargetTuple ...Daniel Sanders1-4/+3
LLDB needs to be updated in the same commit. llvm-svn: 247686
2015-09-15Replace Triple with a new TargetTuple in MCTargetDesc/* and related. NFC.Daniel Sanders1-3/+4
Summary: This is the first patch in the series to migrate Triple's (which are ambiguous) to TargetTuple's (which aren't). For the moment, TargetTuple simply passes all requests to the Triple object it holds. Once it has replaced Triple, it will start to implement the interface in a more suitable way. This change makes some changes to the public C++ API. In particular, InitMCSubtargetInfo(), createMCRelocationInfo(), and createMCSymbolizer() now take TargetTuples instead of Triples. The other public C++ API's have been left as-is for the moment to reduce patch size. This commit also contains a trivial patch to clang to account for the C++ API change. Reviewers: rengolin Subscribers: jyknight, dschuff, arsenm, rampitec, danalbert, srhines, javed.absar, dsanders, echristo, emaste, jholewinski, tberghammer, ted, jfb, llvm-commits, rengolin Differential Revision: http://reviews.llvm.org/D10969 llvm-svn: 247683
2015-09-07[llvm-readobj] Shrink code a little bit. No functional change.Davide Italiano1-36/+9
llvm-svn: 246976
2015-09-02[llvm-reaodbj] Simplify code. No functional change (intended).Davide Italiano1-24/+8
llvm-svn: 246676
2015-08-26[llvm-objdump] Use the new MinVersion API introduced in r245938. NFC.Davide Italiano1-8/+12
llvm-svn: 246031
2015-08-13Remove and forbid raw_svector_ostream::flush() calls.Yaron Keren1-2/+0
After r244870 flush() will only compare two null pointers and return, doing nothing but wasting run time. The call is not required any more as the stream and its SmallString are always in sync. Thanks to David Blaikie for reviewing. llvm-svn: 244928
2015-08-13Remove raw_svector_ostream::resync and users. It's no-op after r244870.Yaron Keren1-1/+0
llvm-svn: 244888
2015-08-07Convert getSymbolSection to return an ErrorOr.Rafael Espindola1-4/+2
This function can actually fail since the symbol contains an index to the section and that can be invalid. llvm-svn: 244375
2015-08-05[llvm-objdump] Call exit(1) on error, i.e. fail early.Davide Italiano1-2/+1
Previously we kept going on partly corrupted input, which might result in garbage being printed, or even worse, random crashes. Rafael mentioned that this is the GNU behavior as well, but after some discussion we both agreed it's probably better to emit a reasonable error message and exit. As a side-effect of this commit, now we don't rely on global state for error codes anymore. objdump was the last tool in the toolchain which needed to be converted. Hopefully the old behavior won't sneak into the tree again. llvm-svn: 244019
2015-07-29[llvm-objdump] Merging MachO DumpSections in to FilterSections. Simplifying ↵Colin LeMahieu1-10/+5
some predicate logic. llvm-svn: 243556
2015-07-08llvm-objdump: Replace the -macho -raw option with a generic -raw-clang-astAdrian Prantl1-10/+1
option that works with all object container formats. Now that clang modules/PCH are object containers this option is useful to to construct pipes like llvm-objdump -raw-clang-ast foo.pcm | llvm-bcanalyzer - to inspect the AST contents in a PCH container. Will be tested via clang. Belatedly addresses review feedback for r233390. llvm-svn: 241659
2015-07-07Delete UnknownAddress. It is a perfectly valid symbol value.Rafael Espindola1-5/+2
getSymbolValue now returns a value that in convenient for most callers: * 0 for undefined * symbol size for common symbols * offset/address for symbols the rest Code that needs something more specific can check getSymbolFlags. llvm-svn: 241605
2015-07-03Use getValue instead of getAddress in a few MachO only cases.Rafael Espindola1-23/+9
In MachO the value of the symbol is always the address, so we can use the simpler function. llvm-svn: 241364
2015-07-02Return ErrorOr from SymbolRef::getName.Rafael Espindola1-42/+66
This function can really fail since the string table offset can be out of bounds. Using ErrorOr makes sure the error is checked. Hopefully a lot of the boilerplate code in tools/* can go away once we have a diagnostic manager in Object. llvm-svn: 241297
2015-06-29Don't return error_code from function that never fails.Rafael Espindola1-18/+9
llvm-svn: 241021
2015-06-26Rename getObjectFile to getObject for consistency.Rafael Espindola1-3/+3
llvm-svn: 240785
2015-06-26Simplify getSymbolType.Rafael Espindola1-11/+6
This is still a really odd function. Most calls are in object format specific contexts and should probably be replaced with a more direct query, but at least now this is not too obnoxious to use. llvm-svn: 240777
2015-06-24Change how symbol sizes are handled in lib/Object.Rafael Espindola1-6/+5
COFF and MachO only define symbol sizes for common symbols. Reflect that in the class hierarchy by having a method for common symbols only in the base and a general one in ELF. This avoids the need of using a magic value for the size, which had a few problems * Most callers didn't check for it. * The ones that did could not tell the magic value from a file actually having that value. llvm-svn: 240529
2015-06-19Fix "the the" in comments.Eric Christopher1-1/+1
llvm-svn: 240112
2015-06-07[objdump] Moving PrintImmHex out of MachODump and in to llvm-objdump and ↵Colin LeMahieu1-4/+0
setting instprinter appropriately. llvm-svn: 239265
2015-06-03[Object, MachO] Introduce MachOObjectFile::load_commands() range iterator.Alexey Samsonov1-65/+18
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-05-28[llvm] Parameterizing the output stream for dumpbytes and outputting ↵Colin LeMahieu1-8/+8
directly to stream. llvm-svn: 238453
2015-05-21Make it easier to use DwarfContext with MCJITKeno Fischer1-1/+1
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-04-30For llvm-objdump, with the -archive-headers and -macho options, use the ↵Kevin Enderby1-4/+10
-non-verbose option to print the archive headers using raw numeric values. Also add the -archive-member-offsets for use with these to also trigger printing of the offset of the archive member from the start of the archive. llvm-svn: 236252
2015-04-23Move DIContext.h to common DebugInfo location.Zachary Turner1-2/+3
This will enable us to create a PDBContext so as to expose some amount of debug info functionality through a common interace. Differential Revision: http://reviews.llvm.org/D9205 Reviewed by: Alexey Samsonov llvm-svn: 235612
2015-04-16For llvm-objdump, dump the (__OBJC,__protocol) section for Objc1 32-bit ↵Kevin Enderby1-0/+52
Mach-O files with the -section option as objc_protocol_t structs. llvm-svn: 235141
2015-04-16[NFC] [MachO] remove extra semicolonsJingyue Wu1-4/+4
llvm-svn: 235130
2015-04-16For llvm-objdump added support for printing Objc1 32-bit runtime meta dataKevin Enderby1-11/+836
with the existing -objc-meta-data and -macho options for Mach-O files. llvm-svn: 235119
2015-04-06Fix failure on builder clang-cmake-mips where it was printing a 32-bit addressKevin Enderby1-1/+2
incorrectly because it came from an expression using S.getAddress() which always returns a 64-bit value. llvm-svn: 234251
2015-04-06For llvm-objdump added support for printing Objc2 32-bit runtime meta dataKevin Enderby1-20/+887
with the existing -objc-meta-data and -macho options for Mach-O files. llvm-svn: 234185
2015-04-01Fix sanitizer-x86_64-linux-fast failure that was not deleting the bindtable.Kevin Enderby1-0/+3
llvm-svn: 233856
2015-04-01Add the option -objc-meta-data to llvm-objdump used with -macho toKevin Enderby1-11/+1228
print the Objective-C runtime meta data for Mach-O files. There are three types of Objective-C runtime meta data, Objc2 64-bit, Objc2 32-bit and Objc1 32-bit. This prints the first of these types. The changes to print the others will follow next. llvm-svn: 233840
2015-03-31Replace the MCSubtargetInfo parameter with a Triple when creatingEric Christopher1-3/+3
an MCInstPrinter. Update all callers and use where we wanted a Triple previously. llvm-svn: 233648
2015-03-28[Objdump] Pass the correct subtarget to printInst.Akira Hatanaka1-2/+2
This fixes a bug I introduced in r233411. llvm-svn: 233484
2015-03-27[MCInstPrinter] Enable MCInstPrinter to change its behavior based on theAkira Hatanaka1-3/+3
per-function subtarget. Currently, code-gen passes the default or generic subtarget to the constructors of MCInstPrinter subclasses (see LLVMTargetMachine::addPassesToEmitFile), which enables some targets (AArch64, ARM, and X86) to change their instprinter's behavior based on the subtarget feature bits. Since the backend can now use different subtargets for each function, instprinter has to be changed to use the per-function subtarget rather than the default subtarget. This patch takes the first step towards enabling instprinter to change its behavior based on the per-function subtarget. It adds a bit "PassSubtarget" to AsmWriter which tells table-gen to pass a reference to MCSubtargetInfo to the various print methods table-gen auto-generates. I will follow up with changes to instprinters of AArch64, ARM, and X86. llvm-svn: 233411
2015-03-27Add a -raw option to the -section mode of llvm-objdump.Adrian Prantl1-3/+13
llvm-svn: 233390
2015-03-23Refactor: simplify boolean expressions in llvm-objdumpDavid Blaikie1-235/+224
Simplify boolean expressions involving `true` and `false` with `clang-tidy`. Actually upon inspection a bunch of these boolean variables could be factored away entirely anyway - using find_if and then testing the result before using it. This also helps reduce indentation in the code anyway - and a bunch of other related simplification fell out nearby so I just committed all of that. Patch by Richard Thomson (legalize@xmission.com) Differential Revision: http://reviews.llvm.org/D8517 llvm-svn: 232984
2015-03-18[Objdump] DumpBytes of uint8_t from ArrayRef<uint8_t> instead of char from ↵Colin LeMahieu1-15/+10
StringRef. Removing reinterpret_casts. llvm-svn: 232659