From: Daniel Dunbar Date: Wed, 15 Apr 2009 02:56:18 +0000 (+0000) Subject: Tweaks to Objective-C metadata (32 & 64-bit) to match llvm-gcc. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0bf2199b79b1ca2dcbb0d0406fd90335c8575752;p=clang Tweaks to Objective-C metadata (32 & 64-bit) to match llvm-gcc. - Set alignment on property lists. - 32-bit: o Set section on property lists. o Fix section name for category class methods. o Fix symbol name for property lists. o Fix section name for class method. o Set alignment and section on class extension structure. o Set alignment on a number of things: instance variables, methods, method descriptions, the symbols structure. - 64-bit: o Fix section flags for protocol list. I doubt most of these were problems in practice, but it is nice to match llvm-gcc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69132 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index dd55e655ce..744481e92f 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -1308,10 +1308,12 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(const std::string &Name, Values[2] = llvm::ConstantArray::get(AT, Properties); llvm::Constant *Init = llvm::ConstantStruct::get(Values); - // No special section on property lists? llvm::GlobalVariable *GV = - CreateMetadataVar(Name, Init, (ObjCABI == 2) ? "__DATA, __objc_const" : 0, - 0, true); + CreateMetadataVar(Name, Init, + (ObjCABI == 2) ? "__DATA, __objc_const" : + "__OBJC,__property,regular,no_dead_strip", + (ObjCABI == 2) ? 8 : 4, + true); return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.PropertyListPtrTy); } @@ -1345,7 +1347,7 @@ llvm::Constant *CGObjCMac::EmitMethodDescList(const std::string &Name, Values[1] = llvm::ConstantArray::get(AT, Methods); llvm::Constant *Init = llvm::ConstantStruct::get(Values); - llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, Section, 0, true); + llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, Section, 4, true); return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.MethodDescriptionListPtrTy); } @@ -1397,7 +1399,7 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { InstanceMethods); Values[3] = EmitMethodList(std::string("\01L_OBJC_CATEGORY_CLASS_METHODS_") + ExtName, - "__OBJC,__cat_class_meth,regular,no_dead_strip", + "__OBJC,__cat_cls_meth,regular,no_dead_strip", ClassMethods); if (Category) { Values[4] = @@ -1411,7 +1413,7 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { // If there is no category @interface then there can be no properties. if (Category) { - Values[6] = EmitPropertyList(std::string("\01L_OBJC_$_PROP_LIST_") + ExtName, + Values[6] = EmitPropertyList(std::string("\01l_OBJC_$_PROP_LIST_") + ExtName, OCD, Category, ObjCTypes); } else { Values[6] = llvm::Constant::getNullValue(ObjCTypes.PropertyListPtrTy); @@ -1580,7 +1582,7 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID, Values[ 6] = EmitIvarList(ID, true); Values[ 7] = EmitMethodList("\01L_OBJC_CLASS_METHODS_" + ID->getNameAsString(), - "__OBJC,__inst_meth,regular,no_dead_strip", + "__OBJC,__cls_meth,regular,no_dead_strip", Methods); // cache is always NULL. Values[ 8] = llvm::Constant::getNullValue(ObjCTypes.CachePtrTy); @@ -1658,7 +1660,7 @@ CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID) { // FIXME: Output weak_ivar_layout string. // Values[1] = BuildIvarLayout(ID, false); Values[1] = GetIvarLayoutName(0, ObjCTypes); - Values[2] = EmitPropertyList("\01L_OBJC_$_PROP_LIST_" + ID->getNameAsString(), + Values[2] = EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + ID->getNameAsString(), ID, ID->getClassInterface(), ObjCTypes); // Return null if no extension bits are used. @@ -1668,7 +1670,8 @@ CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID) { llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ClassExtensionTy, Values); return CreateMetadataVar("\01L_OBJC_CLASSEXT_" + ID->getNameAsString(), - Init, 0, 0, true); + Init, "__OBJC,__class_ext,regular,no_dead_strip", + 4, true); } /// countInheritedIvars - count number of ivars in class and its super class(s) @@ -1785,9 +1788,8 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID, GV = CreateMetadataVar("\01L_OBJC_INSTANCE_VARIABLES_" + ID->getNameAsString(), Init, "__OBJC,__instance_vars,regular,no_dead_strip", - 0, true); - return llvm::ConstantExpr::getBitCast(GV, - ObjCTypes.IvarListPtrTy); + 4, true); + return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.IvarListPtrTy); } /* @@ -1837,7 +1839,7 @@ llvm::Constant *CGObjCMac::EmitMethodList(const std::string &Name, Values[2] = llvm::ConstantArray::get(AT, Methods); llvm::Constant *Init = llvm::ConstantStruct::get(Values); - llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, Section, 0, true); + llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, Section, 4, true); return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.MethodListPtrTy); } @@ -2488,7 +2490,7 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() { llvm::GlobalVariable *GV = CreateMetadataVar("\01L_OBJC_SYMBOLS", Init, "__OBJC,__symbols,regular,no_dead_strip", - 0, true); + 4, true); return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.SymtabPtrTy); } @@ -2505,7 +2507,7 @@ llvm::Value *CGObjCMac::EmitClassRef(CGBuilderTy &Builder, Entry = CreateMetadataVar("\01L_OBJC_CLASS_REFERENCES_", Casted, "__OBJC,__cls_refs,literal_pointers,no_dead_strip", - 0, true); + 4, true); } return Builder.CreateLoad(Entry, false, "tmp"); @@ -2521,7 +2523,7 @@ llvm::Value *CGObjCMac::EmitSelector(CGBuilderTy &Builder, Selector Sel) { Entry = CreateMetadataVar("\01L_OBJC_SELECTOR_REFERENCES_", Casted, "__OBJC,__message_refs,literal_pointers,no_dead_strip", - 0, true); + 4, true); } return Builder.CreateLoad(Entry, false, "tmp"); @@ -4765,7 +4767,7 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol( &CGM.getModule()); PTGV->setAlignment( CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.ProtocolnfABIPtrTy)); - PTGV->setSection("__DATA, __objc_protolist"); + PTGV->setSection("__DATA, __objc_protolist, coalesced, no_dead_strip"); PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility); UsedGlobals.push_back(PTGV); return Entry; @@ -5055,9 +5057,9 @@ llvm::Value *CGObjCNonFragileABIMac::EmitClassRef(CGBuilderTy &Builder, ObjCTypes.ClassnfABIPtrTy)); if (IsSuper) - Entry->setSection("__DATA,__objc_superrefs,regular,no_dead_strip"); + Entry->setSection("__DATA, __objc_superrefs, regular, no_dead_strip"); else - Entry->setSection("__DATA,__objc_classrefs,regular,no_dead_strip"); + Entry->setSection("__DATA, __objc_classrefs, regular, no_dead_strip"); UsedGlobals.push_back(Entry); } diff --git a/test/CodeGenObjC/metadata-symbols-32.m b/test/CodeGenObjC/metadata-symbols-32.m new file mode 100644 index 0000000000..867dfca684 --- /dev/null +++ b/test/CodeGenObjC/metadata-symbols-32.m @@ -0,0 +1,82 @@ +// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm -o %t %s && +// RUNX: llvm-gcc -m32 -emit-llvm -S -o %t %s && + +// RUN: grep '@"\\01L_OBJC_CATEGORY_A_Cat" = internal global .*section "__OBJC,__category,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_CATEGORY_CLASS_METHODS_A_Cat" = internal global .*section "__OBJC,__cat_cls_meth,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_CATEGORY_INSTANCE_METHODS_A_Cat" = internal global .*section "__OBJC,__cat_inst_meth,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_CLASSEXT_A" = internal global .*section "__OBJC,__class_ext,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_CLASS_A" = internal global .*section "__OBJC,__class,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_CLASS_METHODS_A" = internal global .*section "__OBJC,__cls_meth,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_CLASS_NAME_[0-9]*" = internal global .*section "__TEXT,__cstring,cstring_literals", align 1' %t && +// RUN: grep '@"\\01L_OBJC_CLASS_PROTOCOLS_A" = internal global .*section "__OBJC,__cat_cls_meth,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_CLASS_REFERENCES_[0-9]*" = internal global .*section "__OBJC,__cls_refs,literal_pointers,no_dead_strip", align 4' %t && + +// Clang's Obj-C 32-bit doesn't emit ivars for the root class. +// RUNX: grep '@"\\01L_OBJC_CLASS_VARIABLES_A" = internal global .*section "__OBJC,__class_vars,regular,no_dead_strip", align 4' %t && + +// RUN: grep '@"\\01L_OBJC_INSTANCE_METHODS_A" = internal global .*section "__OBJC,__inst_meth,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_INSTANCE_VARIABLES_A" = internal global .*section "__OBJC,__instance_vars,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_METACLASS_A" = internal global .*section "__OBJC,__meta_class,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_METH_VAR_NAME_[0-9]*" = internal global .*section "__TEXT,__cstring,cstring_literals", align 1' %t && +// RUN: grep '@"\\01L_OBJC_METH_VAR_TYPE_[0-9]*" = internal global .*section "__TEXT,__cstring,cstring_literals", align 1' %t && +// RUN: grep '@"\\01L_OBJC_MODULES" = internal global .*section "__OBJC,__module_info,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_PROP_NAME_ATTR_[0-9]*" = internal global .*section "__TEXT,__cstring,cstring_literals", align 1' %t && +// RUN: grep '@"\\01L_OBJC_PROTOCOL_CLASS_METHODS_P" = internal global .*section "__OBJC,__cat_cls_meth,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_PROTOCOL_INSTANCE_METHODS_P" = internal global .*section "__OBJC,__cat_inst_meth,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_PROTOCOL_P" = internal global .*section "__OBJC,__protocol,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_SELECTOR_REFERENCES_[0-9]*" = internal global .*section "__OBJC,__message_refs,literal_pointers,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01L_OBJC_SYMBOLS" = internal global .*section "__OBJC,__symbols,regular,no_dead_strip", align 4' %t && +// RUN: grep '@"\\01l_OBJC_$_PROP_LIST_A" = internal global .*section "__OBJC,__property,regular,no_dead_strip", align 4' %t && + +// RUN: true + +/* + +Here is a handy command for looking at llvm-gcc's output: +llvm-gcc -m32 -emit-llvm -S -o - metadata-symbols-32.m | \ + grep '=.*global' | \ + sed -e 's#global.*, section#global ... section#' | \ + sort + +*/ + +@interface B +@end +@interface C +@end + +@protocol P ++(void) fm0; +-(void) im0; +@end + +@interface A

{ + int _ivar; +} + +@property (assign) int ivar; + ++(void) fm0; +-(void) im0; +@end + +@implementation A +@synthesize ivar = _ivar; ++(void) fm0 { +} +-(void) im0 { +} +@end + +@implementation A (Cat) ++(void) fm1 { +} +-(void) im1 { +} +@end + +void *f0() { + [B im0]; + [C im1]; +} + diff --git a/test/CodeGenObjC/metadata-symbols-64.m b/test/CodeGenObjC/metadata-symbols-64.m new file mode 100644 index 0000000000..9f7f2f39dd --- /dev/null +++ b/test/CodeGenObjC/metadata-symbols-64.m @@ -0,0 +1,91 @@ +// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-llvm -o %t %s && +// RUNX: llvm-gcc -m64 -emit-llvm -S -o %t %s && + +// RUN: grep '@"OBJC_CLASS_$_A" = global' %t && +// RUN: grep '@"OBJC_CLASS_$_B" = external global' %t && + +// FIXME: This is currently broken in clang, we are emitting two +// references to the same ivar (one using \01, and one not). +// RUNX: grep '@"OBJC_IVAR_$_A._ivar" = global .* section "__DATA, __objc_const", align 8' %t && + +// RUN: grep '@"OBJC_METACLASS_$_A" = global .* section "__DATA, __objc_data", align 8' %t && +// RUN: grep '@"\\01L_OBJC_CLASSLIST_REFERENCES_$_[0-9]*" = internal global .* section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8' %t && +// RUN: grep '@"\\01L_OBJC_CLASS_NAME_[0-9]*" = internal global .* section "__TEXT,__cstring,cstring_literals", align 1' %t && +// RUN: grep '@"\\01L_OBJC_LABEL_CATEGORY_$" = internal global .* section "__DATA, __objc_catlist, regular, no_dead_strip", align 8' %t && +// RUN: grep '@"\\01L_OBJC_LABEL_CLASS_$" = internal global .* section "__DATA, __objc_classlist, regular, no_dead_strip", align 8' %t && +// RUN: grep '@"\\01L_OBJC_METH_VAR_NAME_[0-9]*" = internal global .* section "__TEXT,__cstring,cstring_literals", align 1' %t && +// RUN: grep '@"\\01L_OBJC_METH_VAR_TYPE_[0-9]*" = internal global .* section "__TEXT,__cstring,cstring_literals", align 1' %t && +// RUN: grep '@"\\01L_OBJC_PROP_NAME_ATTR_[0-9]*" = internal global .* section "__TEXT,__cstring,cstring_literals", align 1' %t && + +// FIXME: clang is not currently using "optimized" message dispatch in 64-bit mode. +// RUNX: grep '@"\\01L_OBJC_SELECTOR_REFERENCES_[0-9]*" = internal global .* section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip", align 8' %t && + +// RUN: grep '@"\\01l_OBJC_$_CATEGORY_A_$_Cat" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_$_CATEGORY_CLASS_METHODS_A_$_Cat" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_$_CATEGORY_INSTANCE_METHODS_A_$_Cat" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_$_CLASS_METHODS_A" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_$_INSTANCE_METHODS_A" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_$_INSTANCE_VARIABLES_A" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_$_PROP_LIST_A" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_$_PROTOCOL_CLASS_METHODS_P" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_$_PROTOCOL_INSTANCE_METHODS_P" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_CLASS_PROTOCOLS_$_A" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_CLASS_RO_$_A" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_LABEL_PROTOCOL_$_P" = weak hidden global .* section "__DATA, __objc_protolist, coalesced, no_dead_strip", align 8' %t && +// RUN: grep '@"\\01l_OBJC_METACLASS_RO_$_A" = internal global .* section "__DATA, __objc_const", align 8' %t && +// RUN: grep '@"\\01l_OBJC_PROTOCOL_$_P" = weak hidden global .* section "__DATA,__datacoal_nt,coalesced", align 8' %t && +// RUN: grep '@_objc_empty_cache = external global' %t && +// RUN: grep '@_objc_empty_vtable = external global' %t && + +// RUN: true + +/* + +Here is a handy command for looking at llvm-gcc's output: +llvm-gcc -m64 -emit-llvm -S -o - metadata-symbols-64.m | \ + grep '=.*global' | \ + sed -e 's#global.*, section#global ... section#' | \ + sort + +*/ + +@interface B +@end +@interface C +@end + +@protocol P ++(void) fm0; +-(void) im0; +@end + +@interface A

{ + int _ivar; +} + +@property (assign) int ivar; + ++(void) fm0; +-(void) im0; +@end + +@implementation A +@synthesize ivar = _ivar; ++(void) fm0 { +} +-(void) im0 { +} +@end + +@implementation A (Cat) ++(void) fm1 { +} +-(void) im1 { +} +@end + +void *f0() { + [B im0]; + [C im1]; +} +