@@ -296,9 +296,9 @@ class ObjCProtocolInitializerVisitor
296
296
// Check if the ObjC runtime already has a descriptor for this
297
297
// protocol. If so, use it.
298
298
SmallString<32 > buf;
299
- auto protocolName
300
- = IGM. getAddrOfGlobalString ( proto->getObjCRuntimeName (buf));
301
-
299
+ auto protocolName = IGM. getAddrOfGlobalString (
300
+ proto->getObjCRuntimeName (buf), CStringSectionType::ObjCClassName );
301
+
302
302
auto existing = Builder.CreateCall (objc_getProtocol, protocolName);
303
303
auto isNull = Builder.CreateICmpEQ (existing,
304
304
llvm::ConstantPointerNull::get (IGM.ProtocolDescriptorPtrTy ));
@@ -1056,16 +1056,14 @@ void IRGenModule::SetCStringLiteralSection(llvm::GlobalVariable *GV,
1056
1056
case llvm::Triple::MachO:
1057
1057
switch (Type) {
1058
1058
case ObjCLabelType::ClassName:
1059
- GV->setSection (" __TEXT,__objc_classname,cstring_literals " );
1059
+ GV->setSection (IRGenModule::ObjCClassNameSectionName );
1060
1060
return ;
1061
1061
case ObjCLabelType::MethodVarName:
1062
- GV->setSection (" __TEXT,__objc_methname,cstring_literals" );
1062
+ case ObjCLabelType::PropertyName:
1063
+ GV->setSection (IRGenModule::ObjCMethodNameSectionName);
1063
1064
return ;
1064
1065
case ObjCLabelType::MethodVarType:
1065
- GV->setSection (" __TEXT,__objc_methtype,cstring_literals" );
1066
- return ;
1067
- case ObjCLabelType::PropertyName:
1068
- GV->setSection (" __TEXT,__objc_methname,cstring_literals" );
1066
+ GV->setSection (IRGenModule::ObjCMethodTypeSectionName);
1069
1067
return ;
1070
1068
}
1071
1069
case llvm::Triple::ELF:
@@ -4240,9 +4238,10 @@ static TypeEntityReference
4240
4238
getObjCClassByNameReference (IRGenModule &IGM, ClassDecl *cls) {
4241
4239
auto kind = TypeReferenceKind::DirectObjCClassName;
4242
4240
SmallString<64 > objcRuntimeNameBuffer;
4243
- auto ref = IGM.getAddrOfGlobalString (
4244
- cls->getObjCRuntimeName (objcRuntimeNameBuffer),
4245
- /* willBeRelativelyAddressed=*/ true );
4241
+ auto ref =
4242
+ IGM.getAddrOfGlobalString (cls->getObjCRuntimeName (objcRuntimeNameBuffer),
4243
+ CStringSectionType::ObjCClassName,
4244
+ /* willBeRelativelyAddressed=*/ true );
4246
4245
4247
4246
return TypeEntityReference (kind, ref);
4248
4247
}
@@ -4799,9 +4798,9 @@ void IRGenModule::emitAccessibleFunction(StringRef sectionName,
4799
4798
4800
4799
// -- Field: Name (record name)
4801
4800
{
4802
- llvm::Constant *name =
4803
- getAddrOfGlobalString ( func.getFunctionName (),
4804
- /* willBeRelativelyAddressed=*/ true );
4801
+ llvm::Constant *name = getAddrOfGlobalString (
4802
+ func.getFunctionName (), CStringSectionType::Default ,
4803
+ /* willBeRelativelyAddressed=*/ true );
4805
4804
fields.addRelativeAddress (name);
4806
4805
}
4807
4806
@@ -6023,15 +6022,34 @@ Address IRGenFunction::createAlloca(llvm::Type *type,
6023
6022
// / FIXME: willBeRelativelyAddressed is only needed to work around an ld64 bug
6024
6023
// / resolving relative references to coalesceable symbols.
6025
6024
// / It should be removed when fixed. rdar://problem/22674524
6026
- llvm::Constant *IRGenModule::getAddrOfGlobalString (StringRef data,
6027
- bool willBeRelativelyAddressed,
6028
- bool useOSLogSection) {
6029
- useOSLogSection = useOSLogSection &&
6030
- TargetInfo.OutputObjectFormat == llvm::Triple::MachO;
6025
+ llvm::Constant *
6026
+ IRGenModule::getAddrOfGlobalString (StringRef data, CStringSectionType type,
6027
+ bool willBeRelativelyAddressed) {
6028
+ if (TargetInfo.OutputObjectFormat != llvm::Triple::MachO)
6029
+ type = CStringSectionType::Default;
6030
+ StringRef sectionName;
6031
+ switch (type) {
6032
+ case CStringSectionType::Default:
6033
+ sectionName = " " ;
6034
+ break ;
6035
+ case CStringSectionType::ObjCClassName:
6036
+ sectionName = ObjCClassNameSectionName;
6037
+ break ;
6038
+ case CStringSectionType::ObjCMethodName:
6039
+ sectionName = ObjCMethodNameSectionName;
6040
+ break ;
6041
+ case CStringSectionType::ObjCMethodType:
6042
+ sectionName = ObjCMethodTypeSectionName;
6043
+ break ;
6044
+ case CStringSectionType::OSLogString:
6045
+ sectionName = OSLogStringSectionName;
6046
+ break ;
6047
+ case CStringSectionType::NumTypes:
6048
+ llvm_unreachable (" invalid type" );
6049
+ }
6031
6050
6032
6051
// Check whether this string already exists.
6033
- auto &entry = useOSLogSection ? GlobalOSLogStrings[data] :
6034
- GlobalStrings[data];
6052
+ auto &entry = GlobalStrings[static_cast <size_t >(type)][data];
6035
6053
6036
6054
if (entry.second ) {
6037
6055
// FIXME: Clear unnamed_addr if the global will be relative referenced
@@ -6053,9 +6071,6 @@ llvm::Constant *IRGenModule::getAddrOfGlobalString(StringRef data,
6053
6071
(llvm::Twine (" .nul" ) + llvm::Twine (i)).toVector (name);
6054
6072
}
6055
6073
6056
- auto sectionName =
6057
- useOSLogSection ? " __TEXT,__oslogstring,cstring_literals" : " " ;
6058
-
6059
6074
entry = createStringConstant (data, willBeRelativelyAddressed,
6060
6075
sectionName, name);
6061
6076
return entry.second ;
@@ -6067,9 +6082,11 @@ IRGenModule::getAddrOfGlobalIdentifierString(StringRef data,
6067
6082
if (Lexer::identifierMustAlwaysBeEscaped (data)) {
6068
6083
llvm::SmallString<256 > name;
6069
6084
Mangle::Mangler::appendRawIdentifierForRuntime (data, name);
6070
- return getAddrOfGlobalString (name, willBeRelativelyAddressed);
6085
+ return getAddrOfGlobalString (name, CStringSectionType::Default,
6086
+ willBeRelativelyAddressed);
6071
6087
}
6072
- return getAddrOfGlobalString (data, willBeRelativelyAddressed);
6088
+ return getAddrOfGlobalString (data, CStringSectionType::Default,
6089
+ willBeRelativelyAddressed);
6073
6090
}
6074
6091
6075
6092
// / Get or create a global UTF-16 string constant.
0 commit comments