From 6b3454a219cee5ef36c4668961f93a5c32deab61 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Tue, 26 May 2009 07:52:18 +0000 Subject: [PATCH] Fix for PR4140: Add the start of a Linux toolchain (basically, just barely enough to get the given usage of -print-file-name working). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72412 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/HostInfo.h | 2 ++ lib/Driver/Driver.cpp | 2 ++ lib/Driver/HostInfo.cpp | 58 +++++++++++++++++++++++++++++++++ lib/Driver/ToolChains.cpp | 16 +++++++++ lib/Driver/ToolChains.h | 6 ++++ 5 files changed, 84 insertions(+) diff --git a/include/clang/Driver/HostInfo.h b/include/clang/Driver/HostInfo.h index fc86d878bb..020bb3ab5a 100644 --- a/include/clang/Driver/HostInfo.h +++ b/include/clang/Driver/HostInfo.h @@ -73,6 +73,8 @@ const HostInfo *createFreeBSDHostInfo(const Driver &D, const llvm::Triple& Triple); const HostInfo *createDragonFlyHostInfo(const Driver &D, const llvm::Triple& Triple); +const HostInfo *createLinuxHostInfo(const Driver &D, + const llvm::Triple& Triple); const HostInfo *createUnknownHostInfo(const Driver &D, const llvm::Triple& Triple); diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 76dc46cfa8..d9a2c2c393 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1161,6 +1161,8 @@ const HostInfo *Driver::GetHostInfo(const char *TripleStr) const { return createDragonFlyHostInfo(*this, Triple); case llvm::Triple::FreeBSD: return createFreeBSDHostInfo(*this, Triple); + case llvm::Triple::Linux: + return createLinuxHostInfo(*this, Triple); default: return createUnknownHostInfo(*this, Triple); } diff --git a/lib/Driver/HostInfo.cpp b/lib/Driver/HostInfo.cpp index f60d25e754..a9713cea47 100644 --- a/lib/Driver/HostInfo.cpp +++ b/lib/Driver/HostInfo.cpp @@ -322,6 +322,58 @@ ToolChain *DragonFlyHostInfo::getToolChain(const ArgList &Args, return TC; } +// Linux Host Info + +/// LinuxHostInfo - Linux host information implementation. +class LinuxHostInfo : public HostInfo { + /// Cache of tool chains we have created. + mutable llvm::StringMap ToolChains; + +public: + LinuxHostInfo(const Driver &D, const llvm::Triple& Triple) + : HostInfo(D, Triple) {} + ~LinuxHostInfo(); + + virtual bool useDriverDriver() const; + + virtual types::ID lookupTypeForExtension(const char *Ext) const { + return types::lookupTypeForExtension(Ext); + } + + virtual ToolChain *getToolChain(const ArgList &Args, + const char *ArchName) const; +}; + +LinuxHostInfo::~LinuxHostInfo() { + for (llvm::StringMap::iterator + it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it) + delete it->second; +} + +bool LinuxHostInfo::useDriverDriver() const { + return false; +} + +ToolChain *LinuxHostInfo::getToolChain(const ArgList &Args, + const char *ArchName) const { + + assert(!ArchName && + "Unexpected arch name on platform without driver driver support."); + + ArchName = getArchName().c_str(); + + ToolChain *&TC = ToolChains[ArchName]; + + if (!TC) { + llvm::Triple TCTriple(getTriple()); + TCTriple.setArchName(getArchName()); + + TC = new toolchains::Linux(*this, TCTriple); + } + + return TC; +} + } const HostInfo * @@ -342,6 +394,12 @@ clang::driver::createDragonFlyHostInfo(const Driver &D, return new DragonFlyHostInfo(D, Triple); } +const HostInfo * +clang::driver::createLinuxHostInfo(const Driver &D, + const llvm::Triple& Triple) { + return new LinuxHostInfo(D, Triple); +} + const HostInfo * clang::driver::createUnknownHostInfo(const Driver &D, const llvm::Triple& Triple) { diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 718f6280b3..436d343dd0 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -419,6 +419,22 @@ Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { return *T; } +/// Linux toolchain (very bare-bones at the moment). + +Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple) + : Generic_GCC(Host, Triple) { + getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/"); + getFilePaths().push_back("/lib/"); + getFilePaths().push_back("/usr/lib/"); + // FIXME: Figure out some way to get gcc's libdir + // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need + // crtbegin.o/crtend.o/etc., and want static versions of various + // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably + // get away with using shared versions in /usr/lib, though. + // We could fall back to the approach we used for includes (a massive + // list), but that's messy at best. +} + /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 5a5c13bf2e..3ecd1715da 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -121,6 +121,12 @@ public: virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; }; +class VISIBILITY_HIDDEN Linux : public Generic_GCC { +public: + Linux(const HostInfo &Host, const llvm::Triple& Triple); +}; + + } // end namespace toolchains } // end namespace driver } // end namespace clang -- 2.40.0