Skip to content

Commit

Permalink
Improve resiliency when rooting broken assemblies (#103962)
Browse files Browse the repository at this point in the history
Do a couple more upfront checks to trigger exceptions when it's recoverable. Fixes #103843.

We still eventually crash when generating debug information since we don't have fine grained tracking of what parts of the type we looked at. The user would need to drop debug info generation, or stop feeding us garbage.
  • Loading branch information
MichalStrehovsky authored Jun 26, 2024
1 parent f6e5e24 commit d6581f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ public static void CheckCanGenerateMethod(MethodDesc method)

private static void CheckTypeCanBeUsedInSignature(TypeDesc type)
{
MetadataType defType = type as MetadataType;

defType?.ComputeTypeContainsGCPointers();
((CompilerTypeSystemContext)type.Context).EnsureLoadableType(type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ public void AddCompilationRoot(TypeDesc type, string reason)

public void AddReflectionRoot(TypeDesc type, string reason)
{
_factory.TypeSystemContext.EnsureLoadableType(type);
TypeDesc lookedAtType = type;
do
{
_factory.TypeSystemContext.EnsureLoadableType(lookedAtType);
lookedAtType = (lookedAtType as MetadataType)?.ContainingType;
}
while (lookedAtType != null);

_rootAdder(_factory.ReflectedType(type), reason);
}

Expand All @@ -64,6 +71,7 @@ public void AddReflectionRoot(FieldDesc field, string reason)
if (!_factory.MetadataManager.IsReflectionBlocked(field))
{
_factory.TypeSystemContext.EnsureLoadableType(field.OwningType);
_factory.TypeSystemContext.EnsureLoadableType(field.FieldType);
_rootAdder(_factory.ReflectedField(field), reason);
}
}
Expand Down

0 comments on commit d6581f8

Please sign in to comment.