[release/10.0] Fix missing call to write barrier in static constructors of ref structs#125613
Open
janvorli wants to merge 1 commit intodotnet:release/10.0from
Open
[release/10.0] Fix missing call to write barrier in static constructors of ref structs#125613janvorli wants to merge 1 commit intodotnet:release/10.0from
janvorli wants to merge 1 commit intodotnet:release/10.0from
Conversation
…rs of ref structs The JIT was incorrectly handling initialization of static fields of ref structs. It was not adding call to JIT_ByRefWriteBarrier when setting these fields even though these statics live in GC heap. This issue was introduced in .NET 10 in dotnet#111733 This change fixes it and adds a regression test that causes fatal error when run with DOTNET_HeapVerify=1.
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a CoreCLR JIT importer annotation bug where stores to static fields declared on byref-like (ref struct) types could be incorrectly treated as targeting a non-heap location, which can suppress required write barriers and lead to GC heap corruption.
Changes:
- Update importer logic to only mark “field owner is byref-like ⇒ target not on heap” for non-static fields.
- Clarify the comment to reflect the corrected condition (byref-like owner and non-static).
You can also share your feedback on Copilot code review. Take the survey.
EgorBo
approved these changes
Mar 16, 2026
This was referenced Mar 16, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change fixes it and adds a regression test that causes fatal error when run with DOTNET_HeapVerify=1.
Backport of #125418 to release/10.0
Customer Impact
A customer has reported intermittent crashes in their application after migrating to .NET 10. Analysis has revealed GC heap corruption where a reference field of an object was pointing to a stale address of another object.
The JIT was incorrectly handling initialization of static fields of ref structs. It was not adding call to JIT_ByRefWriteBarrier when setting these fields even though these statics live in GC heap.
Regression
Testing
CI tests, local manual directed test provided by the customer
Risk
Low, the change just adds write barrier call for static fields of ref structs that were missing.