Skip to content

[mono] AOT-compile methods that use the IL jmp opcode#129708

Open
pavelsavara wants to merge 2 commits into
dotnet:mainfrom
pavelsavara:mono-aot-jmp-as-call
Open

[mono] AOT-compile methods that use the IL jmp opcode#129708
pavelsavara wants to merge 2 commits into
dotnet:mainfrom
pavelsavara:mono-aot-jmp-as-call

Conversation

@pavelsavara

Copy link
Copy Markdown
Member

Summary

Methods that use the IL jmp opcode (CEE_JMP) are excluded from the AOT image on Mono and crash at runtime under full-AOT.

Root cause

In the CEE_JMP handler, the non-llvm_only path compiles jmp to a real tail call (OP_TAILCALL) and calls DISABLE_AOT(cfg). Under full-AOT (aot-only) the method is then absent from the AOT image, so the first call to it fails with:

System.ExecutionEngineException: Attempting to JIT compile method '...' while running in aot-only mode.

(JIT mode is fine — a real tail call works there.)

The llvm_only path already avoids this by emitting jmp as a normal call followed by a return.

Fix

Extend the llvm_only call+return handling to AOT compilation (cfg->llvm_only || cfg->compile_aot). For the non-llvm_only AOT case the call is emitted as a plain call (tailcall = FALSE), which is AOT-able by both the LLVM and the Mono code generators. This is observably equivalent for jmp — transfer to the target with the current arguments and return its result — it just does not reuse the caller's stack frame. The JIT keeps the real tail call.

Validation

Built Mono + LLVM full-AOT on x64 and ran JIT/jit64/localloc/call/call05_large and call05_small (localloc + jmp):

  • Before: ExecutionEngineException under full-AOT (the jmp method func0 was missing from the image; only a PLT stub was emitted).
  • After: both pass under full-AOT and JIT; func0 is present in the AOT image.

Note

This pull request was prepared with the assistance of GitHub Copilot.

The IL `jmp` opcode (CEE_JMP) is compiled to a real tail call (OP_TAILCALL) on
the non-llvm_only path, which disables AOT for the whole method (DISABLE_AOT).
Under full-AOT (aot-only) the method is then left out of the AOT image, so the
first call to it fails at runtime with "Attempting to JIT compile method ...
while running in aot-only mode".

The llvm_only path already avoids this by emitting `jmp` as a normal call
followed by a return. Extend that to AOT compilation: when compiling for AOT,
emit the jmp as a call + return instead of a real tail call, so the method can
be AOT compiled. This is observably equivalent for jmp (transfer to the target
with the current arguments and return its result); it just does not reuse the
caller's stack frame. The JIT keeps the real tail call.

Fixes the Mono full-AOT failures of the JIT/jit64/localloc/call/call05_large and
call05_small tests, which were crashing with ExecutionEngineException under
full-AOT because their `jmp` method was excluded from the AOT image.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Mono’s IL CEE_JMP handling during AOT compilation so methods containing jmp are no longer excluded from the AOT image (avoiding aot-only/full-AOT runtime failures due to missing compiled methods).

Changes:

  • Treat CEE_JMP as “call + return” when cfg->compile_aot (in addition to the existing cfg->llvm_only handling), instead of emitting a real OP_TAILCALL that triggers DISABLE_AOT(cfg).
  • Ensure the AOT path emits a plain call (non-tailcall) so it remains AOT-able by both LLVM and Mono code generators.

fsig = mono_method_signature_internal (cmethod);
int nargs = fsig->param_count + fsig->hasthis;
if (cfg->llvm_only) {
if (cfg->llvm_only || cfg->compile_aot) {
These tests use the IL jmp opcode from a method that also uses localloc; with the AOT compiler now emitting such methods, they pass under Mono full-AOT. Remove the ActiveIssue annotation so CI exercises the fix.
pavelsavara added a commit that referenced this pull request Jun 22, 2026
Re-link the disabled Mono full-AOT tests from the #129508 tracking issue to the individual PRs that fix them (nullabletypes -> #129702, call05_large/small -> #129708, WPF_3226 -> #129710, b143840 -> #129713, UnitTest_GVM_TypeLoadException -> #129715). The tests stay disabled; Runtime_105619 keeps the #129508 link.
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