$OpenBSD: patch-tools_clang_lib_Driver_ToolChains_cpp,v 1.10 2017/02/10 09:37:43 ajacoutot Exp $

Use the integrated assembler by default on Sparc and Mips64.

--- tools/clang/lib/Driver/ToolChains.cpp.orig	Wed Jan 25 19:51:14 2017
+++ tools/clang/lib/Driver/ToolChains.cpp	Wed Jan 25 20:44:55 2017
@@ -2919,15 +2919,20 @@ bool Generic_GCC::IsIntegratedAssemblerDefault() const
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
   case llvm::Triple::systemz:
+  case llvm::Triple::sparc:
+  case llvm::Triple::sparcel:
+  case llvm::Triple::sparcv9:
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
     return true;
   case llvm::Triple::mips64:
   case llvm::Triple::mips64el:
-    // Enabled for Debian mips64/mips64el only. Other targets are unable to
+    // Enabled for Debian and OpenBSD mips64/mips64el only. Other targets are unable to
     // distinguish N32 from N64.
     if (getTriple().getEnvironment() == llvm::Triple::GNUABI64)
       return true;
+    if (getTriple().getOS() == llvm::Triple::OpenBSD)
+      return true;
     return false;
   default:
     return false;
@@ -3609,8 +3614,7 @@ void Haiku::addLibStdCxxIncludePaths(const llvm::opt::
 OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple,
                  const ArgList &Args)
     : Generic_ELF(D, Triple, Args) {
-  getFilePaths().push_back(getDriver().Dir + "/../lib");
-  getFilePaths().push_back("/usr/lib");
+  getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
 }
 
 Tool *OpenBSD::buildAssembler() const {
@@ -3618,6 +3622,50 @@ Tool *OpenBSD::buildAssembler() const {
 }
 
 Tool *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); }
+
+ToolChain::CXXStdlibType OpenBSD::GetCXXStdlibType(const ArgList &Args) const {
+  if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
+    StringRef Value = A->getValue();
+    if (Value == "libstdc++")
+      return ToolChain::CST_Libstdcxx;
+    if (Value == "libc++")
+      return ToolChain::CST_Libcxx;
+
+    getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args);
+  }
+  return ToolChain::CST_Libstdcxx;
+}
+
+void OpenBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
+                                          ArgStringList &CC1Args) const {
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+      DriverArgs.hasArg(options::OPT_nostdincxx))
+    return;
+
+  /* XXX handle libc++ includes */
+
+  addSystemInclude(DriverArgs, CC1Args,
+                   getDriver().SysRoot + "${LOCALBASE}/include/c++/${GCC_VER}");
+
+  addSystemInclude(DriverArgs, CC1Args,
+                   getDriver().SysRoot + "${LOCALBASE}/include/c++/${GCC_VER}/${GCC_CONFIG}");
+  addSystemInclude(DriverArgs, CC1Args,
+                   getDriver().SysRoot + "${LOCALBASE}/include/c++/${GCC_VER}/backward");
+}
+
+void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args,
+                                 ArgStringList &CmdArgs) const {
+ switch (GetCXXStdlibType(Args)) {
+  case ToolChain::CST_Libcxx:
+    CmdArgs.push_back("-lc++");
+    CmdArgs.push_back("-lc++abi");
+    CmdArgs.push_back("-lpthread");
+    break;
+  case ToolChain::CST_Libstdcxx:
+    CmdArgs.push_back("-lestdc++");
+    break;
+  }
+}
 
 /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly.
 
