forked from OSchip/llvm-project
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. llvm-svn: 131404
This commit is contained in:
parent
5ec1941e58
commit
637603a7cc
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue