Make the triple an explicit argument of FindTargetProgramPath.
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
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index a8998c4..19a830c 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -47,8 +47,9 @@
 /// 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 @@
 
   // 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 @@
   }
 
   const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(),
-                                                              "as"));
+                                                      ToolTriple.getTriple(),
+                                                      "as"));
   C.addCommand(new Command(JA, *this, Exec, CmdArgs));
 }
 
@@ -3651,7 +3654,8 @@
 
   // 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 @@
   }
 
   const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(),
-                                                              "ld"));
+                                                      ToolTriple.getTriple(),
+                                                      "ld"));
   C.addCommand(new Command(JA, *this, Exec, CmdArgs));
 }