Skip to content

Commit bfee5fb

Browse files
committed
IRGen: Emit list of Objective-C resilient class stubs in __objc_stublist section
Part of <rdar://problem/55000892>.
1 parent 5983960 commit bfee5fb

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,11 @@ void IRGenModule::addObjCClass(llvm::Constant *classPtr, bool nonlazy) {
897897
ObjCNonLazyClasses.push_back(classPtr);
898898
}
899899

900+
/// Add the given global value to the Objective-C resilient class stub list.
901+
void IRGenModule::addObjCClassStub(llvm::Constant *classPtr) {
902+
ObjCClassStubs.push_back(classPtr);
903+
}
904+
900905
void IRGenModule::addRuntimeResolvableType(GenericTypeDecl *type) {
901906
// Collect the nominal type records we emit into a special section.
902907
RuntimeResolvableTypes.push_back(type);
@@ -995,6 +1000,12 @@ void IRGenModule::emitGlobalLists() {
9951000
"regular,no_dead_strip"),
9961001
llvm::GlobalValue::InternalLinkage, Int8PtrTy, false);
9971002

1003+
// So do resilient class stubs.
1004+
emitGlobalList(*this, ObjCClassStubs, "objc_class_stubs",
1005+
GetObjCSectionName("__objc_stublist",
1006+
"regular,no_dead_strip"),
1007+
llvm::GlobalValue::InternalLinkage, Int8PtrTy, false);
1008+
9981009
// So do categories.
9991010
emitGlobalList(*this, ObjCCategories, "objc_categories",
10001011
GetObjCSectionName("__objc_catlist",

lib/IRGen/GenMeta.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3794,6 +3794,8 @@ void irgen::emitClassMetadata(IRGenModule &IGM, ClassDecl *classDecl,
37943794
classDecl, NotForDefinition,
37953795
TypeMetadataAddress::AddressPoint);
37963796
emitObjCClassSymbol(IGM, classDecl, stub);
3797+
3798+
IGM.addObjCClassStub(stub);
37973799
}
37983800
}
37993801
break;

lib/IRGen/IRGenModule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ class IRGenModule {
10041004
void addUsedGlobal(llvm::GlobalValue *global);
10051005
void addCompilerUsedGlobal(llvm::GlobalValue *global);
10061006
void addObjCClass(llvm::Constant *addr, bool nonlazy);
1007+
void addObjCClassStub(llvm::Constant *addr);
10071008
void addProtocolConformance(ConformanceDescription &&conformance);
10081009

10091010
llvm::Constant *emitSwiftProtocols();
@@ -1121,6 +1122,8 @@ class IRGenModule {
11211122
/// List of Objective-C classes that require nonlazy realization, bitcast to
11221123
/// i8*.
11231124
SmallVector<llvm::WeakTrackingVH, 4> ObjCNonLazyClasses;
1125+
/// List of Objective-C resilient class stubs, bitcast to i8*.
1126+
SmallVector<llvm::WeakTrackingVH, 4> ObjCClassStubs;
11241127
/// List of Objective-C categories, bitcast to i8*.
11251128
SmallVector<llvm::WeakTrackingVH, 4> ObjCCategories;
11261129
/// List of Objective-C categories on class stubs, bitcast to i8*.

test/IRGen/class_update_callback_with_stub.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ import resilient_objc_class
102102

103103
// NEGATIVE-NOT: @objc_classes =
104104

105+
// -- ... but they do appear in the stub list
106+
107+
// CHECK-LABEL: @objc_class_stubs = internal global
108+
// CHECK-SAME: @"$s31class_update_callback_with_stub25ResilientNSObjectSubclassCMs"
109+
// CHECK-SAME: , section "__DATA,__objc_stublist,regular,no_dead_strip"
110+
105111
// -- The category list
106112

107113
// CHECK-LABEL: @objc_categories = internal global

0 commit comments

Comments
 (0)