diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index c81160c51cf76..52771c2a6fe15 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, @@ -328,7 +328,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 9ae468cd2a36b..148c309b52d57 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. -std::string rerootPath(llvm::StringRef path); +llvm::StringRef 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 f32027b2bcbf7..55582731aab94 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 location.str(); + return saver.save(location.str()); } } return {}; } -std::string macho::rerootPath(StringRef path) { +StringRef macho::rerootPath(StringRef path) { if (!path::is_absolute(path, path::Style::posix) || path.endswith(".o")) - return std::string(path); + return path; - if (Optional rerootedPath = + if (Optional rerootedPath = findPathCombination(path, config->systemLibraryRoots)) return *rerootedPath; - return std::string(path); + return path; } Optional macho::loadArchiveMember(MemoryBufferRef mb,