diff options
Diffstat (limited to 'lib/Driver')
-rw-r--r-- | lib/Driver/Driver.cpp | 28 | ||||
-rw-r--r-- | lib/Driver/Makefile | 3 | ||||
-rw-r--r-- | lib/Driver/ToolChains.cpp | 145 | ||||
-rw-r--r-- | lib/Driver/ToolChains.h | 5 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 104 | ||||
-rw-r--r-- | lib/Driver/Tools.h | 1 |
6 files changed, 140 insertions, 146 deletions
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index ab4bd49..852a018 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -26,6 +26,7 @@ #include "clang/Basic/Version.h" #include "llvm/ADT/StringSet.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/Path.h" @@ -66,6 +67,14 @@ Driver::Driver(llvm::StringRef _Name, llvm::StringRef _Dir, CCCUseClangCXX = false; } + + // Compute the path to the resource directory. + llvm::sys::Path P(Dir); + P.eraseComponent(); // Remove /bin from foo/bin + P.appendComponent("lib"); + P.appendComponent("clang"); + P.appendComponent(CLANG_VERSION_STRING); + ResourceDir = P.str(); } Driver::~Driver() { @@ -273,15 +282,7 @@ void Driver::PrintHelp(bool ShowHidden) const { void Driver::PrintVersion(const Compilation &C, llvm::raw_ostream &OS) const { // FIXME: The following handlers should use a callback mechanism, we don't // know what the client would like to do. -#ifdef CLANG_VENDOR - OS << CLANG_VENDOR; -#endif - OS << "clang version " CLANG_VERSION_STRING " (" - << getClangSubversionPath(); - if (unsigned Revision = getClangSubversionRevision()) - OS << " " << Revision; - OS << ")" << '\n'; - + OS << getClangFullVersion() << '\n'; const ToolChain &TC = C.getDefaultToolChain(); OS << "Target: " << TC.getTripleString() << '\n'; @@ -675,7 +676,7 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const { } // Build the pipeline for this file. - Action *Current = new InputAction(*InputArg, InputType); + llvm::OwningPtr<Action> Current(new InputAction(*InputArg, InputType)); for (unsigned i = 0; i != NumSteps; ++i) { phases::ID Phase = types::getCompilationPhase(InputType, i); @@ -686,8 +687,7 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const { // Queue linker inputs. if (Phase == phases::Link) { assert(i + 1 == NumSteps && "linking must be final compilation step."); - LinkerInputs.push_back(Current); - Current = 0; + LinkerInputs.push_back(Current.take()); break; } @@ -698,14 +698,14 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const { continue; // Otherwise construct the appropriate action. - Current = ConstructPhaseAction(Args, Phase, Current); + Current.reset(ConstructPhaseAction(Args, Phase, Current.take())); if (Current->getType() == types::TY_Nothing) break; } // If we ended with something, add to the output list. if (Current) - Actions.push_back(Current); + Actions.push_back(Current.take()); } // Add a link action if necessary. diff --git a/lib/Driver/Makefile b/lib/Driver/Makefile index 4c3ca5c..dbacf8b 100644 --- a/lib/Driver/Makefile +++ b/lib/Driver/Makefile @@ -13,8 +13,5 @@ BUILD_ARCHIVE = 1 CXXFLAGS = -fno-rtti CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include -ifdef CLANG_VENDOR -CPPFLAGS += -DCLANG_VENDOR='"$(CLANG_VENDOR) "' -endif include $(LEVEL)/Makefile.common diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 42657d9..a9c6a68 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -47,6 +47,69 @@ Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple, IPhoneOSVersionMin = "3.0"; } +// FIXME: Can we tablegen this? +static const char *GetArmArchForMArch(llvm::StringRef Value) { + if (Value == "armv6k") + return "armv6"; + + if (Value == "armv5tej") + return "armv5"; + + if (Value == "xscale") + return "xscale"; + + if (Value == "armv4t") + return "armv4t"; + + if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" || + Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" || + Value == "armv7m") + return "armv7"; + + return 0; +} + +// FIXME: Can we tablegen this? +static const char *GetArmArchForMCpu(llvm::StringRef Value) { + if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" || + Value == "arm946e-s" || Value == "arm966e-s" || + Value == "arm968e-s" || Value == "arm10e" || + Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" || + Value == "arm1026ej-s") + return "armv5"; + + if (Value == "xscale") + return "xscale"; + + if (Value == "arm1136j-s" || Value == "arm1136jf-s" || + Value == "arm1176jz-s" || Value == "arm1176jzf-s") + return "armv6"; + + if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3") + return "armv7"; + + return 0; +} + +llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const { + switch (getTriple().getArch()) { + default: + return getArchName(); + + case llvm::Triple::arm: { + if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) + if (const char *Arch = GetArmArchForMArch(A->getValue(Args))) + return Arch; + + if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) + if (const char *Arch = GetArmArchForMCpu(A->getValue(Args))) + return Arch; + + return "arm"; + } + } +} + DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, const unsigned (&DarwinVersion)[3], const unsigned (&_GCCVersion)[3], bool IsIPhoneOS) @@ -118,10 +181,6 @@ DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, Path += ToolChainDir; getProgramPaths().push_back(Path); - Path = getDriver().Dir; - Path += "/../libexec"; - getProgramPaths().push_back(Path); - getProgramPaths().push_back(getDriver().Dir); } @@ -235,13 +294,6 @@ DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple, bool IsIPhoneOS) : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS) { - // Add the relative libexec dir (for clang-cc). - // - // FIXME: We should sink clang-cc into libexec/clang/<version>/. - std::string Path = getDriver().Dir; - Path += "/../libexec"; - getProgramPaths().push_back(Path); - // We expect 'as', 'ld', etc. to be adjacent to our install dir. getProgramPaths().push_back(getDriver().Dir); } @@ -253,12 +305,10 @@ void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args, void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { - // Check for static linking. - if (Args.hasArg(options::OPT_static)) { - // FIXME: We need to have compiler-rt available (perhaps as - // libclang_static.a) to link against. + // Darwin doesn't support real static executables, don't link any runtime + // libraries with -static. + if (Args.hasArg(options::OPT_static)) return; - } // Reject -static-libgcc for now, we can deal with this when and if someone // cares. This is useful in situations where someone wants to statically link @@ -269,12 +319,52 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, return; } - // Otherwise link libSystem, which should have the support routines. - // - // FIXME: This is only true for 10.6 and beyond. Legacy support isn't - // critical, but it should work... we should just link in the static - // compiler-rt library. + // Otherwise link libSystem, then the dynamic runtime library, and finally any + // target specific static runtime library. CmdArgs.push_back("-lSystem"); + + // Select the dynamic runtime library and the target specific static library. + const char *DarwinStaticLib = 0; + if (isIPhoneOS()) { + CmdArgs.push_back("-lgcc_s.1"); + + // We may need some static functions for armv6/thumb which are required to + // be in the same linkage unit as their caller. + if (getDarwinArchName(Args) == "armv6") + DarwinStaticLib = "libclang_rt.armv6.a"; + } else { + unsigned MacosxVersionMin[3]; + getMacosxVersionMin(Args, MacosxVersionMin); + + // The dynamic runtime library was merged with libSystem for 10.6 and + // beyond; only 10.4 and 10.5 need an additional runtime library. + if (isMacosxVersionLT(MacosxVersionMin, 10, 5)) + CmdArgs.push_back("-lgcc_s.10.4"); + else if (isMacosxVersionLT(MacosxVersionMin, 10, 6)) + CmdArgs.push_back("-lgcc_s.10.5"); + + // For OS X, we only need a static runtime library when targetting 10.4, to + // provide versions of the static functions which were omitted from + // 10.4.dylib. + if (isMacosxVersionLT(MacosxVersionMin, 10, 5)) + DarwinStaticLib = "libclang_rt.10.4.a"; + } + + /// Add the target specific static library, if needed. + if (DarwinStaticLib) { + llvm::sys::Path P(getDriver().ResourceDir); + P.appendComponent("lib"); + P.appendComponent("darwin"); + P.appendComponent(DarwinStaticLib); + + // For now, allow missing resource libraries to support developers who may + // not have compiler-rt checked out or integrated into their build. + if (!P.exists()) + getDriver().Diag(clang::diag::warn_drv_missing_resource_library) + << P.str(); + else + CmdArgs.push_back(Args.MakeArgString(P.str())); + } } void Darwin::getMacosxVersionMin(const ArgList &Args, @@ -544,10 +634,6 @@ const char *Darwin::GetForcedPicModel() const { Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) : ToolChain(Host, Triple) { - std::string Path(getDriver().Dir); - Path += "/../libexec"; - getProgramPaths().push_back(Path); - getProgramPaths().push_back(getDriver().Dir); } @@ -684,11 +770,6 @@ Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple) : Generic_GCC(Host, Triple) { - // Path mangling to find libexec - std::string Path(getDriver().Dir); - - Path += "/../libexec"; - getProgramPaths().push_back(Path); getProgramPaths().push_back(getDriver().Dir); getFilePaths().push_back(getDriver().Dir + "/../lib"); @@ -753,10 +834,6 @@ DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) : Generic_GCC(Host, Triple) { // Path mangling to find libexec - std::string Path(getDriver().Dir); - - Path += "/../libexec"; - getProgramPaths().push_back(Path); getProgramPaths().push_back(getDriver().Dir); getFilePaths().push_back(getDriver().Dir + "/../lib"); diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 374ad8c..3ca6ad8 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -85,6 +85,11 @@ public: Res[2] = DarwinVersion[1]; } + /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler + /// invocation. For example, Darwin treats different ARM variations as + /// distinct architectures. + llvm::StringRef getDarwinArchName(const ArgList &Args) const; + /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is /// either the -mmacosx-version-min, or the current version if unspecified. void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 010953d..afb22a2 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -9,7 +9,6 @@ #include "Tools.h" -#include "clang/Basic/Version.h" #include "clang/Driver/Action.h" #include "clang/Driver/Arg.h" #include "clang/Driver/ArgList.h" @@ -864,15 +863,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc); // Pass the path to compiler resource files. - // - // FIXME: Get this from a configuration object. - llvm::sys::Path P(D.Dir); - P.eraseComponent(); // Remove /bin from foo/bin - P.appendComponent("lib"); - P.appendComponent("clang"); - P.appendComponent(CLANG_VERSION_STRING); CmdArgs.push_back("-resource-dir"); - CmdArgs.push_back(Args.MakeArgString(P.str())); + CmdArgs.push_back(D.ResourceDir.c_str()); // Add preprocessing options like -I, -D, etc. if we are using the // preprocessor. @@ -1857,87 +1849,17 @@ static bool isSourceSuffix(const char *Str) { .Default(false); } -// FIXME: Can we tablegen this? -static const char *GetArmArchForMArch(llvm::StringRef Value) { - if (Value == "armv6k") - return "armv6"; - - if (Value == "armv5tej") - return "armv5"; - - if (Value == "xscale") - return "xscale"; - - if (Value == "armv4t") - return "armv4t"; - - if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" || - Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" || - Value == "armv7m") - return "armv7"; - - return 0; -} - -// FIXME: Can we tablegen this? -static const char *GetArmArchForMCpu(llvm::StringRef Value) { - if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" || - Value == "arm946e-s" || Value == "arm966e-s" || - Value == "arm968e-s" || Value == "arm10e" || - Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" || - Value == "arm1026ej-s") - return "armv5"; - - if (Value == "xscale") - return "xscale"; - - if (Value == "arm1136j-s" || Value == "arm1136jf-s" || - Value == "arm1176jz-s" || Value == "arm1176jzf-s") - return "armv6"; - - if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3") - return "armv7"; - - return 0; -} - void darwin::DarwinTool::AddDarwinArch(const ArgList &Args, ArgStringList &CmdArgs) const { + llvm::StringRef ArchName = getDarwinToolChain().getDarwinArchName(Args); + // Derived from darwin_arch spec. CmdArgs.push_back("-arch"); + CmdArgs.push_back(Args.MakeArgString(ArchName)); - switch (getToolChain().getTriple().getArch()) { - default: - CmdArgs.push_back(Args.MakeArgString(getToolChain().getArchName())); - break; - - case llvm::Triple::arm: { - if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { - if (const char *Arch = GetArmArchForMArch(A->getValue(Args))) { - CmdArgs.push_back(Arch); - return; - } - } - - if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { - if (const char *Arch = GetArmArchForMCpu(A->getValue(Args))) { - CmdArgs.push_back(Arch); - return; - } - } - - CmdArgs.push_back("arm"); + // FIXME: Is this needed anymore? + if (ArchName == "arm") CmdArgs.push_back("-force_cpusubtype_ALL"); - return; - } - } -} - -void darwin::DarwinTool::AddDarwinSubArch(const ArgList &Args, - ArgStringList &CmdArgs) const { - // Derived from darwin_subarch spec, not sure what the distinction - // exists for but at least for this chain it is the same. - AddDarwinArch(Args, CmdArgs); } void darwin::Link::AddLinkArgs(const ArgList &Args, @@ -1954,11 +1876,9 @@ void darwin::Link::AddLinkArgs(const ArgList &Args, } if (!Args.hasArg(options::OPT_dynamiclib)) { - if (Args.hasArg(options::OPT_force__cpusubtype__ALL)) { - AddDarwinArch(Args, CmdArgs); - CmdArgs.push_back("-force_cpusubtype_ALL"); - } else - AddDarwinSubArch(Args, CmdArgs); + AddDarwinArch(Args, CmdArgs); + // FIXME: Why do this only on this path? + Args.AddLastArg(CmdArgs, options::OPT_force__cpusubtype__ALL); Args.AddLastArg(CmdArgs, options::OPT_bundle); Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader); @@ -1992,11 +1912,7 @@ void darwin::Link::AddLinkArgs(const ArgList &Args, Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version, "-dylib_current_version"); - if (Args.hasArg(options::OPT_force__cpusubtype__ALL)) { - AddDarwinArch(Args, CmdArgs); - // NOTE: We don't add -force_cpusubtype_ALL on this path. Ok. - } else - AddDarwinSubArch(Args, CmdArgs); + AddDarwinArch(Args, CmdArgs); Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name, "-dylib_install_name"); diff --git a/lib/Driver/Tools.h b/lib/Driver/Tools.h index 8f7da52..abd8cfc 100644 --- a/lib/Driver/Tools.h +++ b/lib/Driver/Tools.h @@ -130,7 +130,6 @@ namespace darwin { class VISIBILITY_HIDDEN DarwinTool : public Tool { protected: void AddDarwinArch(const ArgList &Args, ArgStringList &CmdArgs) const; - void AddDarwinSubArch(const ArgList &Args, ArgStringList &CmdArgs) const; const toolchains::Darwin &getDarwinToolChain() const { return reinterpret_cast<const toolchains::Darwin&>(getToolChain()); |