@@ -296,9 +296,9 @@ class ObjCProtocolInitializerVisitor
296296 // Check if the ObjC runtime already has a descriptor for this
297297 // protocol. If so, use it.
298298 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+
302302 auto existing = Builder.CreateCall (objc_getProtocol, protocolName);
303303 auto isNull = Builder.CreateICmpEQ (existing,
304304 llvm::ConstantPointerNull::get (IGM.ProtocolDescriptorPtrTy ));
@@ -1056,16 +1056,14 @@ void IRGenModule::SetCStringLiteralSection(llvm::GlobalVariable *GV,
10561056 case llvm::Triple::MachO:
10571057 switch (Type) {
10581058 case ObjCLabelType::ClassName:
1059- GV->setSection (" __TEXT,__objc_classname,cstring_literals " );
1059+ GV->setSection (IRGenModule::ObjCClassNameSectionName );
10601060 return ;
10611061 case ObjCLabelType::MethodVarName:
1062- GV->setSection (" __TEXT,__objc_methname,cstring_literals" );
1062+ case ObjCLabelType::PropertyName:
1063+ GV->setSection (IRGenModule::ObjCMethodNameSectionName);
10631064 return ;
10641065 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);
10691067 return ;
10701068 }
10711069 case llvm::Triple::ELF:
@@ -4240,9 +4238,10 @@ static TypeEntityReference
42404238getObjCClassByNameReference (IRGenModule &IGM, ClassDecl *cls) {
42414239 auto kind = TypeReferenceKind::DirectObjCClassName;
42424240 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 );
42464245
42474246 return TypeEntityReference (kind, ref);
42484247}
@@ -4799,9 +4798,9 @@ void IRGenModule::emitAccessibleFunction(StringRef sectionName,
47994798
48004799 // -- Field: Name (record name)
48014800 {
4802- llvm::Constant *name =
4803- getAddrOfGlobalString ( func.getFunctionName (),
4804- /* willBeRelativelyAddressed=*/ true );
4801+ llvm::Constant *name = getAddrOfGlobalString (
4802+ func.getFunctionName (), CStringSectionType::Default ,
4803+ /* willBeRelativelyAddressed=*/ true );
48054804 fields.addRelativeAddress (name);
48064805 }
48074806
@@ -6023,15 +6022,34 @@ Address IRGenFunction::createAlloca(llvm::Type *type,
60236022// / FIXME: willBeRelativelyAddressed is only needed to work around an ld64 bug
60246023// / resolving relative references to coalesceable symbols.
60256024// / 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+ }
60316050
60326051 // 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];
60356053
60366054 if (entry.second ) {
60376055 // FIXME: Clear unnamed_addr if the global will be relative referenced
@@ -6053,9 +6071,6 @@ llvm::Constant *IRGenModule::getAddrOfGlobalString(StringRef data,
60536071 (llvm::Twine (" .nul" ) + llvm::Twine (i)).toVector (name);
60546072 }
60556073
6056- auto sectionName =
6057- useOSLogSection ? " __TEXT,__oslogstring,cstring_literals" : " " ;
6058-
60596074 entry = createStringConstant (data, willBeRelativelyAddressed,
60606075 sectionName, name);
60616076 return entry.second ;
@@ -6067,9 +6082,11 @@ IRGenModule::getAddrOfGlobalIdentifierString(StringRef data,
60676082 if (Lexer::identifierMustAlwaysBeEscaped (data)) {
60686083 llvm::SmallString<256 > name;
60696084 Mangle::Mangler::appendRawIdentifierForRuntime (data, name);
6070- return getAddrOfGlobalString (name, willBeRelativelyAddressed);
6085+ return getAddrOfGlobalString (name, CStringSectionType::Default,
6086+ willBeRelativelyAddressed);
60716087 }
6072- return getAddrOfGlobalString (data, willBeRelativelyAddressed);
6088+ return getAddrOfGlobalString (data, CStringSectionType::Default,
6089+ willBeRelativelyAddressed);
60736090}
60746091
60756092// / Get or create a global UTF-16 string constant.
0 commit comments