From 5184f69041166257e4c6a15e572d12c676cd0c31 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Mon, 22 Mar 2021 10:14:03 -0700 Subject: [PATCH] Revert "[Driver] Gnu.cpp: drop an unneeded special rule related to sysroot" This reverts commits 56700e937903969a4a95f68c59e38e35daaaa1ea and c2f9086b6184a132ec8cac7edeb620813796e1e8. Breaks multiple Android bots, e.g. https://lab.llvm.org/buildbot/#/builders/77/builds/4777. --- clang/lib/Driver/ToolChains/Gnu.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index a046e8e..193c944 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2832,7 +2832,17 @@ void Generic_GCC::AddMultilibPaths(const Driver &D, SelectedMultilib.osSuffix(), Paths); - addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); + // If the GCC installation we found is inside of the sysroot, we want to + // prefer libraries installed in the parent prefix of the GCC installation. + // It is important to *not* use these paths when the GCC installation is + // outside of the system root as that can pick up unintended libraries. + // This usually happens when there is an external cross compiler on the + // host system, and a more minimal sysroot available that is the target of + // the cross. Note that GCC does include some of these directories in some + // configurations but this seems somewhere between questionable and simply + // a bug. + if (StringRef(LibPath).startswith(SysRoot)) + addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); } } @@ -2851,6 +2861,8 @@ void Generic_GCC::AddMultiarchPaths(const Driver &D, Paths); } + // See comments above on the multilib variant for details of why this is + // included even from outside the sysroot. const std::string &LibPath = std::string(GCCInstallation.getParentLibPath()); const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); @@ -2858,7 +2870,11 @@ void Generic_GCC::AddMultiarchPaths(const Driver &D, addPathIfExists( D, LibPath + "/../" + GCCTriple.str() + "/lib" + Multilib.osSuffix(), Paths); - addPathIfExists(D, LibPath, Paths); + + // See comments above on the multilib variant for details of why this is + // only included from within the sysroot. + if (StringRef(LibPath).startswith(SysRoot)) + addPathIfExists(D, LibPath, Paths); } } -- 2.7.4