Repository navigation
Report byref-like struct arguments to the GC in helper-based tail calls - #136019
Merged
Merged
Conversation
TailCallHelp::GenerateGCDescriptor skipped value types without GC series, but byref-like structs such as Span<T> have no series and still contain interior pointers. These were not reported while stored in the tail call arg buffer, so a GC between the store-args and call-target stubs left the callee with a stale pointer. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8a8cb9fd-0c26-426d-9657-9398252f7bce
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke |
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8a8cb9fd-0c26-426d-9657-9398252f7bce
jkotas
approved these changes
Oct 18, 2026
Member
|
Can we add a regression test in IL? |
jkotas
self-requested a review
October 18, 2026 06:00
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8a8cb9fd-0c26-426d-9657-9398252f7bce
Member
Author
added |
EgorBo
marked this pull request as ready for review
October 18, 2026 14:10
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8a8cb9fd-0c26-426d-9657-9398252f7bce
Member
Author
Not reliably just like with any GC hole tests, my previous version of that test included a loop with GC.Collect, but such tests are slow (and gcstress makes them even slower), so I pushed a simple version. Before the fix it would fail probably a few times a week I guess. |
Member
|
Backport candidate? |
Merged
2 of 4 tasks
JulieLeeMSFT
pushed a commit
that referenced
this pull request
Oct 19, 2026
…-based tail calls (#136082) Fixes Issue #136010 <!-- Issue Number --> main PR #136019 <!-- Link to PR if any that fixed this in the main branch. --> # Description <!-- Give a brief summary of the issue and how the pull request is fixing it. --> Backport of #136019 to release/11.0. Include byref-like structs when generating the GC descriptor for the helper-based tail-call argument buffer. The IL regression test is placed under the release branch's existing merged runner. # Customer Impact <!-- What is the impact to customers of not taking this fix? --> - [x] Customer reported - [ ] Found internally Safe managed code passing a `Span<T>` through a helper-based tail call can suffer memory corruption, wrong results, hangs, or fatal crashes if a GC moves the underlying array while the arguments are buffered. Reported with F# on Windows x64. # Regression <!-- Is this fixing a problem that was introduced in the most recent release, ie., fixing a regression? --> - [ ] Yes - [x] No The issue also reproduces on .NET 8, 9, and 10. # Testing <!-- What kind of testing has been done with the fix. --> Test is added. # Risk <!-- Please assess the risk of taking this fix. Provide details backing up your assessment. --> Low. Uses existing GC-layout handling for byref-like structs. Co-authored-by: Copilot <[email protected]> Copilot-Session: 293a4931-e666-4c2c-bf85-571092949275
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
TailCallHelp::GenerateGCDescriptorskipped value types that have no GC series, but byref-like structs such asSpan<T>have none and still contain an interior pointer. It was not reported to the GC while stored in the tail call arg buffer, so a GC betweenIL_STUB_StoreTailCallArgsandIL_STUB_CallTailCallTargetleft the callee with a stale pointer into the old location of the array.Treat byref-like structs like structs with GC pointers when building the descriptor.
getClassGClayoutStaticalready reports their byref fields asTYPE_GC_BYREF.Adds a minimal IL regression test: a helper-based tail call with a
Span<int>argument. It needs a GC between the tail call stubs to fail, so it is mainly caught by the GC stress legs.Fixes #136010