Skip to content

Conversation

@bholmes
Copy link
Contributor

@bholmes bholmes commented Aug 16, 2021

When a callvirt instruction is encountered on a static method, there is
a hard abort/crash. This commit avoids the problem.

When a callvirt instruction is encountered on a static method, there is
a hard abort/crash. This commit avoids the problem.
@ghost ghost added area-Codegen-JIT-mono community-contribution Indicates that the PR has been added by a community member labels Aug 16, 2021
@bholmes
Copy link
Contributor Author

bholmes commented Aug 16, 2021

Here is a small program that shows the abort.

using System;
using System.Reflection;
using System.Reflection.Emit;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            MethodInfo testMethod = typeof(Program).GetMethod("TestMethod");

            DynamicMethod dynamicMethod = new DynamicMethod("TestMethod", typeof(int), new Type[0], restrictedSkipVisibility: true);
            ILGenerator iLGenerator = dynamicMethod.GetILGenerator();
            iLGenerator.Emit(OpCodes.Callvirt, testMethod);
            iLGenerator.Emit(OpCodes.Ret);
            var ttt = (Func<int>)dynamicMethod.CreateDelegate(typeof(Func<int>));

            Console.WriteLine($"{ttt()}");
        }

        static public int TestMethod ()
        {
            return 42;
        }
    }
}

From this sample, the real problem is probably that CreateDelegate is not throwing because of the invalid IL. My commit does not address this aspect.

@bholmes
Copy link
Contributor Author

bholmes commented Aug 16, 2021

Can we sync this with the Mono repo as well?

@lambdageek
Copy link
Member

/azp run sync-runtime-to-mono

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lambdageek
Copy link
Member

@bholmes looks like the bot couldn't do the backport to mono/mono for some reason - could you open a PR manually

@bholmes
Copy link
Contributor Author

bholmes commented Aug 18, 2021

@bholmes looks like the bot couldn't do the backport to mono/mono for some reason - could you open a PR manually

mono/mono#21194

@akoeplinger
Copy link
Member

The wasm test failures are caused by #57501.

@akoeplinger akoeplinger merged commit 1ea615c into dotnet:main Aug 19, 2021
@srxqds
Copy link
Contributor

srxqds commented Aug 19, 2021

backport to .net6.0?

@akoeplinger
Copy link
Member

/backport to release/6.0-rc1

@github-actions
Copy link
Contributor

Started backporting to release/6.0-rc1: https://github.com/dotnet/runtime/actions/runs/1147170411

@ghost ghost locked as resolved and limited conversation to collaborators Sep 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Codegen-JIT-mono community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants