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