llvm.org GIT mirror llvm / da78537
Backing out commit r250906 as it broke lld. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250908 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 3 years ago
18 changed file(s) with 100 addition(s) and 357 deletion(s). Raw diff Collapse all Expand all
6464 bool isThinMember() const;
6565
6666 public:
67 Child(const Archive *Parent, const char *Start,
68 std::error_code *EC);
69 static ErrorOr> create(const Archive *Parent,
70 const char *Start);
67 Child(const Archive *Parent, const char *Start);
7168
7269 bool operator ==(const Child &other) const {
7370 assert(Parent == other.Parent);
7976 }
8077
8178 const Archive *getParent() const { return Parent; }
82 ErrorOr getNext() const;
79 Child getNext() const;
8380
8481 ErrorOr getName() const;
8582 StringRef getRawName() const { return getHeader()->getName(); }
9592 return getHeader()->getAccessMode();
9693 }
9794 /// \return the size of the archive member without the header or padding.
98 ErrorOr getSize() const;
95 uint64_t getSize() const;
9996 /// \return the size in the archive header for this member.
100 ErrorOr getRawSize() const;
97 uint64_t getRawSize() const;
10198
10299 ErrorOr getBuffer() const;
103100 uint64_t getChildOffset() const;
109106 };
110107
111108 class child_iterator {
112 ErrorOr child;
113
114 public:
115 child_iterator() : child(Child(nullptr, nullptr, nullptr)) {}
109 Child child;
110
111 public:
112 child_iterator() : child(Child(nullptr, nullptr)) {}
116113 child_iterator(const Child &c) : child(c) {}
117 child_iterator(std::error_code EC) : child(EC) {}
118 const ErrorOr *operator->() const { return &child; }
119 const ErrorOr &operator*() const { return child; }
114 const Child *operator->() const { return &child; }
115 const Child &operator*() const { return child; }
120116
121117 bool operator==(const child_iterator &other) const {
122 if ((*this)->getError())
123 return false;
124 if (other->getError())
125 return false;
126 return (*this)->get() == other->get();
118 return child == other.child;
127119 }
128120
129121 bool operator!=(const child_iterator &other) const {
130122 return !(*this == other);
131123 }
132124
133 // No operator< as we can't do less than compares with iterators that
134 // contain errors.
135
136 // Code in loops with child_iterators must check for errors on each loop
137 // iteration. And if there is an error break out of the loop.
125 bool operator<(const child_iterator &other) const {
126 return child < other.child;
127 }
128
138129 child_iterator &operator++() { // Preincrement
139 assert(child && "Can't increment iterator with error");
140 child = child->getNext();
130 child = child.getNext();
141131 return *this;
142132 }
143133 };
221211 StringRef getSymbolTable() const {
222212 // We know that the symbol table is not an external file,
223213 // so we just assert there is no error.
224 return *(*SymbolTable)->getBuffer();
214 return *SymbolTable->getBuffer();
225215 }
226216 uint32_t getNumberOfSymbols() const;
227217
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;
9493
9594 public:
9695 template
183182 return toPointer(getStorage());
184183 }
185184
186 const_pointer operator ->() const {
187 return toPointer(getStorage());
188 }
189
190185 reference operator *() {
191 return *getStorage();
192 }
193
194 const_reference operator *() const {
195186 return *getStorage();
196187 }
197188
254245 return Val;
255246 }
256247
257 const_pointer toPointer(const_pointer Val) const {
258 return Val;
259 }
260
261248 pointer toPointer(wrap *Val) {
262249 return &Val->get();
263250 }
264
265 const_pointer toPointer(const wrap *Val) const {
266 return &Val->get();
267 }
268
269251
270252 storage_type *getStorage() {
271253 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 (*ChildIt && ChildIt != A->child_end()) {
320 if (ChildIt != A->child_end()) {
321321 // FIXME: Support nested archives?
322322 ErrorOr> ChildBinOrErr =
323 (*ChildIt)->getAsBinary();
323 ChildIt->getAsBinary();
324324 if (ChildBinOrErr.getError())
325325 continue;
326326 std::unique_ptr &ChildBin = ChildBinOrErr.get();
252252 object::Archive *A = OB.getBinary();
253253 // Look for our symbols in each Archive
254254 object::Archive::child_iterator ChildIt = A->findSym(Name);
255 if (*ChildIt && ChildIt != A->child_end()) {
255 if (ChildIt != A->child_end()) {
256256 // FIXME: Support nested archives?
257257 ErrorOr> ChildBinOrErr =
258 (*ChildIt)->getAsBinary();
258 ChildIt->getAsBinary();
259259 if (ChildBinOrErr.getError())
260260 continue;
261261 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; // Size is not a decimal number.
48 return object_error::parse_failed;
4949 return Ret;
5050 }
5151
8181 return Ret;
8282 }
8383
84 Archive::Child::Child(const Archive *Parent, const char *Start,
85 std::error_code *EC)
84 Archive::Child::Child(const Archive *Parent, const char *Start)
8685 : Parent(Parent) {
8786 if (!Start)
8887 return;
9089 uint64_t Size = sizeof(ArchiveMemberHeader);
9190 Data = StringRef(Start, Size);
9291 if (!isThinMember()) {
93 ErrorOr MemberSize = getRawSize();
94 if (MemberSize.getError()) {
95 assert (EC && "Error must be caught");
96 *EC = MemberSize.getError();
97 return;
98 }
99 Size += MemberSize.get();
92 Size += getRawSize();
10093 Data = StringRef(Start, Size);
10194 }
10295
10699 StringRef Name = getRawName();
107100 if (Name.startswith("#1/")) {
108101 uint64_t NameSize;
109 if (Name.substr(3).rtrim(" ").getAsInteger(10, NameSize)) {
110 if (EC)
111 *EC = object_error::parse_failed; // Long name offset is not an integer.
112 return;
113 }
102 if (Name.substr(3).rtrim(" ").getAsInteger(10, NameSize))
103 llvm_unreachable("Long name length is not an integer");
114104 StartOfFile += NameSize;
115105 }
116106 }
117107
118 ErrorOr> Archive::Child::create(
119 const Archive *Parent, const char *Start) {
120 std::error_code EC;
121 std::unique_ptr Ret(new Archive::Child(Parent, Start, &EC));
122 if (EC)
123 return EC;
124 return std::move(Ret);
125 }
126
127 ErrorOr Archive::Child::getSize() const {
108 uint64_t Archive::Child::getSize() const {
128109 if (Parent->IsThin) {
129110 ErrorOr Size = getHeader()->getSize();
130 if (std::error_code EC = Size.getError())
131 return EC;
111 if (Size.getError())
112 return 0;
132113 return Size.get();
133114 }
134115 return Data.size() - StartOfFile;
135116 }
136117
137 ErrorOr Archive::Child::getRawSize() const {
118 uint64_t Archive::Child::getRawSize() const {
138119 ErrorOr Size = getHeader()->getSize();
139 if (std::error_code EC = Size.getError())
140 return EC;
120 if (Size.getError())
121 return 0;
141122 return Size.get();
142123 }
143124
147128 }
148129
149130 ErrorOr Archive::Child::getBuffer() const {
150 if (!isThinMember()) {
151 ErrorOr Size = getSize();
152 if (std::error_code EC = Size.getError())
153 return EC;
154 return StringRef(Data.data() + StartOfFile, Size.get());
155 }
131 if (!isThinMember())
132 return StringRef(Data.data() + StartOfFile, getSize());
156133 ErrorOr Name = getName();
157134 if (std::error_code EC = Name.getError())
158135 return EC;
166143 return Parent->ThinBuffers.back()->getBuffer();
167144 }
168145
169 ErrorOr Archive::Child::getNext() const {
146 Archive::Child Archive::Child::getNext() const {
170147 size_t SpaceToSkip = Data.size();
171148 // If it's odd, add 1 to make it even.
172 size_t Pad = 0;
173149 if (SpaceToSkip & 1)
174 Pad++;
175
176 const char *NextLoc = Data.data() + SpaceToSkip + Pad;
177
178 // Check to see if this is at the end of the archive.
179 if (NextLoc == Parent->Data.getBufferEnd() ||
180 NextLoc == Parent->Data.getBufferEnd() - Pad )
181 return Child(Parent, nullptr, nullptr);
150 ++SpaceToSkip;
151
152 const char *NextLoc = Data.data() + SpaceToSkip;
182153
183154 // Check to see if this is past the end of the archive.
184 if (NextLoc > Parent->Data.getBufferEnd())
185 return object_error::parse_failed;
186
187 auto ChildOrErr = Child::create(Parent, NextLoc);
188 if (std::error_code EC = ChildOrErr.getError())
189 return EC;
190 return std::move(*ChildOrErr.get());
155 if (NextLoc >= Parent->Data.getBufferEnd())
156 return Child(Parent, nullptr);
157
158 return Child(Parent, NextLoc);
191159 }
192160
193161 uint64_t Archive::Child::getChildOffset() const {
209177 // Get the offset.
210178 std::size_t offset;
211179 if (name.substr(1).rtrim(" ").getAsInteger(10, offset))
212 return object_error::parse_failed; // Long name offset is not an integer.
213 // Check for bad stringtable iterator.
214 if (std::error_code EC = Parent->StringTable->getError())
215 return EC;
216 const char *addr = (*Parent->StringTable)->Data.begin()
180 llvm_unreachable("Long name offset is not an integer");
181 const char *addr = Parent->StringTable->Data.begin()
217182 + sizeof(ArchiveMemberHeader)
218183 + offset;
219184 // Verify it.
220 auto Size = (*Parent->StringTable)->getSize();
221 if (std::error_code EC = Size.getError())
222 return EC;
223185 if (Parent->StringTable == Parent->child_end()
224 || addr < ((*Parent->StringTable)->Data.begin()
186 || addr < (Parent->StringTable->Data.begin()
225187 + sizeof(ArchiveMemberHeader))
226 || addr > ((*Parent->StringTable)->Data.begin()
188 || addr > (Parent->StringTable->Data.begin()
227189 + sizeof(ArchiveMemberHeader)
228 + Size.get()))
190 + Parent->StringTable->getSize()))
229191 return object_error::parse_failed;
230192
231193 // GNU long file names end with a "/\n".
237199 } else if (name.startswith("#1/")) {
238200 uint64_t name_size;
239201 if (name.substr(3).rtrim(" ").getAsInteger(10, name_size))
240 return object_error::parse_failed; // Long name offset is not an integer.
202 llvm_unreachable("Long name length is not an ingeter");
241203 return Data.substr(sizeof(ArchiveMemberHeader), name_size)
242204 .rtrim(StringRef("\0", 1));
243205 }
293255 child_iterator i = child_begin(false);
294256 child_iterator e = child_end();
295257
296 if (!*i || i == e) {
297 ec = i->getError();
298 return;
299 }
300
301 StringRef Name = (*i)->getRawName();
258 if (i == e) {
259 ec = std::error_code();
260 return;
261 }
262
263 StringRef Name = i->getRawName();
302264
303265 // Below is the pattern that is used to figure out the archive format
304266 // GNU archive format
323285 Format = K_BSD;
324286 SymbolTable = i;
325287 ++i;
326 if (!*i) {
327 ec = i->getError();
328 return;
329 }
330
331288 FirstRegular = i;
332289 ec = std::error_code();
333290 return;
336293 if (Name.startswith("#1/")) {
337294 Format = K_BSD;
338295 // We know this is BSD, so getName will work since there is no string table.
339 ErrorOr NameOrErr = (*i)->getName();
296 ErrorOr NameOrErr = i->getName();
340297 ec = NameOrErr.getError();
341298 if (ec)
342299 return;
344301 if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
345302 SymbolTable = i;
346303 ++i;
347 if (!*i) {
348 ec = i->getError();
349 return;
350 }
351304 }
352305 FirstRegular = i;
353306 return;
365318 has64SymTable = true;
366319
367320 ++i;
368 if (!*i || i == e) {
369 ec = i->getError();
321 if (i == e) {
322 ec = std::error_code();
370323 return;
371324 }
372 Name = (*i)->getRawName();
325 Name = i->getRawName();
373326 }
374327
375328 if (Name == "//") {
376329 Format = has64SymTable ? K_MIPS64 : K_GNU;
377330 StringTable = i;
378331 ++i;
379 if (!*i) {
380 ec = i->getError();
381 return;
382 }
383332 FirstRegular = i;
384333 ec = std::error_code();
385334 return;
401350 SymbolTable = i;
402351
403352 ++i;
404 if (!*i) {
405 ec = i->getError();
406 return;
407 }
408353 if (i == e) {
409354 FirstRegular = i;
410355 ec = std::error_code();
411356 return;
412357 }
413358
414 Name = (*i)->getRawName();
359 Name = i->getRawName();
415360
416361 if (Name == "//") {
417362 StringTable = i;
418363 ++i;
419 if (!*i) {
420 ec = i->getError();
421 return;
422 }
423364 }
424365
425366 FirstRegular = i;
434375 return FirstRegular;
435376
436377 const char *Loc = Data.getBufferStart() + strlen(Magic);
437 auto ChildOrErr = Child::create(this, Loc);
438 if (std::error_code EC = ChildOrErr.getError())
439 return child_iterator(EC);
440 Child c = *(ChildOrErr.get());
441 return child_iterator(c);
378 Child c(this, Loc);
379 return c;
442380 }
443381
444382 Archive::child_iterator Archive::child_end() const {
445 // This with a second argument of nullptr can't return an Error.
446 auto ChildOrErr = Child::create(this, nullptr);
447 if (ChildOrErr.getError())
448 llvm_unreachable("Can't create Archive::child_end().");
449 Child c = *(ChildOrErr.get());
450 return child_iterator(c);
383 return Child(this, nullptr);
451384 }
452385
453386 StringRef Archive::Symbol::getName() const {
499432 }
500433
501434 const char *Loc = Parent->getData().begin() + Offset;
502 auto ChildOrErr = Child::create(Parent, Loc);
503 if (std::error_code EC = ChildOrErr.getError())
504 return EC;
505 child_iterator Iter(std::move(*ChildOrErr.get()));
435 child_iterator Iter(Child(Parent, Loc));
506436 return Iter;
507437 }
508438
346346 MemberRef = Buffers.back()->getMemBufferRef();
347347 } else {
348348 object::Archive::child_iterator OldMember = Member.getOld();
349 assert((!Thin || (*OldMember && (*OldMember)->getParent()->isThin())) &&
349 assert((!Thin || OldMember->getParent()->isThin()) &&
350350 "Thin archives cannot refers to member of other archives");
351351 ErrorOr MemberBufferOrErr =
352 (*OldMember)->getMemoryBufferRef();
352 OldMember->getMemoryBufferRef();
353353 if (auto EC = MemberBufferOrErr.getError())
354354 return std::make_pair("", EC);
355355 MemberRef = MemberBufferOrErr.get();
397397 Perms = Status.permissions();
398398 } else {
399399 object::Archive::child_iterator OldMember = I.getOld();
400 ModTime = (*OldMember)->getLastModified();
401 UID = (*OldMember)->getUID();
402 GID = (*OldMember)->getGID();
403 Perms = (*OldMember)->getAccessMode();
400 ModTime = OldMember->getLastModified();
401 UID = OldMember->getUID();
402 GID = OldMember->getGID();
403 Perms = OldMember->getAccessMode();
404404 }
405405
406406 if (I.isNewMember()) {
411411 Status.getSize());
412412 } else {
413413 object::Archive::child_iterator OldMember = I.getOld();
414 ErrorOr Size = (*OldMember)->getSize();
415 if (std::error_code EC = Size.getError())
416 return std::make_pair("", EC);
417414 printMemberHeader(Out, Kind, Thin, I.getName(), StringMapIndexIter,
418 ModTime, UID, GID, Perms, Size.get());
415 ModTime, UID, GID, Perms, OldMember->getSize());
419416 }
420417
421418 if (!Thin)
+0
-13
test/tools/llvm-objdump/Inputs/malformed-archives/libbogus1.a less more
None !
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
-13
test/tools/llvm-objdump/Inputs/malformed-archives/libbogus2.a less more
None !
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
-16
test/tools/llvm-objdump/Inputs/malformed-archives/libbogus3.a less more
None !
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
-20
test/tools/llvm-objdump/malformed-archives.test less more
None // 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/malformed-archives/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: llvm-objdump -macho -archive-headers \
10 # RUN: %p/Inputs/malformed-archives/libbogus2.a \
11 # RUN: 2>&1 | FileCheck -check-prefix=bogus2 %s
12
13 # bogus2: hello.c
14
15 # RUN: llvm-objdump -macho -archive-headers \
16 # RUN: %p/Inputs/malformed-archives/libbogus3.a \
17 # RUN: 2>&1 | FileCheck -check-prefix=bogus3 %s
18
19 # bogus3: foo.c
108108 Buffers.reserve(CurrentArchives.size());
109109
110110 for (const auto &CurrentArchive : CurrentArchives) {
111 for (auto ChildOrErr : CurrentArchive->children()) {
112 if (auto Err = ChildOrErr.getError())
113 return Err;
114 const auto &Child = *ChildOrErr;
111 for (const auto &Child : CurrentArchive->children()) {
115112 if (auto NameOrErr = Child.getName()) {
116113 if (*NameOrErr == Filename) {
117114 if (Timestamp != sys::TimeValue::PosixZeroTime() &&
337337 printMode(Mode & 007);
338338 outs() << ' ' << C.getUID();
339339 outs() << '/' << C.getGID();
340 ErrorOr Size = C.getSize();
341 if (Size.getError())
342 outs() << ' ' << "bad size";
343 else
344 outs() << ' ' << format("%6llu", Size.get());
340 outs() << ' ' << format("%6llu", C.getSize());
345341 outs() << ' ' << C.getLastModified().str();
346342 outs() << ' ';
347343 }
406402 }
407403
408404 bool Filter = !Members.empty();
409 for (auto &ChildOrErr : OldArchive->children()) {
410 if (ChildOrErr.getError()) {
411 errs() << ToolName << ": error reading '" << ArchiveName
412 << "': " << ChildOrErr.getError().message() << "!\n";
413 return;
414 }
415 const object::Archive::Child &C = *ChildOrErr;
416
405 for (const object::Archive::Child &C : OldArchive->children()) {
417406 ErrorOr NameOrErr = C.getName();
418407 failIfError(NameOrErr.getError());
419408 StringRef Name = NameOrErr.get();
458447 void addMember(std::vector &Members,
459448 object::Archive::child_iterator I, StringRef Name,
460449 int Pos = -1) {
461 if (I->getError())
462 fail("New member is not valid: " + I->getError().message());
463 if (Thin && !(*I)->getParent()->isThin())
450 if (Thin && !I->getParent()->isThin())
464451 fail("Cannot convert a regular archive to a thin one");
465452 NewArchiveIterator NI(I, Name);
466453 if (Pos == -1)
481468 object::Archive::child_iterator I,
482469 StringRef Name,
483470 std::vector::iterator &Pos) {
484 if (I->getError())
485 fail("Invalid member: " + I->getError().message());
486
487471 if (Operation == QuickAppend || Members.empty())
488472 return IA_AddOldMember;
489473
515499 // operation.
516500 sys::fs::file_status Status;
517501 failIfError(sys::fs::status(*MI, Status), *MI);
518 if (Status.getLastModificationTime() < (*I)->getLastModified()) {
502 if (Status.getLastModificationTime() < I->getLastModified()) {
519503 if (PosName.empty())
520504 return IA_AddOldMember;
521505 return IA_MoveOldMember;
538522 int InsertPos = -1;
539523 StringRef PosName = sys::path::filename(RelPos);
540524 if (OldArchive) {
541 for (auto &ChildOrErr : OldArchive->children()) {
542 failIfError(ChildOrErr.getError());
543 auto &Child = ChildOrErr.get();
525 for (auto &Child : OldArchive->children()) {
544526 int Pos = Ret.size();
545527 ErrorOr NameOrErr = Child.getName();
546528 failIfError(NameOrErr.getError());
743725 failIfError(LibOrErr.getError(), "Could not parse library");
744726 Archives.push_back(std::move(*LibOrErr));
745727 object::Archive &Lib = *Archives.back();
746 for (auto &MemberOrErr : Lib.children()) {
747 failIfError(MemberOrErr.getError());
748 auto &Member = MemberOrErr.get();
728 for (auto &Member : Lib.children()) {
749729 ErrorOr NameOrErr = Member.getName();
750730 failIfError(NameOrErr.getError());
751731 addMember(NewMembers, Member, *NameOrErr);
481481 }
482482
483483 static void dumpArchive(const Archive *Arc) {
484 for (auto &ErrorOrChild : Arc->children()) {
485 if (std::error_code EC = ErrorOrChild.getError()) {
486 reportError(Arc->getFileName(), EC.message());
487 break;
488 }
489 const Archive::Child &ArcC = *ErrorOrChild;
484 for (const Archive::Child &ArcC : Arc->children()) {
490485 ErrorOr> ChildOrErr = ArcC.getAsBinary();
491486 if (std::error_code EC = ChildOrErr.getError()) {
492487 // Ignore non-object files.
944944 if (I != E) {
945945 outs() << "Archive map\n";
946946 for (; I != E; ++I) {
947 ErrorOr ErrorOrChild = I->getMember();
948 if (error(ErrorOrChild.getError()))
947 ErrorOr C = I->getMember();
948 if (error(C.getError()))
949949 return;
950 auto &C = *(ErrorOrChild.get());
951 ErrorOr FileNameOrErr = C.get().getName();
950 ErrorOr FileNameOrErr = C.get()->getName();
952951 if (error(FileNameOrErr.getError()))
953952 return;
954953 StringRef SymName = I->getName();
960959
961960 for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
962961 I != E; ++I) {
963 if (I->getError())
964 break;
965 auto &C = I->get();
966 ErrorOr> ChildOrErr = C.getAsBinary(&Context);
962 ErrorOr> ChildOrErr = I->getAsBinary(&Context);
967963 if (ChildOrErr.getError())
968964 continue;
969965 if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) {
10181014 for (Archive::child_iterator AI = A->child_begin(),
10191015 AE = A->child_end();
10201016 AI != AE; ++AI) {
1021 if(AI->getError())
1022 break;
1023 auto &C = AI->get();
10241017 ErrorOr> ChildOrErr =
1025 C.getAsBinary(&Context);
1018 AI->getAsBinary(&Context);
10261019 if (ChildOrErr.getError())
10271020 continue;
10281021 if (SymbolicFile *O =
10751068 for (Archive::child_iterator AI = A->child_begin(),
10761069 AE = A->child_end();
10771070 AI != AE; ++AI) {
1078 if(AI->getError())
1079 break;
1080 auto &C = AI->get();
10811071 ErrorOr> ChildOrErr =
1082 C.getAsBinary(&Context);
1072 AI->getAsBinary(&Context);
10831073 if (ChildOrErr.getError())
10841074 continue;
10851075 if (SymbolicFile *O =
11271117 std::unique_ptr &A = *AOrErr;
11281118 for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
11291119 AI != AE; ++AI) {
1130 if(AI->getError())
1131 continue;
1132 auto &C = AI->get();
11331120 ErrorOr> ChildOrErr =
1134 C.getAsBinary(&Context);
1121 AI->getAsBinary(&Context);
11351122 if (ChildOrErr.getError())
11361123 continue;
11371124 if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) {
14161416 outs() << format("%3d/", UID);
14171417 unsigned GID = C.getGID();
14181418 outs() << format("%-3d ", GID);
1419 ErrorOr Size = C.getRawSize();
1420 if (Size.getError())
1421 outs() << "bad size" << " ";
1422 else
1423 outs() << format("%5" PRId64, Size.get()) << " ";
1419 uint64_t Size = C.getRawSize();
1420 outs() << format("%5" PRId64, Size) << " ";
14241421
14251422 StringRef RawLastModified = C.getRawLastModified();
14261423 if (verbose) {
14561453 static void printArchiveHeaders(Archive *A, bool verbose, bool print_offset) {
14571454 if (A->hasSymbolTable()) {
14581455 Archive::child_iterator S = A->getSymbolTableChild();
1459 if (!S->getError()) {
1460 Archive::Child C = S->get();
1461 printArchiveChild(C, verbose, print_offset);
1462 }
1456 Archive::Child C = *S;
1457 printArchiveChild(C, verbose, print_offset);
14631458 }
14641459 for (Archive::child_iterator I = A->child_begin(), E = A->child_end(); I != E;
14651460 ++I) {
1466 if(I->getError())
1467 break;
1468 Archive::Child C = I->get();
1461 Archive::Child C = *I;
14691462 printArchiveChild(C, verbose, print_offset);
14701463 }
14711464 }
15021495 printArchiveHeaders(A, !NonVerbose, ArchiveMemberOffsets);
15031496 for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
15041497 I != E; ++I) {
1505 if (I->getError())
1506 break;
1507 auto &C = I->get();
1508 ErrorOr> ChildOrErr = C.getAsBinary();
1498 ErrorOr> ChildOrErr = I->getAsBinary();
15091499 if (ChildOrErr.getError())
15101500 continue;
15111501 if (MachOObjectFile *O = dyn_cast(&*ChildOrErr.get())) {
15531543 for (Archive::child_iterator AI = A->child_begin(),
15541544 AE = A->child_end();
15551545 AI != AE; ++AI) {
1556 if (AI->getError())
1557 break;
1558 auto &C = AI->get();
1559 ErrorOr> ChildOrErr = C.getAsBinary();
1546 ErrorOr> ChildOrErr = AI->getAsBinary();
15601547 if (ChildOrErr.getError())
15611548 continue;
15621549 if (MachOObjectFile *O =
15981585 for (Archive::child_iterator AI = A->child_begin(),
15991586 AE = A->child_end();
16001587 AI != AE; ++AI) {
1601 if (AI->getError())
1602 break;
1603 auto &C = AI->get();
1604 ErrorOr> ChildOrErr = C.getAsBinary();
1588 ErrorOr> ChildOrErr = AI->getAsBinary();
16051589 if (ChildOrErr.getError())
16061590 continue;
16071591 if (MachOObjectFile *O =
16371621 printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
16381622 for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
16391623 AI != AE; ++AI) {
1640 if (AI->getError())
1641 break;
1642 auto &C = AI->get();
1643 ErrorOr> ChildOrErr = C.getAsBinary();
1624 ErrorOr> ChildOrErr = AI->getAsBinary();
16441625 if (ChildOrErr.getError())
16451626 continue;
16461627 if (MachOObjectFile *O =
15351535
15361536 /// @brief Dump each object file in \a a;
15371537 static void DumpArchive(const Archive *a) {
1538 for (auto &ErrorOrChild : a->children()) {
1539 if (std::error_code EC = ErrorOrChild.getError()) {
1540 report_error(a->getFileName(), EC);
1541 break;
1542 }
1543 const Archive::Child &C = *ErrorOrChild;
1538 for (const Archive::Child &C : a->children()) {
15441539 ErrorOr> ChildOrErr = C.getAsBinary();
15451540 if (std::error_code EC = ChildOrErr.getError())
15461541 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 (auto &ErrorOrChild : Arc->children()) {
380 if (std::error_code EC = ErrorOrChild.getError()) {
381 reportError(Arc->getFileName(), EC.message());
382 break;
383 }
384 const auto &Child = *ErrorOrChild;
379 for (const auto &Child : Arc->children()) {
385380 ErrorOr> ChildOrErr = Child.getAsBinary();
386381 if (std::error_code EC = ChildOrErr.getError()) {
387382 // Ignore non-object files.
426426 for (object::Archive::child_iterator i = a->child_begin(),
427427 e = a->child_end();
428428 i != e; ++i) {
429 if (i->getError()) {
430 errs() << ToolName << ": " << file << ": " << i->getError().message()
431 << ".\n";
432 break;
433 }
434 auto &c = i->get();
435 ErrorOr> ChildOrErr = c.getAsBinary();
429 ErrorOr> ChildOrErr = i->getAsBinary();
436430 if (std::error_code EC = ChildOrErr.getError()) {
437431 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
438432 continue;
494488 for (object::Archive::child_iterator i = UA->child_begin(),
495489 e = UA->child_end();
496490 i != e; ++i) {
497 if (std::error_code EC = i->getError()) {
498 errs() << ToolName << ": " << file << ": " << EC.message()
499 << ".\n";
500 break;
501 }
502 auto &c = i->get();
503 ErrorOr> ChildOrErr = c.getAsBinary();
491 ErrorOr> ChildOrErr = i->getAsBinary();
504492 if (std::error_code EC = ChildOrErr.getError()) {
505493 errs() << ToolName << ": " << file << ": " << EC.message()
506494 << ".\n";
577565 for (object::Archive::child_iterator i = UA->child_begin(),
578566 e = UA->child_end();
579567 i != e; ++i) {
580 if (std::error_code EC = i->getError()) {
581 errs() << ToolName << ": " << file << ": " << EC.message()
582 << ".\n";
583 break;
584 }
585 auto &c = i->get();
586 ErrorOr> ChildOrErr = c.getAsBinary();
568 ErrorOr> ChildOrErr = i->getAsBinary();
587569 if (std::error_code EC = ChildOrErr.getError()) {
588570 errs() << ToolName << ": " << file << ": " << EC.message()
589571 << ".\n";
647629 for (object::Archive::child_iterator i = UA->child_begin(),
648630 e = UA->child_end();
649631 i != e; ++i) {
650 if (std::error_code EC = i->getError()) {
651 errs() << ToolName << ": " << file << ": " << EC.message()
652 << ".\n";
653 break;
654 }
655 auto &c = i->get();
656 ErrorOr> ChildOrErr = c.getAsBinary();
632 ErrorOr> ChildOrErr = i->getAsBinary();
657633 if (std::error_code EC = ChildOrErr.getError()) {
658634 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
659635 continue;