[Driver] Check normalized triples for multiarch runtime path

Previously we only 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.

Unfortunatelly, 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 also check the normalized
triple when constructing paths for multiarch runtimes.

Differential Revision: https://reviews.llvm.org/D50547

llvm-svn: 340471
This commit is contained in:
Petr Hosek 2018-08-22 22:56:46 +00:00
parent e2efbbe571
commit 678c1c6ccc
14 changed files with 23 additions and 7 deletions

View File

@ -116,6 +116,9 @@ private:
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 @@ public:
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; }

View File

@ -74,10 +74,17 @@ ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
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 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
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::AddCXXStdlibLibArgs(const ArgList &Args,
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));