summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objdump/MachODump.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix a crash in running llvm-objdump -t with an invalid Mach-O file alreadyKevin Enderby2016-03-231-6/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in the test suite. While this is not really an interesting tool and option to run on a Mach-O file to show the symbol table in a generic libObject format it shouldn’t crash. The reason for the crash was in MachOObjectFile::getSymbolType() when it was calling MachOObjectFile::getSymbolSection() without checking its return value for the error case. What makes this fix require a fair bit of diffs is that the method getSymbolType() is in the class ObjectFile defined without an ErrorOr<> so I needed to add that all the sub classes.  And all of the uses needed to be updated and the return value needed to be checked for the error case. The MachOObjectFile version of getSymbolType() “can” get an error in trying to come up with the libObject’s internal SymbolRef::Type when the Mach-O symbol symbol type is an N_SECT type because the code is trying to select from the SymbolRef::ST_Data or SymbolRef::ST_Function values for the SymbolRef::Type. And it needs the Mach-O section to use isData() and isBSS to determine if it will return SymbolRef::ST_Data. One other possible fix I considered is to simply return SymbolRef::ST_Other when MachOObjectFile::getSymbolSection() returned an error. But since in the past when I did such changes that “ate an error in the libObject code” I was asked instead to push the error out of the libObject code I chose not to implement the fix this way. As currently written both the COFF and ELF versions of getSymbolType() can’t get an error. But if isReservedSectionNumber() wanted to check for the two known negative values rather than allowing all negative values or the code wanted to add the same check as in getSymbolAddress() to use getSection() and check for the error then these versions of getSymbolType() could return errors. At the end of the day the error printed now is the generic “Invalid data was encountered while parsing the file” for object_error::parse_failed. In the future when we thread Lang’s new TypedError for recoverable error handling though libObject this will improve. And where the added // Diagnostic(… comment is, it would be changed to produce and error message like “bad section index (42) for symbol at index 8” for this case. llvm-svn: 264187
* Update the comments for the macho-invalid-zero-ncmds test and fixKevin Enderby2016-01-261-0/+4
| | | | | | | | llvm-objdump when printing the Mach Header to print the unknown cputype and cpusubtype fields as decimal instead of not printing them at all. And change the test to check for that. llvm-svn: 258826
* Reflect the MC/MCDisassembler split on the include/ level.Benjamin Kramer2016-01-261-1/+1
| | | | | | No functional change, just moving code around. llvm-svn: 258818
* Re-submit r256008 "Improve DWARFDebugFrame::parse to also handle __eh_frame."Igor Laevsky2016-01-261-258/+6
| | | | | | | Originally this change was causing failures on windows buildbots. But those problems were fixed in r258806. llvm-svn: 258811
* [llvm-readobj] Remove dead code. Add an assertion instead.Davide Italiano2016-01-131-2/+3
| | | | | | | | | | When we arrive at the end of the function, the validation of the object has been done already. In theory, so, we should never arrive here with something broken as the object isn't mutated. Practice sometimes proves theory to be wrong, so leave an assertion instead, as suggested by David Blaikie, to catch bugs. llvm-svn: 257570
* [llvm-objdump] Use report_error() and improve error coverage.Davide Italiano2016-01-131-4/+2
| | | | llvm-svn: 257561
* For llvm-objdump, add the option -private-header (without the trailing ’s’)Kevin Enderby2016-01-131-9/+22
| | | | | | | | | | | | | | | to only print the first private header. Which for Mach-O files only prints the Mach header and not the subsequent load commands. Which is used by scripts to match what the darwin otool(1) with the -h flag does without the -l flag. For non-Mach-O files it has the same functionality as -private-headers (with the trailing ’s’). rdar://24158331 llvm-svn: 257548
* [llvm-objdump] Use appropriate helper. NFC.Davide Italiano2015-12-211-2/+1
| | | | llvm-svn: 256156
* Revert "Improve DWARFDebugFrame::parse to also handle __eh_frame."Pete Cooper2015-12-181-6/+258
| | | | | | | | This reverts commit r256008. Its breaking multiple buildbots, although works for me locally. llvm-svn: 256013
* Improve DWARFDebugFrame::parse to also handle __eh_frame.Pete Cooper2015-12-181-258/+6
| | | | | | | | | | | | | | | LLVM MC has single methods which can handle the output of EH frame and DWARF CIE's and FDE's. This code improves DWARFDebugFrame::parse to do the same for parsing. This also allows llvm-objdump to support the --dwarf=frames option which objdump supports. This option dumps the .eh_frame section using the new code in DWARFDebugFrame::parse. http://reviews.llvm.org/D15535 Reviewed by Rafael Espindola. llvm-svn: 256008
* [llvm-objdump/MachODump] Shrink code a little bit. NFC.Davide Italiano2015-12-151-4/+1
| | | | llvm-svn: 255701
* Factor out some duplication. NFC.Pete Cooper2015-12-141-44/+20
| | | | llvm-svn: 255569
* Start implementing FDE dumping when printing the eh_frame.Pete Cooper2015-12-141-5/+107
| | | | | | | | | | This code adds some simple decoding of the FDE's in an eh_frame. There's still more to be done in terms of error handling and verification. Also, we need to be able to decode the CFI's. llvm-svn: 255550
* Print the eh_frame section in MachoDump.Pete Cooper2015-12-141-1/+180
| | | | | | | | | | | | | | This is the start of work to dump the contents of the eh_frame section. It currently emits CIE entries. FDE entries will come later. It also needs improved error checking which will follow soon. http://reviews.llvm.org/D15502 Reviewed by Kevin Enderby and Lang Hames. llvm-svn: 255546
* [llvm-objdump/MachoDump] Simplify.Davide Italiano2015-12-121-7/+3
| | | | llvm-svn: 255443
* [llvm-objdump/MachODump] Reduce code duplication.Davide Italiano2015-12-111-69/+41
| | | | llvm-svn: 255380
* [llvm-objdump/MachO] Don't cut'n'paste the same code over and over.Davide Italiano2015-12-081-20/+8
| | | | | | Use the appropriate helper instead. llvm-svn: 254990
* [llvm-objdump/MachoDump] Make code much more concise.Davide Italiano2015-12-071-20/+5
| | | | llvm-svn: 254888
* [Object, MachO] Mark symbols from DATA and BSS sections as ST_DataKuba Brecka2015-11-121-1/+1
| | | | | | | | In `MachOObjectFile::getSymbolType` we currently always return `SymbolRef::ST_Function` for symbols from any section. In order for llvm-symbolizer to correctly symbolize Mach-O globals, symbols from data and BSS sections should return `SymbolRef::ST_Data`. Differential Revision: http://reviews.llvm.org/D14576 llvm-svn: 252867
* Reapply r250906 with many suggested updates from Rafael Espindola.Kevin Enderby2015-11-051-7/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The needed lld matching changes to be submitted immediately next, but this revision will cause lld failures with this alone which is expected. This removes the eating of the error in Archive::Child::getSize() when the 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. The test cases use archives with text files so one can see the non-digit character, in this case a ‘%’, in the size field. These changes will require corresponding changes to the lld project. That will be committed immediately after this change. But this revision will cause lld failures with this alone which is expected. llvm-svn: 252192
* MachO: support tvOS and watchOS version min commands in llvm-objdumpTim Northover2015-11-021-7/+22
| | | | llvm-svn: 251834
* This can take a const reference. NFC.Rafael Espindola2015-10-311-1/+1
| | | | llvm-svn: 251753
* Simplify handling of archive Symbol tables.Rafael Espindola2015-10-311-7/+2
| | | | | | We only need to store a StringRef. llvm-svn: 251748
* Simplify boolean expressions in tools/llvm-objdump.Rafael Espindola2015-10-241-2/+2
| | | | | | Patch by Richard. llvm-svn: 251215
* Backing out commit r250906 as it broke lld.Kevin Enderby2015-10-211-28/+9
| | | | llvm-svn: 250908
* This removes the eating of the error in Archive::Child::getSize() when the ↵Kevin Enderby2015-10-211-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
* Fix a bugs in the Mach-O disassembler when disassembling from aKevin Enderby2015-10-101-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
* Fix use of uninitialized bool, found by ubsan in portion ofRichard Smith2015-10-091-6/+10
| | | | | | test/tools/llvm-objdump/malformed-machos.test added in r249845. llvm-svn: 249909
* Fixed two bugs in llvm-objdump’s printing of Objective-C meta dataKevin Enderby2015-10-091-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
* Fix a bug in llvm-objdump’s printing of Objective-C meta dataKevin Enderby2015-10-081-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
* Fix a bug in llvm-objdump’s printing of Objective-C meta dataKevin Enderby2015-10-081-3/+9
| | | | | | | from malformed Mach-O files that caused a crash because of loops in the class meta data. llvm-svn: 249700
* Fix two bugs in llvm-objdump’s printing of Objective-C meta dataKevin Enderby2015-10-061-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
* Fix Clang-tidy modernize-use-nullptr warnings in examples and include ↵Hans Wennborg2015-09-291-4/+5
| | | | | | | | | | directories; other minor cleanups. Patch by Eugene Zelenko! Differential Revision: http://reviews.llvm.org/D13172 llvm-svn: 248811
* Use makeArrayRef or None to avoid unnecessarily mentioning the ArrayRef type ↵Craig Topper2015-09-211-8/+8
| | | | | | extra times. NFC llvm-svn: 248140
* Revert r247692: Replace Triple with a new TargetTuple in MCTargetDesc/* and ↵Daniel Sanders2015-09-151-4/+3
| | | | | | | | related. NFC. Eric has replied and has demanded the patch be reverted. llvm-svn: 247702
* Re-commit r247683: Replace Triple with a new TargetTuple in MCTargetDesc/* ↵Daniel Sanders2015-09-151-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
* Revert r247684 - Replace Triple with a new TargetTuple ...Daniel Sanders2015-09-151-4/+3
| | | | | | LLDB needs to be updated in the same commit. llvm-svn: 247686
* Replace Triple with a new TargetTuple in MCTargetDesc/* and related. NFC.Daniel Sanders2015-09-151-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
* [llvm-readobj] Shrink code a little bit. No functional change.Davide Italiano2015-09-071-36/+9
| | | | llvm-svn: 246976
* [llvm-reaodbj] Simplify code. No functional change (intended).Davide Italiano2015-09-021-24/+8
| | | | llvm-svn: 246676
* [llvm-objdump] Use the new MinVersion API introduced in r245938. NFC.Davide Italiano2015-08-261-8/+12
| | | | llvm-svn: 246031
* Remove and forbid raw_svector_ostream::flush() calls.Yaron Keren2015-08-131-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
* Remove raw_svector_ostream::resync and users. It's no-op after r244870.Yaron Keren2015-08-131-1/+0
| | | | llvm-svn: 244888
* Convert getSymbolSection to return an ErrorOr.Rafael Espindola2015-08-071-4/+2
| | | | | | | This function can actually fail since the symbol contains an index to the section and that can be invalid. llvm-svn: 244375
* [llvm-objdump] Call exit(1) on error, i.e. fail early.Davide Italiano2015-08-051-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
* [llvm-objdump] Merging MachO DumpSections in to FilterSections. Simplifying ↵Colin LeMahieu2015-07-291-10/+5
| | | | | | some predicate logic. llvm-svn: 243556
* llvm-objdump: Replace the -macho -raw option with a generic -raw-clang-astAdrian Prantl2015-07-081-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
* Delete UnknownAddress. It is a perfectly valid symbol value.Rafael Espindola2015-07-071-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
* Use getValue instead of getAddress in a few MachO only cases.Rafael Espindola2015-07-031-23/+9
| | | | | | | In MachO the value of the symbol is always the address, so we can use the simpler function. llvm-svn: 241364
* Return ErrorOr from SymbolRef::getName.Rafael Espindola2015-07-021-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
OpenPOWER on IntegriCloud