-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[mono][interp] Disable inlining of methods that call methods using StackCrawlMark #116134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The stack mark is used only to prevent inlining of the callers of this method (since it sets a flag on the method in question). The stack mark itself is not currently used on mono.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request disables inlining for methods that call methods marked with special flags (such as those using StackCrawlMark) to prevent incorrect results due to inlining. Key changes include:
- Adding a flag check (METHOD_ATTRIBUTE_REQSECOBJ) in the interpreter transform to prevent inlining.
- Updating the signature of ves_icall_System_Reflection_Assembly_GetCallingAssembly and its registration in icall-def.h.
- Replacing the public extern GetCallingAssembly with a managed implementation that passes a StackCrawlMark parameter in Assembly.Mono.cs.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/mono/mono/mini/interp/transform.c | Added a flag check to disable inlining for methods requiring a security object. |
src/mono/mono/metadata/icall.c | Updated signature of GetCallingAssembly to accept a StackCrawlMark parameter. |
src/mono/mono/metadata/icall-def.h | Adjusted the HANDLES macro to reflect the new parameter count and type. |
src/mono/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs | Replaced the extern GetCallingAssembly with a managed wrapper that sets a default StackCrawlMark. |
Comments suppressed due to low confidence (1)
src/mono/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs:46
- The removal of the DynamicSecurityMethod attribute from GetCallingAssembly might affect required security semantics for stack walks. Verify if this change is intentional and restore the attribute if needed.
public static Assembly GetCallingAssembly()
@@ -3854,6 +3854,8 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target | |||
} else if (td->method->wrapper_type == MONO_WRAPPER_RUNTIME_INVOKE) { | |||
// This scenario causes https://github.com/dotnet/runtime/issues/83792 | |||
return FALSE; | |||
} else if (target_method->flags & METHOD_ATTRIBUTE_REQSECOBJ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider adding a brief comment explaining why the METHOD_ATTRIBUTE_REQSECOBJ flag check is necessary in this context to prevent unintended inlining.
Copilot uses AI. Check for mistakes.
Tagging subscribers to this area: @BrzVlad, @kotlarmilos |
With JIT we don't inline methods doing calls. This is no longer the case on interpreter, since .NET8, after #83548. The side effect of that change was that, because we weren't checking for the presence of the StackCrawlMark attribute, we could be inlining the callers of special methods like
Type.GetType
,MethodBase.GetCurrentMethod
,Assembly.GetCallingAssembly
etc. This would make them return incorrect results. Given inlining happens only once the method is tiered up, this regression wasn't detected.