[cfe-commits] r69132 - in /cfe/trunk: lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/metadata-symbols-32.m test/CodeGenObjC/metadata-symbols-64.m

Daniel Dunbar daniel at zuster.org
Tue Apr 14 19:56:18 PDT 2009


Author: ddunbar
Date: Tue Apr 14 21:56:18 2009
New Revision: 69132

URL: http://llvm.org/viewvc/llvm-project?rev=69132&view=rev
Log:
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.

Added:
    cfe/trunk/test/CodeGenObjC/metadata-symbols-32.m
    cfe/trunk/test/CodeGenObjC/metadata-symbols-64.m
Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=69132&r1=69131&r2=69132&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Apr 14 21:56:18 2009
@@ -1308,10 +1308,12 @@
   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 @@
   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 @@
                    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 @@
 
   // 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 @@
   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 @@
   // 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 @@
   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 @@
     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 @@
   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::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 @@
     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 @@
     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 @@
                                       &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 @@
                                                   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);
   }
   

Added: cfe/trunk/test/CodeGenObjC/metadata-symbols-32.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/metadata-symbols-32.m?rev=69132&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/metadata-symbols-32.m (added)
+++ cfe/trunk/test/CodeGenObjC/metadata-symbols-32.m Tue Apr 14 21:56:18 2009
@@ -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
+
+*/
+
+ at interface B
+ at end
+ at interface C
+ at end
+
+ at protocol P
++(void) fm0;
+-(void) im0;
+ at end
+
+ at interface A<P> {
+  int _ivar;
+}
+ 
+ at property (assign) int ivar;
+
++(void) fm0;
+-(void) im0;
+ at end
+
+ at implementation A
+ at synthesize ivar = _ivar;
++(void) fm0 {
+}
+-(void) im0 {
+}
+ at end
+
+ at implementation A (Cat)
++(void) fm1 {
+}
+-(void) im1 {
+}
+ at end
+
+void *f0() {
+   [B im0];
+   [C im1];
+}
+

Added: cfe/trunk/test/CodeGenObjC/metadata-symbols-64.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/metadata-symbols-64.m?rev=69132&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/metadata-symbols-64.m (added)
+++ cfe/trunk/test/CodeGenObjC/metadata-symbols-64.m Tue Apr 14 21:56:18 2009
@@ -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
+
+*/
+
+ at interface B
+ at end
+ at interface C
+ at end
+
+ at protocol P
++(void) fm0;
+-(void) im0;
+ at end
+
+ at interface A<P> {
+  int _ivar;
+}
+ 
+ at property (assign) int ivar;
+
++(void) fm0;
+-(void) im0;
+ at end
+
+ at implementation A
+ at synthesize ivar = _ivar;
++(void) fm0 {
+}
+-(void) im0 {
+}
+ at end
+
+ at implementation A (Cat)
++(void) fm1 {
+}
+-(void) im1 {
+}
+ at end
+
+void *f0() {
+   [B im0];
+   [C im1];
+}
+





More information about the cfe-commits mailing list