From 972d8b3c8522c02b68f727655547063f12e87d5e Mon Sep 17 00:00:00 2001 From: adamperlin Date: Mon, 20 Apr 2026 15:16:53 -0700 Subject: [PATCH 1/2] Move implReadyToRunUnsupported() call for funclets before wasm codegen. This avoids a bug where we compile a method under opts that inlines a method with exceptions, bail out because of funclets, then recompile without the inlinee under minopts, leaving stale relocs on the host side. --- src/coreclr/jit/codegencommon.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index d01f10408d9bfe..600bd38bfbb9fb 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -1967,6 +1967,22 @@ void CodeGen::genUpdateCurrentFunclet(BasicBlock* block) // void CodeGen::genGenerateCode(void** codePtr, uint32_t* nativeSizeOfCode) { +#if defined(TARGET_WASM) + // Fail at this point for any method with funclets, since the Wasm we produce + // for such methods requires post-processing by the host before it can be validated. + // This must be done BEFORE codegen, because of the edge case of a method + // which only needs funclets if compiled with optimizations (e.g., if we inline a method that has EH into a method that does not). + // In these cases, if we fail compilation of the optimized method AFTER codegen and then go to recompile the same method with minopts and + // succeed, we may be leaving stale relocs on the host side that only applied to the optimized version, + // which will cause unexpected behavior. + // TODO-WASM: Remove this once the host can do the processing. + // + if ((JitConfig.JitWasmFunclets() == 0) && (m_compiler->compFuncCount() > 1)) + { + JITDUMP("Failing R2R codegen because method has funclets.\n"); + implReadyToRunUnsupported(); + } +#endif #ifdef DEBUG if (verbose) @@ -2014,18 +2030,6 @@ void CodeGen::genGenerateCode(void** codePtr, uint32_t* nativeSizeOfCode) } #endif // defined(TARGET_WASM) #endif // DEBUG - -#if defined(TARGET_WASM) - // Also fail at this point for any method with funclets, since the Wasm we produce - // for such methods requires post-processing by the host before it can be validated. - // TODO-WASM: Remove this once the host can do the processing. - // - if ((JitConfig.JitWasmFunclets() == 0) && (m_compiler->compFuncCount() > 1)) - { - JITDUMP("Failing R2R codegen because method has funclets.\n"); - implReadyToRunUnsupported(); - } -#endif } //---------------------------------------------------------------------- From 36a9db678ec176f387ff8555b86d7616cf961a3f Mon Sep 17 00:00:00 2001 From: adamperlin Date: Tue, 21 Apr 2026 11:26:03 -0700 Subject: [PATCH 2/2] jit-format --- src/coreclr/jit/codegencommon.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 600bd38bfbb9fb..f0a57c43158770 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -1971,10 +1971,10 @@ void CodeGen::genGenerateCode(void** codePtr, uint32_t* nativeSizeOfCode) // Fail at this point for any method with funclets, since the Wasm we produce // for such methods requires post-processing by the host before it can be validated. // This must be done BEFORE codegen, because of the edge case of a method - // which only needs funclets if compiled with optimizations (e.g., if we inline a method that has EH into a method that does not). - // In these cases, if we fail compilation of the optimized method AFTER codegen and then go to recompile the same method with minopts and - // succeed, we may be leaving stale relocs on the host side that only applied to the optimized version, - // which will cause unexpected behavior. + // which only needs funclets if compiled with optimizations (e.g., if we inline a method that has EH into a method + // that does not). In these cases, if we fail compilation of the optimized method AFTER codegen and then go to + // recompile the same method with minopts and succeed, we may be leaving stale relocs on the host side that only + // applied to the optimized version, which will cause unexpected behavior. // TODO-WASM: Remove this once the host can do the processing. // if ((JitConfig.JitWasmFunclets() == 0) && (m_compiler->compFuncCount() > 1))