@@ -3644,6 +3644,43 @@ static void copySuperclassMetadataToSubclass(ClassMetadata *theClass,
3644
3644
#endif
3645
3645
}
3646
3646
3647
+ static void installOverrideInVTable (
3648
+ ClassDescriptor::MethodOverrideDescriptor const &descriptor,
3649
+ ClassDescriptor::OverrideTableHeader const *overrideTable,
3650
+ void **classWords) {
3651
+ // Get the base class and method.
3652
+ auto *baseClass = cast_or_null<ClassDescriptor>(descriptor.Class .get ());
3653
+ auto *baseMethod = descriptor.Method .get ();
3654
+
3655
+ // If the base method is null, it's an unavailable weak-linked
3656
+ // symbol.
3657
+ if (baseClass == nullptr || baseMethod == nullptr )
3658
+ return ;
3659
+
3660
+ // Calculate the base method's vtable offset from the
3661
+ // base method descriptor. The offset will be relative
3662
+ // to the base class's vtable start offset.
3663
+ auto baseClassMethods = baseClass->getMethodDescriptors ();
3664
+
3665
+ // If the method descriptor doesn't land within the bounds of the
3666
+ // method table, abort.
3667
+ if (baseMethod < baseClassMethods.begin () ||
3668
+ baseMethod >= baseClassMethods.end ()) {
3669
+ fatalError (0 ,
3670
+ " resilient vtable at %p contains out-of-bounds "
3671
+ " method descriptor %p\n " ,
3672
+ overrideTable, baseMethod);
3673
+ }
3674
+
3675
+ // Install the method override in our vtable.
3676
+ auto baseVTable = baseClass->getVTableDescriptor ();
3677
+ auto offset = (baseVTable->getVTableOffset (baseClass) +
3678
+ (baseMethod - baseClassMethods.data ()));
3679
+ swift_ptrauth_init_code_or_data (&classWords[offset], descriptor.getImpl (),
3680
+ baseMethod->Flags .getExtraDiscriminator (),
3681
+ !baseMethod->Flags .isData ());
3682
+ }
3683
+
3647
3684
// / Using the information in the class context descriptor, fill in in the
3648
3685
// / immediate vtable entries for the class and install overrides of any
3649
3686
// / superclass vtable entries.
@@ -3667,40 +3704,10 @@ static void initClassVTable(ClassMetadata *self) {
3667
3704
if (description->hasOverrideTable ()) {
3668
3705
auto *overrideTable = description->getOverrideTable ();
3669
3706
auto overrideDescriptors = description->getMethodOverrideDescriptors ();
3670
-
3671
3707
for (unsigned i = 0 , e = overrideTable->NumEntries ; i < e; ++i) {
3672
3708
auto &descriptor = overrideDescriptors[i];
3673
3709
3674
- // Get the base class and method.
3675
- auto *baseClass = cast_or_null<ClassDescriptor>(descriptor.Class .get ());
3676
- auto *baseMethod = descriptor.Method .get ();
3677
-
3678
- // If the base method is null, it's an unavailable weak-linked
3679
- // symbol.
3680
- if (baseClass == nullptr || baseMethod == nullptr )
3681
- continue ;
3682
-
3683
- // Calculate the base method's vtable offset from the
3684
- // base method descriptor. The offset will be relative
3685
- // to the base class's vtable start offset.
3686
- auto baseClassMethods = baseClass->getMethodDescriptors ();
3687
-
3688
- // If the method descriptor doesn't land within the bounds of the
3689
- // method table, abort.
3690
- if (baseMethod < baseClassMethods.begin () ||
3691
- baseMethod >= baseClassMethods.end ()) {
3692
- fatalError (0 , " resilient vtable at %p contains out-of-bounds "
3693
- " method descriptor %p\n " ,
3694
- overrideTable, baseMethod);
3695
- }
3696
-
3697
- // Install the method override in our vtable.
3698
- auto baseVTable = baseClass->getVTableDescriptor ();
3699
- auto offset = (baseVTable->getVTableOffset (baseClass) +
3700
- (baseMethod - baseClassMethods.data ()));
3701
- swift_ptrauth_init_code_or_data (&classWords[offset], descriptor.getImpl (),
3702
- baseMethod->Flags .getExtraDiscriminator (),
3703
- !baseMethod->Flags .isData ());
3710
+ installOverrideInVTable (descriptor, overrideTable, classWords);
3704
3711
}
3705
3712
}
3706
3713
}
0 commit comments