diff options
Diffstat (limited to 'lib/Driver')
-rw-r--r-- | lib/Driver/ToolChains.cpp | 5 | ||||
-rw-r--r-- | lib/Driver/ToolChains.h | 7 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 35 |
3 files changed, 38 insertions, 9 deletions
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index e125ab78f4..5ff82c7600 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -93,12 +93,17 @@ bool Darwin::hasARCRuntime() const { return !isMacosxVersionLT(10, 7); } +bool Darwin::hasSubscriptingRuntime() const { + return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 8); +} + /// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0. void Darwin::configureObjCRuntime(ObjCRuntime &runtime) const { if (runtime.getKind() != ObjCRuntime::NeXT) return ToolChain::configureObjCRuntime(runtime); runtime.HasARC = runtime.HasWeak = hasARCRuntime(); + runtime.HasSubscripting = hasSubscriptingRuntime(); // So far, objc_terminate is only available in iOS 5. // FIXME: do the simulator logic properly. diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 0d591107de..aee21741dd 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -205,6 +205,7 @@ private: std::string MacosxVersionMin; bool hasARCRuntime() const; + bool hasSubscriptingRuntime() const; private: void AddDeploymentTarget(DerivedArgList &Args) const; @@ -252,6 +253,12 @@ public: return TargetIsIPhoneOSSimulator; } + bool isTargetMacOS() const { + return !isTargetIOSSimulator() && + !isTargetIPhoneOS() && + ARCRuntimeForSimulator == ARCSimulator_None; + } + bool isTargetInitialized() const { return TargetInitialized; } void getTargetVersion(unsigned (&Res)[3]) const { diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 0849c8d620..38f21c0882 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -136,6 +136,13 @@ static bool isObjCAutoRefCount(const ArgList &Args) { return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); } +/// \brief Determine whether we are linking the ObjC runtime. +static bool isObjCRuntimeLinked(const ArgList &Args) { + if (isObjCAutoRefCount(Args)) + return true; + return Args.hasArg(options::OPT_fobjc_link_runtime); +} + static void addProfileRT(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, llvm::Triple Triple) { @@ -4025,7 +4032,7 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-lcrt1.o"); else if (getDarwinToolChain().isMacosxVersionLT(10, 6)) CmdArgs.push_back("-lcrt1.10.5.o"); - else + else if (getDarwinToolChain().isMacosxVersionLT(10, 8)) CmdArgs.push_back("-lcrt1.10.6.o"); // darwin_crt2 spec is empty. @@ -4064,14 +4071,24 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, getDarwinToolChain().AddLinkSearchPathArgs(Args, CmdArgs); - // In ARC, if we don't have runtime support, link in the runtime - // stubs. We have to do this *before* adding any of the normal - // linker inputs so that its initializer gets run first. - if (isObjCAutoRefCount(Args)) { - ObjCRuntime runtime; - getDarwinToolChain().configureObjCRuntime(runtime); - if (!runtime.HasARC) - getDarwinToolChain().AddLinkARCArgs(Args, CmdArgs); + if (isObjCRuntimeLinked(Args)) { + // Avoid linking compatibility stubs on i386 mac. + if (!getDarwinToolChain().isTargetMacOS() || + getDarwinToolChain().getArchName() != "i386") { + // If we don't have ARC or subscripting runtime support, link in the + // runtime stubs. We have to do this *before* adding any of the normal + // linker inputs so that its initializer gets run first. + ObjCRuntime runtime; + getDarwinToolChain().configureObjCRuntime(runtime); + // We use arclite library for both ARC and subscripting support. + if ((!runtime.HasARC && isObjCAutoRefCount(Args)) || + !runtime.HasSubscripting) + getDarwinToolChain().AddLinkARCArgs(Args, CmdArgs); + CmdArgs.push_back("-framework"); + CmdArgs.push_back("Foundation"); + } + // Link libobj. + CmdArgs.push_back("-lobjc"); } AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |