summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-nm/llvm-nm.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Change llvm-objdump, llvm-nm and llvm-size when reporting an object file errorKevin Enderby2016-05-171-8/+46
| | | | | | | | | | | | | | | | | | | | | when the object is in an archive to use something like libx.a(foo.o) as part of the error message. Also changed llvm-objdump and llvm-size to be like llvm-nm and ignore non-object files in archives and not produce any error message. To do this Archive::Child::getAsBinary() was changed from ErrorOr<...> to Expected<...> then that was threaded up to its users. Converting this interface to Expected<> from ErrorOr<> does involve touching a number of places. To contain the changes for now the use of errorToErrorCode() is still used in one place yet to be fully converted. Again 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 comments for those. llvm-svn: 269784
* Thread Expected<...> up from libObject’s getType() for symbols to allow ↵Kevin Enderby2016-05-021-8/+15
| | | | | | | | | | | | | | | | | | | | | | 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
* MachO: remove weird ARM/Thumb interface from MachOObjectFileTim Northover2016-04-221-2/+2
| | | | | | | | | | | | | | | | Only one consumer (llvm-objdump) actually cared about the fact that there were two triples. Others were actively working around the fact that the Triple returned by getArch might have been invalid. As for llvm-objdump, it needs to be acutely aware of both Triples anyway, so being generic in the exposed API is no benefit. Also rename the version of getArch returning a Triple. Users were having to pass an unwanted nullptr to disambiguate the two, which was nasty. The only functional change here is that armv7m and armv7em object files no longer crash llvm-objdump. llvm-svn: 267249
* Thread Expected<...> up from libObject’s getName() for symbols to allow ↵Kevin Enderby2016-04-201-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [NFC] Header cleanupMehdi Amini2016-04-181-0/+1
| | | | | | | | | | | | | | Removed some unused headers, replaced some headers with forward class declarations. Found using simple scripts like this one: clear && ack --cpp -l '#include "llvm/ADT/IndexedMap.h"' | xargs grep -L 'IndexedMap[<]' | xargs grep -n --color=auto 'IndexedMap' Patch by Eugene Kosov <claprix@yandex.ru> Differential Revision: http://reviews.llvm.org/D19219 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266595
* Remove every uses of getGlobalContext() in LLVM (but the C API)Mehdi Amini2016-04-141-1/+1
| | | | | | | | | | | At the same time, fixes InstructionsTest::CastInst unittest: yes you can leave the IR in an invalid state and exit when you don't destroy the context (like the global one), no longer now. This is the first part of http://reviews.llvm.org/D19094 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266379
* Fix repeated conditional expression (PR20711)Hans Wennborg2016-04-111-1/+1
| | | | llvm-svn: 265990
* Thread Expected<...> up from createMachOObjectFile() to allow llvm-objdump ↵Kevin Enderby2016-04-061-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix some bugs in the posix output of llvm-nm. Which is documented onKevin Enderby2016-03-291-12/+21
| | | | | | | | | | | | | | http://pubs.opengroup.org/onlinepubs/9699919799/utilities/nm.html . 1) For Mach-O files the code was not printing the values in hex as is the default. 2) The values printed had leading zeros which they should not have. 3) The address for undefined symbols was printed as spaces instead of 0. 4) With the -A option with posix output for an archive did not use square brackets around the archive member name. rdar://25311883 and rdar://25299678 llvm-svn: 264778
* [llvm-nm] Fix r264247James Molloy2016-03-241-1/+1
| | | | | | I committed the test changes successfully but managed to miss the actual code change! (lack of git -a) llvm-svn: 264249
* [llvm-nm] Restore the previous behaviour (pre r262525).Davide Italiano2016-03-021-2/+1
| | | | | | | | It broke some buildbots. Pointy-hat to: me llvm-svn: 262529
* [llvm-nm] Fix rendering of -s grouping with all the othe options.Davide Italiano2016-03-021-1/+2
| | | | llvm-svn: 262525
* [llvm-nm] In C++, main implicitly returns 0. Pointed out by David Blaikie.Davide Italiano2016-02-191-2/+0
| | | | llvm-svn: 261300
* [llvm-nm] Simplify code logic. Rewrite a single function an inline.Davide Italiano2016-02-111-16/+4
| | | | llvm-svn: 260482
* [llvm-nm] Minor style change. Prefer EXIT_SUCCESS over 0.Davide Italiano2016-02-101-1/+1
| | | | llvm-svn: 260470
* [llvm-nm] Prefer range-based loop over explicit iterator.Davide Italiano2016-02-101-3/+2
| | | | llvm-svn: 260459
* [llvm-nm] Add -radix optionHemant Kulkarni2016-02-101-3/+30
| | | | | | Differential Revision: http://reviews.llvm.org/D16822 llvm-svn: 260392
* [llvm-nm] Remove excessive parenthesis, noticed by David Blaikie.Davide Italiano2016-02-081-3/+3
| | | | llvm-svn: 260173
* [llvm-nm] Yet another attempt of simplifying code.Davide Italiano2016-02-081-11/+5
| | | | llvm-svn: 260166
* [llvm-nm] Prefer empty() over size() == 0.Davide Italiano2016-02-051-1/+1
| | | | | | Thanks to David Blaikie for pointing this out! llvm-svn: 259938
* [llvm-nm] Transform a switch() statement in a pair of if(s).Davide Italiano2016-02-051-7/+2
| | | | | | | This is more uniform wrt what other tools do and makes the code a little bit more readable. llvm-svn: 259937
* [llvm-nm] Simplify code logic. NFCI.Davide Italiano2016-02-051-7/+3
| | | | llvm-svn: 259917
* [llvm-nm] Simplify the code a bit. NFCI.Davide Italiano2016-02-011-6/+2
| | | | | | Fix a style violation while I'm here. llvm-svn: 259391
* [llvm-nm] Add a comment to explain why we initialize MC.Davide Italiano2016-01-291-0/+1
| | | | llvm-svn: 259266
* [llvm-nm] Remove redundant check for file validity.Davide Italiano2016-01-271-2/+0
| | | | | | | | We already perform it at the beginning of the function so we can't arrive here with an invalid object. Also, add a test so that bugs won't sneak in the future. llvm-svn: 258982
* [llvm-nm] Roll several conditions into a single if. NFCI.Davide Italiano2016-01-261-7/+2
| | | | llvm-svn: 258846
* [llvm-nm] Simplify. No functional changes intended.Davide Italiano2016-01-261-4/+3
| | | | llvm-svn: 258837
* Fix MachOObjectFile::getSymbolName() to not call report_fatal_error()Kevin Enderby2016-01-221-2/+5
| | | | | | | | | | | but to return object_error::parse_failed.  Then made the code in llvm-nm do for Mach-O files what is done in the darwin native tools which is to print "bad string index" for bad string indexes. Updated the error message in the llvm-objdump test, and added tests to show llvm-nm prints "bad string index" and a test to print the actual bad string index value which in this case is 0xfe000002 when printing the fields as raw hex. llvm-svn: 258520
* Fix MachOObjectFile::getSymbolSection() to not call report_fatal_error()Kevin Enderby2016-01-211-2/+11
| | | | | | | | | but to return object_error::parse_failed.  Then made the code in llvm-nm do for Mach-O files what is done in the darwin native tools which is to print "(?,?)" or just "s" for bad section indexes. Also added a test to show it prints the bad section index of "42" when printing the fields as raw hex. llvm-svn: 258434
* GlobalValue: use getValueType() instead of getType()->getPointerElementType().Manuel Jacob2016-01-161-1/+1
| | | | | | | | | | | | Reviewers: mjacob Subscribers: jholewinski, arsenm, dsanders, dblaikie Patch by Eduard Burtescu. Differential Revision: http://reviews.llvm.org/D16260 llvm-svn: 257999
* Fix UMR in llvm-nm on IR object files in printDarwinSymbolReid Kleckner2015-11-191-5/+4
| | | | llvm-svn: 253529
* Fix llvm-nm(1) printing of llvm-bitcode files for -format darwin to match ↵Kevin Enderby2015-11-101-45/+113
| | | | | | | | darwin’s nm(1). Also a small fix to match printing of Mach-O objects with -format posix. llvm-svn: 252567
* Reapply r250906 with many suggested updates from Rafael Espindola.Kevin Enderby2015-11-051-5/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Don't implicitly construct a Archive::child_iterator.Rafael Espindola2015-11-031-2/+2
| | | | llvm-svn: 251878
* Allow llvm-nm’s single letter command line flags to be grouped.Kevin Enderby2015-11-021-18/+22
| | | | | | | | | | Which is needed if we want to replace darwin’s nm(1) with llvm-nm as there are many uses of grouped flags. The added test case is one specific case that is in real use. rdar://23337419 llvm-svn: 251864
* Implemented the code to make llvm-nm’s -g option work.Kevin Enderby2015-10-301-0/+3
| | | | | | | | | | | | | While llvm-nm parses the -g option and has help that describes it as: -extern-only - Show only external symbols There is no code in the program to use the boolean valve it sets from the command line. rdar://23261095 llvm-svn: 251718
* Backing out commit r250906 as it broke lld.Kevin Enderby2015-10-211-20/+7
| | | | llvm-svn: 250908
* This removes the eating of the error in Archive::Child::getSize() when the ↵Kevin Enderby2015-10-211-7/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Clang-tidy modernize-use-nullptr warnings in source directories and ↵Hans Wennborg2015-10-061-5/+6
| | | | | | | | | | generated files; other minor cleanups. Patch by Eugene Zelenko! Differential Revision: http://reviews.llvm.org/D13321 llvm-svn: 249482
* Convert getSymbolSection to return an ErrorOr.Rafael Espindola2015-08-071-8/+8
| | | | | | | This function can actually fail since the symbol contains an index to the section and that can be invalid. llvm-svn: 244375
* Use std::make_tuple to reduce code duplication.Rafael Espindola2015-07-131-27/+8
| | | | | | Thanks to David Blaikie for the suggestion. llvm-svn: 242074
* Delete UnknownAddress. It is a perfectly valid symbol value.Rafael Espindola2015-07-071-11/+7
| | | | | | | | | | | 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
* llvm-nm: treat weak undefined as undefined.Rafael Espindola2015-07-061-12/+18
| | | | | | This matches the behavior of gnu ld. llvm-svn: 241512
* Swap operands instead of using !.Rafael Espindola2015-07-061-1/+1
| | | | | | | | This avoids returning true for A == B. Thanks to Benjamin Kramer for noticing it. llvm-svn: 241490
* When sorting by address, undefined symbols go first.Rafael Espindola2015-07-061-0/+4
| | | | | | This matches gnu nm. llvm-svn: 241488
* Reduce code duplication. NFC.Rafael Espindola2015-07-061-41/+17
| | | | llvm-svn: 241484
* Fix printing of common symbols.Rafael Espindola2015-07-061-4/+9
| | | | | | Printing the symbol size matches the behavior or both gnu nm and freebsd nm. llvm-svn: 241480
* Return ErrorOr from getSymbolAddress.Rafael Espindola2015-07-031-1/+3
| | | | | | | It can fail trying to get the section on ELF and COFF. This makes sure the error is handled. llvm-svn: 241366
* Return ErrorOr from SymbolRef::getName.Rafael Espindola2015-07-021-6/+6
| | | | | | | | | | | | 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
* Simplify isSymbolList64Bit. NFC.Rafael Espindola2015-06-261-9/+1
| | | | llvm-svn: 240784
OpenPOWER on IntegriCloud