llvm.org GIT mirror llvm / 268709a
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 Kevin Enderby 3 years ago
18 changed file(s) with 302 addition(s) and 92 deletion(s). Raw diff Collapse all Expand all
6565 bool isThinMember() const;
6666
6767 public:
68 Child(const Archive *Parent, const char *Start);
68 Child(const Archive *Parent, const char *Start, std::error_code *EC);
6969 Child(const Archive *Parent, StringRef Data, uint16_t StartOfFile);
7070
7171 bool operator ==(const Child &other) const {
7474 }
7575
7676 const Archive *getParent() const { return Parent; }
77 Child getNext() const;
77 ErrorOr getNext() const;
7878
7979 ErrorOr getName() const;
8080 StringRef getRawName() const { return getHeader()->getName(); }
9090 return getHeader()->getAccessMode();
9191 }
9292 /// \return the size of the archive member without the header or padding.
93 uint64_t getSize() const;
93 ErrorOr getSize() const;
9494 /// \return the size in the archive header for this member.
95 uint64_t getRawSize() const;
95 ErrorOr getRawSize() const;
9696
9797 ErrorOr getBuffer() const;
9898 uint64_t getChildOffset() const;
104104 };
105105
106106 class child_iterator {
107 Child child;
108
109 public:
110 child_iterator() : child(Child(nullptr, nullptr)) {}
107 ErrorOr child;
108
109 public:
110 child_iterator() : child(Child(nullptr, nullptr, nullptr)) {}
111111 child_iterator(const Child &c) : child(c) {}
112 const Child *operator->() const { return &child; }
113 const Child &operator*() const { return child; }
112 child_iterator(std::error_code EC) : child(EC) {}
113 const ErrorOr *operator->() const { return &child; }
114 const ErrorOr &operator*() const { return child; }
114115
115116 bool operator==(const child_iterator &other) const {
116 return child == other.child;
117 // We ignore error states so that comparisions with end() work, which
118 // allows range loops.
119 if (child.getError() || other.child.getError())
120 return false;
121 return *child == *other.child;
117122 }
118123
119124 bool operator!=(const child_iterator &other) const {
120125 return !(*this == other);
121126 }
122127
128 // Code in loops with child_iterators must check for errors on each loop
129 // iteration. And if there is an error break out of the loop.
123130 child_iterator &operator++() { // Preincrement
124 child = child.getNext();
131 assert(child && "Can't increment iterator with error");
132 child = child->getNext();
125133 return *this;
126134 }
127135 };
9090 typedef typename std::remove_reference::type &reference;
9191 typedef const typename std::remove_reference::type &const_reference;
9292 typedef typename std::remove_reference::type *pointer;
93 typedef const typename std::remove_reference::type *const_pointer;
9394
9495 public:
9596 template
182183 return toPointer(getStorage());
183184 }
184185
186 const_pointer operator->() const { return toPointer(getStorage()); }
187
185188 reference operator *() {
186189 return *getStorage();
187190 }
191
192 const_reference operator*() const { return *getStorage(); }
188193
189194 private:
190195 template
245250 return Val;
246251 }
247252
253 const_pointer toPointer(const_pointer Val) const { return Val; }
254
248255 pointer toPointer(wrap *Val) {
249256 return &Val->get();
250257 }
258
259 const_pointer toPointer(const wrap *Val) const { return &Val->get(); }
251260
252261 storage_type *getStorage() {
253262 assert(!HasError && "Cannot get value when an error exists!");
317317 object::Archive *A = OB.getBinary();
318318 // Look for our symbols in each Archive
319319 object::Archive::child_iterator ChildIt = A->findSym(Name);
320 if (std::error_code EC = ChildIt->getError())
321 report_fatal_error(EC.message());
320322 if (ChildIt != A->child_end()) {
321323 // FIXME: Support nested archives?
322324 ErrorOr> ChildBinOrErr =
323 ChildIt->getAsBinary();
325 (*ChildIt)->getAsBinary();
324326 if (ChildBinOrErr.getError())
325327 continue;
326328 std::unique_ptr &ChildBin = ChildBinOrErr.get();
251251 object::Archive *A = OB.getBinary();
252252 // Look for our symbols in each Archive
253253 object::Archive::child_iterator ChildIt = A->findSym(Name);
254 if (std::error_code EC = ChildIt->getError())
255 report_fatal_error(EC.message());
254256 if (ChildIt != A->child_end()) {
255257 // FIXME: Support nested archives?
256258 ErrorOr> ChildBinOrErr =
257 ChildIt->getAsBinary();
259 (*ChildIt)->getAsBinary();
258260 if (ChildBinOrErr.getError())
259261 continue;
260262 std::unique_ptr &ChildBin = ChildBinOrErr.get();
4545 ErrorOr ArchiveMemberHeader::getSize() const {
4646 uint32_t Ret;
4747 if (llvm::StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, Ret))
48 return object_error::parse_failed;
48 return object_error::parse_failed; // Size is not a decimal number.
4949 return Ret;
5050 }
5151
8585 uint16_t StartOfFile)
8686 : Parent(Parent), Data(Data), StartOfFile(StartOfFile) {}
8787
88 Archive::Child::Child(const Archive *Parent, const char *Start)
88 Archive::Child::Child(const Archive *Parent, const char *Start,
89 std::error_code *EC)
8990 : Parent(Parent) {
9091 if (!Start)
9192 return;
9394 uint64_t Size = sizeof(ArchiveMemberHeader);
9495 Data = StringRef(Start, Size);
9596 if (!isThinMember()) {
96 Size += getRawSize();
97 ErrorOr MemberSize = getRawSize();
98 if ((*EC = MemberSize.getError()))
99 return;
100 Size += MemberSize.get();
97101 Data = StringRef(Start, Size);
98102 }
99103
109113 }
110114 }
111115
112 uint64_t Archive::Child::getSize() const {
116 ErrorOr Archive::Child::getSize() const {
113117 if (Parent->IsThin) {
114118 ErrorOr Size = getHeader()->getSize();
115 if (Size.getError())
116 return 0;
119 if (std::error_code EC = Size.getError())
120 return EC;
117121 return Size.get();
118122 }
119123 return Data.size() - StartOfFile;
120124 }
121125
122 uint64_t Archive::Child::getRawSize() const {
126 ErrorOr Archive::Child::getRawSize() const {
123127 ErrorOr Size = getHeader()->getSize();
124 if (Size.getError())
125 return 0;
128 if (std::error_code EC = Size.getError())
129 return EC;
126130 return Size.get();
127131 }
128132
132136 }
133137
134138 ErrorOr Archive::Child::getBuffer() const {
135 if (!isThinMember())
136 return StringRef(Data.data() + StartOfFile, getSize());
139 if (!isThinMember()) {
140 ErrorOr Size = getSize();
141 if (std::error_code EC = Size.getError())
142 return EC;
143 return StringRef(Data.data() + StartOfFile, Size.get());
144 }
137145 ErrorOr Name = getName();
138146 if (std::error_code EC = Name.getError())
139147 return EC;
147155 return Parent->ThinBuffers.back()->getBuffer();
148156 }
149157
150 Archive::Child Archive::Child::getNext() const {
158 ErrorOr Archive::Child::getNext() const {
151159 size_t SpaceToSkip = Data.size();
152160 // If it's odd, add 1 to make it even.
153161 if (SpaceToSkip & 1)
155163
156164 const char *NextLoc = Data.data() + SpaceToSkip;
157165
166 // Check to see if this is at the end of the archive.
167 if (NextLoc == Parent->Data.getBufferEnd())
168 return Child(Parent, nullptr, nullptr);
169
158170 // Check to see if this is past the end of the archive.
159 if (NextLoc >= Parent->Data.getBufferEnd())
160 return Child(Parent, nullptr);
161
162 return Child(Parent, NextLoc);
171 if (NextLoc > Parent->Data.getBufferEnd())
172 return object_error::parse_failed;
173
174 std::error_code EC;
175 Child Ret(Parent, NextLoc, &EC);
176 if (EC)
177 return EC;
178 return Ret;
163179 }
164180
165181 uint64_t Archive::Child::getChildOffset() const {
254270 }
255271
256272 // Get the special members.
257 child_iterator i = child_begin(false);
258 child_iterator e = child_end();
259
260 if (i == e) {
273 child_iterator I = child_begin(false);
274 if ((ec = I->getError()))
275 return;
276 child_iterator E = child_end();
277
278 if (I == E) {
261279 ec = std::error_code();
262280 return;
263281 }
264
265 StringRef Name = i->getRawName();
282 const Child *C = &**I;
283
284 auto Increment = [&]() {
285 ++I;
286 if ((ec = I->getError()))
287 return true;
288 C = &**I;
289 return false;
290 };
291
292 StringRef Name = C->getRawName();
266293
267294 // Below is the pattern that is used to figure out the archive format
268295 // GNU archive format
287314 Format = K_BSD;
288315 // We know that the symbol table is not an external file, so we just assert
289316 // there is no error.
290 SymbolTable = *i->getBuffer();
291 ++i;
292 setFirstRegular(*i);
317 SymbolTable = *C->getBuffer();
318 if (Increment())
319 return;
320 setFirstRegular(*C);
321
293322 ec = std::error_code();
294323 return;
295324 }
297326 if (Name.startswith("#1/")) {
298327 Format = K_BSD;
299328 // We know this is BSD, so getName will work since there is no string table.
300 ErrorOr NameOrErr = i->getName();
329 ErrorOr NameOrErr = C->getName();
301330 ec = NameOrErr.getError();
302331 if (ec)
303332 return;
305334 if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
306335 // We know that the symbol table is not an external file, so we just
307336 // assert there is no error.
308 SymbolTable = *i->getBuffer();
309 ++i;
337 SymbolTable = *C->getBuffer();
338 if (Increment())
339 return;
310340 }
311 setFirstRegular(*i);
341 setFirstRegular(*C);
312342 return;
313343 }
314344
321351 if (Name == "/" || Name == "/SYM64/") {
322352 // We know that the symbol table is not an external file, so we just assert
323353 // there is no error.
324 SymbolTable = *i->getBuffer();
354 SymbolTable = *C->getBuffer();
325355 if (Name == "/SYM64/")
326356 has64SymTable = true;
327357
328 ++i;
329 if (i == e) {
358 if (Increment())
359 return;
360 if (I == E) {
330361 ec = std::error_code();
331362 return;
332363 }
333 Name = i->getRawName();
364 Name = C->getRawName();
334365 }
335366
336367 if (Name == "//") {
337368 Format = has64SymTable ? K_MIPS64 : K_GNU;
338369 // The string table is never an external member, so we just assert on the
339370 // ErrorOr.
340 StringTable = *i->getBuffer();
341 ++i;
342 setFirstRegular(*i);
371 StringTable = *C->getBuffer();
372 if (Increment())
373 return;
374 setFirstRegular(*C);
343375 ec = std::error_code();
344376 return;
345377 }
346378
347379 if (Name[0] != '/') {
348380 Format = has64SymTable ? K_MIPS64 : K_GNU;
349 setFirstRegular(*i);
381 setFirstRegular(*C);
350382 ec = std::error_code();
351383 return;
352384 }
359391 Format = K_COFF;
360392 // We know that the symbol table is not an external file, so we just assert
361393 // there is no error.
362 SymbolTable = *i->getBuffer();
363
364 ++i;
365 if (i == e) {
366 setFirstRegular(*i);
394 SymbolTable = *C->getBuffer();
395
396 if (Increment())
397 return;
398
399 if (I == E) {
400 setFirstRegular(*C);
367401 ec = std::error_code();
368402 return;
369403 }
370404
371 Name = i->getRawName();
405 Name = C->getRawName();
372406
373407 if (Name == "//") {
374408 // The string table is never an external member, so we just assert on the
375409 // ErrorOr.
376 StringTable = *i->getBuffer();
377 ++i;
378 }
379
380 setFirstRegular(*i);
410 StringTable = *C->getBuffer();
411 if (Increment())
412 return;
413 }
414
415 setFirstRegular(*C);
381416 ec = std::error_code();
382417 }
383418
389424 return Child(this, FirstRegularData, FirstRegularStartOfFile);
390425
391426 const char *Loc = Data.getBufferStart() + strlen(Magic);
392 Child c(this, Loc);
393 return c;
427 std::error_code EC;
428 Child c(this, Loc, &EC);
429 if (EC)
430 return child_iterator(EC);
431 return child_iterator(c);
394432 }
395433
396434 Archive::child_iterator Archive::child_end() const {
397 return Child(this, nullptr);
435 return Child(this, nullptr, nullptr);
398436 }
399437
400438 StringRef Archive::Symbol::getName() const {
446484 }
447485
448486 const char *Loc = Parent->getData().begin() + Offset;
449 return Child(Parent, Loc);
487 std::error_code EC;
488 Child C(Parent, Loc, &EC);
489 if (EC)
490 return EC;
491 return C;
450492 }
451493
452494 Archive::Symbol Archive::Symbol::getNext() const {
3838 : IsNewMember(false), Name(Name), OldMember(OldMember) {}
3939
4040 NewArchiveIterator::NewArchiveIterator(StringRef FileName)
41 : IsNewMember(true), Name(FileName), OldMember(nullptr, nullptr) {}
41 : IsNewMember(true), Name(FileName), OldMember(nullptr, nullptr, nullptr) {}
4242
4343 StringRef NewArchiveIterator::getName() const { return Name; }
4444
411411 Status.getSize());
412412 } else {
413413 const object::Archive::Child &OldMember = I.getOld();
414 ErrorOr Size = OldMember.getSize();
415 if (std::error_code EC = Size.getError())
416 return std::make_pair("", EC);
414417 printMemberHeader(Out, Kind, Thin, I.getName(), StringMapIndexIter,
415 ModTime, UID, GID, Perms, OldMember.getSize());
418 ModTime, UID, GID, Perms, Size.get());
416419 }
417420
418421 if (!Thin)
0 !
1 hello.c 1444941273 124 0 100644 10% `
2 #include
3 #include
4 int
5 main()
6 {
7 printf("Hello World\n");
8 return EXIT_SUCCESS;
9 }
10 foo.c 1444941645 124 0 100644 1% `
11 void foo(void){}
12
0 !
1 hello.c 1444941273 124 0 100644 102 `
2 #include
3 #include
4 int
5 main()
6 {
7 printf("Hello World\n");
8 return EXIT_SUCCESS;
9 }
10 foo.c 1444941645 124 0 100644 1% `
11 void foo(void){}
12
0 !
1 hello.c 1444941273 124 0 100644 102 `
2 #include
3 #include
4 int
5 main()
6 {
7 printf("Hello World\n");
8 return EXIT_SUCCESS;
9 }
10 foo.c 1444941645 124 0 100644 171 `
11 void foo(void){}
12
13 bar.c 1445026190 124 0 100644 17 `
14 void foo(void){}
15
0 // These test checks that llvm-objdump will not crash with malformed Archive
1 // files. So the check line is not all that important but the bug fixes to
2 // make sure llvm-objdump is robust is what matters.
3 # RUN: llvm-objdump -macho -archive-headers \
4 # RUN: %p/Inputs/libbogus1.a \
5 # RUN: 2>&1 | FileCheck -check-prefix=bogus1 %s
6
7 # bogus1: Invalid data was encountered while parsing the file
8
9 # RUN: not llvm-objdump -macho -archive-headers \
10 # RUN: %p/Inputs/libbogus2.a \
11 # RUN: 2>&1 | FileCheck -check-prefix=bogus2 %s
12
13 # bogus2: LLVM ERROR: Invalid data was encountered while parsing the file
14
15 # RUN: not llvm-objdump -macho -archive-headers \
16 # RUN: %p/Inputs/libbogus3.a \
17 # RUN: 2>&1 | FileCheck -check-prefix=bogus3 %s
18
19 # bogus3: LLVM ERROR: Invalid data was encountered while parsing the file
108108 Buffers.reserve(CurrentArchives.size());
109109
110110 for (const auto &CurrentArchive : CurrentArchives) {
111 for (const auto &Child : CurrentArchive->children()) {
111 for (auto ChildOrErr : CurrentArchive->children()) {
112 if (std::error_code Err = ChildOrErr.getError())
113 return Err;
114 const auto &Child = *ChildOrErr;
112115 if (auto NameOrErr = Child.getName()) {
113116 if (*NameOrErr == Filename) {
114117 if (Timestamp != sys::TimeValue::PosixZeroTime() &&
337337 printMode(Mode & 007);
338338 outs() << ' ' << C.getUID();
339339 outs() << '/' << C.getGID();
340 outs() << ' ' << format("%6llu", C.getSize());
340 ErrorOr Size = C.getSize();
341 failIfError(Size.getError());
342 outs() << ' ' << format("%6llu", Size.get());
341343 outs() << ' ' << C.getLastModified().str();
342344 outs() << ' ';
343345 }
402404 }
403405
404406 bool Filter = !Members.empty();
405 for (const object::Archive::Child &C : OldArchive->children()) {
407 for (auto &ChildOrErr : OldArchive->children()) {
408 failIfError(ChildOrErr.getError());
409 const object::Archive::Child &C = *ChildOrErr;
410
406411 ErrorOr NameOrErr = C.getName();
407412 failIfError(NameOrErr.getError());
408413 StringRef Name = NameOrErr.get();
522527 int InsertPos = -1;
523528 StringRef PosName = sys::path::filename(RelPos);
524529 if (OldArchive) {
525 for (auto &Child : OldArchive->children()) {
530 for (auto &ChildOrErr : OldArchive->children()) {
531 failIfError(ChildOrErr.getError());
532 auto &Child = ChildOrErr.get();
526533 int Pos = Ret.size();
527534 ErrorOr NameOrErr = Child.getName();
528535 failIfError(NameOrErr.getError());
725732 failIfError(LibOrErr.getError(), "Could not parse library");
726733 Archives.push_back(std::move(*LibOrErr));
727734 object::Archive &Lib = *Archives.back();
728 for (auto &Member : Lib.children()) {
735 for (auto &MemberOrErr : Lib.children()) {
736 failIfError(MemberOrErr.getError());
737 auto &Member = MemberOrErr.get();
729738 ErrorOr NameOrErr = Member.getName();
730739 failIfError(NameOrErr.getError());
731740 addMember(NewMembers, Member, *NameOrErr);
481481 }
482482
483483 static void dumpArchive(const Archive *Arc) {
484 for (const Archive::Child &ArcC : Arc->children()) {
484 for (auto &ErrorOrChild : Arc->children()) {
485 error(ErrorOrChild.getError());
486 const Archive::Child &ArcC = *ErrorOrChild;
485487 ErrorOr> ChildOrErr = ArcC.getAsBinary();
486488 if (std::error_code EC = ChildOrErr.getError()) {
487489 // Ignore non-object files.
966966
967967 for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
968968 I != E; ++I) {
969 ErrorOr> ChildOrErr = I->getAsBinary(&Context);
969 if (error(I->getError()))
970 return;
971 auto &C = I->get();
972 ErrorOr> ChildOrErr = C.getAsBinary(&Context);
970973 if (ChildOrErr.getError())
971974 continue;
972975 if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) {
10211024 for (Archive::child_iterator AI = A->child_begin(),
10221025 AE = A->child_end();
10231026 AI != AE; ++AI) {
1027 if (error(AI->getError()))
1028 return;
1029 auto &C = AI->get();
10241030 ErrorOr> ChildOrErr =
1025 AI->getAsBinary(&Context);
1031 C.getAsBinary(&Context);
10261032 if (ChildOrErr.getError())
10271033 continue;
10281034 if (SymbolicFile *O =
10751081 for (Archive::child_iterator AI = A->child_begin(),
10761082 AE = A->child_end();
10771083 AI != AE; ++AI) {
1084 if (error(AI->getError()))
1085 return;
1086 auto &C = AI->get();
10781087 ErrorOr> ChildOrErr =
1079 AI->getAsBinary(&Context);
1088 C.getAsBinary(&Context);
10801089 if (ChildOrErr.getError())
10811090 continue;
10821091 if (SymbolicFile *O =
11241133 std::unique_ptr &A = *AOrErr;
11251134 for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
11261135 AI != AE; ++AI) {
1127 ErrorOr> ChildOrErr =
1128 AI->getAsBinary(&Context);
1136 if (error(AI->getError()))
1137 return;
1138 auto &C = AI->get();
1139 ErrorOr> ChildOrErr = C.getAsBinary(&Context);
11291140 if (ChildOrErr.getError())
11301141 continue;
11311142 if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) {
14161416 outs() << format("%3d/", UID);
14171417 unsigned GID = C.getGID();
14181418 outs() << format("%-3d ", GID);
1419 uint64_t Size = C.getRawSize();
1420 outs() << format("%5" PRId64, Size) << " ";
1419 ErrorOr Size = C.getRawSize();
1420 if (std::error_code EC = Size.getError())
1421 report_fatal_error(EC.message());
1422 outs() << format("%5" PRId64, Size.get()) << " ";
14211423
14221424 StringRef RawLastModified = C.getRawLastModified();
14231425 if (verbose) {
14531455 static void printArchiveHeaders(Archive *A, bool verbose, bool print_offset) {
14541456 for (Archive::child_iterator I = A->child_begin(false), E = A->child_end();
14551457 I != E; ++I) {
1456 Archive::Child C = *I;
1458 if (std::error_code EC = I->getError())
1459 report_fatal_error(EC.message());
1460 const Archive::Child &C = **I;
14571461 printArchiveChild(C, verbose, print_offset);
14581462 }
14591463 }
14901494 printArchiveHeaders(A, !NonVerbose, ArchiveMemberOffsets);
14911495 for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
14921496 I != E; ++I) {
1493 ErrorOr> ChildOrErr = I->getAsBinary();
1497 if (std::error_code EC = I->getError()) {
1498 errs() << "llvm-objdump: '" << Filename << "': " << EC.message()
1499 << ".\n";
1500 exit(1);
1501 }
1502 auto &C = I->get();
1503 ErrorOr> ChildOrErr = C.getAsBinary();
14941504 if (ChildOrErr.getError())
14951505 continue;
14961506 if (MachOObjectFile *O = dyn_cast(&*ChildOrErr.get())) {
15381548 for (Archive::child_iterator AI = A->child_begin(),
15391549 AE = A->child_end();
15401550 AI != AE; ++AI) {
1541 ErrorOr> ChildOrErr = AI->getAsBinary();
1551 if (std::error_code EC = AI->getError()) {
1552 errs() << "llvm-objdump: '" << Filename
1553 << "': " << EC.message() << ".\n";
1554 exit(1);
1555 }
1556 auto &C = AI->get();
1557 ErrorOr> ChildOrErr = C.getAsBinary();
15421558 if (ChildOrErr.getError())
15431559 continue;
15441560 if (MachOObjectFile *O =
15801596 for (Archive::child_iterator AI = A->child_begin(),
15811597 AE = A->child_end();
15821598 AI != AE; ++AI) {
1583 ErrorOr> ChildOrErr = AI->getAsBinary();
1599 if (std::error_code EC = AI->getError()) {
1600 errs() << "llvm-objdump: '" << Filename << "': " << EC.message()
1601 << ".\n";
1602 exit(1);
1603 }
1604 auto &C = AI->get();
1605 ErrorOr> ChildOrErr = C.getAsBinary();
15841606 if (ChildOrErr.getError())
15851607 continue;
15861608 if (MachOObjectFile *O =
16161638 printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
16171639 for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
16181640 AI != AE; ++AI) {
1619 ErrorOr> ChildOrErr = AI->getAsBinary();
1641 if (std::error_code EC = AI->getError()) {
1642 errs() << "llvm-objdump: '" << Filename << "': " << EC.message()
1643 << ".\n";
1644 exit(1);
1645 }
1646 auto &C = AI->get();
1647 ErrorOr> ChildOrErr = C.getAsBinary();
16201648 if (ChildOrErr.getError())
16211649 continue;
16221650 if (MachOObjectFile *O =
15361536
15371537 /// @brief Dump each object file in \a a;
15381538 static void DumpArchive(const Archive *a) {
1539 for (const Archive::Child &C : a->children()) {
1539 for (auto &ErrorOrChild : a->children()) {
1540 if (std::error_code EC = ErrorOrChild.getError())
1541 report_error(a->getFileName(), EC);
1542 const Archive::Child &C = *ErrorOrChild;
15401543 ErrorOr> ChildOrErr = C.getAsBinary();
15411544 if (std::error_code EC = ChildOrErr.getError())
15421545 if (EC != object_error::invalid_file_type)
376376
377377 /// @brief Dumps each object file in \a Arc;
378378 static void dumpArchive(const Archive *Arc) {
379 for (const auto &Child : Arc->children()) {
379 for (auto &ErrorOrChild : Arc->children()) {
380 if (std::error_code EC = ErrorOrChild.getError())
381 reportError(Arc->getFileName(), EC.message());
382 const auto &Child = *ErrorOrChild;
380383 ErrorOr> ChildOrErr = Child.getAsBinary();
381384 if (std::error_code EC = ChildOrErr.getError()) {
382385 // Ignore non-object files.
427427 for (object::Archive::child_iterator i = a->child_begin(),
428428 e = a->child_end();
429429 i != e; ++i) {
430 ErrorOr> ChildOrErr = i->getAsBinary();
430 if (i->getError()) {
431 errs() << ToolName << ": " << file << ": " << i->getError().message()
432 << ".\n";
433 exit(1);
434 }
435 auto &c = i->get();
436 ErrorOr> ChildOrErr = c.getAsBinary();
431437 if (std::error_code EC = ChildOrErr.getError()) {
432438 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
433439 continue;
489495 for (object::Archive::child_iterator i = UA->child_begin(),
490496 e = UA->child_end();
491497 i != e; ++i) {
492 ErrorOr> ChildOrErr = i->getAsBinary();
498 if (std::error_code EC = i->getError()) {
499 errs() << ToolName << ": " << file << ": " << EC.message()
500 << ".\n";
501 exit(1);
502 }
503 auto &c = i->get();
504 ErrorOr> ChildOrErr = c.getAsBinary();
493505 if (std::error_code EC = ChildOrErr.getError()) {
494506 errs() << ToolName << ": " << file << ": " << EC.message()
495507 << ".\n";
566578 for (object::Archive::child_iterator i = UA->child_begin(),
567579 e = UA->child_end();
568580 i != e; ++i) {
569 ErrorOr> ChildOrErr = i->getAsBinary();
581 if (std::error_code EC = i->getError()) {
582 errs() << ToolName << ": " << file << ": " << EC.message()
583 << ".\n";
584 exit(1);
585 }
586 auto &c = i->get();
587 ErrorOr> ChildOrErr = c.getAsBinary();
570588 if (std::error_code EC = ChildOrErr.getError()) {
571589 errs() << ToolName << ": " << file << ": " << EC.message()
572590 << ".\n";
630648 for (object::Archive::child_iterator i = UA->child_begin(),
631649 e = UA->child_end();
632650 i != e; ++i) {
633 ErrorOr> ChildOrErr = i->getAsBinary();
651 if (std::error_code EC = i->getError()) {
652 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
653 exit(1);
654 }
655 auto &c = i->get();
656 ErrorOr> ChildOrErr = c.getAsBinary();
634657 if (std::error_code EC = ChildOrErr.getError()) {
635658 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
636659 continue;