[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
This revision was automatically updated to reflect the committed changes. Closed by commit rC340471: [Driver] Check normalized triples for multiarch runtime path (authored by phosek, committed by ). Changed prior to commit: https://reviews.llvm.org/D50547?vs=161821&id=162090#toc Repository: rC Clang https://reviews.llvm.org/D50547 Files: include/clang/Driver/ToolChain.h lib/Driver/ToolChain.cpp test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.asan-preinit.a test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.asan.so test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.builtins.a test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.fuzzer.a test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.scudo.so test/Driver/Inputs/resource_dir_with_per_target_subdir/i386-linux-gnu/lib/libclang_rt.builtins.a test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.asan-preinit.a test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.asan.so test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.builtins.a test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.fuzzer.a test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.scudo.so test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-linux-gnu/lib/libclang_rt.builtins.a Index: lib/Driver/ToolChain.cpp === --- lib/Driver/ToolChain.cpp +++ lib/Driver/ToolChain.cpp @@ -74,10 +74,17 @@ const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { - SmallString<128> P(D.ResourceDir); + SmallString<128> P; + + P.assign(D.ResourceDir); llvm::sys::path::append(P, D.getTargetTriple(), "lib"); if (getVFS().exists(P)) -getFilePaths().push_back(P.str()); +getLibraryPaths().push_back(P.str()); + + P.assign(D.ResourceDir); + llvm::sys::path::append(P, Triple.str(), "lib"); + if (getVFS().exists(P)) +getLibraryPaths().push_back(P.str()); std::string CandidateLibPath = getArchSpecificLibPath(); if (getVFS().exists(CandidateLibPath)) @@ -362,12 +369,11 @@ const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a"); - const Driver &D = getDriver(); - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) { + for (const auto &LibPath : getLibraryPaths()) { +SmallString<128> P(LibPath); llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix); -return P.str(); +if (getVFS().exists(P)) + return P.str(); } StringRef Arch = getArchNameForCompilerRTLib(*this, Args); @@ -762,6 +768,10 @@ void ToolChain::AddFilePathLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { + for (const auto &LibPath : getLibraryPaths()) +if(LibPath.length() > 0) + CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); + for (const auto &LibPath : getFilePaths()) if(LibPath.length() > 0) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); Index: include/clang/Driver/ToolChain.h === --- include/clang/Driver/ToolChain.h +++ include/clang/Driver/ToolChain.h @@ -116,6 +116,9 @@ const RTTIMode CachedRTTIMode; + /// The list of toolchain specific path prefixes to search for libraries. + path_list LibraryPaths; + /// The list of toolchain specific path prefixes to search for files. path_list FilePaths; @@ -213,6 +216,9 @@ return EffectiveTriple; } + path_list &getLibraryPaths() { return LibraryPaths; } + const path_list &getLibraryPaths() const { return LibraryPaths; } + path_list &getFilePaths() { return FilePaths; } const path_list &getFilePaths() const { return FilePaths; } Index: lib/Driver/ToolChain.cpp === --- lib/Driver/ToolChain.cpp +++ lib/Driver/ToolChain.cpp @@ -74,10 +74,17 @@ const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { - SmallString<128> P(D.ResourceDir); + SmallString<128> P; + + P.assign(D.ResourceDir); llvm::sys::path::append(P, D.getTargetTriple(), "lib"); if (getVFS().exists(P)) -getFilePaths().push_back(P.str()); +getLibraryPaths().push_back(P.str()); + + P.assign(D.ResourceDir); + llvm::
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
beanz accepted this revision. beanz added a comment. LGTM as-is Comment at: clang/lib/Driver/ToolChain.cpp:372 - const Driver &D = getDriver(); - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) { + for (const auto &LibPath : getLibraryPaths()) { +SmallString<128> P(LibPath); phosek wrote: > One possible alternative I've considered would be to simply return > `-lclang_rt..` instead of returning the full path when > `getLibraryPaths()` is not empty. That should work because we add all paths > in this list as `-L` in `AddFilePathLibArgs` and it's more consistent with > e.g. `-lgcc_s`. I'd prefer not doing that since Darwin doesn't call AddFilePathLibArgs, and adjusting to that is a larger change on the Darwin side. Repository: rC Clang https://reviews.llvm.org/D50547 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
phosek added inline comments. Comment at: clang/lib/Driver/ToolChain.cpp:372 - const Driver &D = getDriver(); - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) { + for (const auto &LibPath : getLibraryPaths()) { +SmallString<128> P(LibPath); One possible alternative I've considered would be to simply return `-lclang_rt..` instead of returning the full path when `getLibraryPaths()` is not empty. That should work because we add all paths in this list as `-L` in `AddFilePathLibArgs` and it's more consistent with e.g. `-lgcc_s`. Repository: rC Clang https://reviews.llvm.org/D50547 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
phosek updated this revision to Diff 161821. Herald added a reviewer: javed.absar. Repository: rC Clang https://reviews.llvm.org/D50547 Files: clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChain.cpp clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.asan-preinit.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.asan.so clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.builtins.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.fuzzer.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.scudo.so clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/i386-linux-gnu/lib/libclang_rt.builtins.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.asan-preinit.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.asan.so clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.builtins.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.fuzzer.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.scudo.so clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-linux-gnu/lib/libclang_rt.builtins.a Index: clang/lib/Driver/ToolChain.cpp === --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -74,10 +74,17 @@ const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { - SmallString<128> P(D.ResourceDir); + SmallString<128> P; + + P.assign(D.ResourceDir); llvm::sys::path::append(P, D.getTargetTriple(), "lib"); if (getVFS().exists(P)) -getFilePaths().push_back(P.str()); +getLibraryPaths().push_back(P.str()); + + P.assign(D.ResourceDir); + llvm::sys::path::append(P, Triple.str(), "lib"); + if (getVFS().exists(P)) +getLibraryPaths().push_back(P.str()); std::string CandidateLibPath = getArchSpecificLibPath(); if (getVFS().exists(CandidateLibPath)) @@ -362,12 +369,11 @@ const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a"); - const Driver &D = getDriver(); - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) { + for (const auto &LibPath : getLibraryPaths()) { +SmallString<128> P(LibPath); llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix); -return P.str(); +if (getVFS().exists(P)) + return P.str(); } StringRef Arch = getArchNameForCompilerRTLib(*this, Args); @@ -765,6 +771,10 @@ for (const auto &LibPath : getFilePaths()) if(LibPath.length() > 0) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); + + for (const auto &LibPath : getLibraryPaths()) +if(LibPath.length() > 0) + CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); } void ToolChain::AddCCKextLibArgs(const ArgList &Args, Index: clang/include/clang/Driver/ToolChain.h === --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -122,6 +122,9 @@ /// The list of toolchain specific path prefixes to search for programs. path_list ProgramPaths; + /// The list of toolchain specific path prefixes to search for libraries. + path_list LibraryPaths; + mutable std::unique_ptr Clang; mutable std::unique_ptr Assemble; mutable std::unique_ptr Link; @@ -219,6 +222,9 @@ path_list &getProgramPaths() { return ProgramPaths; } const path_list &getProgramPaths() const { return ProgramPaths; } + path_list &getLibraryPaths() { return LibraryPaths; } + const path_list &getLibraryPaths() const { return LibraryPaths; } + const MultilibSet &getMultilibs() const { return Multilibs; } const SanitizerArgs& getSanitizerArgs() const; Index: clang/lib/Driver/ToolChain.cpp === --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -74,10 +74,17 @@ const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { - SmallString<128> P(D.ResourceDir); + SmallString<128> P; + + P.assign(D.ResourceDir); llvm::sys::path::append(P, D.getTargetTriple(), "lib"); if (getVFS().exists(P)) -getFilePaths().push_back(P.str()); +getLibraryPaths().push_back(P.str()); + +
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
phosek added a comment. I also need to create the following empty files for tests to pass (somehow those are not displayed by Phabricator): clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.asan-preinit.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.asan.so clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.builtins.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.fuzzer.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/aarch64-fuchsia/lib/libclang_rt.scudo.so clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/i386-linux-gnu/lib/libclang_rt.builtins.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.asan-preinit.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.asan.so clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.builtins.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.fuzzer.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-fuchsia/lib/libclang_rt.scudo.so clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/x86_64-linux-gnu/lib/libclang_rt.builtins.a Repository: rC Clang https://reviews.llvm.org/D50547 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
phosek updated this revision to Diff 161818. Repository: rC Clang https://reviews.llvm.org/D50547 Files: clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChain.cpp Index: clang/lib/Driver/ToolChain.cpp === --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -74,10 +74,8 @@ const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) -getFilePaths().push_back(P.str()); + if (llvm::Optional TargetLibPath = getTargetLibPath()) +getFilePaths().push_back(*TargetLibPath); std::string CandidateLibPath = getArchSpecificLibPath(); if (getVFS().exists(CandidateLibPath)) @@ -362,10 +360,8 @@ const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a"); - const Driver &D = getDriver(); - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) { + if (llvm::Optional TargetLibPath = getTargetLibPath()) { +SmallString<128> P(*TargetLibPath); llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix); return P.str(); } @@ -384,6 +380,21 @@ return Args.MakeArgString(getCompilerRT(Args, Component, Shared)); } +Optional ToolChain::getTargetLibPath() const { + const Driver &D = getDriver(); + SmallString<128> P(D.ResourceDir); + llvm::sys::path::append(P, D.getTargetTriple(), "lib"); + if (getVFS().exists(P)) { +return std::string(P.str()); + } else { +P.assign(D.ResourceDir); +llvm::sys::path::append(P, Triple.str(), "lib"); +if (getVFS().exists(P)) + return std::string(P.str()); + } + return None; +} + std::string ToolChain::getArchSpecificLibPath() const { SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getOSLibName(), Index: clang/include/clang/Driver/ToolChain.h === --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -362,6 +362,10 @@ StringRef Component, bool Shared = false) const; + // Returns /lib/. This is used by runtimes to find + // per-target libraries. + Optional getTargetLibPath() const; + // Returns /lib//. This is used by runtimes (such // as OpenMP) to find arch-specific libraries. std::string getArchSpecificLibPath() const; Index: clang/lib/Driver/ToolChain.cpp === --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -74,10 +74,8 @@ const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) -getFilePaths().push_back(P.str()); + if (llvm::Optional TargetLibPath = getTargetLibPath()) +getFilePaths().push_back(*TargetLibPath); std::string CandidateLibPath = getArchSpecificLibPath(); if (getVFS().exists(CandidateLibPath)) @@ -362,10 +360,8 @@ const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a"); - const Driver &D = getDriver(); - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) { + if (llvm::Optional TargetLibPath = getTargetLibPath()) { +SmallString<128> P(*TargetLibPath); llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix); return P.str(); } @@ -384,6 +380,21 @@ return Args.MakeArgString(getCompilerRT(Args, Component, Shared)); } +Optional ToolChain::getTargetLibPath() const { + const Driver &D = getDriver(); + SmallString<128> P(D.ResourceDir); + llvm::sys::path::append(P, D.getTargetTriple(), "lib"); + if (getVFS().exists(P)) { +return std::string(P.str()); + } else { +P.assign(D.ResourceDir); +llvm::sys::path::append(P, Triple.str(), "lib"); +if (getVFS().exists(P)) + return std::string(P.str()); + } + return None; +} + std::string ToolChain::getArchSpecificLibPath() const { SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getOSLibName(), Index: clang/include/clang/Driver/ToolChain.h === --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -362,6 +362,10 @@
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
beanz added a comment. Just want to bring an IRC conversation that I had with @phosek into the proper code review. This patch is great as-is, but if we want to extend this to Darwin there are some problems because of how Darwin handles triples. Specifically Darwin has multiple potentially valid triples that can mean the same things. For example x86_64-apple-darwin17.7.0 and x86_64-apple-macos10.13.6 are 100% interchangeable (even down to referring to the same OS version). Things get even stranger when you start talking about the -simulator triples... This means that to support this in Darwin we need to support iterating over a list of triples. We also probably want to cache that list so that we don't run `getVFS().exists(...)` over and over again. @phosek said on IRC he will update the patch to reflect our conversation. Thanks @phosek for all the great work on this! Repository: rC Clang https://reviews.llvm.org/D50547 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
beanz accepted this revision. beanz added a comment. This revision is now accepted and ready to land. LGTM! Repository: rC Clang https://reviews.llvm.org/D50547 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
phosek added a comment. In https://reviews.llvm.org/D50547#1198218, @rnk wrote: > Would it be to much to check both the normalized and non-normalized? Done, currently I'm only checking the provided target triple followed by the normalized one, I'm not checking the effective triple but it'd be easy to add if we decide to do that as well. Repository: rC Clang https://reviews.llvm.org/D50547 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
phosek updated this revision to Diff 161031. Repository: rC Clang https://reviews.llvm.org/D50547 Files: clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChain.cpp Index: clang/lib/Driver/ToolChain.cpp === --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -74,10 +74,8 @@ const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) -getFilePaths().push_back(P.str()); + if (llvm::Optional TargetLibPath = getTargetLibPath()) +getFilePaths().push_back(*TargetLibPath); std::string CandidateLibPath = getArchSpecificLibPath(); if (getVFS().exists(CandidateLibPath)) @@ -362,10 +360,8 @@ const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a"); - const Driver &D = getDriver(); - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) { + if (llvm::Optional TargetLibPath = getTargetLibPath()) { +SmallString<128> P(*TargetLibPath); llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix); return P.str(); } @@ -384,6 +380,21 @@ return Args.MakeArgString(getCompilerRT(Args, Component, Shared)); } +Optional ToolChain::getTargetLibPath() const { + const Driver &D = getDriver(); + SmallString<128> P(D.ResourceDir); + llvm::sys::path::append(P, D.getTargetTriple(), "lib"); + if (getVFS().exists(P)) { +return std::string(P.str()); + } else { +P.assign(D.ResourceDir); +llvm::sys::path::append(P, Triple.str(), "lib"); +if (getVFS().exists(P)) + return std::string(P.str()); + } + return None; +} + std::string ToolChain::getArchSpecificLibPath() const { SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getOSLibName(), Index: clang/include/clang/Driver/ToolChain.h === --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -362,6 +362,10 @@ StringRef Component, bool Shared = false) const; + // Returns /lib/. This is used by runtimes to find + // per-target libraries. + Optional getTargetLibPath() const; + // Returns /lib//. This is used by runtimes (such // as OpenMP) to find arch-specific libraries. std::string getArchSpecificLibPath() const; Index: clang/lib/Driver/ToolChain.cpp === --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -74,10 +74,8 @@ const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) -getFilePaths().push_back(P.str()); + if (llvm::Optional TargetLibPath = getTargetLibPath()) +getFilePaths().push_back(*TargetLibPath); std::string CandidateLibPath = getArchSpecificLibPath(); if (getVFS().exists(CandidateLibPath)) @@ -362,10 +360,8 @@ const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a"); - const Driver &D = getDriver(); - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) { + if (llvm::Optional TargetLibPath = getTargetLibPath()) { +SmallString<128> P(*TargetLibPath); llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix); return P.str(); } @@ -384,6 +380,21 @@ return Args.MakeArgString(getCompilerRT(Args, Component, Shared)); } +Optional ToolChain::getTargetLibPath() const { + const Driver &D = getDriver(); + SmallString<128> P(D.ResourceDir); + llvm::sys::path::append(P, D.getTargetTriple(), "lib"); + if (getVFS().exists(P)) { +return std::string(P.str()); + } else { +P.assign(D.ResourceDir); +llvm::sys::path::append(P, Triple.str(), "lib"); +if (getVFS().exists(P)) + return std::string(P.str()); + } + return None; +} + std::string ToolChain::getArchSpecificLibPath() const { SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getOSLibName(), Index: clang/include/clang/Driver/ToolChain.h === --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -362,6 +362,10 @@
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
rnk added a comment. Would it be to much to check both the normalized and non-normalized? Repository: rC Clang https://reviews.llvm.org/D50547 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path
phosek created this revision. phosek added reviewers: rnk, echristo, chandlerc, beanz. Herald added subscribers: cfe-commits, JDevlieghere, mgorny. Previously we used target triple as provided which matches the GCC behavior, but it also means that all clients have to be consistent in their spelling of target triples since e.g. x86_64-linux-gnu and x86_64-unknown-linux-gnu will result in Clang driver looking at two different paths when searching for runtime libraries. Unfortunately, as it turned out many clients aren't consistent in their spelling of target triples, e.g. many Linux distributions use the shorter spelling but config.guess and rustc insist on using the normalized variant which is causing issues. To avoid having to ship multiple copies of runtimes for different triple spelling or rely on symlinks which are not portable, we should use the normalized triple when constructing paths for multiarch runtimes. Repository: rC Clang https://reviews.llvm.org/D50547 Files: clang/cmake/caches/Fuchsia-stage2.cmake clang/lib/Driver/ToolChain.cpp Index: clang/lib/Driver/ToolChain.cpp === --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -75,7 +75,7 @@ : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); + llvm::sys::path::append(P, Triple.str(), "lib"); if (getVFS().exists(P)) getFilePaths().push_back(P.str()); @@ -364,7 +364,7 @@ const Driver &D = getDriver(); SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); + llvm::sys::path::append(P, TT.str(), "lib"); if (getVFS().exists(P)) { llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix); return P.str(); Index: clang/cmake/caches/Fuchsia-stage2.cmake === --- clang/cmake/caches/Fuchsia-stage2.cmake +++ clang/cmake/caches/Fuchsia-stage2.cmake @@ -35,31 +35,31 @@ foreach(target i386;x86_64;armhf;aarch64) if(LINUX_${target}_SYSROOT) # Set the per-target builtins options. - list(APPEND BUILTIN_TARGETS "${target}-linux-gnu") - set(BUILTINS_${target}-linux-gnu_CMAKE_SYSTEM_NAME Linux CACHE STRING "") - set(BUILTINS_${target}-linux-gnu_CMAKE_BUILD_TYPE Release CACHE STRING "") - set(BUILTINS_${target}-linux-gnu_CMAKE_SYSROOT ${LINUX_${target}_SYSROOT} CACHE STRING "") + list(APPEND BUILTIN_TARGETS "${target}-unknown-linux-gnu") + set(BUILTINS_${target}-unknown-linux-gnu_CMAKE_SYSTEM_NAME Linux CACHE STRING "") + set(BUILTINS_${target}-unknown-linux-gnu_CMAKE_BUILD_TYPE Release CACHE STRING "") + set(BUILTINS_${target}-unknown-linux-gnu_CMAKE_SYSROOT ${LINUX_${target}_SYSROOT} CACHE STRING "") # Set the per-target runtimes options. - list(APPEND RUNTIME_TARGETS "${target}-linux-gnu") - set(RUNTIMES_${target}-linux-gnu_CMAKE_SYSTEM_NAME Linux CACHE STRING "") - set(RUNTIMES_${target}-linux-gnu_CMAKE_BUILD_TYPE Release CACHE STRING "") - set(RUNTIMES_${target}-linux-gnu_CMAKE_SYSROOT ${LINUX_${target}_SYSROOT} CACHE STRING "") - set(RUNTIMES_${target}-linux-gnu_LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBUNWIND_INSTALL_LIBRARY OFF CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBCXXABI_INSTALL_LIBRARY OFF CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_SANITIZER_CXX_ABI "libc++" CACHE STRING "") - set(RUNTIMES_${target}-linux-gnu_SANITIZER_CXX_ABI_INTREE ON CACHE BOOL "") - set(RUNTIMES_${target}-linux-gnu_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "") + list(APPEND RUNTIME_TARGETS "${target}-unknown-linux-gnu") + set(RUNTIMES_${target}-unknown-linux-gnu_CMAKE_SYSTEM_NAME Linux CACHE STRING "") + set(RUNTIMES_${target}-unknown-linux-gnu_CMAKE_BUILD_TYPE Release CACHE STRING "") + set(RUNTIMES_${target}-unknown-linux-gnu_CMAKE_SYSROOT ${LINUX_${target}_SYSROOT} CACHE STRING "") + set(RUNTIMES_${target