[BOLT][NFC] Report errors from RewriteInstance discoverStorage and run

Further improve error handling in BOLT by reporting `RewriteInstance` errors in
a library and fuzzer-friendly way instead of exiting.

Follow-up to D119658

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D120224
This commit is contained in:
Amir Ayupov
2022-02-23 19:30:30 -08:00
parent ba061713d3
commit af6e66f44c
5 changed files with 48 additions and 34 deletions

View File

@@ -241,7 +241,8 @@ int main(int argc, char **argv) {
exit(1);
}
RI.run();
if (Error E = RI.run())
report_error(opts::InputFilename, std::move(E));
} else if (auto *O = dyn_cast<MachOObjectFile>(&Binary)) {
auto MachORIOrErr =
MachORewriteInstance::createMachORewriteInstance(O, ToolPath);
@@ -292,12 +293,14 @@ int main(int argc, char **argv) {
<< "\n";
outs() << "BOLT-DIFF: *** Binary 1 fdata: " << opts::InputDataFilename
<< "\n";
RI1.run();
if (Error E = RI1.run())
report_error(opts::InputFilename, std::move(E));
outs() << "BOLT-DIFF: *** Analyzing binary 2: " << opts::InputFilename2
<< "\n";
outs() << "BOLT-DIFF: *** Binary 2 fdata: "
<< opts::InputDataFilename2 << "\n";
RI2.run();
if (Error E = RI2.run())
report_error(opts::InputFilename2, std::move(E));
RI1.compare(RI2);
} else {
report_error(opts::InputFilename2, object_error::invalid_file_type);