From: Eli Friedman Date: Wed, 3 Jun 2009 18:59:56 +0000 (+0000) Subject: PR4308: Fix support for -m32/-m64 on Linux. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e2567d6b1d9d046ca98aa3ab6a6b06ea5ea398b;p=clang PR4308: Fix support for -m32/-m64 on Linux. I'll look into cleaning this up a bit as a followup. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72794 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/HostInfo.h b/include/clang/Driver/HostInfo.h index 020bb3ab5a..3485f5fbfd 100644 --- a/include/clang/Driver/HostInfo.h +++ b/include/clang/Driver/HostInfo.h @@ -28,10 +28,10 @@ namespace driver { /// being run from. For testing purposes, the HostInfo used by the /// driver may differ from the actual host. class HostInfo { +protected: const Driver &TheDriver; const llvm::Triple Triple; -protected: HostInfo(const Driver &D, const llvm::Triple &_Triple); public: diff --git a/lib/Driver/HostInfo.cpp b/lib/Driver/HostInfo.cpp index 603b3ab230..2d577f82fd 100644 --- a/lib/Driver/HostInfo.cpp +++ b/lib/Driver/HostInfo.cpp @@ -194,11 +194,13 @@ ToolChain *UnknownHostInfo::getToolChain(const ArgList &Args, std::string Arch = getArchName(); ArchName = Arch.c_str(); if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) { - if (getArchName() == "i386" || getArchName() == "x86_64") { - ArchName = + if (Triple.getArch() == llvm::Triple::x86 || + Triple.getArch() == llvm::Triple::x86_64) { + ArchName = (A->getOption().getId() == options::OPT_m32) ? "i386" : "x86_64"; - } else if (getArchName() == "powerpc" || getArchName() == "powerpc64") { - ArchName = + } else if (Triple.getArch() == llvm::Triple::ppc || + Triple.getArch() == llvm::Triple::ppc64) { + ArchName = (A->getOption().getId() == options::OPT_m32) ? "powerpc" : "powerpc64"; } } @@ -361,13 +363,26 @@ ToolChain *LinuxHostInfo::getToolChain(const ArgList &Args, assert(!ArchName && "Unexpected arch name on platform without driver driver support."); - ArchName = getArchName().c_str(); - + // Automatically handle some instances of -m32/-m64 we know about. + std::string Arch = getArchName(); + ArchName = Arch.c_str(); + if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) { + if (Triple.getArch() == llvm::Triple::x86 || + Triple.getArch() == llvm::Triple::x86_64) { + ArchName = + (A->getOption().getId() == options::OPT_m32) ? "i386" : "x86_64"; + } else if (Triple.getArch() == llvm::Triple::ppc || + Triple.getArch() == llvm::Triple::ppc64) { + ArchName = + (A->getOption().getId() == options::OPT_m32) ? "powerpc" : "powerpc64"; + } + } + ToolChain *&TC = ToolChains[ArchName]; if (!TC) { llvm::Triple TCTriple(getTriple()); - TCTriple.setArchName(getArchName()); + TCTriple.setArchName(ArchName); TC = new toolchains::Linux(*this, TCTriple); }