From: Jez Ng Date: Fri, 18 Jun 2021 06:32:31 +0000 (-0400) Subject: [lld-macho] Have path-related functions return std::string, not StringRef X-Git-Tag: llvmorg-14-init~3588 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d31fb8d122b1117cf20a9edc09812db8472e930;p=platform%2Fupstream%2Fllvm.git [lld-macho] Have path-related functions return std::string, not StringRef findLibrary() returned a StringRef while findFramework & other helper functions returned std::strings. Standardize on std::string. (I initially tried making the helper functions all return StringRefs, but I realized we shouldn't return input StringRefs since their lifetimes would not be obvious from the calling code.) --- diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index aa8049e..726ca3e 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 148c309..9ae468c 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 5558273..f32027b 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,