diff --git a/lld/MachO/Driver.h b/lld/MachO/Driver.h --- a/lld/MachO/Driver.h +++ b/lld/MachO/Driver.h @@ -53,9 +53,8 @@ // Check for both libfoo.dylib and libfoo.tbd (in that order). llvm::Optional resolveDylibPath(llvm::StringRef path); -llvm::Optional loadDylib(llvm::MemoryBufferRef mbref, - DylibFile *umbrella = nullptr, - bool isBundleLoader = false); +DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr, + bool isBundleLoader = false); // Search for all possible combinations of `{root}/{name}.{extension}`. // If \p extensions are not specified, then just search for `{root}/{name}`. diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -293,8 +293,8 @@ case file_magic::macho_dynamically_linked_shared_lib: case file_magic::macho_dynamically_linked_shared_lib_stub: case file_magic::tapi_file: - if (Optional dylibFile = loadDylib(mbref)) - newFile = *dylibFile; + if (DylibFile *dylibFile = loadDylib(mbref)) + newFile = dylibFile; break; case file_magic::bitcode: newFile = make(mbref); @@ -305,9 +305,8 @@ // as a bundle loader. if (!isBundleLoader) error(path + ": unhandled file type"); - if (Optional dylibFile = - loadDylib(mbref, nullptr, isBundleLoader)) - newFile = *dylibFile; + if (DylibFile *dylibFile = loadDylib(mbref, nullptr, isBundleLoader)) + newFile = dylibFile; break; default: error(path + ": unhandled file type"); diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp --- a/lld/MachO/DriverUtils.cpp +++ b/lld/MachO/DriverUtils.cpp @@ -197,9 +197,8 @@ // especially if it's a commonly re-exported core library. static DenseMap loadedDylibs; -Optional macho::loadDylib(MemoryBufferRef mbref, - DylibFile *umbrella, - bool isBundleLoader) { +DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella, + bool isBundleLoader) { CachedHashStringRef path(mbref.getBufferIdentifier()); DylibFile *file = loadedDylibs[path]; if (file) @@ -211,7 +210,7 @@ if (!result) { error("could not load TAPI file at " + mbref.getBufferIdentifier() + ": " + toString(result.takeError())); - return {}; + return nullptr; } file = make(**result, umbrella, isBundleLoader); } else { diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -730,11 +730,11 @@ } // The path can point to either a dylib or a .tbd file. -static Optional loadDylib(StringRef path, DylibFile *umbrella) { +static DylibFile *loadDylib(StringRef path, DylibFile *umbrella) { Optional mbref = readFile(path); if (!mbref) { error("could not read dylib file at " + path); - return {}; + return nullptr; } return loadDylib(*mbref, umbrella); } @@ -748,9 +748,8 @@ // // Re-exports can either refer to on-disk files, or to documents within .tbd // files. -static Optional -findDylib(StringRef path, DylibFile *umbrella, - const InterfaceFile *currentTopLevelTapi) { +DylibFile *findDylib(StringRef path, DylibFile *umbrella, + const InterfaceFile *currentTopLevelTapi) { if (path::is_absolute(path, path::Style::posix)) for (StringRef root : config->systemLibraryRoots) if (Optional dylibPath = @@ -771,7 +770,7 @@ if (Optional dylibPath = resolveDylibPath(path)) return loadDylib(*dylibPath, umbrella); - return {}; + return nullptr; } // If a re-exported dylib is public (lives in /usr/lib or @@ -796,12 +795,11 @@ void loadReexport(StringRef path, DylibFile *umbrella, const InterfaceFile *currentTopLevelTapi) { - Optional reexport = - findDylib(path, umbrella, currentTopLevelTapi); + DylibFile *reexport = findDylib(path, umbrella, currentTopLevelTapi); if (!reexport) error("unable to locate re-export with install name " + path); else if (isImplicitlyLinked(path)) - inputFiles.insert(*reexport); + inputFiles.insert(reexport); } DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella, @@ -869,7 +867,7 @@ const auto *c = reinterpret_cast(cmd); StringRef dylibPath = reinterpret_cast(c) + read32le(&c->dylib.name); - Optional dylib = findDylib(dylibPath, umbrella, nullptr); + DylibFile *dylib = findDylib(dylibPath, umbrella, nullptr); if (!dylib) error(Twine("unable to locate library '") + dylibPath + "' loaded from '" + toString(this) + "' for -flat_namespace");