@@ -6562,15 +6562,20 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocolRef(
6562
6562
const ObjCProtocolDecl *PD) {
6563
6563
llvm::GlobalVariable *&Entry = Protocols[PD->getIdentifier ()];
6564
6564
6565
- if (!Entry)
6565
+ if (!Entry) {
6566
6566
// We use the initializer as a marker of whether this is a forward
6567
6567
// reference or not. At module finalization we add the empty
6568
6568
// contents for protocols which were referenced but never defined.
6569
- Entry =
6570
- new llvm::GlobalVariable (CGM.getModule (), ObjCTypes.ProtocolnfABITy ,
6571
- false , llvm::GlobalValue::ExternalLinkage,
6572
- nullptr ,
6573
- " \01 l_OBJC_PROTOCOL_$_" + PD->getObjCRuntimeNameAsString ());
6569
+ llvm::SmallString<64 > Protocol;
6570
+ llvm::raw_svector_ostream (Protocol) << " \01 l_OBJC_PROTOCOL_$_"
6571
+ << PD->getObjCRuntimeNameAsString ();
6572
+
6573
+ Entry = new llvm::GlobalVariable (CGM.getModule (), ObjCTypes.ProtocolnfABITy ,
6574
+ false , llvm::GlobalValue::ExternalLinkage,
6575
+ nullptr , Protocol);
6576
+ if (!CGM.getTriple ().isOSBinFormatMachO ())
6577
+ Entry->setComdat (CGM.getModule ().getOrInsertComdat (Protocol));
6578
+ }
6574
6579
6575
6580
return Entry;
6576
6581
}
@@ -6688,10 +6693,16 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol(
6688
6693
Entry->setLinkage (llvm::GlobalValue::WeakAnyLinkage);
6689
6694
Entry->setInitializer (Init);
6690
6695
} else {
6691
- Entry =
6692
- new llvm::GlobalVariable (CGM.getModule (), ObjCTypes.ProtocolnfABITy ,
6693
- false , llvm::GlobalValue::WeakAnyLinkage, Init,
6694
- " \01 l_OBJC_PROTOCOL_$_" + PD->getObjCRuntimeNameAsString ());
6696
+ llvm::SmallString<64 > Protocol;
6697
+ llvm::raw_svector_ostream (Protocol) << " \01 l_OBJC_PROTOCOL_$_"
6698
+ << PD->getObjCRuntimeNameAsString ();
6699
+
6700
+ Entry = new llvm::GlobalVariable (CGM.getModule (), ObjCTypes.ProtocolnfABITy ,
6701
+ false , llvm::GlobalValue::WeakAnyLinkage,
6702
+ Init, Protocol);
6703
+ if (!CGM.getTriple ().isOSBinFormatMachO ())
6704
+ Entry->setComdat (CGM.getModule ().getOrInsertComdat (Protocol));
6705
+
6695
6706
Entry->setAlignment (
6696
6707
CGM.getDataLayout ().getABITypeAlignment (ObjCTypes.ProtocolnfABITy ));
6697
6708
@@ -6702,13 +6713,20 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol(
6702
6713
6703
6714
// Use this protocol meta-data to build protocol list table in section
6704
6715
// __DATA, __objc_protolist
6716
+ llvm::SmallString<64 > ProtocolRef;
6717
+ llvm::raw_svector_ostream (ProtocolRef) << " \01 l_OBJC_LABEL_PROTOCOL_$_"
6718
+ << PD->getObjCRuntimeNameAsString ();
6719
+
6705
6720
llvm::GlobalVariable *PTGV =
6706
6721
new llvm::GlobalVariable (CGM.getModule (), ObjCTypes.ProtocolnfABIPtrTy ,
6707
6722
false , llvm::GlobalValue::WeakAnyLinkage, Entry,
6708
- " \01 l_OBJC_LABEL_PROTOCOL_$_" + PD->getObjCRuntimeNameAsString ());
6723
+ ProtocolRef);
6724
+ if (!CGM.getTriple ().isOSBinFormatMachO ())
6725
+ PTGV->setComdat (CGM.getModule ().getOrInsertComdat (ProtocolRef));
6709
6726
PTGV->setAlignment (
6710
6727
CGM.getDataLayout ().getABITypeAlignment (ObjCTypes.ProtocolnfABIPtrTy ));
6711
- PTGV->setSection (" __DATA, __objc_protolist, coalesced, no_dead_strip" );
6728
+ if (CGM.getTriple ().isOSBinFormatMachO ())
6729
+ PTGV->setSection (" __DATA, __objc_protolist, coalesced, no_dead_strip" );
6712
6730
PTGV->setVisibility (llvm::GlobalValue::HiddenVisibility);
6713
6731
CGM.addCompilerUsedGlobal (PTGV);
6714
6732
return Entry;
0 commit comments