llvm.org GIT mirror llvm / aacf2fb
[Object] Re-apply r275316 now that I have the corresponding LLD patch ready. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275361 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 3 years ago
15 changed file(s) with 242 addition(s) and 203 deletion(s). Raw diff Collapse all Expand all
105105 };
106106
107107 class child_iterator {
108 ErrorOr child;
109
110 public:
111 child_iterator() : child(Child(nullptr, nullptr, nullptr)) {}
112 child_iterator(const Child &c) : child(c) {}
113 child_iterator(std::error_code EC) : child(EC) {}
114 const ErrorOr *operator->() const { return &child; }
115 const ErrorOr &operator*() const { return child; }
108 Child C;
109 Error *E;
110
111 public:
112 child_iterator() : C(Child(nullptr, nullptr, nullptr)), E(nullptr) {}
113 child_iterator(const Child &C, Error *E) : C(C), E(E) {}
114 const Child *operator->() const { return &C; }
115 const Child &operator*() const { return C; }
116116
117117 bool operator==(const child_iterator &other) const {
118 // We ignore error states so that comparisions with end() work, which
119 // allows range loops.
120 if (child.getError() || other.child.getError())
121 return false;
122 return *child == *other.child;
118 // Ignore errors here: If an error occurred during increment then getNext
119 // will have been set to child_end(), and the following comparison should
120 // do the right thing.
121 return C == other.C;
123122 }
124123
125124 bool operator!=(const child_iterator &other) const {
129128 // Code in loops with child_iterators must check for errors on each loop
130129 // iteration. And if there is an error break out of the loop.
131130 child_iterator &operator++() { // Preincrement
132 assert(child && "Can't increment iterator with error");
133 child = child->getNext();
131 assert(E && "Can't increment iterator with no Error attached");
132 if (auto ChildOrErr = C.getNext())
133 C = *ChildOrErr;
134 else {
135 ErrorAsOutParameter ErrAsOutParam(*E);
136 C = C.getParent()->child_end().C;
137 *E = errorCodeToError(ChildOrErr.getError());
138 E = nullptr;
139 }
134140 return *this;
135141 }
136142 };
189195 Kind kind() const { return (Kind)Format; }
190196 bool isThin() const { return IsThin; }
191197
192 child_iterator child_begin(bool SkipInternal = true) const;
198 child_iterator child_begin(Error &Err, bool SkipInternal = true) const;
193199 child_iterator child_end() const;
194 iterator_range children(bool SkipInternal = true) const {
195 return make_range(child_begin(SkipInternal), child_end());
200 iterator_range children(Error &Err,
201 bool SkipInternal = true) const {
202 return make_range(child_begin(Err, SkipInternal), child_end());
196203 }
197204
198205 symbol_iterator symbol_begin() const;
207214 }
208215
209216 // check if a symbol is in the archive
210 child_iterator findSym(StringRef name) const;
217 child_iterator findSym(Error &Err, StringRef name) const;
211218
212219 bool hasSymbolTable() const;
213220 StringRef getSymbolTable() const { return SymbolTable; }
939939 std::function GetExitCode;
940940 };
941941
942 /// Report a serious error, calling any installed error handler. See
943 /// ErrorHandling.h.
944 LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err,
945 bool gen_crash_diag = true);
946
942947 } // namespace llvm
943948
944949 #endif // LLVM_SUPPORT_ERROR_H
326326 for (object::OwningBinary &OB : Archives) {
327327 object::Archive *A = OB.getBinary();
328328 // Look for our symbols in each Archive
329 object::Archive::child_iterator ChildIt = A->findSym(Name);
330 if (std::error_code EC = ChildIt->getError())
331 report_fatal_error(EC.message());
329 Error Err;
330 object::Archive::child_iterator ChildIt = A->findSym(Err, Name);
331 if (Err)
332 report_fatal_error(std::move(Err));
332333 if (ChildIt != A->child_end()) {
333334 // FIXME: Support nested archives?
334335 Expected> ChildBinOrErr =
335 (*ChildIt)->getAsBinary();
336 ChildIt->getAsBinary();
336337 if (!ChildBinOrErr) {
337338 // TODO: Actually report errors helpfully.
338339 consumeError(ChildBinOrErr.takeError());
257257 for (object::OwningBinary &OB : Archives) {
258258 object::Archive *A = OB.getBinary();
259259 // Look for our symbols in each Archive
260 object::Archive::child_iterator ChildIt = A->findSym(Name);
261 if (std::error_code EC = ChildIt->getError())
262 report_fatal_error(EC.message());
260 Error Err;
261 object::Archive::child_iterator ChildIt = A->findSym(Err, Name);
262 if (Err)
263 report_fatal_error(std::move(Err));
263264 if (ChildIt != A->child_end()) {
264265 // FIXME: Support nested archives?
265266 Expected> ChildBinOrErr =
266 (*ChildIt)->getAsBinary();
267 ChildIt->getAsBinary();
267268 if (!ChildBinOrErr) {
268269 // TODO: Actually report errors helpfully.
269270 consumeError(ChildBinOrErr.takeError());
297297 }
298298
299299 // Get the special members.
300 child_iterator I = child_begin(false);
301 std::error_code ec;
302 if ((ec = I->getError())) {
303 Err = errorCodeToError(ec);
304 return;
305 }
300 child_iterator I = child_begin(Err, false);
301 if (Err)
302 return;
306303 child_iterator E = child_end();
307304
308305 // This is at least a valid empty archive. Since an empty archive is the
314311 Err = Error::success();
315312 return;
316313 }
317 const Child *C = &**I;
314 const Child *C = &*I;
318315
319316 auto Increment = [&]() {
320317 ++I;
321 if ((Err = errorCodeToError(I->getError())))
318 if (Err)
322319 return true;
323 C = &**I;
320 C = &*I;
324321 return false;
325322 };
326323
365362 Format = K_BSD;
366363 // We know this is BSD, so getName will work since there is no string table.
367364 ErrorOr NameOrErr = C->getName();
368 ec = NameOrErr.getError();
369 if (ec) {
365 if (auto ec = NameOrErr.getError()) {
370366 Err = errorCodeToError(ec);
371367 return;
372368 }
464460 Err = Error::success();
465461 }
466462
467 Archive::child_iterator Archive::child_begin(bool SkipInternal) const {
463 Archive::child_iterator Archive::child_begin(Error &Err,
464 bool SkipInternal) const {
468465 if (Data.getBufferSize() == 8) // empty archive.
469466 return child_end();
470467
471468 if (SkipInternal)
472 return Child(this, FirstRegularData, FirstRegularStartOfFile);
469 return child_iterator(Child(this, FirstRegularData,
470 FirstRegularStartOfFile),
471 &Err);
473472
474473 const char *Loc = Data.getBufferStart() + strlen(Magic);
475474 std::error_code EC;
476 Child c(this, Loc, &EC);
477 if (EC)
478 return child_iterator(EC);
479 return child_iterator(c);
475 Child C(this, Loc, &EC);
476 if (EC) {
477 ErrorAsOutParameter ErrAsOutParam(Err);
478 Err = errorCodeToError(EC);
479 return child_end();
480 }
481 return child_iterator(C, &Err);
480482 }
481483
482484 Archive::child_iterator Archive::child_end() const {
483 return Child(this, nullptr, nullptr);
485 return child_iterator(Child(this, nullptr, nullptr), nullptr);
484486 }
485487
486488 StringRef Archive::Symbol::getName() const {
664666 return read32le(buf);
665667 }
666668
667 Archive::child_iterator Archive::findSym(StringRef name) const {
669 Archive::child_iterator Archive::findSym(Error &Err, StringRef name) const {
668670 Archive::symbol_iterator bs = symbol_begin();
669671 Archive::symbol_iterator es = symbol_end();
670672
671673 for (; bs != es; ++bs) {
672674 StringRef SymName = bs->getName();
673675 if (SymName == name) {
674 ErrorOr ResultOrErr = bs->getMember();
675 // FIXME: Should we really eat the error?
676 if (ResultOrErr.getError())
676 if (auto MemberOrErr = bs->getMember()) {
677 return child_iterator(*MemberOrErr, &Err);
678 } else {
679 ErrorAsOutParameter ErrAsOutParam(Err);
680 Err = errorCodeToError(MemberOrErr.getError());
677681 return child_end();
678 return ResultOrErr.get();
682 }
679683 }
680684 }
681685 return child_end();
6363 });
6464 }
6565
66
6667 std::error_code ErrorList::convertToErrorCode() const {
6768 return std::error_code(static_cast(ErrorErrorCode::MultipleErrors),
6869 *ErrorErrorCat);
9899 return EC;
99100 }
100101
102 void report_fatal_error(Error Err, bool GenCrashDiag) {
103 assert(Err && "report_fatal_error called with success value");
104 std::string ErrMsg;
105 {
106 raw_string_ostream ErrStream(ErrMsg);
107 logAllUnhandledErrors(std::move(Err), ErrStream, "");
108 }
109 report_fatal_error(ErrMsg);
101110 }
111
112 }
101101 Buffers.reserve(CurrentArchives.size());
102102
103103 for (const auto &CurrentArchive : CurrentArchives) {
104 for (auto ChildOrErr : CurrentArchive->children()) {
105 if (std::error_code Err = ChildOrErr.getError())
106 return Err;
107 const auto &Child = *ChildOrErr;
104 Error Err;
105 for (auto Child : CurrentArchive->children(Err)) {
108106 if (auto NameOrErr = Child.getName()) {
109107 if (*NameOrErr == Filename) {
110108 if (Timestamp != sys::TimeValue::PosixZeroTime() &&
122120 }
123121 }
124122 }
123 if (Err)
124 return errorToErrorCode(std::move(Err));
125125 }
126126
127127 if (Buffers.empty())
404404 fail("extracting from a thin archive is not supported");
405405
406406 bool Filter = !Members.empty();
407 for (auto &ChildOrErr : OldArchive->children()) {
408 failIfError(ChildOrErr.getError());
409 const object::Archive::Child &C = *ChildOrErr;
410
411 ErrorOr NameOrErr = C.getName();
412 failIfError(NameOrErr.getError());
413 StringRef Name = NameOrErr.get();
414
415 if (Filter) {
416 auto I = std::find(Members.begin(), Members.end(), Name);
417 if (I == Members.end())
418 continue;
419 Members.erase(I);
407 {
408 Error Err;
409 for (auto &C : OldArchive->children(Err)) {
410 ErrorOr NameOrErr = C.getName();
411 failIfError(NameOrErr.getError());
412 StringRef Name = NameOrErr.get();
413
414 if (Filter) {
415 auto I = std::find(Members.begin(), Members.end(), Name);
416 if (I == Members.end())
417 continue;
418 Members.erase(I);
419 }
420
421 switch (Operation) {
422 default:
423 llvm_unreachable("Not a read operation");
424 case Print:
425 doPrint(Name, C);
426 break;
427 case DisplayTable:
428 doDisplayTable(Name, C);
429 break;
430 case Extract:
431 doExtract(Name, C);
432 break;
433 }
420434 }
421
422 switch (Operation) {
423 default:
424 llvm_unreachable("Not a read operation");
425 case Print:
426 doPrint(Name, C);
427 break;
428 case DisplayTable:
429 doDisplayTable(Name, C);
430 break;
431 case Extract:
432 doExtract(Name, C);
433 break;
434 }
435 }
435 failIfError(std::move(Err));
436 }
437
436438 if (Members.empty())
437439 return;
438440 for (StringRef Name : Members)
530532 int InsertPos = -1;
531533 StringRef PosName = sys::path::filename(RelPos);
532534 if (OldArchive) {
533 for (auto &ChildOrErr : OldArchive->children()) {
534 failIfError(ChildOrErr.getError());
535 auto &Child = ChildOrErr.get();
535 Error Err;
536 for (auto &Child : OldArchive->children(Err)) {
536537 int Pos = Ret.size();
537538 ErrorOr NameOrErr = Child.getName();
538539 failIfError(NameOrErr.getError());
567568 if (MemberI != Members.end())
568569 Members.erase(MemberI);
569570 }
571 failIfError(std::move(Err));
570572 }
571573
572574 if (Operation == Delete)
763765 "Could not parse library");
764766 Archives.push_back(std::move(*LibOrErr));
765767 object::Archive &Lib = *Archives.back();
766 for (auto &MemberOrErr : Lib.children()) {
767 failIfError(MemberOrErr.getError());
768 addMember(NewMembers, *MemberOrErr);
768 {
769 Error Err;
770 for (auto &Member : Lib.children(Err))
771 addMember(NewMembers, Member);
772 failIfError(std::move(Err));
769773 }
770774 break;
771775 }
4747 outs() << "\nError reading file: " << EC.message() << ".\n";
4848 outs().flush();
4949 exit(1);
50 }
51
52 static void error(Error Err) {
53 if (Err) {
54 logAllUnhandledErrors(std::move(Err), outs(), "Error reading file: ");
55 outs().flush();
56 exit(1);
57 }
5058 }
5159
5260 } // namespace llvm
481489 }
482490
483491 static void dumpArchive(const Archive *Arc) {
484 for (auto &ErrorOrChild : Arc->children()) {
485 error(ErrorOrChild.getError());
486 const Archive::Child &ArcC = *ErrorOrChild;
492 Error Err;
493 for (auto &ArcC : Arc->children(Err)) {
487494 Expected> ChildOrErr = ArcC.getAsBinary();
488495 if (!ChildOrErr) {
489496 // Ignore non-object files.
503510 else
504511 reportError(Arc->getFileName(), cxxdump_error::unrecognized_file_format);
505512 }
513 error(std::move(Err));
506514 }
507515
508516 static void dumpInput(StringRef File) {
11081108 }
11091109 }
11101110
1111 for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
1112 I != E; ++I) {
1113 if (error(I->getError()))
1114 return;
1115 auto &C = I->get();
1116 Expected> ChildOrErr = C.getAsBinary(&Context);
1117 if (!ChildOrErr) {
1118 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
1119 error(std::move(E), Filename, C);
1120 continue;
1111 {
1112 Error Err;
1113 for (auto &C : A->children(Err)) {
1114 Expected> ChildOrErr = C.getAsBinary(&Context);
1115 if (!ChildOrErr) {
1116 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
1117 error(std::move(E), Filename, C);
1118 continue;
1119 }
1120 if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) {
1121 if (!checkMachOAndArchFlags(O, Filename))
1122 return;
1123 if (!PrintFileName) {
1124 outs() << "\n";
1125 if (isa(O)) {
1126 outs() << Filename << "(" << O->getFileName() << ")";
1127 } else
1128 outs() << O->getFileName();
1129 outs() << ":\n";
1130 }
1131 dumpSymbolNamesFromObject(*O, false, Filename);
1132 }
11211133 }
1122 if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) {
1123 if (!checkMachOAndArchFlags(O, Filename))
1124 return;
1125 if (!PrintFileName) {
1126 outs() << "\n";
1127 if (isa(O)) {
1128 outs() << Filename << "(" << O->getFileName() << ")";
1129 } else
1130 outs() << O->getFileName();
1131 outs() << ":\n";
1132 }
1133 dumpSymbolNamesFromObject(*O, false, Filename);
1134 }
1134 if (Err)
1135 error(std::move(Err), A->getFileName());
11351136 }
11361137 return;
11371138 }
11731174 } else if (Expected> AOrErr =
11741175 I->getAsArchive()) {
11751176 std::unique_ptr &A = *AOrErr;
1176 for (Archive::child_iterator AI = A->child_begin(),
1177 AE = A->child_end();
1178 AI != AE; ++AI) {
1179 if (error(AI->getError()))
1180 return;
1181 auto &C = AI->get();
1177 Error Err;
1178 for (auto &C : A->children(Err)) {
11821179 Expected> ChildOrErr =
11831180 C.getAsBinary(&Context);
11841181 if (!ChildOrErr) {
12081205 ArchitectureName);
12091206 }
12101207 }
1208 if (Err)
1209 error(std::move(Err), A->getFileName());
12111210 } else {
12121211 consumeError(AOrErr.takeError());
12131212 error(Filename + " for architecture " +
12461245 } else if (Expected> AOrErr =
12471246 I->getAsArchive()) {
12481247 std::unique_ptr &A = *AOrErr;
1249 for (Archive::child_iterator AI = A->child_begin(),
1250 AE = A->child_end();
1251 AI != AE; ++AI) {
1252 if (error(AI->getError()))
1253 return;
1254 auto &C = AI->get();
1248 Error Err;
1249 for (auto &C : A->children(Err)) {
12551250 Expected> ChildOrErr =
12561251 C.getAsBinary(&Context);
12571252 if (!ChildOrErr) {
12711266 dumpSymbolNamesFromObject(*O, false, ArchiveName);
12721267 }
12731268 }
1269 if (Err)
1270 error(std::move(Err), A->getFileName());
12741271 } else {
12751272 consumeError(AOrErr.takeError());
12761273 error(Filename + " for architecture " +
13151312 } else if (Expected> AOrErr =
13161313 I->getAsArchive()) {
13171314 std::unique_ptr &A = *AOrErr;
1318 for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
1319 AI != AE; ++AI) {
1320 if (error(AI->getError()))
1321 return;
1322 auto &C = AI->get();
1315 Error Err;
1316 for (auto &C : A->children(Err)) {
13231317 Expected> ChildOrErr =
13241318 C.getAsBinary(&Context);
13251319 if (!ChildOrErr) {
13481342 dumpSymbolNamesFromObject(*O, false, ArchiveName, ArchitectureName);
13491343 }
13501344 }
1345 if (Err)
1346 error(std::move(Err), A->getFileName());
13511347 } else {
13521348 consumeError(AOrErr.takeError());
13531349 error(Filename + " for architecture " +
15341534 }
15351535
15361536 static void printArchiveHeaders(Archive *A, bool verbose, bool print_offset) {
1537 for (Archive::child_iterator I = A->child_begin(false), E = A->child_end();
1538 I != E; ++I) {
1539 if (std::error_code EC = I->getError())
1540 report_fatal_error(EC.message());
1541 const Archive::Child &C = **I;
1537 Error Err;
1538 for (const auto &C : A->children(Err, false))
15421539 printArchiveChild(C, verbose, print_offset);
1543 }
1540 if (Err)
1541 report_fatal_error(std::move(Err));
15441542 }
15451543
15461544 // ParseInputMachO() parses the named Mach-O file in Filename and handles the
15711569 outs() << "Archive : " << Filename << "\n";
15721570 if (ArchiveHeaders)
15731571 printArchiveHeaders(A, !NonVerbose, ArchiveMemberOffsets);
1574 for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
1575 I != E; ++I) {
1576 if (std::error_code EC = I->getError())
1577 report_error(Filename, EC);
1578 auto &C = I->get();
1572 Error Err;
1573 for (auto &C : A->children(Err)) {
15791574 Expected> ChildOrErr = C.getAsBinary();
15801575 if (!ChildOrErr) {
15811576 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
15881583 ProcessMachO(Filename, O, O->getFileName());
15891584 }
15901585 }
1586 if (Err)
1587 report_error(Filename, std::move(Err));
15911588 return;
15921589 }
15931590 if (UniversalHeaders) {
16291626 outs() << "\n";
16301627 if (ArchiveHeaders)
16311628 printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
1632 for (Archive::child_iterator AI = A->child_begin(),
1633 AE = A->child_end();
1634 AI != AE; ++AI) {
1635 if (std::error_code EC = AI->getError())
1636 report_error(Filename, EC);
1637 auto &C = AI->get();
1629 Error Err;
1630 for (auto &C : A->children(Err)) {
16381631 Expected> ChildOrErr = C.getAsBinary();
16391632 if (!ChildOrErr) {
16401633 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
16451638 dyn_cast(&*ChildOrErr.get()))
16461639 ProcessMachO(Filename, O, O->getFileName(), ArchitectureName);
16471640 }
1641 if (Err)
1642 report_error(Filename, std::move(Err));
16481643 } else {
16491644 consumeError(AOrErr.takeError());
16501645 error("Mach-O universal file: " + Filename + " for " +
16861681 outs() << "Archive : " << Filename << "\n";
16871682 if (ArchiveHeaders)
16881683 printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
1689 for (Archive::child_iterator AI = A->child_begin(),
1690 AE = A->child_end();
1691 AI != AE; ++AI) {
1692 if (std::error_code EC = AI->getError())
1693 report_error(Filename, EC);
1694 auto &C = AI->get();
1684 Error Err;
1685 for (auto &C : A->children(Err)) {
16951686 Expected> ChildOrErr = C.getAsBinary();
16961687 if (!ChildOrErr) {
16971688 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
17021693 dyn_cast(&*ChildOrErr.get()))
17031694 ProcessMachO(Filename, O, O->getFileName());
17041695 }
1696 if (Err)
1697 report_error(Filename, std::move(Err));
17051698 } else {
17061699 consumeError(AOrErr.takeError());
17071700 error("Mach-O universal file: " + Filename + " for architecture " +
17391732 outs() << "\n";
17401733 if (ArchiveHeaders)
17411734 printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
1742 for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
1743 AI != AE; ++AI) {
1744 if (std::error_code EC = AI->getError())
1745 report_error(Filename, EC);
1746 auto &C = AI->get();
1735 Error Err;
1736 for (auto &C : A->children(Err)) {
17471737 Expected> ChildOrErr = C.getAsBinary();
17481738 if (!ChildOrErr) {
17491739 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
17571747 ArchitectureName);
17581748 }
17591749 }
1750 if (Err)
1751 report_error(Filename, std::move(Err));
17601752 } else {
17611753 consumeError(AOrErr.takeError());
17621754 error("Mach-O universal file: " + Filename + " for architecture " +
17011701
17021702 /// @brief Dump each object file in \a a;
17031703 static void DumpArchive(const Archive *a) {
1704 for (auto &ErrorOrChild : a->children()) {
1705 if (std::error_code EC = ErrorOrChild.getError())
1706 report_error(a->getFileName(), EC);
1707 const Archive::Child &C = *ErrorOrChild;
1704 Error Err;
1705 for (auto &C : a->children(Err)) {
17081706 Expected> ChildOrErr = C.getAsBinary();
17091707 if (!ChildOrErr) {
17101708 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
17161714 else
17171715 report_error(a->getFileName(), object_error::invalid_file_type);
17181716 }
1717 if (Err)
1718 report_error(a->getFileName(), std::move(Err));
17191719 }
17201720
17211721 /// @brief Open file and figure out how to dump it.
292292 Input = "";
293293
294294 reportError(Twine(Input) + ": " + Message);
295 }
296
297 static void reportError(StringRef Input, Error Err) {
298 if (Input == "-")
299 Input = "";
300 std::string ErrMsg;
301 {
302 raw_string_ostream ErrStream(ErrMsg);
303 logAllUnhandledErrors(std::move(Err), ErrStream, Input + ": ");
304 }
305 reportError(ErrMsg);
295306 }
296307
297308 static bool isMipsArch(unsigned Arch) {
423434
424435 /// @brief Dumps each object file in \a Arc;
425436 static void dumpArchive(const Archive *Arc) {
426 for (auto &ErrorOrChild : Arc->children()) {
427 if (std::error_code EC = ErrorOrChild.getError())
428 reportError(Arc->getFileName(), EC.message());
429 const auto &Child = *ErrorOrChild;
437 Error Err;
438 for (auto &Child : Arc->children(Err)) {
430439 Expected> ChildOrErr = Child.getAsBinary();
431440 if (!ChildOrErr) {
432441 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) {
443452 else
444453 reportError(Arc->getFileName(), readobj_error::unrecognized_file_format);
445454 }
455 if (Err)
456 reportError(Arc->getFileName(), std::move(Err));
446457 }
447458
448459 /// @brief Dumps each object file in \a MachO Universal Binary;
526526
527527 if (Archive *a = dyn_cast(&Bin)) {
528528 // This is an archive. Iterate over each member and display its sizes.
529 for (object::Archive::child_iterator i = a->child_begin(),
530 e = a->child_end();
531 i != e; ++i) {
532 if (error(i->getError()))
533 exit(1);
534 Expected> ChildOrErr = i->get().getAsBinary();
529 Error Err;
530 for (auto &C : a->children(Err)) {
531 Expected> ChildOrErr = C.getAsBinary();
535532 if (!ChildOrErr) {
536533 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
537 error(std::move(E), a->getFileName(), i->get());
534 error(std::move(E), a->getFileName(), C);
538535 continue;
539536 }
540537 if (ObjectFile *o = dyn_cast(&*ChildOrErr.get())) {
554551 }
555552 }
556553 }
554 if (Err)
555 error(std::move(Err), a->getFileName());
557556 } else if (MachOUniversalBinary *UB =
558557 dyn_cast(&Bin)) {
559558 // If we have a list of architecture flags specified dump only those.
596595 std::unique_ptr &UA = *AOrErr;
597596 // This is an archive. Iterate over each member and display its
598597 // sizes.
599 for (object::Archive::child_iterator i = UA->child_begin(),
600 e = UA->child_end();
601 i != e; ++i) {
602 if (error(i->getError()))
603 exit(1);
604 Expected> ChildOrErr =
605 i->get().getAsBinary();
598 Error Err;
599 for (auto &C : UA->children(Err)) {
600 Expected> ChildOrErr = C.getAsBinary();
606601 if (!ChildOrErr) {
607602 if (auto E = isNotObjectErrorInvalidFileType(
608603 ChildOrErr.takeError()))
609 error(std::move(E), UA->getFileName(), i->get(),
604 error(std::move(E), UA->getFileName(), C,
610605 ArchFlags.size() > 1 ?
611606 StringRef(I->getArchTypeName()) : StringRef());
612607 continue;
636631 }
637632 }
638633 }
634 if (Err)
635 error(std::move(Err), UA->getFileName());
639636 } else {
640637 consumeError(AOrErr.takeError());
641638 error("Mach-O universal file: " + file + " for architecture " +
687684 std::unique_ptr &UA = *AOrErr;
688685 // This is an archive. Iterate over each member and display its
689686 // sizes.
690 for (object::Archive::child_iterator i = UA->child_begin(),
691 e = UA->child_end();
692 i != e; ++i) {
693 if (error(i->getError()))
694 exit(1);
695 Expected> ChildOrErr =
696 i->get().getAsBinary();
687 Error Err;
688 for (auto &C : UA->children(Err)) {
689 Expected> ChildOrErr = C.getAsBinary();
697690 if (!ChildOrErr) {
698691 if (auto E = isNotObjectErrorInvalidFileType(
699692 ChildOrErr.takeError()))
700 error(std::move(E), UA->getFileName(), i->get());
693 error(std::move(E), UA->getFileName(), C);
701694 continue;
702695 }
703696 if (ObjectFile *o = dyn_cast(&*ChildOrErr.get())) {
720713 }
721714 }
722715 }
716 if (Err)
717 error(std::move(Err), UA->getFileName());
723718 } else {
724719 consumeError(AOrErr.takeError());
725720 error("Mach-O universal file: " + file + " for architecture " +
764759 I->getAsArchive()) {
765760 std::unique_ptr &UA = *AOrErr;
766761 // This is an archive. Iterate over each member and display its sizes.
767 for (object::Archive::child_iterator i = UA->child_begin(),
768 e = UA->child_end();
769 i != e; ++i) {
770 if (error(i->getError()))
771 exit(1);
772 Expected> ChildOrErr = i->get().getAsBinary();
762 Error Err;
763 for (auto &C : UA->children(Err)) {
764 Expected> ChildOrErr = C.getAsBinary();
773765 if (!ChildOrErr) {
774766 if (auto E = isNotObjectErrorInvalidFileType(
775767 ChildOrErr.takeError()))
776 error(std::move(E), UA->getFileName(), i->get(), MoreThanOneArch ?
768 error(std::move(E), UA->getFileName(), C, MoreThanOneArch ?
777769 StringRef(I->getArchTypeName()) : StringRef());
778770 continue;
779771 }
797789 }
798790 }
799791 }
792 if (Err)
793 error(std::move(Err), UA->getFileName());
800794 } else {
801795 consumeError(AOrErr.takeError());
802796 error("Mach-O universal file: " + file + " for architecture " +
134134 FailIfError(E.getError());
135135 }
136136
137 static void FailIfError(Error Err) {
138 if (Err) {
139 logAllUnhandledErrors(std::move(Err), errs(), "Error: ");
140 exit(1);
141 }
142 }
143
137144 template static void FailIfError(Expected &E) {
138 if (E)
139 return;
140 logAllUnhandledErrors(E.takeError(), errs(), "Error: ");
145 FailIfError(E.takeError());
141146 }
142147
143148 static void FailIfNotEmpty(const llvm::Twine &E) {
416421 static void
417422 visitObjectFiles(const object::Archive &A,
418423 function_ref Fn) {
419 for (auto &ErrorOrChild : A.children()) {
420 FailIfError(ErrorOrChild);
421 const object::Archive::Child &C = *ErrorOrChild;
424 Error Err;
425 for (auto &C : A.children(Err)) {
422426 Expected> ChildOrErr = C.getAsBinary();
423427 FailIfError(errorToErrorCode(ChildOrErr.takeError()));
424428 if (auto *O = dyn_cast(&*ChildOrErr.get()))
426430 else
427431 FailIfError(object::object_error::invalid_file_type);
428432 }
433 FailIfError(std::move(Err));
429434 }
430435
431436 static void