提交 703d58e9 编写于 作者: J Jan Vorlicek

Fix crossgen2 handling of direct calls to abstract methods

This change fixes two differences between old and new crossgen in the
getCallInfo method. Direct calls to abstract methods were being compiled
as if they were possible and lead to runtime crash in the call chain
from the PreStubWorker.
上级 05090222
......@@ -915,7 +915,7 @@ private static bool IsDynamicStatics(TypeDesc type)
// a static method would have never found an instance method.
if (originalMethod.Signature.IsStatic && (flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_CALLVIRT) != 0)
{
throw new BadImageFormatException();
throw new RequiresRuntimeJitException("CallVirt to static method");
}
exactType = type;
......@@ -1037,15 +1037,15 @@ private static bool IsDynamicStatics(TypeDesc type)
// Static methods are always direct calls
directCall = true;
}
else if ((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_CALLVIRT) == 0 || resolvedConstraint)
{
directCall = true;
}
else if (targetMethod.OwningType.IsInterface && targetMethod.IsAbstract)
{
// Backwards compat: calls to abstract interface methods are treated as callvirt
directCall = false;
}
else if ((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_CALLVIRT) == 0 || resolvedConstraint)
{
directCall = true;
}
else
{
bool devirt;
......@@ -1090,6 +1090,14 @@ private static bool IsDynamicStatics(TypeDesc type)
if (directCall)
{
// Direct calls to abstract methods are not allowed
if (targetMethod.IsAbstract &&
// Compensate for always treating delegates as direct calls above
!(((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_LDFTN) != 0) && ((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_CALLVIRT) != 0) && !resolvedCallVirt))
{
throw new RequiresRuntimeJitException("Direct calls to abstract methods are not allowed");
}
bool allowInstParam = (flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_ALLOWINSTPARAM) != 0;
if (!allowInstParam && canonMethod.RequiresInstArg())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册