Repository navigation
Resolve diagnostic info for delegates pointing to stubs of folded methods - #137982
Draft
MichalStrehovsky wants to merge 1 commit into
Draft
MichalStrehovsky wants to merge 1 commit into
MichalStrehovsky wants to merge 1 commit into
Conversation
…hods When a method body is folded with the body of a different method, delegates pointing to stubs that forward to it (address-taken jump stubs, unboxing stubs, instantiating unboxing thunks) couldn't be mapped back to the right method. * Emit stack trace records keyed by such stubs. On WASM, stubs don't have a virtual IP so they're recorded by function pointer only (new IsStub command). * Look up function pointers in the stack trace tables without going through the code manager, which only knows about the managed code range. * Look up the stub before its target in DiagnosticMethodInfo.Create(Delegate) and in reflection's Delegate.Method lookup. * Add a StackTraceMetadata test variant that folds all identical method bodies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 81bced03-ceeb-4535-bba7-0bd66971e80d
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 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, @dotnet/ilc-contrib |
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The coupled NativeAOT metadata, WASM function identities, and runtime decoding paths require platform-specific execution to validate folding and exact generic identity, but those tests were not run.
No open issues 🎉
What changed in this PR
This PR preserves method identity in NativeAOT delegate diagnostics and reflection when identical method bodies are folded together, addressing #136811.
Changes:
- Emits diagnostic records keyed by forwarding stubs, with function-pointer-only records on WebAssembly.
- Resolves stub identities before falling back to their target bodies, without relying on code-manager ownership for diagnostic lookup.
- Expands delegate regression coverage and adds a test variant that enables folding across different methods.
| File | Description |
|---|---|
src/tests/nativeaot/SmokeTests/StackTraceMetadata/StackTraceMetadata_FoldAll.csproj |
Adds a smoke-test variant with all-body folding enabled. |
src/tests/nativeaot/SmokeTests/StackTraceMetadata/BodyFoldingTest.cs |
Adds generic and unboxing delegate identity checks, including diagnostic-only targets. |
src/coreclr/tools/Common/Internal/Runtime/StackTraceData.cs |
Defines the IsStub metadata command flag. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs |
Generates stub-keyed records for folded targets. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceMethodMappingNode.cs |
Serializes stub records and counts address-keyed entries separately. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs |
Excludes stub records from line-number mappings. |
src/coreclr/nativeaot/System.Private.StackTraceMetadata/src/Internal/StackTraceMetadata/StackTraceMetadata.cs |
Decodes stub records and searches module metadata directly by function pointer. |
src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs |
Prefers original stub pointers during reflection reverse lookup. |
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Delegate.NativeAot.cs |
Looks up diagnostic information for the stub before its target. |
Review effort: Balanced
Open
3 tasks
This was referenced Nov 20, 2026
This branch has not been deployed
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.
Fixes #136811
When a method body is folded with the body of a different method, delegates pointing to stubs that forward to it (address-taken jump stubs, unboxing stubs, instantiating unboxing thunks) couldn't be mapped back to the right method.