From: Bob Wilson Date: Fri, 7 Oct 2011 17:54:41 +0000 (+0000) Subject: Clang driver changes for iOS 5.0 and OS X Lion support. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=163b151809beef8f917fd16c546016e83ae3e361;p=clang Clang driver changes for iOS 5.0 and OS X Lion support. Check whether the libc++ library is available when using -stdlib=libc++, and also adjust the check for whether to link with -lgcc_s.1. Patch by Ted Kremenek and Daniel Dunbar. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141374 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index f76af053d9..3c0e4f53d3 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -65,6 +65,9 @@ def err_drv_command_signalled : Error< "%0 command failed due to signal %1 (use -v to see invocation)">; def err_drv_invalid_mfloat_abi : Error< "invalid float ABI '%0'">; +def err_drv_invalid_libcxx_deployment : Error< + "invalid deployment target for -stdlib=libc++ (requires %0 or later)">; + def err_drv_I_dash_not_supported : Error< "'%0' not supported, please use -iquote instead">; def err_drv_unknown_argument : Error<"unknown argument: '%0'">; diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 63f827fa61..07481c1ee3 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -48,7 +48,8 @@ using namespace clang; Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple) : ToolChain(Host, Triple), TargetInitialized(false), - ARCRuntimeForSimulator(ARCSimulator_None) + ARCRuntimeForSimulator(ARCSimulator_None), + LibCXXForSimulator(LibCXXSimulator_None) { // Compute the initial Darwin version based on the host. bool HadExtra; @@ -421,8 +422,9 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, if (isTargetIPhoneOS()) { // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, // it never went into the SDK. - if (!isTargetIOSSimulator()) - CmdArgs.push_back("-lgcc_s.1"); + // Linking against libgcc_s.1 isn't needed for iOS 5.0+ + if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator()) + CmdArgs.push_back("-lgcc_s.1"); // We currently always need a static runtime library for iOS. AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); @@ -503,6 +505,8 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { Major < 10 && Minor < 100 && Micro < 100) { ARCRuntimeForSimulator = Major < 5 ? ARCSimulator_NoARCRuntime : ARCSimulator_HasARCRuntime; + LibCXXForSimulator = Major < 5 ? LibCXXSimulator_NotAvailable + : LibCXXSimulator_Available; } break; } @@ -910,6 +914,33 @@ DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, // argument. AddDeploymentTarget(*DAL); + // Validate the C++ standard library choice. + CXXStdlibType Type = GetCXXStdlibType(*DAL); + if (Type == ToolChain::CST_Libcxx) { + switch (LibCXXForSimulator) { + case LibCXXSimulator_None: + // Handle non-simulator cases. + if (isTargetIPhoneOS()) { + if (isIPhoneOSVersionLT(5, 0)) { + getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) + << "iOS 5.0"; + } + } else { + if (isMacosxVersionLT(10, 7)) { + getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) + << "Mac OS X 10.7"; + } + } + break; + case LibCXXSimulator_NotAvailable: + getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) + << "iOS 5.0"; + break; + case LibCXXSimulator_Available: + break; + } + } + return DAL; } diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index c9ff3a0473..dfcb253acd 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -66,6 +66,12 @@ private: ARCSimulator_NoARCRuntime } ARCRuntimeForSimulator; + mutable enum { + LibCXXSimulator_None, + LibCXXSimulator_NotAvailable, + LibCXXSimulator_Available + } LibCXXForSimulator; + private: /// Whether we are targeting iPhoneOS target. mutable bool TargetIsIPhoneOS;