llvm.org GIT mirror llvm / 0b21d88
Change Archive::create() from ErrorOr<...> to Expected<...> and update its clients. This commit will break the next lld builds. I’ll be committing the matching change for lld next. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274160 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 4 years ago
7 changed file(s) with 44 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
175175 }
176176 };
177177
178 Archive(MemoryBufferRef Source, std::error_code &EC);
179 static ErrorOr> create(MemoryBufferRef Source);
178 Archive(MemoryBufferRef Source, Error &Err);
179 static Expected> create(MemoryBufferRef Source);
180180
181181 enum Kind {
182182 K_GNU,
262262 return BinaryOrErr.takeError();
263263 }
264264
265 ErrorOr> Archive::create(MemoryBufferRef Source) {
266 std::error_code EC;
267 std::unique_ptr Ret(new Archive(Source, EC));
268 if (EC)
269 return EC;
265 Expected> Archive::create(MemoryBufferRef Source) {
266 Error Err;
267 std::unique_ptr Ret(new Archive(Source, Err));
268 if (Err)
269 return std::move(Err);
270270 return std::move(Ret);
271271 }
272272
275275 FirstRegularStartOfFile = C.StartOfFile;
276276 }
277277
278 Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
278 Archive::Archive(MemoryBufferRef Source, Error &Err)
279279 : Binary(Binary::ID_Archive, Source) {
280 ErrorAsOutParameter ErrAsOutParam(Err);
280281 StringRef Buffer = Data.getBuffer();
281282 // Check for sufficient magic.
282283 if (Buffer.startswith(ThinMagic)) {
284285 } else if (Buffer.startswith(Magic)) {
285286 IsThin = false;
286287 } else {
287 ec = object_error::invalid_file_type;
288 Err = make_error("File too small to be an archive",
289 object_error::invalid_file_type);
288290 return;
289291 }
290292
291293 // Get the special members.
292294 child_iterator I = child_begin(false);
293 if ((ec = I->getError()))
294 return;
295 std::error_code ec;
296 if ((ec = I->getError())) {
297 Err = errorCodeToError(ec);
298 return;
299 }
295300 child_iterator E = child_end();
296301
297302 // This is at least a valid empty archive. Since an empty archive is the
300305 Format = K_GNU;
301306
302307 if (I == E) {
303 ec = std::error_code();
308 Err = Error::success();
304309 return;
305310 }
306311 const Child *C = &**I;
307312
308313 auto Increment = [&]() {
309314 ++I;
310 if ((ec = I->getError()))
315 if ((Err = errorCodeToError(I->getError())))
311316 return true;
312317 C = &**I;
313318 return false;
346351 return;
347352 setFirstRegular(*C);
348353
349 ec = std::error_code();
354 Err = Error::success();
350355 return;
351356 }
352357
355360 // We know this is BSD, so getName will work since there is no string table.
356361 ErrorOr NameOrErr = C->getName();
357362 ec = NameOrErr.getError();
358 if (ec)
363 if (ec) {
364 Err = errorCodeToError(ec);
359365 return;
366 }
360367 Name = NameOrErr.get();
361368 if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
362369 // We know that the symbol table is not an external file, so we just
393400 if (Increment())
394401 return;
395402 if (I == E) {
396 ec = std::error_code();
403 Err = Error::success();
397404 return;
398405 }
399406 Name = C->getRawName();
407414 if (Increment())
408415 return;
409416 setFirstRegular(*C);
410 ec = std::error_code();
417 Err = Error::success();
411418 return;
412419 }
413420
414421 if (Name[0] != '/') {
415422 Format = has64SymTable ? K_MIPS64 : K_GNU;
416423 setFirstRegular(*C);
417 ec = std::error_code();
424 Err = Error::success();
418425 return;
419426 }
420427
421428 if (Name != "/") {
422 ec = object_error::parse_failed;
429 Err = errorCodeToError(object_error::parse_failed);
423430 return;
424431 }
425432
433440
434441 if (I == E) {
435442 setFirstRegular(*C);
436 ec = std::error_code();
443 Err = Error::success();
437444 return;
438445 }
439446
448455 }
449456
450457 setFirstRegular(*C);
451 ec = std::error_code();
458 Err = Error::success();
452459 }
453460
454461 Archive::child_iterator Archive::child_begin(bool SkipInternal) const {
4141
4242 switch (Type) {
4343 case sys::fs::file_magic::archive:
44 return errorOrToExpected(Archive::create(Buffer));
44 return Archive::create(Buffer);
4545 case sys::fs::file_magic::elf:
4646 case sys::fs::file_magic::elf_relocatable:
4747 case sys::fs::file_magic::elf_executable:
9595 ObjectData = ParentData.substr(Header64.offset, Header64.size);
9696 StringRef ObjectName = Parent->getFileName();
9797 MemoryBufferRef ObjBuffer(ObjectData, ObjectName);
98 return errorOrToExpected(Archive::create(ObjBuffer));
98 return Archive::create(ObjBuffer);
9999 }
100100
101101 void MachOUniversalBinary::anchor() { }
158158
159159 for (auto MemRef : ArchiveBuffers) {
160160 auto ErrOrArchive = object::Archive::create(MemRef);
161 if (auto Err = ErrOrArchive.getError())
162 return Err;
161 if (!ErrOrArchive)
162 return errorToErrorCode(ErrOrArchive.takeError());
163163 CurrentArchives.push_back(std::move(*ErrOrArchive));
164164 }
165165 return GetArchiveMemberBuffers(Filename, Timestamp);
510510 }
511511 std::unique_ptr &ArBuf = ArBufOrErr.get();
512512
513 ErrorOr> ArOrErr =
513 Expected> ArOrErr =
514514 object::Archive::create(ArBuf->getMemBufferRef());
515 if (std::error_code EC = ArOrErr.getError()) {
516 errs() << EC.message();
515 if (!ArOrErr) {
516 std::string Buf;
517 raw_string_ostream OS(Buf);
518 logAllUnhandledErrors(ArOrErr.takeError(), OS, "");
519 OS.flush();
520 errs() << Buf;
517521 return 1;
518522 }
519523 std::unique_ptr &Ar = ArOrErr.get();
712712 fail("error opening '" + ArchiveName + "': " + EC.message() + "!");
713713
714714 if (!EC) {
715 object::Archive Archive(Buf.get()->getMemBufferRef(), EC);
715 Error Err;
716 object::Archive Archive(Buf.get()->getMemBufferRef(), Err);
717 EC = errorToErrorCode(std::move(Err));
716718 failIfError(EC,
717719 "error loading '" + ArchiveName + "': " + EC.message() + "!");
718720 performOperation(Operation, &Archive, std::move(Buf.get()), NewMembers);
767769 ArchiveBuffers.push_back(std::move(*BufOrErr));
768770 auto LibOrErr =
769771 object::Archive::create(ArchiveBuffers.back()->getMemBufferRef());
770 failIfError(LibOrErr.getError(), "Could not parse library");
772 failIfError(errorToErrorCode(LibOrErr.takeError()),
773 "Could not parse library");
771774 Archives.push_back(std::move(*LibOrErr));
772775 object::Archive &Lib = *Archives.back();
773776 for (auto &MemberOrErr : Lib.children()) {