@@ -2565,28 +2565,12 @@ getProtocolDescriptorEntityReference(IRGenModule &IGM, ProtocolDecl *protocol) {
2565
2565
}
2566
2566
2567
2567
static TypeEntityReference
2568
- getObjCClassRefEntityReference (IRGenModule &IGM, ClassDecl *cls) {
2569
- // A reference to an Objective-C class object.
2570
- assert (cls->isObjC () && " Must have an Objective-C class here" );
2571
-
2572
- auto kind = TypeReferenceKind::IndirectObjCClass;
2573
- auto entity = LinkEntity::forObjCClassRef (cls);
2574
-
2575
- auto ref = IGM.getAddrOfLLVMVariableOrGOTEquivalent (entity);
2576
- assert (!ref.isIndirect ());
2577
-
2578
- return TypeEntityReference (kind, ref.getValue ());
2579
- }
2580
-
2581
- static TypeEntityReference
2582
- getRuntimeOnlyClassEntityReference (IRGenModule &IGM, ClassDecl *cls) {
2583
- assert (cls->getForeignClassKind () == ClassDecl::ForeignKind::RuntimeOnly);
2584
-
2585
- auto namedClangDecl = Mangle::ASTMangler::getClangDeclForMangling (cls);
2586
- assert (namedClangDecl);
2587
-
2568
+ getObjCClassByNameReference (IRGenModule &IGM, ClassDecl *cls) {
2588
2569
auto kind = TypeReferenceKind::DirectObjCClassName;
2589
- auto ref = IGM.getAddrOfGlobalString (namedClangDecl->getName ());
2570
+ SmallString<64 > objcRuntimeNameBuffer;
2571
+ auto ref = IGM.getAddrOfGlobalString (
2572
+ cls->getObjCRuntimeName (objcRuntimeNameBuffer),
2573
+ /* willByRelativelyAddressed=*/ true );
2590
2574
2591
2575
return TypeEntityReference (kind, ref);
2592
2576
}
@@ -2605,17 +2589,22 @@ IRGenModule::getTypeEntityReference(NominalTypeDecl *decl) {
2605
2589
2606
2590
switch (clas->getForeignClassKind ()) {
2607
2591
case ClassDecl::ForeignKind::RuntimeOnly:
2608
- return getRuntimeOnlyClassEntityReference (*this , clas);
2592
+ return getObjCClassByNameReference (*this , clas);
2609
2593
2610
2594
case ClassDecl::ForeignKind::CFType:
2611
2595
return getTypeContextDescriptorEntityReference (*this , clas);
2612
2596
2613
2597
case ClassDecl::ForeignKind::Normal:
2614
2598
if (hasKnownSwiftMetadata (*this , clas)) {
2615
2599
return getTypeContextDescriptorEntityReference (*this , clas);
2616
- } else {
2617
- return getObjCClassRefEntityReference (*this , clas);
2618
2600
}
2601
+
2602
+ // Note: we would like to use an Objective-C class reference, but the
2603
+ // Darwin linker currently has a bug where it will coalesce these symbols
2604
+ // *after* computing a relative offset, causing incorrect relative
2605
+ // offsets in the metadata. Therefore, reference Objective-C classes by
2606
+ // their runtime names.
2607
+ return getObjCClassByNameReference (*this , clas);
2619
2608
}
2620
2609
llvm_unreachable (" bad foreign type kind" );
2621
2610
}
0 commit comments