Commit Graph

225 Commits

Author SHA1 Message Date
Kevin Enderby
a486dcaf36 Thread Expected<...> up from libObject’s getType() for symbols to allow 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268298 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-02 20:28:12 +00:00
Tim Northover
d52a244185 MachO: remove weird ARM/Thumb interface from MachOObjectFile
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267249 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-22 23:21:13 +00:00
Kevin Enderby
813e0cf966 Thread Expected<...> up from libObject’s getName() for symbols to allow 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266919 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-20 21:24:34 +00:00
Mehdi Amini
f6071e14c5 [NFC] Header cleanup
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>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266595 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-18 09:17:29 +00:00
Mehdi Amini
8be7707c14 Remove every uses of getGlobalContext() in LLVM (but the C API)
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>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266379 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-14 21:59:01 +00:00
Hans Wennborg
ea91af800b Fix repeated conditional expression (PR20711)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265990 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-11 20:36:05 +00:00
Kevin Enderby
c6bf9be16d Thread Expected<...> up from createMachOObjectFile() to allow llvm-objdump 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265606 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-06 22:14:09 +00:00
Kevin Enderby
ae7cf58516 Fix some bugs in the posix output of llvm-nm. Which is documented on
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264778 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-29 20:18:07 +00:00
James Molloy
66d1cd5130 [llvm-nm] Fix r264247
I committed the test changes successfully but managed to miss the actual code change! (lack of git -a)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264249 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-24 09:23:51 +00:00
Davide Italiano
ac6554cf16 [llvm-nm] Restore the previous behaviour (pre r262525).
It broke some buildbots.

Pointy-hat to:  me


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262529 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-02 22:33:49 +00:00
Davide Italiano
cf5219da54 [llvm-nm] Fix rendering of -s grouping with all the othe options.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262525 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-02 21:59:31 +00:00
Davide Italiano
b75f2ffaf4 [llvm-nm] In C++, main implicitly returns 0. Pointed out by David Blaikie.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261300 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-19 02:22:54 +00:00
Davide Italiano
e48f9ae77d [llvm-nm] Simplify code logic. Rewrite a single function an inline.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260482 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-11 02:56:02 +00:00
Davide Italiano
1c4040b68f [llvm-nm] Minor style change. Prefer EXIT_SUCCESS over 0.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260470 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-10 23:56:18 +00:00
Davide Italiano
e1244044f3 [llvm-nm] Prefer range-based loop over explicit iterator.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260459 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-10 23:16:17 +00:00
Hemant Kulkarni
d712968e30 [llvm-nm] Add -radix option
Differential Revision: http://reviews.llvm.org/D16822

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260392 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-10 17:51:39 +00:00
Davide Italiano
d95e7b09f3 [llvm-nm] Remove excessive parenthesis, noticed by David Blaikie.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260173 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-08 23:50:23 +00:00
Davide Italiano
68c43d458e [llvm-nm] Yet another attempt of simplifying code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260166 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-08 22:58:26 +00:00
Davide Italiano
b9f7c71bb9 [llvm-nm] Prefer empty() over size() == 0.
Thanks to David Blaikie for pointing this out!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259938 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-05 22:10:42 +00:00
Davide Italiano
48d378b115 [llvm-nm] Transform a switch() statement in a pair of if(s).
This is more uniform wrt what other tools do and makes the code
a little bit more readable.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259937 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-05 22:07:09 +00:00
Davide Italiano
409c5545b1 [llvm-nm] Simplify code logic. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259917 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-05 21:10:48 +00:00
Davide Italiano
88b3e3ebd1 [llvm-nm] Simplify the code a bit. NFCI.
Fix a style violation while I'm here.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259391 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-01 19:22:16 +00:00
Davide Italiano
c98cfb2adf [llvm-nm] Add a comment to explain why we initialize MC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259266 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-29 23:38:05 +00:00
Davide Italiano
1db4cdc3b1 [llvm-nm] Remove redundant check for file validity.
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258982 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-27 20:27:44 +00:00
Davide Italiano
faaeb2ecd8 [llvm-nm] Roll several conditions into a single if. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258846 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-26 19:57:42 +00:00
Davide Italiano
dc5172a78f [llvm-nm] Simplify. No functional changes intended.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258837 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-26 19:28:51 +00:00
Kevin Enderby
161c62450c Fix MachOObjectFile::getSymbolName() to not call report_fatal_error()
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258520 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-22 18:47:14 +00:00
Kevin Enderby
d8116dc95f Fix MachOObjectFile::getSymbolSection() to not call report_fatal_error()
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258434 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-21 21:13:27 +00:00
Manuel Jacob
75e1cfb035 GlobalValue: use getValueType() instead of getType()->getPointerElementType().
Reviewers: mjacob

Subscribers: jholewinski, arsenm, dsanders, dblaikie

Patch by Eduard Burtescu.

Differential Revision: http://reviews.llvm.org/D16260


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257999 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-16 20:30:46 +00:00
Reid Kleckner
697477e00c Fix UMR in llvm-nm on IR object files in printDarwinSymbol
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253529 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-19 00:51:50 +00:00
Kevin Enderby
7f0edadcaf Fix llvm-nm(1) printing of llvm-bitcode files for -format darwin to match darwin’s nm(1).
Also a small fix to match printing of Mach-O objects with -format posix.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252567 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-10 00:31:08 +00:00
Kevin Enderby
268709a810 Reapply r250906 with many suggested updates from Rafael Espindola.
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252192 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-05 19:24:56 +00:00
Rafael Espindola
030d7a3004 Don't implicitly construct a Archive::child_iterator.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251878 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-03 01:32:40 +00:00
Kevin Enderby
06e1752041 Allow llvm-nm’s single letter command line flags to be grouped.
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251864 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-02 23:42:05 +00:00
Kevin Enderby
05f3dabc64 Implemented the code to make llvm-nm’s -g option work.
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251718 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-30 19:55:32 +00:00
Kevin Enderby
da785374d9 Backing out commit r250906 as it broke lld.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250908 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-21 17:13:20 +00:00
Kevin Enderby
e36c14fbed 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.

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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250906 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-21 16:59:24 +00:00
Hans Wennborg
4d651e440b Fix Clang-tidy modernize-use-nullptr warnings in source directories and generated files; other minor cleanups.
Patch by Eugene Zelenko!

Differential Revision: http://reviews.llvm.org/D13321

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249482 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-06 23:24:35 +00:00
Rafael Espindola
e84d8c12d5 Convert getSymbolSection to return an ErrorOr.
This function can actually fail since the symbol contains an index to the
section and that can be invalid.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244375 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-07 23:27:14 +00:00
Rafael Espindola
6d0b72637c Use std::make_tuple to reduce code duplication.
Thanks to David Blaikie for the suggestion.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242074 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-13 22:01:02 +00:00
Rafael Espindola
7b7c81cd35 Delete UnknownAddress. It is a perfectly valid symbol value.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241605 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-07 17:12:59 +00:00
Rafael Espindola
fa2ca74300 llvm-nm: treat weak undefined as undefined.
This matches the behavior of gnu ld.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241512 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-06 21:36:23 +00:00
Rafael Espindola
9c3967db0f Swap operands instead of using !.
This avoids returning true for A == B.

Thanks to Benjamin Kramer for noticing it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241490 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-06 19:24:40 +00:00
Rafael Espindola
40b3496f9a When sorting by address, undefined symbols go first.
This matches gnu nm.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241488 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-06 19:21:04 +00:00
Rafael Espindola
be2ff7bc98 Reduce code duplication. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241484 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-06 18:48:47 +00:00
Rafael Espindola
e473de21aa Fix printing of common symbols.
Printing the symbol size matches the behavior or both gnu nm and freebsd nm.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241480 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-06 18:18:44 +00:00
Rafael Espindola
5954faae4d Return ErrorOr from getSymbolAddress.
It can fail trying to get the section on ELF and COFF. This makes sure the
error is handled.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241366 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-03 18:19:00 +00:00
Rafael Espindola
8a80641a85 Return ErrorOr from SymbolRef::getName.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241297 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-02 20:55:21 +00:00
Rafael Espindola
9aa455951b Simplify isSymbolList64Bit. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240784 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 14:11:54 +00:00
Rafael Espindola
6909cca568 Simplify isObject. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240783 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 13:24:23 +00:00