From 7e76ec5cbe232020cd5e3d872ac9c3b381f96dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Fri, 16 Oct 2026 17:05:34 +0900 Subject: [PATCH 1/2] Require matching WASM function types when folding method bodies Identical bodies can have different WASM function types when parameters are unused. An address-taken method's jump stub forwards its parameters to the folded body, producing invalid WASM if their signatures differ. Compare lowered function types before folding on WASM. This accounts for hidden ABI parameters and leaves other architectures unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a6f3a617-acae-4f4f-95d3-20b2a0bac43c --- .../ILCompiler.Compiler/Compiler/MethodBodyDeduplicator.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MethodBodyDeduplicator.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MethodBodyDeduplicator.cs index 94880f401f49b3..d4ec3067631241 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MethodBodyDeduplicator.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MethodBodyDeduplicator.cs @@ -7,6 +7,7 @@ using ILCompiler.DependencyAnalysis; using Internal.IL.Stubs; +using Internal.JitInterface; using Internal.TypeSystem; namespace ILCompiler @@ -156,6 +157,11 @@ public bool Equals(MethodInternKey a, MethodInternKey b) && a.Method.Method.GetTypicalMethodDefinition() != b.Method.Method.GetTypicalMethodDefinition()) return false; + // Identical WASM bodies can still have different types when some parameters are unused. + if (_factory.Target.IsWasm + && !WasmLowering.GetSignature(a.Method.Method).FuncType.Equals(WasmLowering.GetSignature(b.Method.Method).FuncType)) + return false; + ObjectNode.ObjectData o1data = ((ObjectNode)a.Method).GetData(_factory, relocsOnly: false); ObjectNode.ObjectData o2data = ((ObjectNode)b.Method).GetData(_factory, relocsOnly: false); From d096062a9607b477100b1059d0298f4061f9f4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Mon, 19 Oct 2026 14:07:12 +0900 Subject: [PATCH 2/2] Feedback --- .../aot/ILCompiler.Compiler/Compiler/MethodBodyDeduplicator.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MethodBodyDeduplicator.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MethodBodyDeduplicator.cs index 8263e0fa9a9d6c..8f216769b7911c 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MethodBodyDeduplicator.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MethodBodyDeduplicator.cs @@ -78,6 +78,9 @@ public MethodInternKey(IMethodBodyNode node, NodeFactory factory, Dictionary