Skip to content

Commit e914183

Browse files
Support for arbitrary self-referential static fields on a type (#118413)
- Instead of loading the static field type, use metadata directly to pull the needed info if we can't load the target type. - Add tests covering various scenarios found by customers in the last year or so - Remove existing scheme which could handle directly self referential statics - Defer checking RVA static valuetypes for their field type until a later type loader stage - Add VMFLAG for HasRVAStaticFields - Remove VMFLAG for HasPublicFields, this was found to be unused (its a legacy of an old CAS type loader check which no longer exists) Fixes #104511
1 parent 59ce21a commit e914183

File tree

6 files changed

+281
-225
lines changed

6 files changed

+281
-225
lines changed

src/coreclr/vm/class.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,22 @@ void ClassLoader::LoadExactParents(MethodTable* pMT)
11381138
EnsureLoaded(TypeHandle(pMT->GetCanonicalMethodTable()), CLASS_LOAD_EXACTPARENTS);
11391139
}
11401140

1141+
if (pMT->GetClass()->HasRVAStaticFields())
1142+
{
1143+
ApproxFieldDescIterator fdIterator(pMT, ApproxFieldDescIterator::STATIC_FIELDS);
1144+
FieldDesc* pFD = NULL;
1145+
while ((pFD = fdIterator.Next()) != NULL)
1146+
{
1147+
if (pFD->IsByValue() && pFD->IsRVA())
1148+
{
1149+
if (pFD->GetApproxFieldTypeHandleThrowing().GetMethodTable()->GetClass()->HasFieldsWhichMustBeInited())
1150+
{
1151+
ThrowHR(COR_E_BADIMAGEFORMAT);
1152+
}
1153+
}
1154+
}
1155+
}
1156+
11411157
LoadExactParentAndInterfacesTransitively(pMT);
11421158

11431159
if (pMT->GetClass()->HasVTableMethodImpl())

src/coreclr/vm/class.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,15 +1317,15 @@ class EEClass // DO NOT CREATE A NEW EEClass USING NEW!
13171317
LIMITED_METHOD_CONTRACT;
13181318
m_VMFlags |= (DWORD)VMFLAG_INLINE_ARRAY;
13191319
}
1320-
DWORD HasNonPublicFields()
1320+
DWORD HasRVAStaticFields()
13211321
{
13221322
LIMITED_METHOD_CONTRACT;
1323-
return (m_VMFlags & VMFLAG_HASNONPUBLICFIELDS);
1323+
return (m_VMFlags & VMFLAG_HASRVASTATICFIELDS);
13241324
}
1325-
void SetHasNonPublicFields()
1325+
void SetHasRVAStaticFields()
13261326
{
13271327
LIMITED_METHOD_CONTRACT;
1328-
m_VMFlags |= (DWORD)VMFLAG_HASNONPUBLICFIELDS;
1328+
m_VMFlags |= (DWORD)VMFLAG_HASRVASTATICFIELDS;
13291329
}
13301330
DWORD IsNotTightlyPacked()
13311331
{
@@ -1647,7 +1647,7 @@ class EEClass // DO NOT CREATE A NEW EEClass USING NEW!
16471647

16481648
VMFLAG_INLINE_ARRAY = 0x00010000,
16491649
VMFLAG_NO_GUID = 0x00020000,
1650-
VMFLAG_HASNONPUBLICFIELDS = 0x00040000,
1650+
VMFLAG_HASRVASTATICFIELDS = 0x00040000,
16511651
VMFLAG_HAS_CUSTOM_FIELD_ALIGNMENT = 0x00080000,
16521652
VMFLAG_CONTAINS_STACK_PTR = 0x00100000,
16531653
VMFLAG_PREFER_ALIGN8 = 0x00200000, // Would like to have 8-byte alignment

0 commit comments

Comments
 (0)