Implement Assembly.GetCallingAssembly for native AOT - #129963
#129963Implement Assembly.GetCallingAssembly for native AOT#129963MichalStrehovsky merged 4 commits intodotnet:maindotnet/runtime:mainfrom MichalStrehovsky:port-getcallingasmMichalStrehovsky/runtime:port-getcallingasmCopy head branch name to clipboard
Assembly.GetCallingAssembly for native AOT#129963Conversation
Fixes dotnet#129961 * Use stack trace data to find the calling assembly. * It is therefore only supportable if stack trace data is available. Block for the same reason under F5 debugging (CoreCLR). This is why it's a breaking change. * Maintain an arbitrary list of methods to skip in stacktraces to make calling this API work in a .cctor. Matches similar arbitrary list in CoreCLR to the extent that is covered by tests. * `canTailCall` is now same between ILC and crossgen2.
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
Pull request overview
Enables Assembly.GetCallingAssembly() on NativeAOT by deriving the calling assembly from stack-trace metadata, and updates the toolchain/JIT interface to keep tailcall behavior consistent across ILC and crossgen2. The PR also re-enables/extends relevant reflection tests now that NativeAOT support is present.
Changes:
- Implement
Assembly.GetCallingAssembly()for NativeAOT usingStackFrame+DiagnosticMethodInfowhen stack traces are supported. - Gate
GetCallingAssembly()onStackTrace.IsSupported(CoreCLR + NativeAOT) with a new resource string for the error. - Unify
canTailCallhandling by moving logic into the common JIT interface implementation and adjust tests accordingly.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.NativeAot.cs | Adds NativeAOT implementation of GetCallingAssembly() via stack walking and method info extraction. |
| src/coreclr/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs | Adds a StackTrace.IsSupported gate before CoreCLR’s existing stack-crawl-based implementation. |
| src/libraries/System.Private.CoreLib/src/Resources/Strings.resx | Adds a new resource string for the “stack trace support disabled” error path. |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Centralizes canTailCall logic and adjusts method attribute reporting for RequireSecObject. |
| src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs | Removes duplicate canTailCall implementation in favor of the common version. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs | Removes duplicate canTailCall implementation in favor of the common version. |
| src/libraries/System.Runtime/tests/System.Reflection.Tests/AssemblyTests.cs | Re-enables NativeAOT coverage and adds a delegate-based GetCallingAssembly test. |
| src/libraries/System.Runtime/tests/System.Reflection.Tests/MethodInfoTests.cs | Re-enables the aggressive-inlining callstack test on NativeAOT by removing an ActiveIssue skip. |
| src/libraries/System.Runtime/tests/System.Reflection.Tests/TestAssembly/ClassToInvoke.cs | Adds a helper method to invoke a delegate from a separate assembly for test coverage. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/ba-g new test added in #126124 is failing. will need disabling I guess, going to look at it next. |
|
Caution Security scanning requires review for Breaking Change Documentation DetailsThe threat detection results could not be parsed. The workflow output should be reviewed before merging. Review the workflow run logs for details. Breaking Change DocumentationA breaking change draft has been prepared for this PR. 👉 Click here to create the issue in dotnet/docs After creating the issue, please email a link to it to Note This documentation was generated with AI assistance from Copilot.
|
* Use stack trace data to find the calling assembly. * It is therefore only supportable if stack trace data is available. Block for the same reason under F5 debugging (CoreCLR). This is why it's a breaking change. * Maintain an arbitrary list of methods to skip in stacktraces to make calling this API work in a .cctor. Matches similar arbitrary list in CoreCLR to the extent that is covered by tests. * `canTailCall` is now same between ILC and crossgen2. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
canTailCallis now same between ILC and crossgen2.