diff options
author | Kevin Enderby <enderby@apple.com> | 2016-06-28 23:16:13 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2016-06-28 23:16:13 +0000 |
commit | 42398051d8fb6fed821703280b1da4bc0694ceea (patch) | |
tree | 4c5ba4d9ec19e6b14129eeb31f620f68ed612f0b /llvm/tools/llvm-size/llvm-size.cpp | |
parent | 9c12639370c43d58d43f9a5a87128f1da5c93a1c (diff) | |
download | bcm5719-llvm-42398051d8fb6fed821703280b1da4bc0694ceea.tar.gz bcm5719-llvm-42398051d8fb6fed821703280b1da4bc0694ceea.zip |
Finish cleaning up most of the error handling in libObject’s MachOUniversalBinary
and its clients to use the new llvm::Error model for error handling.
Changed getAsArchive() from ErrorOr<...> to Expected<...> so now all
interfaces there use the new llvm::Error model for return values.
In the two places it had if (!Parent) this is actually a program error so changed
from returning errorCodeToError(object_error::parse_failed) to calling
report_fatal_error() with a message.
In getObjectForArch() added error messages to its two llvm::Error return values
instead of returning errorCodeToError(object_error::arch_not_found) with no
error message.
For the llvm-obdump, llvm-nm and llvm-size clients since the only binary files in
Mach-O Universal Binaries that are supported are Mach-O files or archives with
Mach-O objects, updated their logic to generate an error when a slice contains
something like an ELF binary instead of ignoring it. And added a test case for
that.
The last error stuff to be cleaned up for libObject’s MachOUniversalBinary is
the use of errorOrToExpected(Archive::create(ObjBuffer)) which needs
Archive::create() to be changed from ErrorOr<...> to Expected<...> first,
which I’ll work on next.
llvm-svn: 274079
Diffstat (limited to 'llvm/tools/llvm-size/llvm-size.cpp')
-rw-r--r-- | llvm/tools/llvm-size/llvm-size.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/llvm/tools/llvm-size/llvm-size.cpp b/llvm/tools/llvm-size/llvm-size.cpp index 544eb104f5f..ecc0a0eac3c 100644 --- a/llvm/tools/llvm-size/llvm-size.cpp +++ b/llvm/tools/llvm-size/llvm-size.cpp @@ -99,6 +99,13 @@ static bool error(std::error_code ec) { return true; } +static bool error(Twine Message) { + HadError = true; + errs() << ToolName << ": " << Message << ".\n"; + errs().flush(); + return true; +} + // This version of error() prints the archive name and member name, for example: // "libx.a(foo.o)" after the ToolName before the error message. It sets // HadError but returns allowing the code to move on to other archive members. @@ -585,7 +592,7 @@ static void printFileSectionSizes(StringRef file) { error(std::move(E), file, ArchFlags.size() > 1 ? StringRef(I->getArchTypeName()) : StringRef()); return; - } else if (ErrorOr<std::unique_ptr<Archive>> AOrErr = + } else if (Expected<std::unique_ptr<Archive>> AOrErr = I->getAsArchive()) { std::unique_ptr<Archive> &UA = *AOrErr; // This is an archive. Iterate over each member and display its @@ -630,6 +637,11 @@ static void printFileSectionSizes(StringRef file) { } } } + } else { + consumeError(AOrErr.takeError()); + error("Mach-O universal file: " + file + " for architecture " + + StringRef(I->getArchTypeName()) + + " is not a Mach-O file or an archive file"); } } } @@ -671,7 +683,7 @@ static void printFileSectionSizes(StringRef file) { } else if (auto E = isNotObjectErrorInvalidFileType(UO.takeError())) { error(std::move(E), file); return; - } else if (ErrorOr<std::unique_ptr<Archive>> AOrErr = + } else if (Expected<std::unique_ptr<Archive>> AOrErr = I->getAsArchive()) { std::unique_ptr<Archive> &UA = *AOrErr; // This is an archive. Iterate over each member and display its @@ -709,6 +721,11 @@ static void printFileSectionSizes(StringRef file) { } } } + } else { + consumeError(AOrErr.takeError()); + error("Mach-O universal file: " + file + " for architecture " + + StringRef(I->getArchTypeName()) + + " is not a Mach-O file or an archive file"); } return; } @@ -744,7 +761,7 @@ static void printFileSectionSizes(StringRef file) { error(std::move(E), file, MoreThanOneArch ? StringRef(I->getArchTypeName()) : StringRef()); return; - } else if (ErrorOr<std::unique_ptr<Archive>> AOrErr = + } else if (Expected<std::unique_ptr<Archive>> AOrErr = I->getAsArchive()) { std::unique_ptr<Archive> &UA = *AOrErr; // This is an archive. Iterate over each member and display its sizes. @@ -781,6 +798,11 @@ static void printFileSectionSizes(StringRef file) { } } } + } else { + consumeError(AOrErr.takeError()); + error("Mach-O universal file: " + file + " for architecture " + + StringRef(I->getArchTypeName()) + + " is not a Mach-O file or an archive file"); } } } else if (ObjectFile *o = dyn_cast<ObjectFile>(&Bin)) { |