@@ -556,7 +556,7 @@ static llvm::GlobalVariable *
556556emitGlobalList (IRGenModule &IGM, ArrayRef<llvm::WeakTrackingVH> handles,
557557 StringRef name, StringRef section,
558558 llvm::GlobalValue::LinkageTypes linkage, llvm::Type *eltTy,
559- bool isConstant, bool asContiguousArray) {
559+ bool isConstant, bool asContiguousArray, bool canBeStrippedByLinker = false ) {
560560 // Do nothing if the list is empty.
561561 if (handles.empty ()) return nullptr ;
562562
@@ -578,8 +578,12 @@ emitGlobalList(IRGenModule &IGM, ArrayRef<llvm::WeakTrackingVH> handles,
578578 var->setSection (section);
579579 var->setAlignment (llvm::MaybeAlign (alignment.getValue ()));
580580 disableAddressSanitizer (IGM, var);
581- if (llvm::GlobalValue::isLocalLinkage (linkage))
582- IGM.addUsedGlobal (var);
581+ if (llvm::GlobalValue::isLocalLinkage (linkage)) {
582+ if (canBeStrippedByLinker)
583+ IGM.addCompilerUsedGlobal (var);
584+ else
585+ IGM.addUsedGlobal (var);
586+ }
583587
584588 if (IGM.IRGen .Opts .ConditionalRuntimeRecords ) {
585589 // Allow dead-stripping `var` (the runtime record from the global list)
@@ -616,8 +620,12 @@ emitGlobalList(IRGenModule &IGM, ArrayRef<llvm::WeakTrackingVH> handles,
616620
617621 // Mark the variable as used if doesn't have external linkage.
618622 // (Note that we'd specifically like to not put @llvm.used in itself.)
619- if (llvm::GlobalValue::isLocalLinkage (linkage))
620- IGM.addUsedGlobal (var);
623+ if (llvm::GlobalValue::isLocalLinkage (linkage)) {
624+ if (canBeStrippedByLinker)
625+ IGM.addCompilerUsedGlobal (var);
626+ else
627+ IGM.addUsedGlobal (var);
628+ }
621629 return var;
622630}
623631
@@ -962,6 +970,10 @@ void IRGenModule::addCompilerUsedGlobal(llvm::GlobalValue *global) {
962970 LLVMCompilerUsed.push_back (global);
963971}
964972
973+ void IRGenModule::addGenericROData (llvm::Constant *RODataAddr) {
974+ GenericRODatas.push_back (RODataAddr);
975+ }
976+
965977// / Add the given global value to the Objective-C class list.
966978void IRGenModule::addObjCClass (llvm::Constant *classPtr, bool nonlazy) {
967979 ObjCClasses.push_back (classPtr);
@@ -1067,6 +1079,14 @@ void IRGenModule::SetCStringLiteralSection(llvm::GlobalVariable *GV,
10671079
10681080void IRGenModule::emitGlobalLists () {
10691081 if (ObjCInterop) {
1082+ if (IRGen.Opts .EmitGenericRODatas ) {
1083+ emitGlobalList (
1084+ *this , GenericRODatas, " generic_ro_datas" ,
1085+ GetObjCSectionName (" __swift_rodatas" , " regular" ),
1086+ llvm::GlobalValue::InternalLinkage, Int8PtrTy, /* isConstant*/ false ,
1087+ /* asContiguousArray*/ true , /* canBeStrippedByLinker*/ true );
1088+ }
1089+
10701090 // Objective-C class references go in a variable with a meaningless
10711091 // name but a magic section.
10721092 emitGlobalList (
0 commit comments