Skip to content

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

Merged
pavelsavara merged 4 commits into
dotnet:mainfrom
pavelsavara:mono-aot-jmp-as-call
Jun 24, 2026
Merged

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

Conversation

@pavelsavara

@pavelsavara pavelsavara commented Jun 22, 2026

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.


Part of the MonoAOT LLVM 23 full-AOT regression set tracked by #129508. Built and tested together with the Emscripten 5.0.6 / LLVM 23 bump on #129396, where the re-enabled call05_large / call05_small tests pass on the runtime-llvm AllSubsets_Mono_LLVMFULLAOT_RuntimeTests leg.

Contributes to #129508.

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.

Comment thread src/mono/mono/mini/method-to-ir.c
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.
Copilot AI review requested due to automatic review settings June 23, 2026 10:17

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/mono/mono/mini/method-to-ir.c
test_5_jmp was tagged !FULLAOT because jmp could not be AOT-compiled; this PR fixes that, so run it under full-AOT for regression coverage. Also soften the lowering comment: emitting jmp as call+return is not a true tailcall (it adds a stack frame, so stack traces can differ).
@pavelsavara

Copy link
Copy Markdown
Member Author

/ba-g unrelated failures

@pavelsavara pavelsavara merged commit b06f62f into dotnet:main Jun 24, 2026
128 of 130 checks passed
@pavelsavara pavelsavara deleted the mono-aot-jmp-as-call branch June 24, 2026 10:18
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jun 25, 2026
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.

3 participants