[cfe-commits] r165430 - in /cfe/trunk: lib/Driver/ToolChains.cpp test/Driver/bitrig.c

Chandler Carruth chandlerc at gmail.com
Mon Oct 8 14:31:38 PDT 2012


Author: chandlerc
Date: Mon Oct  8 16:31:38 2012
New Revision: 165430

URL: http://llvm.org/viewvc/llvm-project?rev=165430&view=rev
Log:
Make Bitrig's clang understand -stdlib= correctly.
With this patch Bitrig can use a different c++ library without pain and
within the normal commandline parameters.

Original patch by David Hill, with lots of fixes and cleanup by me.

Added:
    cfe/trunk/test/Driver/bitrig.c
Modified:
    cfe/trunk/lib/Driver/ToolChains.cpp

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=165430&r1=165429&r2=165430&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Oct  8 16:31:38 2012
@@ -1664,19 +1664,43 @@
       DriverArgs.hasArg(options::OPT_nostdincxx))
     return;
 
-  std::string Triple = getTriple().str();
-  if (Triple.substr(0, 5) == "amd64")
-    Triple.replace(0, 5, "x86_64");
-
-  addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/4.6.2");
-  addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/4.6.2/backward");
-  addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/4.6.2/" + Triple);
+  switch (GetCXXStdlibType(DriverArgs)) {
+  case ToolChain::CST_Libcxx:
+    addSystemInclude(DriverArgs, CC1Args,
+                     getDriver().SysRoot + "/usr/include/c++/");
+    break;
+  case ToolChain::CST_Libstdcxx:
+    addSystemInclude(DriverArgs, CC1Args,
+                     getDriver().SysRoot + "/usr/include/c++/stdc++");
+    addSystemInclude(DriverArgs, CC1Args,
+                     getDriver().SysRoot + "/usr/include/c++/stdc++/backward");
 
+    StringRef Triple = getTriple().str();
+    if (Triple.startswith("amd64"))
+      addSystemInclude(DriverArgs, CC1Args,
+                       getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" +
+                       Triple.substr(5));
+    else
+      addSystemInclude(DriverArgs, CC1Args,
+                       getDriver().SysRoot + "/usr/include/c++/stdc++/" +
+                       Triple);
+    break;
+  }
 }
 
 void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args,
                                  ArgStringList &CmdArgs) const {
-  CmdArgs.push_back("-lstdc++");
+  switch (GetCXXStdlibType(Args)) {
+  case ToolChain::CST_Libcxx:
+    CmdArgs.push_back("-lc++");
+    CmdArgs.push_back("-lcxxrt");
+    // Include supc++ to provide Unwind until provided by libcxx.
+    CmdArgs.push_back("-lgcc");
+    break;
+  case ToolChain::CST_Libstdcxx:
+    CmdArgs.push_back("-lstdc++");
+    break;
+  }
 }
 
 /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.

Added: cfe/trunk/test/Driver/bitrig.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/bitrig.c?rev=165430&view=auto
==============================================================================
--- cfe/trunk/test/Driver/bitrig.c (added)
+++ cfe/trunk/test/Driver/bitrig.c Mon Oct  8 16:31:38 2012
@@ -0,0 +1,14 @@
+// RUN: %clang -no-canonical-prefixes -ccc-clang-archs "" -target amd64-pc-bitrig %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-C %s
+// CHECK-LD-C: clang{{.*}}" "-cc1" "-triple" "amd64-pc-bitrig"
+// CHECK-LD-C: ld{{.*}}" {{.*}} "-lc" "-lclang_rt.amd64"
+
+// RUN: %clangxx -no-canonical-prefixes -ccc-clang-archs "" -target amd64-pc-bitrig %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-CXX %s
+// CHECK-LD-CXX: clang{{.*}}" "-cc1" "-triple" "amd64-pc-bitrig" 
+// CHECK-LD-CXX: ld{{.*}}" {{.*}} "-lstdc++" "-lm" "-lc" "-lclang_rt.amd64"
+
+// RUN: %clangxx -stdlib=libc++ -no-canonical-prefixes -ccc-clang-archs "" -target amd64-pc-bitrig %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-CXX-STDLIB %s
+// CHECK-LD-CXX-STDLIB: clang{{.*}}" "-cc1" "-triple" "amd64-pc-bitrig"
+// CHECK-LD-CXX-STDLIB: ld{{.*}}" {{.*}} "-lc++" "-lcxxrt" "-lgcc" "-lm" "-lc" "-lclang_rt.amd64"





More information about the cfe-commits mailing list