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
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user