Skip to content
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

[mono][interp] Fix execution of delegate invoke wrapper with interpreter #111310

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented Jan 11, 2025

The wrapper was relatively recently changed to icall into mono_get_addr_compiled_method in order to obtain a native function pointer to call using calli. This is incorrect on interpreter where we expect an InterpMethod*. This commit adds a new opcode instead, that on jit it goes through the same icall path, while on interpeter in similarly computes the appropiate method to call.

On a separate track, it might be useful to investigate whether the necessary delegate invoke wrapper should have been present in the aot image and not be executed with the interpreter in the first place.

Likely regressed after #83461.

Should fix #110995.

The wrapper was relatively recently changed to icall into mono_get_addr_compiled_method in order to obtain a native function pointer to call using calli. This is incorrect on interpreter where we expect an `InterpMethod*`. This commit adds a new opcode instead, that on jit it goes through the same icall path, while on interpeter in similarly computes the appropiate method to call.

On a separate track, it might be useful to investigate whether the necessary delegate invoke wrapper should have been present in the aot image and not be executed with the interpreter in the first place.
Copy link
Member

@kotlarmilos kotlarmilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Do you want to add a test case in src/tests/JIT/Methodical/delegate/VirtualDelegate.cs?

@BrzVlad
Copy link
Member Author

BrzVlad commented Jan 14, 2025

@kotlarmilos Unfortunately this scenario is not easily tested given this path is not hit in interp only. One would need a very specific aot/interp transition, that we currently don't have testing support for.

@BrzVlad BrzVlad merged commit 5a395ed into dotnet:main Jan 15, 2025
66 of 69 checks passed
@vitek-karas
Copy link
Member

@BrzVlad could you please start the backports of this for 9 and 8?

@BrzVlad
Copy link
Member Author

BrzVlad commented Jan 22, 2025

/backport to release/8.0-staging

@BrzVlad
Copy link
Member Author

BrzVlad commented Jan 22, 2025

/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/12906960733

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/12906962891

Copy link
Contributor

@BrzVlad backporting to "release/8.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: [mono][interp] Fix execution of delegate invoke wrapper with interpreter
Using index info to reconstruct a base tree...
M	src/mono/mono/metadata/marshal-lightweight.c
M	src/mono/mono/mini/interp/interp.c
M	src/mono/mono/mini/interp/mintops.def
M	src/mono/mono/mini/interp/transform.c
M	src/mono/mono/mini/method-to-ir.c
Falling back to patching base and 3-way merge...
Auto-merging src/mono/mono/mini/method-to-ir.c
Auto-merging src/mono/mono/mini/interp/transform.c
Auto-merging src/mono/mono/mini/interp/mintops.def
Auto-merging src/mono/mono/mini/interp/interp.c
CONFLICT (content): Merge conflict in src/mono/mono/mini/interp/interp.c
Auto-merging src/mono/mono/metadata/marshal-lightweight.c
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 [mono][interp] Fix execution of delegate invoke wrapper with interpreter
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

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.

iOS app crashes when calling GetValue on Virtual Property
3 participants