@@ -1436,9 +1436,10 @@ namespace {
1436
1436
weakLinkage);
1437
1437
}
1438
1438
1439
- void emitRODataFields (ConstantStructBuilder &b,
1440
- ForMetaClass_t forMeta,
1441
- HasUpdateCallback_t hasUpdater) {
1439
+ void emitRODataFields (
1440
+ ConstantStructBuilder &b, ForMetaClass_t forMeta,
1441
+ HasUpdateCallback_t hasUpdater,
1442
+ ForGenericPattern_t isForGeneric = IsNotForGenericPattern) {
1442
1443
assert (FieldLayout && " can't emit rodata for a category" );
1443
1444
1444
1445
// struct _class_ro_t {
@@ -1497,7 +1498,7 @@ namespace {
1497
1498
emitAndAddMethodList (b,
1498
1499
forMeta ? MethodListKind::ClassMethods
1499
1500
: MethodListKind::InstanceMethods,
1500
- llvm::GlobalVariable::InternalLinkage);
1501
+ llvm::GlobalVariable::InternalLinkage, isForGeneric );
1501
1502
1502
1503
// const protocol_list_t *baseProtocols;
1503
1504
// Apparently, this list is the same in the class and the metaclass.
@@ -1530,7 +1531,7 @@ namespace {
1530
1531
1531
1532
// };
1532
1533
}
1533
-
1534
+
1534
1535
llvm::Constant *emitROData (ForMetaClass_t forMeta,
1535
1536
HasUpdateCallback_t hasUpdater) {
1536
1537
ConstantInitBuilder builder (IGM);
@@ -1763,9 +1764,10 @@ namespace {
1763
1764
};
1764
1765
1765
1766
// / Emit the method list and add the pointer to the `builder`.
1766
- void emitAndAddMethodList (ConstantInitBuilder::StructBuilder &builder,
1767
- MethodListKind kind,
1768
- llvm::GlobalValue::LinkageTypes linkage) {
1767
+ void emitAndAddMethodList (
1768
+ ConstantInitBuilder::StructBuilder &builder, MethodListKind kind,
1769
+ llvm::GlobalValue::LinkageTypes linkage,
1770
+ ForGenericPattern_t isForGeneric = IsNotForGenericPattern) {
1769
1771
ArrayRef<MethodDescriptor> methods;
1770
1772
StringRef namePrefix;
1771
1773
switch (kind) {
@@ -1791,7 +1793,7 @@ namespace {
1791
1793
break ;
1792
1794
}
1793
1795
llvm::Constant *methodListPtr =
1794
- buildMethodList (methods, namePrefix, linkage);
1796
+ buildMethodList (methods, namePrefix, linkage, isForGeneric );
1795
1797
builder.add (methodListPtr);
1796
1798
}
1797
1799
@@ -1837,7 +1839,8 @@ namespace {
1837
1839
// / This method does not return a value of a predictable type.
1838
1840
llvm::Constant *buildMethodList (ArrayRef<MethodDescriptor> methods,
1839
1841
StringRef name,
1840
- llvm::GlobalValue::LinkageTypes linkage) {
1842
+ llvm::GlobalValue::LinkageTypes linkage,
1843
+ ForGenericPattern_t isForGeneric) {
1841
1844
return buildOptionalList (
1842
1845
methods, 3 * IGM.getPointerSize (), name,
1843
1846
/* isConst*/ false , linkage,
@@ -2146,10 +2149,11 @@ namespace {
2146
2149
// / \param optionalEltSize - if non-zero, a size which needs
2147
2150
// / to be placed in the list header
2148
2151
template <class C , class Fn >
2149
- llvm::Constant *buildOptionalList (const C &objects, Size optionalEltSize,
2150
- StringRef nameBase, bool isConst,
2151
- llvm::GlobalValue::LinkageTypes linkage,
2152
- Fn &&buildElement) {
2152
+ llvm::Constant *buildOptionalList (
2153
+ const C &objects, Size optionalEltSize, StringRef nameBase,
2154
+ bool isConst, llvm::GlobalValue::LinkageTypes linkage,
2155
+ Fn &&buildElement,
2156
+ ForGenericPattern_t isForGeneric = IsNotForGenericPattern) {
2153
2157
if (objects.empty ())
2154
2158
return null ();
2155
2159
@@ -2187,7 +2191,8 @@ namespace {
2187
2191
2188
2192
fields.fillPlaceholderWithInt (countPosition, countType, count);
2189
2193
2190
- return buildGlobalVariable (fields, nameBase, isConst, linkage);
2194
+ return buildGlobalVariable (fields, nameBase, isConst, linkage,
2195
+ isForGeneric);
2191
2196
}
2192
2197
2193
2198
// / Get the name of the class or protocol to mangle into the ObjC symbol
@@ -2216,9 +2221,10 @@ namespace {
2216
2221
// / Build a private global variable as a structure containing the
2217
2222
// / given fields.
2218
2223
template <class B >
2219
- llvm::Constant *
2220
- buildGlobalVariable (B &fields, StringRef nameBase, bool isConst,
2221
- llvm::GlobalValue::LinkageTypes linkage) {
2224
+ llvm::Constant *buildGlobalVariable (
2225
+ B &fields, StringRef nameBase, bool isConst,
2226
+ llvm::GlobalValue::LinkageTypes linkage,
2227
+ ForGenericPattern_t isForGeneric = IsNotForGenericPattern) {
2222
2228
llvm::SmallString<64 > nameBuffer;
2223
2229
auto var =
2224
2230
fields.finishAndCreateGlobal (Twine (nameBase)
@@ -2235,8 +2241,12 @@ namespace {
2235
2241
2236
2242
switch (IGM.TargetInfo .OutputObjectFormat ) {
2237
2243
case llvm::Triple::MachO:
2238
- var->setSection (isConst ? " __DATA, __objc_const"
2239
- : " __DATA, __objc_data" );
2244
+ if (isForGeneric) {
2245
+ var->setSection (" __DATA, __objc_methlist,regular" );
2246
+ } else {
2247
+ var->setSection (isConst ? " __DATA, __objc_const"
2248
+ : " __DATA, __objc_data" );
2249
+ }
2240
2250
break ;
2241
2251
case llvm::Triple::XCOFF:
2242
2252
case llvm::Triple::COFF:
@@ -2447,17 +2457,17 @@ irgen::emitClassPrivateDataFields(IRGenModule &IGM,
2447
2457
2448
2458
// Note: an update callback is only ever used with the in-place
2449
2459
// initialization pattern, which precludes generic classes.
2450
- builder.emitRODataFields (classRO,
2451
- ForClass,
2452
- DoesNotHaveUpdateCallback);
2460
+ builder.emitRODataFields (classRO, ForClass, DoesNotHaveUpdateCallback,
2461
+ IsForGenericPattern);
2453
2462
classRO.finishAndAddTo (init);
2454
2463
}
2455
2464
2456
2465
Size startOfMetaclassRO = init.getNextOffsetFromGlobal ();
2457
2466
assert (startOfMetaclassRO.isMultipleOf (IGM.getPointerSize ()));
2458
2467
{
2459
2468
auto classRO = init.beginStruct ();
2460
- builder.emitRODataFields (classRO, ForMetaClass, DoesNotHaveUpdateCallback);
2469
+ builder.emitRODataFields (classRO, ForMetaClass, DoesNotHaveUpdateCallback,
2470
+ IsForGenericPattern);
2461
2471
classRO.finishAndAddTo (init);
2462
2472
}
2463
2473
0 commit comments