r189212 - Teach the Linux toolchain about more modern Gentoo installations of GCC

Chandler Carruth chandlerc at gmail.com
Mon Aug 26 01:59:53 PDT 2013


Author: chandlerc
Date: Mon Aug 26 03:59:53 2013
New Revision: 189212

URL: http://llvm.org/viewvc/llvm-project?rev=189212&view=rev
Log:
Teach the Linux toolchain about more modern Gentoo installations of GCC
which add another wrinkle to the installation of the libstdc++ headers.

Add at least some basic testing of the weirdnesses of Gentoo's layout.

Added:
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/crtbegin.o
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/.keep
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/x86_64-pc-linux-gnu/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/x86_64-pc-linux-gnu/lib/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/x86_64-pc-linux-gnu/lib/.keep
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/crtbegin.o
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6/.keep
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/x86_64-pc-linux-gnu/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/x86_64-pc-linux-gnu/lib/
    cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/x86_64-pc-linux-gnu/lib/.keep
Modified:
    cfe/trunk/lib/Driver/ToolChains.cpp
    cfe/trunk/lib/Driver/ToolChains.h
    cfe/trunk/test/Driver/linux-header-search.cpp

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=189212&r1=189211&r2=189212&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Aug 26 03:59:53 2013
@@ -907,17 +907,19 @@ Darwin_Generic_GCC::ComputeEffectiveClan
 /// This is the primary means of forming GCCVersion objects.
 /*static*/
 Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) {
-  const GCCVersion BadVersion = { VersionText.str(), -1, -1, -1, "" };
+  const GCCVersion BadVersion = { VersionText.str(), -1, -1, -1, "", "", "" };
   std::pair<StringRef, StringRef> First = VersionText.split('.');
   std::pair<StringRef, StringRef> Second = First.second.split('.');
 
-  GCCVersion GoodVersion = { VersionText.str(), -1, -1, -1, "" };
+  GCCVersion GoodVersion = { VersionText.str(), -1, -1, -1, "", "", "" };
   if (First.first.getAsInteger(10, GoodVersion.Major) ||
       GoodVersion.Major < 0)
     return BadVersion;
+  GoodVersion.MajorStr = First.first.str();
   if (Second.first.getAsInteger(10, GoodVersion.Minor) ||
       GoodVersion.Minor < 0)
     return BadVersion;
+  GoodVersion.MinorStr = Second.first.str();
 
   // First look for a number prefix and parse that if present. Otherwise just
   // stash the entire patch string in the suffix, and leave the number
@@ -935,7 +937,7 @@ Generic_GCC::GCCVersion Linux::GCCVersio
       if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) ||
           GoodVersion.Patch < 0)
         return BadVersion;
-      GoodVersion.PatchSuffix = PatchText.substr(EndNumber).str();
+      GoodVersion.PatchSuffix = PatchText.substr(EndNumber);
     }
   }
 
@@ -2578,20 +2580,22 @@ void Linux::AddClangCXXStdlibIncludeArgs
   // equivalent to '/usr/include/c++/X.Y' in almost all cases.
   StringRef LibDir = GCCInstallation.getParentLibPath();
   StringRef InstallDir = GCCInstallation.getInstallPath();
-  StringRef Version = GCCInstallation.getVersion().Text;
   StringRef TripleStr = GCCInstallation.getTriple().str();
+  const GCCVersion &Version = GCCInstallation.getVersion();
 
   if (addLibStdCXXIncludePaths(
-          LibDir.str() + "/../include", "/c++/" + Version.str(), TripleStr,
+          LibDir.str() + "/../include", "/c++/" + Version.Text, TripleStr,
           GCCInstallation.getBiarchSuffix(), DriverArgs, CC1Args))
     return;
 
   const std::string IncludePathCandidates[] = {
     // Gentoo is weird and places its headers inside the GCC install, so if the
-    // first attempt to find the headers fails, try this pattern.
-    InstallDir.str() + "/include/g++-v4",
+    // first attempt to find the headers fails, try these patterns.
+    InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." +
+        Version.MinorStr,
+    InstallDir.str() + "/include/g++-v" + Version.MajorStr,
     // Android standalone toolchain has C++ headers in yet another place.
-    LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.str(),
+    LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text,
     // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++,
     // without a subdirectory corresponding to the gcc version.
     LibDir.str() + "/../include/c++",

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=189212&r1=189211&r2=189212&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Mon Aug 26 03:59:53 2013
@@ -50,6 +50,9 @@ protected:
     /// \brief The parsed major, minor, and patch numbers.
     int Major, Minor, Patch;
 
+    /// \brief The text of the parsed major, and major+minor versions.
+    std::string MajorStr, MinorStr;
+
     /// \brief Any textual suffix on the patch number.
     std::string PatchSuffix;
 

Added: cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/crtbegin.o
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/crtbegin.o?rev=189212&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g%2B%2B-v4/.keep?rev=189212&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/x86_64-pc-linux-gnu/lib/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/x86_64-pc-linux-gnu/lib/.keep?rev=189212&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/crtbegin.o
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/crtbegin.o?rev=189212&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g%2B%2B-v4.6/.keep?rev=189212&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/x86_64-pc-linux-gnu/lib/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/x86_64-pc-linux-gnu/lib/.keep?rev=189212&view=auto
==============================================================================
    (empty)

Modified: cfe/trunk/test/Driver/linux-header-search.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/linux-header-search.cpp?rev=189212&r1=189211&r2=189212&view=diff
==============================================================================
--- cfe/trunk/test/Driver/linux-header-search.cpp (original)
+++ cfe/trunk/test/Driver/linux-header-search.cpp Mon Aug 26 03:59:53 2013
@@ -115,3 +115,32 @@
 // CHECK-DEBIAN-PPC64: "-internal-externc-isystem" "[[SYSROOT]]/usr/include/powerpc64-linux-gnu"
 // CHECK-DEBIAN-PPC64: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-DEBIAN-PPC64: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+//
+// Test Gentoo's weirdness both before and after they changed it in their GCC
+// 4.6.4 release.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN:     -target x86_64-unknown-linux-gnu \
+// RUN:     --sysroot=%S/Inputs/gentoo_linux_gcc_4.6.2_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-6-2 %s
+// CHECK-GENTOO-4-6-2: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-6-2: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-6-2: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4"
+// CHECK-GENTOO-4-6-2: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/x86_64-pc-linux-gnu"
+// CHECK-GENTOO-4-6-2: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/backward"
+// CHECK-GENTOO-4-6-2: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-6-2: "-internal-isystem" "{{.*}}{{/|\\\\}}lib{{(64|32)?}}{{/|\\\\}}clang{{/|\\\\}}{{[0-9]\.[0-9]}}{{/|\\\\}}include"
+// CHECK-GENTOO-4-6-2: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-6-2: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN:     -target x86_64-unknown-linux-gnu \
+// RUN:     --sysroot=%S/Inputs/gentoo_linux_gcc_4.6.4_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-6-4 %s
+// CHECK-GENTOO-4-6-4: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-6-4: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-6-4: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6"
+// CHECK-GENTOO-4-6-4: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6/x86_64-pc-linux-gnu"
+// CHECK-GENTOO-4-6-4: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6/backward"
+// CHECK-GENTOO-4-6-4: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-6-4: "-internal-isystem" "{{.*}}{{/|\\\\}}lib{{(64|32)?}}{{/|\\\\}}clang{{/|\\\\}}{{[0-9]\.[0-9]}}{{/|\\\\}}include"
+// CHECK-GENTOO-4-6-4: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-6-4: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"





More information about the cfe-commits mailing list