From 1612b6d757817e267c9ab07ec2779a12c0753d20 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 3 May 2025 20:17:33 -0700 Subject: [PATCH] [crossgen2] Prevent inlining of PInvoke marshalling accross version bubles Contributes to #113742 --- .../Compiler/ReadyToRunCompilationModuleGroupBase.cs | 5 +++++ .../JitInterface/CorInfoImpl.ReadyToRun.cs | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilationModuleGroupBase.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilationModuleGroupBase.cs index 09c12867e50b16..a2ea17ccc111b8 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilationModuleGroupBase.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilationModuleGroupBase.cs @@ -707,6 +707,11 @@ private bool IsNonVersionableWithILTokensThatDoNotNeedTranslationUncached(EcmaMe public sealed override bool GeneratesPInvoke(MethodDesc method) { + // Marshalling behavior isn't modeled as protected by R2R rules, so prevent inlining of marshalling + // defined outside of the version bubble. + if (!VersionsWithMethodBody(method)) + return false; + return !Marshaller.IsMarshallingRequired(method); } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index f58775b559198c..814f3d2db52287 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3079,11 +3079,6 @@ private bool pInvokeMarshalingRequired(CORINFO_METHOD_STRUCT_* handle, CORINFO_S Debug.Assert(!_compilation.NodeFactory.CompilationModuleGroup.GeneratesPInvoke(method)); return true; } - - // Marshalling behavior isn't modeled as protected by R2R rules, so disable pinvoke inlining for code outside - // of the version bubble - if (!_compilation.CompilationModuleGroup.VersionsWithMethodBody(method)) - return true; } catch (RequiresRuntimeJitException) {