aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-05-02Thread Expected<...> up from libObject’s getType() for symbols to allow ↵Kevin Enderby1-9/+10
llvm-objdump to produce a good error message. Produce another specific error message for a malformed Mach-O file when a symbol’s section index is more than the number of sections. The existing test case in test/Object/macho-invalid.test for macho-invalid-section-index-getSectionRawName now reports the error with the message indicating that a symbol at a specific index has a bad section index and that bad section index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values.  So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: "// TODO: Actually report errors helpfully" and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. llvm-svn: 268298
2016-04-22AMDGPU: Fix crash when dumping unknown opcodeMatt Arsenault1-0/+5
I'm for some reason having a problem producing a test. It should be the same as test/MC/X86/invalid_opcode.s, but llvm-mc seems to ignore random bytes. llvm-svn: 267225
2016-04-20Thread Expected<...> up from libObject’s getName() for symbols to allow ↵Kevin Enderby1-14/+20
llvm-objdump to produce a good error message. Produce another specific error message for a malformed Mach-O file when a symbol’s string index is past the end of the string table. The existing test case in test/Object/macho-invalid.test for macho-invalid-symbol-name-past-eof now reports the error with the message indicating that a symbol at a specific index has a bad sting index and that bad string index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. There is some code for this that could be factored into a routine but I would like to leave that for the code owners post-commit to do as they want for handling an llvm::Error. An example of how this could be done is shown in the diff in lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h which had a Check() routine already for std::error_code so I added one like it for llvm::Error . Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values.  So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: “// TODO: Actually report errors helpfully” and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. Note there fixes needed to lld that goes along with this that I will commit right after this. So expect lld not to built after this commit and before the next one. llvm-svn: 266919
2016-04-08Revert r265817Colin LeMahieu1-2/+1
lld tests need to be addressed. llvm-svn: 265822
2016-04-08[llvm-objdump] Printing hex instead of dec by defaultColin LeMahieu1-1/+2
Differential Revision: http://reviews.llvm.org/D18770 llvm-svn: 265817
2016-04-07fix r265645: target dependent printf formatting flags.Valery Pykhtin1-2/+2
llvm-svn: 265649
2016-04-07[AMDGPU] llvm-objdump: Minimal HSA Code Object disassembler support.Valery Pykhtin1-0/+43
Reenable reverted r265550 with endianness issue fixed. Variables of endian-aware types such as ulittle32_t should be explicitly casted to their natural equivalent types before passing it as vararg to printf like functions (format in my case). Added lit config file depending on AMDGPU target as the testcase uses assembler. Differential revision: http://reviews.llvm.org/D16998 llvm-svn: 265645
2016-04-06Thread Expected<...> up from createMachOObjectFile() to allow llvm-objdump ↵Kevin Enderby1-3/+14
to produce a real error message Produce the first specific error message for a malformed Mach-O file describing the problem instead of the generic message for object_error::parse_failed of "Invalid data was encountered while parsing the file”.  Many more good error messages will follow after this first one. This is built on Lang Hames’ great work of adding the ’Error' class for structured error handling and threading Error through MachOObjectFile construction. And making createMachOObjectFile return Expected<...> . So to to get the error to the llvm-obdump tool, I changed the stack of these methods to also return Expected<...> : object::ObjectFile::createObjectFile() object::SymbolicFile::createSymbolicFile() object::createBinary() Then finally in ParseInputMachO() in MachODump.cpp the error can be reported and the specific error message can be printed in llvm-objdump and can be seen in the existing test case for the existing malformed binary but with the updated error message. Converting these interfaces to Expected<> from ErrorOr<> does involve touching a number of places. To contain the changes for now use of errorToErrorCode() and errorOrToExpected() are used where the callers are yet to be converted. Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values. So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: “// TODO: Actually report errors helpfully” and a call something like consumeError(ObjOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. Note there is one fix also needed to lld/COFF/InputFiles.cpp that goes along with this that I will commit right after this. So expect lld not to built after this commit and before the next one. llvm-svn: 265606
2016-04-06Revert "[AMDGPU] llvm-objdump: Minimal HSA Code Object disassembler support."Valery Pykhtin1-41/+0
This reverts commit r265550. There're problems with endianness on dumping instruction bytes. Need to find out how to use support::ulittle32_t type properly. llvm-svn: 265554
2016-04-06[AMDGPU] llvm-objdump: Minimal HSA Code Object disassembler support.Valery Pykhtin1-0/+41
Differential revision: http://reviews.llvm.org/D16998 llvm-svn: 265550
2016-03-23Fix a crash in running llvm-objdump -t with an invalid Mach-O file alreadyKevin Enderby1-1/+3
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
2016-03-21Revert "[llvm-objdump] Printing relocations in executable and shared object ↵Rafael Espindola1-0/+4
files. This partially reverts r215844 by removing test objdump-reloc-shared.test which stated GNU objdump doesn't print relocations, it does." This reverts commit r263971. It produces the wrong results for .rela.dyn. I will add a test. llvm-svn: 263987
2016-03-21[llvm-objdump] Printing relocations in executable and shared object files. ↵Colin LeMahieu1-4/+0
This partially reverts r215844 by removing test objdump-reloc-shared.test which stated GNU objdump doesn't print relocations, it does. In executable and shared object ELF files, relocations in the file contain the final virtual address rather than section offset so this is adjusted to display section offset. Differential revision: http://reviews.llvm.org/D15965 llvm-svn: 263971
2016-03-18[llvm-objdump] Print <unknown> in place of instruction text if it couldn't ↵Colin LeMahieu1-64/+69
be disassembled. llvm-svn: 263793
2016-03-17[llvm-objdump] Add '0x' prefix to a target displacement number to accent its ↵Simon Atanasyan1-1/+1
hex format It might be hard to recognize a hexadecimal number without '0x' prefix. Besides that '0x' prefix corresponds to GNU objdump behaviour. Differential Revision: http://reviews.llvm.org/D18207 llvm-svn: 263705
2016-03-01[lanai] Add ELF enum value and relocations.Jacques Pienaar1-0/+1
Add ELF enum value and relocations for Lanai backed. General Lanai backend discussion on llvm-dev thread "[RFC] Lanai backend" (http://lists.llvm.org/pipermail/llvm-dev/2016-February/095118.html). Differential Revision: http://reviews.llvm.org/D17008 llvm-svn: 262394
2016-01-26Reflect the MC/MCDisassembler split on the include/ level.Benjamin Kramer1-3/+3
No functional change, just moving code around. llvm-svn: 258818
2016-01-26Re-submit r256008 "Improve DWARFDebugFrame::parse to also handle __eh_frame."Igor Laevsky1-1/+13
Originally this change was causing failures on windows buildbots. But those problems were fixed in r258806. llvm-svn: 258811
2016-01-13For llvm-objdump, add the option -private-header (without the trailing ’s’)Kevin Enderby1-2/+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
2016-01-12[WebAssembly] Add a EM_WEBASSEMBLY value, and several bits of code that use it.Dan Gohman1-0/+17
A request has been made to the official registry, but an official value is not yet available. This patch uses a temporary value in order to support development. When an official value is recieved, the value of EM_WEBASSEMBLY will be updated. llvm-svn: 257517
2015-12-29[llvm-objdump] Mark noreturn function as such.Davide Italiano1-1/+2
Match attribute in the header to make MSVC happy. llvm-svn: 256560
2015-12-25[llvm-objdump] Use stderr and not stdout for fatal errors.Davide Italiano1-2/+2
llvm-svn: 256423
2015-12-20[llvm-objdump] Move COFF function to where it belongs.Davide Italiano1-50/+1
Ideally much more stuff should be moved out of llvm-objdump.cpp, but that will happen later. llvm-svn: 256118
2015-12-19[llvm-objdump] Fail early if we can't parse the object header.Davide Italiano1-4/+5
llvm-svn: 256108
2015-12-18Revert "Improve DWARFDebugFrame::parse to also handle __eh_frame."Pete Cooper1-13/+1
This reverts commit r256008. Its breaking multiple buildbots, although works for me locally. llvm-svn: 256013
2015-12-18Improve DWARFDebugFrame::parse to also handle __eh_frame.Pete Cooper1-1/+13
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
2015-12-17[llvm-objdump] Use report_fatal_error() for a more uniform error handling.Davide Italiano1-29/+13
llvm-svn: 255871
2015-12-08[llvm-objdump/MachO] Don't cut'n'paste the same code over and over.Davide Italiano1-1/+1
Use the appropriate helper instead. llvm-svn: 254990
2015-12-03[llvm-objdump] Use report_fatal_error() if we can't find a target.Davide Italiano1-8/+2
llvm-svn: 254654
2015-11-18Fix LLD testsuite fallout from r253429David Majnemer1-4/+4
llvm-svn: 253432
2015-11-18[llvm-objdump] Use the COFF export table for additional symbolsDavid Majnemer1-57/+118
Most linked executables do not have a symbol table in COFF. However, it is pretty typical to have some export entries. Use those entries to inform the disassembler about potential function definitions and call targets. llvm-svn: 253429
2015-11-05Reapply r250906 with many suggested updates from Rafael Espindola.Kevin Enderby1-1/+4
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
2015-11-04[ELF] elfiamcu triple should imply e_machine == EM_IAMCUMichael Kuperstein1-0/+1
Differential Revision: http://reviews.llvm.org/D14109 llvm-svn: 252043
2015-10-21Backing out commit r250906 as it broke lld.Kevin Enderby1-6/+1
llvm-svn: 250908
2015-10-21This removes the eating of the error in Archive::Child::getSize() when the ↵Kevin Enderby1-1/+6
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-07Stop linking all target libraries in llvm-nm and llvm-objdump.Pete Cooper1-1/+0
llvm-nm only needs the target to parse module level assembly in bitcode. It doesn't need a disassembler or codegen. llvm-objdump needs to be able to disassemble a file, but doesn't need asm parsers or codegen. This reduces the sizes of these tools by a few MB each, depending on how many backends are linked in. llvm-svn: 249632
2015-10-01[PATCH] D13360: [llvm-objdump] Teach -d about AArch64 mapping symbolsDavide Italiano1-0/+49
AArch64 uses $d* and $x* to interleave between text and data. llvm-objdump didn't know about this so it ended up printing garbage. This patch is a first step towards a solution of the problem. Differential Revision: http://reviews.llvm.org/D13360 llvm-svn: 249083
2015-10-01[llvm-objdump] Fix time of check to time of use bug.Davide Italiano1-3/+0
There's already a test that covers this situation, so we should be fine. llvm-svn: 248976
2015-09-24[objdump] Make iterator operator* return a reference.Benjamin Kramer1-1/+1
This is closer to the expected behavior of an iterator and avoids awkward warnings from clang's -Wrange-loop-analysis below. llvm-svn: 248497
2015-09-15Revert r247692: Replace Triple with a new TargetTuple in MCTargetDesc/* and ↵Daniel Sanders1-3/+2
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-2/+3
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-3/+2
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-2/+3
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-08-10Use higher level functions in llvm-objdump.Rafael Espindola1-17/+12
This matches the rest of llvm-objdump better and isolates it from upcoming changes to ELFFile. llvm-svn: 244500
2015-08-07Convert getSymbolSection to return an ErrorOr.Rafael Espindola1-2/+3
This function can actually fail since the symbol contains an index to the section and that can be invalid. llvm-svn: 244375
2015-08-06[llvm-objdump] Add missing call to exit(1).Davide Italiano1-0/+1
Reported by: Rafael Espindola. llvm-svn: 244184
2015-08-05[llvm-objdump] Call exit(1) on error, i.e. fail early.Davide Italiano1-69/+31
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-08-03[llvm-objdump] Range-loopify. NFC intended.Davide Italiano1-3/+2
llvm-svn: 243905
2015-07-29[llvm-objdump] Inverting logic to match the word "predicate". Returning ↵Colin LeMahieu1-4/+4
true when we want it rather than when we want to discard it. llvm-svn: 243558
2015-07-29[llvm-objdump] Merging MachO DumpSections in to FilterSections. Simplifying ↵Colin LeMahieu1-14/+15
some predicate logic. llvm-svn: 243556