Implement Assembly.GetCallingAssembly for native AOT#129963
Implement Assembly.GetCallingAssembly for native AOT#129963MichalStrehovsky wants to merge 4 commits into
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). |
| continue; | ||
|
|
||
| // Skip the static constructor invocation machinery so that a GetCallingAssembly | ||
| // called from a class constructor sees the assembly that triggered the cctor. |
There was a problem hiding this comment.
CoreCLR skips reflection invoke too. Do we care?
runtime/src/coreclr/vm/appdomain.cpp
Line 1205 in 0d3df07
There was a problem hiding this comment.
Right, that's the "Matches similar arbitrary list in CoreCLR to the extent that is covered by tests." part of the PR description. If we don't care enough to have tests, then we probably don't care.
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Fixes #129961
canTailCallis now same between ILC and crossgen2.