Reapply r250906 with many suggested updates from Rafael Espindola.
authorKevin Enderby <enderby@apple.com>
Thu, 5 Nov 2015 19:24:56 +0000 (19:24 +0000)
committerKevin Enderby <enderby@apple.com>
Thu, 5 Nov 2015 19:24:56 +0000 (19:24 +0000)
commit268709a81040b9dcee900d836900962d4ea3323c
tree6bba630e7a12f91391537fbb9e02ae9a9ebb2fd5
parentc18c3b8a3085f939e61f84aed7c345c0ba2b5d5f
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
18 files changed:
include/llvm/Object/Archive.h
include/llvm/Support/ErrorOr.h
lib/ExecutionEngine/MCJIT/MCJIT.cpp
lib/ExecutionEngine/Orc/OrcMCJITReplacement.h
lib/Object/Archive.cpp
lib/Object/ArchiveWriter.cpp
test/tools/llvm-objdump/Inputs/libbogus1.a [new file with mode: 0644]
test/tools/llvm-objdump/Inputs/libbogus2.a [new file with mode: 0644]
test/tools/llvm-objdump/Inputs/libbogus3.a [new file with mode: 0644]
test/tools/llvm-objdump/malformed-archives.test [new file with mode: 0644]
tools/dsymutil/BinaryHolder.cpp
tools/llvm-ar/llvm-ar.cpp
tools/llvm-cxxdump/llvm-cxxdump.cpp
tools/llvm-nm/llvm-nm.cpp
tools/llvm-objdump/MachODump.cpp
tools/llvm-objdump/llvm-objdump.cpp
tools/llvm-readobj/llvm-readobj.cpp
tools/llvm-size/llvm-size.cpp