Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pattern recognition for calls to RuntimeHelpers.RunClassConstructor #970

Closed
vitek-karas opened this issue Feb 27, 2020 · 1 comment · Fixed by #1121
Closed

Add pattern recognition for calls to RuntimeHelpers.RunClassConstructor #970

vitek-karas opened this issue Feb 27, 2020 · 1 comment · Fixed by #1121
Assignees
Milestone

Comments

@vitek-karas
Copy link
Member

Linker may decide to trim static .cctor from a class if it doesn't find a need to keep it. Calling System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor is in such case unsafe as it requires the static .cctor to be present to work correctly.

Linker should be able to analyze simple patterns calling the RunClassConstructor and include the necessary static .cctor. The minimum pattern to support should be:

RuntimeHelpers.RunClassConstructor(typeof(MyClass));

Once implement we can basically revert this change in CoreLib dotnet/runtime#31718.
This is a preferred solution to the changes suggested in #966.

@marek-safar
Copy link
Contributor

Interestingly this API is used more often than I thought (2 hits in libraries, 1 in coreclr).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants