Add Clang support for iOS6.

llvm-svn: 164907
This commit is contained in:
Bob Wilson 2012-09-29 23:52:58 +00:00
parent 6fc8fb8da5
commit 2afa011e0b
10 changed files with 151 additions and 22 deletions

View File

@ -157,6 +157,19 @@ public:
llvm_unreachable("bad kind");
}
/// \brief Does this runtime supports optimized setter entrypoints?
bool hasOptimizedSetter() const {
switch (getKind()) {
case MacOSX:
return getVersion() >= VersionTuple(10, 8);
case iOS:
return (getVersion() >= VersionTuple(6));
default:
return false;
}
}
/// Does this runtime allow the use of __weak?
bool allowsWeak() const {
return hasNativeWeak();
@ -177,7 +190,7 @@ public:
switch (getKind()) {
case FragileMacOSX: return false;
case MacOSX: return getVersion() >= VersionTuple(10, 8);
case iOS: return false;
case iOS: return getVersion() >= VersionTuple(6);
// This is really a lie, because some implementations and versions
// of the runtime do not support ARC. Probably -fgnu-runtime

View File

@ -1041,12 +1041,7 @@ static bool hasTrivialSetExpr(const ObjCPropertyImplDecl *PID) {
static bool UseOptimizedSetter(CodeGenModule &CGM) {
if (CGM.getLangOpts().getGC() != LangOptions::NonGC)
return false;
const TargetInfo &Target = CGM.getContext().getTargetInfo();
if (Target.getPlatformName() != "macosx")
return false;
return Target.getPlatformMinVersion() >= VersionTuple(10, 8);
return CGM.getLangOpts().ObjCRuntime.hasOptimizedSetter();
}
void
@ -1106,7 +1101,7 @@ CodeGenFunction::generateObjCSetterBody(const ObjCImplementationDecl *classImpl,
llvm::Value *setOptimizedPropertyFn = 0;
llvm::Value *setPropertyFn = 0;
if (UseOptimizedSetter(CGM)) {
// 10.8 code and GC is off
// 10.8 and iOS 6.0 code and GC is off
setOptimizedPropertyFn =
CGM.getObjCRuntime()
.GetOptimizedPropertySetFunction(strategy.isAtomic(),

View File

@ -332,7 +332,9 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
// Darwin doesn't support real static executables, don't link any runtime
// libraries with -static.
if (Args.hasArg(options::OPT_static))
if (Args.hasArg(options::OPT_static) ||
Args.hasArg(options::OPT_fapple_kext) ||
Args.hasArg(options::OPT_mkernel))
return;
// Reject -static-libgcc for now, we can deal with this when and if someone
@ -676,7 +678,14 @@ void DarwinClang::AddCCKextLibArgs(const ArgList &Args,
llvm::sys::Path P(getDriver().ResourceDir);
P.appendComponent("lib");
P.appendComponent("darwin");
P.appendComponent("libclang_rt.cc_kext.a");
// Use the newer cc_kext for iOS ARM after 6.0.
if (!isTargetIPhoneOS() || isTargetIOSSimulator() ||
!isIPhoneOSVersionLT(6, 0)) {
P.appendComponent("libclang_rt.cc_kext.a");
} else {
P.appendComponent("libclang_rt.cc_kext_ios5.a");
}
// For now, allow missing resource libraries to support developers who may
// not have compiler-rt checked out or integrated into their build.
@ -902,6 +911,25 @@ DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
if (BoundArch)
AddDeploymentTarget(*DAL);
// For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext.
// FIXME: It would be far better to avoid inserting those -static arguments,
// but we can't check the deployment target in the translation code until
// it is set here.
if (isTargetIPhoneOS() && !isIPhoneOSVersionLT(6, 0)) {
for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) {
Arg *A = *it;
++it;
if (A->getOption().getID() != options::OPT_mkernel &&
A->getOption().getID() != options::OPT_fapple_kext)
continue;
assert(it != ie && "unexpected argument translation");
A = *it;
assert(A->getOption().getID() == options::OPT_static &&
"missing expected -static argument");
it = DAL->getArgs().erase(it);
}
}
// Validate the C++ standard library choice.
CXXStdlibType Type = GetCXXStdlibType(*DAL);
if (Type == ToolChain::CST_Libcxx) {

View File

@ -674,7 +674,9 @@ void Clang::AddARMTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs,
bool KernelOrKext) const {
const Driver &D = getToolChain().getDriver();
llvm::Triple Triple = getToolChain().getTriple();
// Get the effective triple, which takes into account the deployment target.
std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args);
llvm::Triple Triple(TripleStr);
// Select the ABI to use.
//
@ -759,8 +761,10 @@ void Clang::AddARMTargetArgs(const ArgList &Args,
// Kernel code has more strict alignment requirements.
if (KernelOrKext) {
CmdArgs.push_back("-backend-option");
CmdArgs.push_back("-arm-long-calls");
if (Triple.getOS() != llvm::Triple::IOS || Triple.isOSVersionLT(6)) {
CmdArgs.push_back("-backend-option");
CmdArgs.push_back("-arm-long-calls");
}
CmdArgs.push_back("-backend-option");
CmdArgs.push_back("-arm-strict-align");
@ -1680,7 +1684,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
}
// Note that these flags are trump-cards. Regardless of the order w.r.t. the
// PIC or PIE options above, if these show up, PIC is disabled.
if (Args.hasArg(options::OPT_mkernel))
llvm::Triple Triple(TripleStr);
if ((Args.hasArg(options::OPT_mkernel) ||
Args.hasArg(options::OPT_fapple_kext)) &&
(Triple.getOS() != llvm::Triple::IOS ||
Triple.isOSVersionLT(6)))
PICDisabled = true;
if (Args.hasArg(options::OPT_static))
PICDisabled = true;
@ -3671,7 +3679,10 @@ void darwin::CC1::AddCC1Args(const ArgList &Args,
CheckCodeGenerationOptions(D, Args);
// Derived from cc1 spec.
if (!Args.hasArg(options::OPT_mkernel) && !Args.hasArg(options::OPT_static) &&
if ((!Args.hasArg(options::OPT_mkernel) ||
(getDarwinToolChain().isTargetIPhoneOS() &&
!getDarwinToolChain().isIPhoneOSVersionLT(6, 0))) &&
!Args.hasArg(options::OPT_static) &&
!Args.hasArg(options::OPT_mdynamic_no_pic))
CmdArgs.push_back("-fPIC");
@ -4125,9 +4136,11 @@ void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-force_cpusubtype_ALL");
if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64 &&
(Args.hasArg(options::OPT_mkernel) ||
Args.hasArg(options::OPT_static) ||
Args.hasArg(options::OPT_fapple_kext)))
(((Args.hasArg(options::OPT_mkernel) ||
Args.hasArg(options::OPT_fapple_kext)) &&
(!getDarwinToolChain().isTargetIPhoneOS() ||
getDarwinToolChain().isIPhoneOSVersionLT(6, 0))) ||
Args.hasArg(options::OPT_static)))
CmdArgs.push_back("-static");
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
@ -4475,7 +4488,7 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
} else if (getDarwinToolChain().isTargetIPhoneOS()) {
if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
CmdArgs.push_back("-lcrt1.o");
else
else if (getDarwinToolChain().isIPhoneOSVersionLT(6, 0))
CmdArgs.push_back("-lcrt1.3.1.o");
} else {
if (getDarwinToolChain().isMacosxVersionLT(10, 5))

View File

@ -74,9 +74,9 @@ RuntimeDirs :=
ifeq ($(OS),Darwin)
RuntimeDirs += darwin
RuntimeLibrary.darwin.Configs := \
eprintf.a 10.4.a osx.a cc_kext.a \
eprintf.a 10.4.a osx.a ios.a cc_kext.a cc_kext_ios5.a \
asan_osx.a asan_osx_dynamic.dylib \
profile_osx.a
profile_osx.a profile_ios.a
endif
# On Linux, include a library which has all the runtime functions.

View File

@ -0,0 +1,33 @@
// RUN: %clang_cc1 %s -emit-llvm -fobjc-runtime=ios-6.0.0 -triple thumbv7-apple-ios6.0.0 -o - | FileCheck %s
// rdar://11915017
@interface I
// void objc_setProperty_nonatomic(id self, SEL _cmd, id newValue, ptrdiff_t offset);
// objc_setProperty(..., NO, NO)
@property (nonatomic, retain) id nonatomicProperty;
// void objc_setProperty_nonatomic_copy(id self, SEL _cmd, id newValue, ptrdiff_t offset);
// objc_setProperty(..., NO, YES)
@property (nonatomic, copy) id nonatomicPropertyCopy;
// void objc_setProperty_atomic(id self, SEL _cmd, id newValue, ptrdiff_t offset);
// objc_setProperty(..., YES, NO)
@property (retain) id atomicProperty;
// void objc_setProperty_atomic_copy(id self, SEL _cmd, id newValue, ptrdiff_t offset);
// objc_setProperty(..., YES, YES)
@property (copy) id atomicPropertyCopy;
@end
@implementation I
@synthesize nonatomicProperty;
@synthesize nonatomicPropertyCopy;
@synthesize atomicProperty;
@synthesize atomicPropertyCopy;
@end
// CHECK: call arm_aapcscc void @objc_setProperty_nonatomic
// CHECK: call arm_aapcscc void @objc_setProperty_nonatomic_copy
// CHECK: call arm_aapcscc void @objc_setProperty_atomic
// CHECK: call arm_aapcscc void @objc_setProperty_atomic_copy

View File

@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-apple-macosx10.8.0 -o - | FileCheck %s
// RUN: %clang_cc1 %s -emit-llvm -fobjc-runtime=macosx-10.8 -triple x86_64-apple-macosx10.8.0 -o - | FileCheck %s
// RUN: %clang_cc1 %s -emit-llvm -fobjc-runtime=ios-6.0.0 -triple x86_64-apple-ios6.0.0 -o - | FileCheck %s
// rdar://10179974
@interface I

View File

@ -0,0 +1,32 @@
// RUN: %clang_cc1 %s -emit-llvm -fobjc-runtime=macosx-10.6.0 -triple x86_64-apple-macosx10.6.0 -o - | FileCheck %s
// rdar://11858187
@interface I
// void objc_setProperty_nonatomic(id self, SEL _cmd, id newValue, ptrdiff_t offset);
// objc_setProperty(..., NO, NO)
@property (nonatomic, retain) id nonatomicProperty;
// void objc_setProperty_nonatomic_copy(id self, SEL _cmd, id newValue, ptrdiff_t offset);
// objc_setProperty(..., NO, YES)
@property (nonatomic, copy) id nonatomicPropertyCopy;
// void objc_setProperty_atomic(id self, SEL _cmd, id newValue, ptrdiff_t offset);
// objc_setProperty(..., YES, NO)
@property (retain) id atomicProperty;
// void objc_setProperty_atomic_copy(id self, SEL _cmd, id newValue, ptrdiff_t offset);
// objc_setProperty(..., YES, YES)
@property (copy) id atomicPropertyCopy;
@end
@implementation I
@synthesize nonatomicProperty;
@synthesize nonatomicPropertyCopy;
@synthesize atomicProperty;
@synthesize atomicPropertyCopy;
@end
// CHECK-NOT: call void @objc_setProperty_nonatomic
// CHECK-NOT: call void @objc_setProperty_nonatomic_copy
// CHECK-NOT: call void @objc_setProperty_atomic
// CHECK-NOT: call void @objc_setProperty_atomic_copy

View File

@ -122,6 +122,10 @@
// RUN: FileCheck -check-prefix=LINK_NO_CRT1 %s < %t.log
// LINK_NO_CRT1-NOT: crt
// RUN: %clang -target armv7-apple-ios6.0 -miphoneos-version-min=6.0 -### %t.o 2> %t.log
// RUN: FileCheck -check-prefix=LINK_NO_IOS_CRT1 %s < %t.log
// LINK_NO_IOS_CRT1-NOT: crt
// RUN: %clang -target i386-apple-darwin12 -pg -### %t.o 2> %t.log
// RUN: FileCheck -check-prefix=LINK_PG %s < %t.log
// LINK_PG: -lgcrt1.o

View File

@ -93,3 +93,13 @@
// RUN: | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC1
// RUN: %clang -c %s -target i386-apple-darwin -mdynamic-no-pic -fPIC -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC2
// Checks for ARM
// RUN: %clang -c %s -arch armv7 -fapple-kext -miphoneos-version-min=6.0.0 -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-PIC2
// RUN: %clang -c %s -arch armv7 -mkernel -miphoneos-version-min=6.0.0 -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-PIC2
// RUN: %clang -c %s -arch armv7 -fapple-kext -miphoneos-version-min=5.0.0 -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC
// RUN: %clang -c %s -arch armv7 -fapple-kext -miphoneos-version-min=6.0.0 -static -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC