diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index d38ca882b1dc097beb73b550bd43039ea20ae479..498e7b53a6e08f6d81c4dbbdf7c02813bd7d618c 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -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())