Skip to content

[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

Merged
merged 2 commits into from
Jun 2, 2025

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented May 30, 2025

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.

BrzVlad added 2 commits May 30, 2025 13:24
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.
@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 10:34
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 30, 2025
@BrzVlad BrzVlad removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 30, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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) {
Copy link
Preview

Copilot AI May 30, 2025

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.

Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

@BrzVlad BrzVlad merged commit f313e8d into dotnet:main Jun 2, 2025
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants