@@ -1319,22 +1319,25 @@ namespace {
1319
1319
assert (TheExtension && " can't emit category data for a class" );
1320
1320
ConstantInitBuilder builder (IGM);
1321
1321
auto fields = builder.beginStruct ();
1322
+ auto internalLinkage = llvm::GlobalVariable::InternalLinkage;
1322
1323
1323
1324
// struct category_t {
1324
1325
// char const *name;
1325
1326
fields.add (IGM.getAddrOfGlobalString (CategoryName));
1326
1327
// const class_t *theClass;
1327
1328
fields.add (getClassMetadataRef ());
1328
1329
// const method_list_t *instanceMethods;
1329
- emitAndAddMethodList (fields, MethodListKind::InstanceMethods);
1330
+ emitAndAddMethodList (fields, MethodListKind::InstanceMethods,
1331
+ internalLinkage);
1330
1332
// const method_list_t *classMethods;
1331
- emitAndAddMethodList (fields, MethodListKind::ClassMethods);
1333
+ emitAndAddMethodList (fields, MethodListKind::ClassMethods,
1334
+ internalLinkage);
1332
1335
// const protocol_list_t *baseProtocols;
1333
- fields.add (buildProtocolList ());
1336
+ fields.add (buildProtocolList (internalLinkage ));
1334
1337
// const property_list_t *properties;
1335
- fields.add (buildPropertyList (ForClass));
1338
+ fields.add (buildPropertyList (ForClass, internalLinkage ));
1336
1339
// const property_list_t *classProperties;
1337
- fields.add (buildPropertyList (ForMetaClass));
1340
+ fields.add (buildPropertyList (ForMetaClass, internalLinkage ));
1338
1341
// uint32_t size;
1339
1342
// FIXME: Clang does this by using non-ad-hoc types for ObjC runtime
1340
1343
// structures.
@@ -1344,13 +1347,14 @@ namespace {
1344
1347
1345
1348
assert (fields.getNextOffsetFromGlobal () == size);
1346
1349
return buildGlobalVariable (fields, " _CATEGORY_" , /* const*/ true ,
1347
- llvm::GlobalVariable::InternalLinkage );
1350
+ internalLinkage );
1348
1351
}
1349
1352
1350
1353
llvm::Constant *emitProtocol () {
1351
1354
ConstantInitBuilder builder (IGM);
1352
1355
auto fields = builder.beginStruct ();
1353
1356
llvm::SmallString<64 > nameBuffer;
1357
+ auto weakLinkage = llvm::GlobalVariable::WeakAnyLinkage;
1354
1358
1355
1359
assert (isBuildingProtocol () && " not emitting a protocol" );
1356
1360
@@ -1360,17 +1364,20 @@ namespace {
1360
1364
// char const *name;
1361
1365
fields.add (IGM.getAddrOfGlobalString (getEntityName (nameBuffer)));
1362
1366
// const protocol_list_t *baseProtocols;
1363
- fields.add (buildProtocolList ());
1367
+ fields.add (buildProtocolList (weakLinkage ));
1364
1368
// const method_list_t *requiredInstanceMethods;
1365
- emitAndAddMethodList (fields, MethodListKind::InstanceMethods);
1369
+ emitAndAddMethodList (fields, MethodListKind::InstanceMethods,
1370
+ weakLinkage);
1366
1371
// const method_list_t *requiredClassMethods;
1367
- emitAndAddMethodList (fields, MethodListKind::ClassMethods);
1372
+ emitAndAddMethodList (fields, MethodListKind::ClassMethods, weakLinkage );
1368
1373
// const method_list_t *optionalInstanceMethods;
1369
- emitAndAddMethodList (fields, MethodListKind::OptionalInstanceMethods);
1374
+ emitAndAddMethodList (fields, MethodListKind::OptionalInstanceMethods,
1375
+ weakLinkage);
1370
1376
// const method_list_t *optionalClassMethods;
1371
- emitAndAddMethodList (fields, MethodListKind::OptionalClassMethods);
1377
+ emitAndAddMethodList (fields, MethodListKind::OptionalClassMethods,
1378
+ weakLinkage);
1372
1379
// const property_list_t *properties;
1373
- fields.add (buildPropertyList (ForClass));
1380
+ fields.add (buildPropertyList (ForClass, weakLinkage ));
1374
1381
1375
1382
// uint32_t size;
1376
1383
// FIXME: Clang does this by using non-ad-hoc types for ObjC runtime
@@ -1392,11 +1399,12 @@ namespace {
1392
1399
// const char *demangledName;
1393
1400
fields.addNullPointer (IGM.Int8PtrTy );
1394
1401
// const property_list_t *classProperties;
1395
- fields.add (buildPropertyList (ForMetaClass));
1402
+ fields.add (buildPropertyList (ForMetaClass, weakLinkage ));
1396
1403
// };
1397
1404
1398
1405
assert (fields.getNextOffsetFromGlobal () == size);
1399
- return buildGlobalVariable (fields, " _PROTOCOL_" , /* const*/ true );
1406
+ return buildGlobalVariable (fields, " _PROTOCOL_" , /* const*/ true ,
1407
+ weakLinkage);
1400
1408
}
1401
1409
1402
1410
void emitRODataFields (ConstantStructBuilder &b,
@@ -1457,12 +1465,14 @@ namespace {
1457
1465
b.add (buildName ());
1458
1466
1459
1467
// const method_list_t *baseMethods;
1460
- emitAndAddMethodList (b, forMeta ? MethodListKind::ClassMethods
1461
- : MethodListKind::InstanceMethods);
1468
+ emitAndAddMethodList (b,
1469
+ forMeta ? MethodListKind::ClassMethods
1470
+ : MethodListKind::InstanceMethods,
1471
+ llvm::GlobalVariable::InternalLinkage);
1462
1472
1463
1473
// const protocol_list_t *baseProtocols;
1464
1474
// Apparently, this list is the same in the class and the metaclass.
1465
- b.add (buildProtocolList ());
1475
+ b.add (buildProtocolList (llvm::GlobalVariable::InternalLinkage ));
1466
1476
1467
1477
// const ivar_list_t *ivars;
1468
1478
if (forMeta) {
@@ -1476,7 +1486,7 @@ namespace {
1476
1486
b.addNullPointer (IGM.Int8PtrTy );
1477
1487
1478
1488
// const property_list_t *baseProperties;
1479
- b.add (buildPropertyList (forMeta));
1489
+ b.add (buildPropertyList (forMeta, llvm::GlobalVariable::InternalLinkage ));
1480
1490
1481
1491
// If hasUpdater is true, the metadata update callback goes here.
1482
1492
if (hasUpdater) {
@@ -1725,7 +1735,8 @@ namespace {
1725
1735
1726
1736
// / Emit the method list and add the pointer to the `builder`.
1727
1737
void emitAndAddMethodList (ConstantInitBuilder::StructBuilder &builder,
1728
- MethodListKind kind) {
1738
+ MethodListKind kind,
1739
+ llvm::GlobalValue::LinkageTypes linkage) {
1729
1740
ArrayRef<MethodDescriptor> methods;
1730
1741
StringRef namePrefix;
1731
1742
switch (kind) {
@@ -1750,7 +1761,8 @@ namespace {
1750
1761
namePrefix = " _PROTOCOL_INSTANCE_METHODS_OPT_" ;
1751
1762
break ;
1752
1763
}
1753
- llvm::Constant *methodListPtr = buildMethodList (methods, namePrefix);
1764
+ llvm::Constant *methodListPtr =
1765
+ buildMethodList (methods, namePrefix, linkage);
1754
1766
builder.add (methodListPtr);
1755
1767
}
1756
1768
@@ -1771,7 +1783,8 @@ namespace {
1771
1783
}
1772
1784
1773
1785
return buildGlobalVariable (array, " _PROTOCOL_METHOD_TYPES_" ,
1774
- /* const*/ true );
1786
+ /* const*/ true ,
1787
+ llvm::GlobalVariable::WeakAnyLinkage);
1775
1788
}
1776
1789
1777
1790
void buildExtMethodTypes (ConstantArrayBuilder &array,
@@ -1794,13 +1807,14 @@ namespace {
1794
1807
// /
1795
1808
// / This method does not return a value of a predictable type.
1796
1809
llvm::Constant *buildMethodList (ArrayRef<MethodDescriptor> methods,
1797
- StringRef name) {
1798
- return buildOptionalList (methods, 3 * IGM.getPointerSize (), name,
1799
- /* isConst*/ false ,
1800
- [&](ConstantArrayBuilder &descriptors,
1801
- MethodDescriptor descriptor) {
1802
- buildMethod (descriptors, descriptor);
1803
- });
1810
+ StringRef name,
1811
+ llvm::GlobalValue::LinkageTypes linkage) {
1812
+ return buildOptionalList (
1813
+ methods, 3 * IGM.getPointerSize (), name,
1814
+ /* isConst*/ false , linkage,
1815
+ [&](ConstantArrayBuilder &descriptors, MethodDescriptor descriptor) {
1816
+ buildMethod (descriptors, descriptor);
1817
+ });
1804
1818
}
1805
1819
1806
1820
/* ** Protocols *********************************************************/
@@ -1817,16 +1831,15 @@ namespace {
1817
1831
// / };
1818
1832
// /
1819
1833
// / This method does not return a value of a predictable type.
1820
- llvm::Constant *buildProtocolList () {
1821
- return buildOptionalList (Protocols, Size (0 ),
1822
- chooseNamePrefix (" _PROTOCOLS_" ,
1823
- " _CATEGORY_PROTOCOLS_" ,
1824
- " _PROTOCOL_PROTOCOLS_" ),
1825
- /* isConst*/ true ,
1826
- [&](ConstantArrayBuilder &descriptors,
1827
- ProtocolDecl *protocol) {
1828
- buildProtocol (descriptors, protocol);
1829
- });
1834
+ llvm::Constant *buildProtocolList (llvm::GlobalValue::LinkageTypes linkage) {
1835
+ return buildOptionalList (
1836
+ Protocols, Size (0 ),
1837
+ chooseNamePrefix (" _PROTOCOLS_" , " _CATEGORY_PROTOCOLS_" ,
1838
+ " _PROTOCOL_PROTOCOLS_" ),
1839
+ /* isConst*/ true , linkage,
1840
+ [&](ConstantArrayBuilder &descriptors, ProtocolDecl *protocol) {
1841
+ buildProtocol (descriptors, protocol);
1842
+ });
1830
1843
}
1831
1844
1832
1845
void buildProtocol (ConstantArrayBuilder &array, ProtocolDecl *protocol) {
@@ -1947,12 +1960,12 @@ namespace {
1947
1960
// / This method does not return a value of a predictable type.
1948
1961
llvm::Constant *buildIvarList () {
1949
1962
Size eltSize = 3 * IGM.getPointerSize () + Size (8 );
1950
- return buildOptionalList (Ivars, eltSize, " _IVARS_ " ,
1951
- /* constant */ true ,
1952
- [&](ConstantArrayBuilder &descriptors ,
1953
- Field field) {
1954
- buildIvar (descriptors, field);
1955
- });
1963
+ return buildOptionalList (
1964
+ Ivars, eltSize, " _IVARS_ " ,
1965
+ /* constant */ true , llvm::GlobalVariable::InternalLinkage ,
1966
+ [&](ConstantArrayBuilder &descriptors, Field field) {
1967
+ buildIvar (descriptors, field);
1968
+ });
1956
1969
}
1957
1970
1958
1971
/* ** Properties ********************************************************/
@@ -2060,12 +2073,14 @@ namespace {
2060
2073
// / };
2061
2074
// /
2062
2075
// / This method does not return a value of a predictable type.
2063
- llvm::Constant *buildPropertyList (ForMetaClass_t classOrMeta) {
2076
+ llvm::Constant *buildPropertyList (ForMetaClass_t classOrMeta,
2077
+ llvm::GlobalValue::LinkageTypes linkage) {
2064
2078
if (classOrMeta == ForClass) {
2065
2079
return buildPropertyList (InstanceProperties,
2066
2080
chooseNamePrefix (" _PROPERTIES_" ,
2067
2081
" _CATEGORY_PROPERTIES_" ,
2068
- " _PROTOCOL_PROPERTIES_" ));
2082
+ " _PROTOCOL_PROPERTIES_" ),
2083
+ linkage);
2069
2084
}
2070
2085
2071
2086
// Older OSs' libobjcs can't handle class property data.
@@ -2077,18 +2092,20 @@ namespace {
2077
2092
return buildPropertyList (ClassProperties,
2078
2093
chooseNamePrefix (" _CLASS_PROPERTIES_" ,
2079
2094
" _CATEGORY_CLASS_PROPERTIES_" ,
2080
- " _PROTOCOL_CLASS_PROPERTIES_" ));
2095
+ " _PROTOCOL_CLASS_PROPERTIES_" ),
2096
+ linkage);
2081
2097
}
2082
2098
2083
- llvm::Constant *buildPropertyList (ArrayRef<VarDecl*> properties,
2084
- StringRef namePrefix) {
2099
+ llvm::Constant *buildPropertyList (ArrayRef<VarDecl *> properties,
2100
+ StringRef namePrefix,
2101
+ llvm::GlobalValue::LinkageTypes linkage) {
2085
2102
Size eltSize = 2 * IGM.getPointerSize ();
2086
- return buildOptionalList (properties, eltSize, namePrefix,
2087
- /* constant */ true ,
2088
- [&](ConstantArrayBuilder &descriptors ,
2089
- VarDecl *property) {
2090
- buildProperty (descriptors, property);
2091
- });
2103
+ return buildOptionalList (
2104
+ properties, eltSize, namePrefix ,
2105
+ /* constant */ true , linkage ,
2106
+ [&](ConstantArrayBuilder &descriptors, VarDecl *property) {
2107
+ buildProperty (descriptors, property);
2108
+ });
2092
2109
}
2093
2110
2094
2111
/* ** General ***********************************************************/
@@ -2100,10 +2117,9 @@ namespace {
2100
2117
// / \param optionalEltSize - if non-zero, a size which needs
2101
2118
// / to be placed in the list header
2102
2119
template <class C , class Fn >
2103
- llvm::Constant *buildOptionalList (const C &objects,
2104
- Size optionalEltSize,
2105
- StringRef nameBase,
2106
- bool isConst,
2120
+ llvm::Constant *buildOptionalList (const C &objects, Size optionalEltSize,
2121
+ StringRef nameBase, bool isConst,
2122
+ llvm::GlobalValue::LinkageTypes linkage,
2107
2123
Fn &&buildElement) {
2108
2124
if (objects.empty ())
2109
2125
return null ();
@@ -2142,9 +2158,9 @@ namespace {
2142
2158
2143
2159
fields.fillPlaceholderWithInt (countPosition, countType, count);
2144
2160
2145
- return buildGlobalVariable (fields, nameBase, isConst);
2161
+ return buildGlobalVariable (fields, nameBase, isConst, linkage );
2146
2162
}
2147
-
2163
+
2148
2164
// / Get the name of the class or protocol to mangle into the ObjC symbol
2149
2165
// / name.
2150
2166
StringRef getEntityName (llvm::SmallVectorImpl<char > &buffer) const {
@@ -2171,9 +2187,9 @@ namespace {
2171
2187
// / Build a private global variable as a structure containing the
2172
2188
// / given fields.
2173
2189
template <class B >
2174
- llvm::Constant *buildGlobalVariable (B &fields, StringRef nameBase, bool isConst,
2175
- llvm::GlobalValue::LinkageTypes linkage =
2176
- llvm::GlobalVariable::WeakAnyLinkage ) {
2190
+ llvm::Constant *
2191
+ buildGlobalVariable (B &fields, StringRef nameBase, bool isConst,
2192
+ llvm::GlobalValue::LinkageTypes linkage ) {
2177
2193
llvm::SmallString<64 > nameBuffer;
2178
2194
auto var =
2179
2195
fields.finishAndCreateGlobal (Twine (nameBase)
0 commit comments