r187427 - Start keeping track of what work was done to detect a GCC installation

Chandler Carruth chandlerc at gmail.com
Tue Jul 30 10:57:09 PDT 2013


Author: chandlerc
Date: Tue Jul 30 12:57:09 2013
New Revision: 187427

URL: http://llvm.org/viewvc/llvm-project?rev=187427&view=rev
Log:
Start keeping track of what work was done to detect a GCC installation
on the system, and report it when running the driver in verbose mode.
Without this it is essentially impossible to understand why a particular
GCC toolchain is used by Clang for libstdc++, libgcc, etc.

This also required threading a hook through the toolchain layers for
a specific toolchain implementation to print custom information under
'clang -v'. The naming here isn't spectacular. Suggestions welcome.

Modified:
    cfe/trunk/include/clang/Driver/ToolChain.h
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/ToolChains.cpp
    cfe/trunk/lib/Driver/ToolChains.h

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=187427&r1=187426&r2=187427&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Tue Jul 30 12:57:09 2013
@@ -145,6 +145,13 @@ public:
   std::string GetFilePath(const char *Name) const;
   std::string GetProgramPath(const char *Name) const;
 
+  /// \brief Dispatch to the specific toolchain for verbose printing.
+  ///
+  /// This is used when handling the verbose option to print detailed,
+  /// toolchain-specific information useful for understanding the behavior of
+  /// the driver on a specific platform.
+  virtual void printVerboseInfo(raw_ostream &OS) const {};
+
   // Platform defaults information
 
   /// HasNativeLTOLinker - Check whether the linker and related tools have

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=187427&r1=187426&r2=187427&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Jul 30 12:57:09 2013
@@ -695,6 +695,10 @@ bool Driver::HandleImmediateArgs(const C
   }
 
   const ToolChain &TC = C.getDefaultToolChain();
+
+  if (C.getArgs().hasArg(options::OPT_v))
+    TC.printVerboseInfo(llvm::errs());
+
   if (C.getArgs().hasArg(options::OPT_print_search_dirs)) {
     llvm::outs() << "programs: =";
     for (ToolChain::path_list::const_iterator it = TC.getProgramPaths().begin(),

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=187427&r1=187426&r2=187427&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Tue Jul 30 12:57:09 2013
@@ -1049,6 +1049,16 @@ Generic_GCC::GCCInstallationDetector::GC
   }
 }
 
+void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const {
+  for (SmallVectorImpl<std::string>::const_iterator
+           I = CandidateGCCInstallPaths.begin(),
+           E = CandidateGCCInstallPaths.end();
+       I != E; ++I)
+    OS << "Found candidate GCC installation: " << *I << "\n";
+
+  OS << "Selected GCC installation: " << GCCInstallPath << "\n";
+}
+
 /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples(
     const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple,
     SmallVectorImpl<StringRef> &LibDirs,
@@ -1383,6 +1393,7 @@ void Generic_GCC::GCCInstallationDetecto
     llvm::error_code EC;
     for (llvm::sys::fs::directory_iterator LI(LibDir + LibSuffix, EC), LE;
          !EC && LI != LE; LI = LI.increment(EC)) {
+      CandidateGCCInstallPaths.push_back(LI->path());
       StringRef VersionText = llvm::sys::path::filename(LI->path());
       GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
       static const GCCVersion MinVersion = { "4.1.1", 4, 1, 1, "" };
@@ -1458,6 +1469,11 @@ Tool *Generic_GCC::buildLinker() const {
   return new tools::gcc::Link(*this);
 }
 
+void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {
+  // Print the information about how we detected the GCC installation.
+  GCCInstallation.print(OS);
+}
+
 bool Generic_GCC::IsUnwindTablesDefault() const {
   return getArch() == llvm::Triple::x86_64;
 }

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=187427&r1=187426&r2=187427&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Tue Jul 30 12:57:09 2013
@@ -68,7 +68,6 @@ protected:
   /// information about it. It starts from the host information provided to the
   /// Driver, and has logic for fuzzing that where appropriate.
   class GCCInstallationDetector {
-
     bool IsValid;
     llvm::Triple GCCTriple;
 
@@ -79,6 +78,10 @@ protected:
 
     GCCVersion Version;
 
+    // We retain the list of install paths that were considered and rejected in
+    // order to print out detailed information in verbose mode.
+    SmallVector<std::string, 4> CandidateGCCInstallPaths;
+
   public:
     GCCInstallationDetector(const Driver &D, const llvm::Triple &TargetTriple,
                             const llvm::opt::ArgList &Args);
@@ -102,6 +105,9 @@ protected:
     /// \brief Get the detected GCC version string.
     const GCCVersion &getVersion() const { return Version; }
 
+    /// \brief Print information about the detected GCC installation.
+    void print(raw_ostream &OS) const;
+
   private:
     static void
     CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
@@ -125,6 +131,8 @@ public:
               const llvm::opt::ArgList &Args);
   ~Generic_GCC();
 
+  virtual void printVerboseInfo(raw_ostream &OS) const;
+
   virtual bool IsUnwindTablesDefault() const;
   virtual bool isPICDefault() const;
   virtual bool isPIEDefault() const;





More information about the cfe-commits mailing list