Skip to content

Commit f957f45

Browse files
committed
factor section names into constants
1 parent 6c235b2 commit f957f45

File tree

5 files changed

+41
-28
lines changed

5 files changed

+41
-28
lines changed

lib/IRGen/GenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
14031403
IGF.IGM.getClangASTContext().getObjCEncodingForType(clangTy, encoding);
14041404

14051405
auto globalString = IGF.IGM.getAddrOfGlobalString(
1406-
encoding, /*sectionName=*/"__TEXT,__objc_methtype,cstring_literals");
1406+
encoding, IRGenModule::ObjCMethodTypeSectionName);
14071407
out.add(globalString);
14081408
return;
14091409
}

lib/IRGen/GenClass.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,8 @@ namespace {
14641464

14651465
// struct category_t {
14661466
// char const *name;
1467-
fields.add(IGM.getAddrOfGlobalString(CategoryName, /*sectionName=*/"__TEXT,__objc_classname,cstring_literals")));
1467+
fields.add(IGM.getAddrOfGlobalString(
1468+
CategoryName, IRGenModule::ObjCClassNameSectionName));
14681469
// const class_t *theClass;
14691470
fields.add(getClassMetadataRef());
14701471
// const method_list_t *instanceMethods;
@@ -1503,7 +1504,8 @@ namespace {
15031504
// Class super;
15041505
fields.addNullPointer(IGM.Int8PtrTy);
15051506
// char const *name;
1506-
fields.add(IGM.getAddrOfGlobalString(getEntityName(nameBuffer), /*sectionName=*/"__TEXT,__objc_classname,cstring_literals")));
1507+
fields.add(IGM.getAddrOfGlobalString(
1508+
getEntityName(nameBuffer), IRGenModule::ObjCClassNameSectionName));
15071509
// const protocol_list_t *baseProtocols;
15081510
fields.add(buildProtocolList(weakLinkage));
15091511
// const method_list_t *requiredInstanceMethods;
@@ -1724,7 +1726,8 @@ namespace {
17241726
}
17251727

17261728
llvm::SmallString<64> buffer;
1727-
Name = IGM.getAddrOfGlobalString(getClass()->getObjCRuntimeName(buffer), /*sectionName=*/"__TEXT,__objc_classname,cstring_literals"));
1729+
Name = IGM.getAddrOfGlobalString(getClass()->getObjCRuntimeName(buffer),
1730+
IRGenModule::ObjCClassNameSectionName);
17281731
return Name;
17291732
}
17301733

@@ -2088,8 +2091,10 @@ namespace {
20882091
else
20892092
fields.addNullPointer(IGM.PtrTy);
20902093

2091-
fields.add(IGM.getAddrOfGlobalString(name), /*sectionName=*/"__TEXT,__objc_methname,cstring_literals"));
2092-
fields.add(IGM.getAddrOfGlobalString(typeEnc), /*sectionName=*/"__TEXT,__objc_methtype,cstring_literals"));
2094+
fields.add(IGM.getAddrOfGlobalString(
2095+
name, IRGenModule::ObjCMethodNameSectionName));
2096+
fields.add(IGM.getAddrOfGlobalString(
2097+
typeEnc, IRGenModule::ObjCMethodTypeSectionName));
20932098

20942099
Size size;
20952100
Alignment alignment;
@@ -2225,8 +2230,11 @@ namespace {
22252230
buildPropertyAttributes(prop, propertyAttributes);
22262231

22272232
auto fields = properties.beginStruct();
2228-
fields.add(IGM.getAddrOfGlobalString(prop->getObjCPropertyName().str(), /*sectionName=*/"__TEXT,__objc_methname,cstring_literals")));
2229-
fields.add(IGM.getAddrOfGlobalString(propertyAttributes, /*sectionName=*/"__TEXT,__objc_methname,cstring_literals")));
2233+
fields.add(
2234+
IGM.getAddrOfGlobalString(prop->getObjCPropertyName().str(),
2235+
IRGenModule::ObjCPropertyNameSectionName));
2236+
fields.add(IGM.getAddrOfGlobalString(
2237+
propertyAttributes, IRGenModule::ObjCPropertyNameSectionName));
22302238
fields.finishAndAddTo(properties);
22312239
}
22322240

lib/IRGen/GenDecl.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ class ObjCProtocolInitializerVisitor
297297
// protocol. If so, use it.
298298
SmallString<32> buf;
299299
auto protocolName = IGM.getAddrOfGlobalString(
300-
proto->getObjCRuntimeName(buf),
301-
/*sectionName=*/"__TEXT,__objc_classname,cstring_literals");
300+
proto->getObjCRuntimeName(buf), IRGenModule::ObjCClassNameSectionName);
302301

303302
auto existing = Builder.CreateCall(objc_getProtocol, protocolName);
304303
auto isNull = Builder.CreateICmpEQ(existing,
@@ -1057,16 +1056,16 @@ void IRGenModule::SetCStringLiteralSection(llvm::GlobalVariable *GV,
10571056
case llvm::Triple::MachO:
10581057
switch (Type) {
10591058
case ObjCLabelType::ClassName:
1060-
GV->setSection("__TEXT,__objc_classname,cstring_literals");
1059+
GV->setSection(IRGenModule::ObjCClassNameSectionName);
10611060
return;
10621061
case ObjCLabelType::MethodVarName:
1063-
GV->setSection("__TEXT,__objc_methname,cstring_literals");
1062+
GV->setSection(IRGenModule::ObjCMethodNameSectionName);
10641063
return;
10651064
case ObjCLabelType::MethodVarType:
1066-
GV->setSection("__TEXT,__objc_methtype,cstring_literals");
1065+
GV->setSection(IRGenModule::ObjCMethodTypeSectionName);
10671066
return;
10681067
case ObjCLabelType::PropertyName:
1069-
GV->setSection("__TEXT,__objc_methname,cstring_literals");
1068+
GV->setSection(IRGenModule::ObjCPropertyNameSectionName);
10701069
return;
10711070
}
10721071
case llvm::Triple::ELF:
@@ -4241,10 +4240,10 @@ static TypeEntityReference
42414240
getObjCClassByNameReference(IRGenModule &IGM, ClassDecl *cls) {
42424241
auto kind = TypeReferenceKind::DirectObjCClassName;
42434242
SmallString<64> objcRuntimeNameBuffer;
4244-
auto ref = IGM.getAddrOfGlobalString(
4245-
cls->getObjCRuntimeName(objcRuntimeNameBuffer),
4246-
/*sectionName=*/"__TEXT,__objc_classname,cstring_literals",
4247-
/*willBeRelativelyAddressed=*/true);
4243+
auto ref =
4244+
IGM.getAddrOfGlobalString(cls->getObjCRuntimeName(objcRuntimeNameBuffer),
4245+
IRGenModule::ObjCClassNameSectionName,
4246+
/*willBeRelativelyAddressed=*/true);
42484247

42494248
return TypeEntityReference(kind, ref);
42504249
}

lib/IRGen/GenObjC.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,9 +1318,8 @@ static llvm::Constant *getObjCEncodingForTypes(IRGenModule &IGM,
13181318
encodingString += llvm::itostr(parmOffset);
13191319
encodingString += fixedParamsString;
13201320
encodingString += paramsString;
1321-
return IGM.getAddrOfGlobalString(
1322-
encodingString,
1323-
/*sectionName=*/"__TEXT,__objc_methtype,cstring_literals");
1321+
return IGM.getAddrOfGlobalString(encodingString,
1322+
IRGenModule::ObjCMethodTypeSectionName);
13241323
}
13251324

13261325
static llvm::Constant *
@@ -1335,12 +1334,12 @@ getObjectEncodingFromClangNode(IRGenModule &IGM, Decl *d,
13351334
if (auto objcMethodDecl = dyn_cast<clang::ObjCMethodDecl>(clangDecl)) {
13361335
typeStr = clangASTContext.getObjCEncodingForMethodDecl(
13371336
objcMethodDecl, useExtendedEncoding /*extended*/);
1338-
sectionName = "__TEXT,__objc_methtype,cstring_literals";
1337+
sectionName = IRGenModule::ObjCMethodTypeSectionName;
13391338
}
13401339
if (auto objcPropertyDecl = dyn_cast<clang::ObjCPropertyDecl>(clangDecl)) {
13411340
typeStr = clangASTContext.getObjCEncodingForPropertyDecl(objcPropertyDecl,
13421341
nullptr);
1343-
sectionName = "__TEXT,__objc_methname,cstring_literals";
1342+
sectionName = IRGenModule::ObjCPropertyNameSectionName;
13441343
}
13451344
if (!typeStr.empty()) {
13461345
return IGM.getAddrOfGlobalString(typeStr.c_str(), sectionName);
@@ -1440,8 +1439,7 @@ irgen::emitObjCGetterDescriptorParts(IRGenModule &IGM, VarDecl *property) {
14401439
TypeStr += "@0:";
14411440
TypeStr += llvm::itostr(PtrSize.getValue());
14421441
descriptor.typeEncoding = IGM.getAddrOfGlobalString(
1443-
TypeStr.c_str(),
1444-
/*sectionName=*/"__TEXT,__objc_methtype,cstring_literals");
1442+
TypeStr.c_str(), IRGenModule::ObjCMethodTypeSectionName);
14451443
descriptor.silFunction = nullptr;
14461444
descriptor.impl = getObjCGetterPointer(IGM, property, descriptor.silFunction);
14471445
return descriptor;
@@ -1519,8 +1517,7 @@ irgen::emitObjCSetterDescriptorParts(IRGenModule &IGM,
15191517
clangASTContext.getObjCEncodingForType(clangType, TypeStr);
15201518
TypeStr += llvm::itostr(ParmOffset);
15211519
descriptor.typeEncoding = IGM.getAddrOfGlobalString(
1522-
TypeStr.c_str(),
1523-
/*sectionName=*/"__TEXT,__objc_methtype,cstring_literals");
1520+
TypeStr.c_str(), IRGenModule::ObjCMethodTypeSectionName);
15241521
descriptor.silFunction = nullptr;
15251522
descriptor.impl = getObjCSetterPointer(IGM, property, descriptor.silFunction);
15261523
return descriptor;
@@ -1627,7 +1624,7 @@ void irgen::emitObjCIVarInitDestroyDescriptor(IRGenModule &IGM,
16271624
llvm::SmallString<8> signature;
16281625
signature = "v" + llvm::itostr(ptrSize * 2) + "@0:" + llvm::itostr(ptrSize);
16291626
descriptor.typeEncoding = IGM.getAddrOfGlobalString(
1630-
signature, /*sectionName=*/"__TEXT,__objc_methtype,cstring_literals");
1627+
signature, IRGenModule::ObjCMethodTypeSectionName);
16311628

16321629
/// The third element is the method implementation pointer.
16331630
descriptor.impl = llvm::ConstantExpr::getBitCast(objcImpl, IGM.Int8PtrTy);

lib/IRGen/IRGenModule.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,15 @@ class IRGenModule {
15441544
const char *getReflectionTypeRefSectionName();
15451545
const char *getMultiPayloadEnumDescriptorSectionName();
15461546

1547+
static constexpr const char ObjCClassNameSectionName[] =
1548+
"__TEXT,__objc_classname,cstring_literals";
1549+
static constexpr const char ObjCMethodNameSectionName[] =
1550+
"__TEXT,__objc_methname,cstring_literals";
1551+
static constexpr const char ObjCMethodTypeSectionName[] =
1552+
"__TEXT,__objc_methtype,cstring_literals";
1553+
static constexpr const char ObjCPropertyNameSectionName[] =
1554+
"__TEXT,__objc_methname,cstring_literals";
1555+
15471556
/// Returns the special builtin types that should be emitted in the stdlib
15481557
/// module.
15491558
llvm::ArrayRef<CanType> getOrCreateSpecialStlibBuiltinTypes();

0 commit comments

Comments
 (0)