[clang] 5184f69 - Revert "[Driver] Gnu.cpp: drop an unneeded special rule related to sysroot"

Arthur Eubanks via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 22 10:16:41 PDT 2021


Author: Arthur Eubanks
Date: 2021-03-22T10:16:19-07:00
New Revision: 5184f69041166257e4c6a15e572d12c676cd0c31

URL: https://github.com/llvm/llvm-project/commit/5184f69041166257e4c6a15e572d12c676cd0c31
DIFF: https://github.com/llvm/llvm-project/commit/5184f69041166257e4c6a15e572d12c676cd0c31.diff

LOG: 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.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Gnu.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index a046e8e7eed8..193c944e7392 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);
   }
 }
 


        


More information about the cfe-commits mailing list