diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index aa8049ebeb6bc..726ca3e00fb16 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -78,9 +78,9 @@ static HeaderFileType getOutputType(const InputArgList &args) { } } -static Optional findLibrary(StringRef name) { +static Optional findLibrary(StringRef name) { if (config->searchDylibsFirst) { - if (Optional path = findPathCombination( + if (Optional path = findPathCombination( "lib" + name, config->librarySearchPaths, {".tbd", ".dylib"})) return path; return findPathCombination("lib" + name, config->librarySearchPaths, @@ -337,7 +337,7 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive, static void addLibrary(StringRef name, bool isNeeded, bool isWeak, bool isReexport, bool isExplicit, bool forceLoad) { - if (Optional path = findLibrary(name)) { + if (Optional path = findLibrary(name)) { if (auto *dylibFile = dyn_cast_or_null( addFile(*path, forceLoad, isExplicit))) { if (isNeeded) diff --git a/lld/MachO/Driver.h b/lld/MachO/Driver.h index 148c309b52d57..9ae468cd2a36b 100644 --- a/lld/MachO/Driver.h +++ b/lld/MachO/Driver.h @@ -58,14 +58,14 @@ DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr, // Search for all possible combinations of `{root}/{name}.{extension}`. // If \p extensions are not specified, then just search for `{root}/{name}`. -llvm::Optional +llvm::Optional findPathCombination(const llvm::Twine &name, const std::vector &roots, ArrayRef extensions = {""}); // If -syslibroot is specified, absolute paths to non-object files may be // rerooted. -llvm::StringRef rerootPath(llvm::StringRef path); +std::string rerootPath(llvm::StringRef path); llvm::Optional loadArchiveMember(MemoryBufferRef, uint32_t modTime, StringRef archiveName, diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp index 55582731aab94..f32027b2bcbf7 100644 --- a/lld/MachO/DriverUtils.cpp +++ b/lld/MachO/DriverUtils.cpp @@ -246,7 +246,7 @@ DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella, return newFile; } -Optional +Optional macho::findPathCombination(const Twine &name, const std::vector &roots, ArrayRef extensions) { @@ -259,21 +259,21 @@ macho::findPathCombination(const Twine &name, bool exists = fs::exists(location); searchedDylib(location, exists); if (exists) - return saver.save(location.str()); + return location.str(); } } return {}; } -StringRef macho::rerootPath(StringRef path) { +std::string macho::rerootPath(StringRef path) { if (!path::is_absolute(path, path::Style::posix) || path.endswith(".o")) - return path; + return std::string(path); - if (Optional rerootedPath = + if (Optional rerootedPath = findPathCombination(path, config->systemLibraryRoots)) return *rerootedPath; - return path; + return std::string(path); } Optional macho::loadArchiveMember(MemoryBufferRef mb,