diff options
-rw-r--r-- | lld/include/lld/Core/LinkingContext.h | 2 | ||||
-rw-r--r-- | lld/include/lld/Core/Resolver.h | 10 | ||||
-rw-r--r-- | lld/include/lld/ReaderWriter/MachOLinkingContext.h | 2 | ||||
-rw-r--r-- | lld/lib/Core/Resolver.cpp | 53 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp | 16 |
5 files changed, 46 insertions, 37 deletions
diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h index 7227b17aee3..cfbc239623a 100644 --- a/lld/include/lld/Core/LinkingContext.h +++ b/lld/include/lld/Core/LinkingContext.h @@ -208,7 +208,7 @@ public: /// errors for any differences between the context state and a loaded file. /// For example, we can error if we try to load a file which is a different /// arch from that being linked. - virtual std::error_code handleLoadedFile(File &file) = 0; + virtual llvm::Error handleLoadedFile(File &file) = 0; /// @} protected: diff --git a/lld/include/lld/Core/Resolver.h b/lld/include/lld/Core/Resolver.h index 33892e9b63a..fb62a779c0a 100644 --- a/lld/include/lld/Core/Resolver.h +++ b/lld/include/lld/Core/Resolver.h @@ -42,13 +42,13 @@ public: // Handle files, this adds atoms from the current file thats // being processed by the resolver - ErrorOr<bool> handleFile(File &); + llvm::Expected<bool> handleFile(File &); // Handle an archive library file. - ErrorOr<bool> handleArchiveFile(File &); + llvm::Expected<bool> handleArchiveFile(File &); // Handle a shared library file. - std::error_code handleSharedLibrary(File &); + llvm::Error handleSharedLibrary(File &); /// @brief do work of merging and resolving and return list bool resolve(); @@ -56,7 +56,7 @@ public: std::unique_ptr<SimpleFile> resultFile() { return std::move(_result); } private: - typedef std::function<ErrorOr<bool>(StringRef)> UndefCallback; + typedef std::function<llvm::Expected<bool>(StringRef)> UndefCallback; bool undefinesAdded(int begin, int end); File *getFile(int &index); @@ -67,7 +67,7 @@ private: void deadStripOptimize(); bool checkUndefines(); void removeCoalescedAwayAtoms(); - ErrorOr<bool> forEachUndefines(File &file, UndefCallback callback); + llvm::Expected<bool> forEachUndefines(File &file, UndefCallback callback); void markLive(const Atom *atom); diff --git a/lld/include/lld/ReaderWriter/MachOLinkingContext.h b/lld/include/lld/ReaderWriter/MachOLinkingContext.h index 4d1233f5af0..acb66138612 100644 --- a/lld/include/lld/ReaderWriter/MachOLinkingContext.h +++ b/lld/include/lld/ReaderWriter/MachOLinkingContext.h @@ -407,7 +407,7 @@ public: void finalizeInputFiles() override; - std::error_code handleLoadedFile(File &file) override; + llvm::Error handleLoadedFile(File &file) override; bool customAtomOrderer(const DefinedAtom *left, const DefinedAtom *right, bool &leftBeforeRight) const; diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp index 7d2aada6c69..7619e4c044d 100644 --- a/lld/lib/Core/Resolver.cpp +++ b/lld/lib/Core/Resolver.cpp @@ -19,6 +19,7 @@ #include "lld/Core/UndefinedAtom.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" @@ -29,9 +30,9 @@ namespace lld { -ErrorOr<bool> Resolver::handleFile(File &file) { +llvm::Expected<bool> Resolver::handleFile(File &file) { if (auto ec = _ctx.handleLoadedFile(file)) - return ec; + return std::move(ec); bool undefAdded = false; for (auto &atom : file.defined().owning_ptrs()) doDefinedAtom(std::move(atom)); @@ -46,7 +47,8 @@ ErrorOr<bool> Resolver::handleFile(File &file) { return undefAdded; } -ErrorOr<bool> Resolver::forEachUndefines(File &file, UndefCallback callback) { +llvm::Expected<bool> Resolver::forEachUndefines(File &file, + UndefCallback callback) { size_t i = _undefineIndex[&file]; bool undefAdded = false; do { @@ -61,8 +63,8 @@ ErrorOr<bool> Resolver::forEachUndefines(File &file, UndefCallback callback) { continue; } auto undefAddedOrError = callback(undefName); - if (undefAddedOrError.getError()) - return undefAddedOrError; + if (auto ec = undefAddedOrError.takeError()) + return std::move(ec); undefAdded |= undefAddedOrError.get(); } } while (i < _undefines.size()); @@ -70,9 +72,10 @@ ErrorOr<bool> Resolver::forEachUndefines(File &file, UndefCallback callback) { return undefAdded; } -ErrorOr<bool> Resolver::handleArchiveFile(File &file) { +llvm::Expected<bool> Resolver::handleArchiveFile(File &file) { ArchiveLibraryFile *archiveFile = cast<ArchiveLibraryFile>(&file); - return forEachUndefines(file, [&](StringRef undefName) -> ErrorOr<bool> { + return forEachUndefines(file, + [&](StringRef undefName) -> llvm::Expected<bool> { if (File *member = archiveFile->find(undefName)) { member->setOrdinal(_ctx.getNextOrdinalAndIncrement()); return handleFile(*member); @@ -81,23 +84,23 @@ ErrorOr<bool> Resolver::handleArchiveFile(File &file) { }); } -std::error_code Resolver::handleSharedLibrary(File &file) { +llvm::Error Resolver::handleSharedLibrary(File &file) { // Add all the atoms from the shared library SharedLibraryFile *sharedLibrary = cast<SharedLibraryFile>(&file); auto undefAddedOrError = handleFile(*sharedLibrary); - if (undefAddedOrError.getError()) - return undefAddedOrError.getError(); + if (auto ec = undefAddedOrError.takeError()) + return std::move(ec); undefAddedOrError = - forEachUndefines(file, [&](StringRef undefName) -> ErrorOr<bool> { + forEachUndefines(file, [&](StringRef undefName) -> llvm::Expected<bool> { auto atom = sharedLibrary->exports(undefName); if (atom.get()) doSharedLibraryAtom(std::move(atom)); return false; }); - if (undefAddedOrError.getError()) - return undefAddedOrError.getError(); - return std::error_code(); + if (auto ec = undefAddedOrError.takeError()) + return std::move(ec); + return llvm::Error(); } bool Resolver::doUndefinedAtom(OwningAtomPtr<UndefinedAtom> atom) { @@ -247,9 +250,11 @@ bool Resolver::resolveUndefines() { assert(!file->hasOrdinal()); file->setOrdinal(_ctx.getNextOrdinalAndIncrement()); auto undefAddedOrError = handleFile(*file); - if (undefAddedOrError.getError()) { - llvm::errs() << "Error in " + file->path() - << ": " << undefAddedOrError.getError().message() << "\n"; + if (auto EC = undefAddedOrError.takeError()) { + // FIXME: This should be passed to logAllUnhandledErrors but it needs + // to be passed a Twine instead of a string. + llvm::errs() << "Error in " + file->path() << ": "; + logAllUnhandledErrors(std::move(EC), llvm::errs(), std::string()); return false; } undefAdded = undefAddedOrError.get(); @@ -259,9 +264,11 @@ bool Resolver::resolveUndefines() { if (!file->hasOrdinal()) file->setOrdinal(_ctx.getNextOrdinalAndIncrement()); auto undefAddedOrError = handleArchiveFile(*file); - if (undefAddedOrError.getError()) { - llvm::errs() << "Error in " + file->path() - << ": " << undefAddedOrError.getError().message() << "\n"; + if (auto EC = undefAddedOrError.takeError()) { + // FIXME: This should be passed to logAllUnhandledErrors but it needs + // to be passed a Twine instead of a string. + llvm::errs() << "Error in " + file->path() << ": "; + logAllUnhandledErrors(std::move(EC), llvm::errs(), std::string()); return false; } undefAdded = undefAddedOrError.get(); @@ -271,8 +278,10 @@ bool Resolver::resolveUndefines() { if (!file->hasOrdinal()) file->setOrdinal(_ctx.getNextOrdinalAndIncrement()); if (auto EC = handleSharedLibrary(*file)) { - llvm::errs() << "Error in " + file->path() - << ": " << EC.message() << "\n"; + // FIXME: This should be passed to logAllUnhandledErrors but it needs + // to be passed a Twine instead of a string. + llvm::errs() << "Error in " + file->path() << ": "; + logAllUnhandledErrors(std::move(EC), llvm::errs(), std::string()); return false; } break; diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index 4431f347b27..67929c972eb 100644 --- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -1040,10 +1040,10 @@ void MachOLinkingContext::finalizeInputFiles() { elements.push_back(llvm::make_unique<GroupEnd>(numLibs)); } -std::error_code MachOLinkingContext::handleLoadedFile(File &file) { +llvm::Error MachOLinkingContext::handleLoadedFile(File &file) { auto *machoFile = dyn_cast<MachOFile>(&file); if (!machoFile) - return std::error_code(); + return llvm::Error(); // Check that the arch of the context matches that of the file. // Also set the arch of the context if it didn't have one. @@ -1051,7 +1051,7 @@ std::error_code MachOLinkingContext::handleLoadedFile(File &file) { _arch = machoFile->arch(); } else if (machoFile->arch() != arch_unknown && machoFile->arch() != _arch) { // Archs are different. - return make_dynamic_error_code(file.path() + + return llvm::make_error<GenericError>(file.path() + Twine(" cannot be linked due to incompatible architecture")); } @@ -1061,7 +1061,7 @@ std::error_code MachOLinkingContext::handleLoadedFile(File &file) { _os = machoFile->OS(); } else if (machoFile->OS() != OS::unknown && machoFile->OS() != _os) { // OSes are different. - return make_dynamic_error_code(file.path() + + return llvm::make_error<GenericError>(file.path() + Twine(" cannot be linked due to incompatible operating systems")); } @@ -1078,7 +1078,7 @@ std::error_code MachOLinkingContext::handleLoadedFile(File &file) { // The file is built with simulator objc, so make sure that the context // is also building with simulator support. if (_os != OS::iOS_simulator) - return make_dynamic_error_code(file.path() + + return llvm::make_error<GenericError>(file.path() + Twine(" cannot be linked. It contains ObjC built for the simulator" " while we are linking a non-simulator target")); assert((_objcConstraint == objc_unknown || @@ -1090,7 +1090,7 @@ std::error_code MachOLinkingContext::handleLoadedFile(File &file) { // The file is built without simulator objc, so make sure that the // context is also building without simulator support. if (_os == OS::iOS_simulator) - return make_dynamic_error_code(file.path() + + return llvm::make_error<GenericError>(file.path() + Twine(" cannot be linked. It contains ObjC built for a non-simulator" " target while we are linking a simulator target")); assert((_objcConstraint == objc_unknown || @@ -1107,10 +1107,10 @@ std::error_code MachOLinkingContext::handleLoadedFile(File &file) { } else if (machoFile->swiftVersion() && machoFile->swiftVersion() != _swiftVersion) { // Swift versions are different. - return make_dynamic_error_code("different swift versions"); + return llvm::make_error<GenericError>("different swift versions"); } - return std::error_code(); + return llvm::Error(); } } // end namespace lld |