]> granicus.if.org Git - clang/commitdiff
Make the triple an explicit argument of FindTargetProgramPath.
authorJoerg Sonnenberger <joerg@bec.de>
Mon, 16 May 2011 13:35:02 +0000 (13:35 +0000)
committerJoerg Sonnenberger <joerg@bec.de>
Mon, 16 May 2011 13:35:02 +0000 (13:35 +0000)
Preserve the original triple in the NetBSD toolchain when using -m32 or
-m64 and the resulting effective target is different from the triple it
started with. This allows -m32 to use the same assembler/linking in
cross-compiling mode and avoids confusion about passing down target
specific flags in that case like --32.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131404 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/HostInfo.cpp
lib/Driver/ToolChains.cpp
lib/Driver/ToolChains.h
lib/Driver/Tools.cpp
lib/Driver/Tools.h

index 198af54c035a749949ff06ccad2d8d4b5fab56bc..3b1c2c73fd74950de16608e0504ff2efa3e7ad60 100644 (file)
@@ -414,15 +414,20 @@ ToolChain *NetBSDHostInfo::CreateToolChain(const ArgList &Args,
         (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
     }
   }
+  llvm::Triple TargetTriple(getTriple());
+  TargetTriple.setArchName(ArchName);
 
-  ToolChain *&TC = ToolChains[ArchName];
-  if (!TC) {
-    llvm::Triple TCTriple(getTriple());
-    TCTriple.setArchName(ArchName);
+  ToolChain *TC;
 
-    TC = new toolchains::NetBSD(*this, TCTriple);
+  // XXX Cache toolchain even if -m32 is used
+  if (Arch == ArchName) {
+    TC = ToolChains[ArchName];
+    if (TC)
+      return TC;
   }
 
+  TC = new toolchains::NetBSD(*this, TargetTriple, getTriple());
+
   return TC;
 }
 
index 4668d7303fc7978c60f057c83b34dba9bd4260e6..d0622904576f814f4a7b79df7b6269e02e8a6fad 100644 (file)
@@ -1043,14 +1043,14 @@ Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA,
 
 /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly.
 
-NetBSD::NetBSD(const HostInfo &Host, const llvm::Triple& Triple)
-  : Generic_ELF(Host, Triple) {
+NetBSD::NetBSD(const HostInfo &Host, const llvm::Triple& Triple,
+               const llvm::Triple& ToolTriple)
+  : Generic_ELF(Host, Triple), ToolTriple(ToolTriple) {
 
   // Determine if we are compiling 32-bit code on an x86_64 platform.
   bool Lib32 = false;
-  if (Triple.getArch() == llvm::Triple::x86 &&
-      llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
-        llvm::Triple::x86_64)
+  if (ToolTriple.getArch() == llvm::Triple::x86_64 &&
+      Triple.getArch() == llvm::Triple::x86)
     Lib32 = true;
 
   if (getDriver().UseStdLib) {
@@ -1080,10 +1080,11 @@ Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA,
       if (UseIntegratedAs)
         T = new tools::ClangAs(*this);
       else
-        T = new tools::netbsd::Assemble(*this);
+        T = new tools::netbsd::Assemble(*this, ToolTriple);
       break;
     case Action::LinkJobClass:
-      T = new tools::netbsd::Link(*this); break;
+      T = new tools::netbsd::Link(*this, ToolTriple);
+      break;
     default:
       T = &Generic_GCC::SelectTool(C, JA, Inputs);
     }
index 7a1a05025296cf78cb1f3e6028578bdd8cce84f7..ace9b847919f16ad91717d98e341a62eeaf1db47 100644 (file)
@@ -308,8 +308,11 @@ public:
 };
 
 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
+  const llvm::Triple ToolTriple;
+
 public:
-  NetBSD(const HostInfo &Host, const llvm::Triple& Triple);
+  NetBSD(const HostInfo &Host, const llvm::Triple& Triple,
+         const llvm::Triple& ToolTriple);
 
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
                            const ActionList &Inputs) const;
index a8998c49a7028d5f979da7fda07874aec0356559..19a830cac1443f76ac0882d9c830ac7c8a183d51 100644 (file)
@@ -47,8 +47,9 @@ using namespace clang::driver::tools;
 /// FindTargetProgramPath - Return path of the target specific version of
 /// ProgName.  If it doesn't exist, return path of ProgName itself.
 static std::string FindTargetProgramPath(const ToolChain &TheToolChain,
+                                         const std::string TripleString,
                                          const char *ProgName) {
-  std::string Executable(TheToolChain.getTripleString() + "-" + ProgName);
+  std::string Executable(TripleString + "-" + ProgName);
   std::string Path(TheToolChain.GetProgramPath(Executable.c_str()));
   if (Path != Executable)
     return Path;
@@ -3597,7 +3598,8 @@ void netbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
 
   // When building 32-bit code on NetBSD/amd64, we have to explicitly
   // instruct as in the base system to assemble 32-bit code.
-  if (getToolChain().getArchName() == "i386")
+  if (ToolTriple.getArch() == llvm::Triple::x86_64 &&
+      getToolChain().getArch() == llvm::Triple::x86)
     CmdArgs.push_back("--32");
 
 
@@ -3620,7 +3622,8 @@ void netbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
   }
 
   const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(),
-                                                              "as"));
+                                                      ToolTriple.getTriple(),
+                                                      "as"));
   C.addCommand(new Command(JA, *this, Exec, CmdArgs));
 }
 
@@ -3651,7 +3654,8 @@ void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
 
   // When building 32-bit code on NetBSD/amd64, we have to explicitly
   // instruct ld in the base system to link 32-bit code.
-  if (getToolChain().getArchName() == "i386") {
+  if (ToolTriple.getArch() == llvm::Triple::x86_64 &&
+      getToolChain().getArch() == llvm::Triple::x86) {
     CmdArgs.push_back("-m");
     CmdArgs.push_back("elf_i386");
   }
@@ -3734,7 +3738,8 @@ void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
   }
 
   const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(),
-                                                              "ld"));
+                                                      ToolTriple.getTriple(),
+                                                      "ld"));
   C.addCommand(new Command(JA, *this, Exec, CmdArgs));
 }
 
index 93abf75722eb9f68ef0f0dad75aa15278aead3a4..4a5a7e47452620254a4ca2fe0a2f72492acf6d90 100644 (file)
@@ -14,6 +14,7 @@
 #include "clang/Driver/Types.h"
 #include "clang/Driver/Util.h"
 
+#include "llvm/ADT/Triple.h"
 #include "llvm/Support/Compiler.h"
 
 namespace clang {
@@ -338,9 +339,12 @@ namespace freebsd {
   /// netbsd -- Directly call GNU Binutils assembler and linker
 namespace netbsd {
   class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
+  private:
+    const llvm::Triple ToolTriple;
+
   public:
-    Assemble(const ToolChain &TC) : Tool("netbsd::Assemble", "assembler",
-                                         TC) {}
+    Assemble(const ToolChain &TC, const llvm::Triple &ToolTriple)
+      : Tool("netbsd::Assemble", "assembler", TC), ToolTriple(ToolTriple) {}
 
     virtual bool hasIntegratedCPP() const { return false; }
 
@@ -351,8 +355,12 @@ namespace netbsd {
                               const char *LinkingOutput) const;
   };
   class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
+  private:
+    const llvm::Triple ToolTriple;
+
   public:
-    Link(const ToolChain &TC) : Tool("netbsd::Link", "linker", TC) {}
+    Link(const ToolChain &TC, const llvm::Triple &ToolTriple)
+      : Tool("netbsd::Ling", "linker", TC), ToolTriple(ToolTriple) {}
 
     virtual bool hasIntegratedCPP() const { return false; }