[PATCH] D87901: [Driver] Filter out <libdir>/gcc and <libdir>/gcc-cross if they do not exists

Dmitry Antipov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 24 00:39:08 PDT 2020


dmantipov updated this revision to Diff 293955.
dmantipov added a comment.

Prefer a bit more meaningful variable names.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87901/new/

https://reviews.llvm.org/D87901

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h


Index: clang/lib/Driver/ToolChains/Gnu.h
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.h
+++ clang/lib/Driver/ToolChains/Gnu.h
@@ -215,6 +215,10 @@
     // Gentoo-specific toolchain configurations are stored here.
     const std::string GentooConfigDir = "/etc/env.d/gcc";
 
+    // Internal flags used to filter out <libdir>/gcc and <libdir>/gcc-cross.
+    bool GCCDirExists;
+    bool GCCCrossDirExists;
+
   public:
     explicit GCCInstallationDetector(const Driver &D) : IsValid(false), D(D) {}
     void init(const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args,
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1945,6 +1945,9 @@
       const std::string LibDir = Prefix + Suffix.str();
       if (!D.getVFS().exists(LibDir))
         continue;
+      // Maybe filter out <libdir>/gcc and <libdir>/gcc-cross.
+      GCCDirExists = D.getVFS().exists(LibDir + "/gcc");
+      GCCCrossDirExists = D.getVFS().exists(LibDir + "/gcc-cross");
       // Try to match the exact target triple first.
       ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, TargetTriple.str());
       // Try rest of possible triples.
@@ -2463,12 +2466,13 @@
     // Whether this library suffix is relevant for the triple.
     bool Active;
   } Suffixes[] = {
-      // This is the normal place.
-      {"gcc/" + CandidateTriple.str(), "../..", true},
+      // This is the normal place if Clang is installed alongside with GCC,
+      // probably with the same prefix. But it's likely does not exists in
+      // case of standalone Clang install.
+      {"gcc/" + CandidateTriple.str(), "../..", GCCDirExists},
 
       // Debian puts cross-compilers in gcc-cross.
-      {"gcc-cross/" + CandidateTriple.str(), "../..",
-       TargetTriple.getOS() != llvm::Triple::Solaris},
+      {"gcc-cross/" + CandidateTriple.str(), "../..", GCCCrossDirExists},
 
       // The Freescale PPC SDK has the gcc libraries in
       // <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well. Only do


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87901.293955.patch
Type: text/x-patch
Size: 2191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200924/da7a9eed/attachment.bin>


More information about the cfe-commits mailing list