From 24e0e75d8a69461199c5124589ba0e800932489b Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 12 May 2026 15:57:34 -0700 Subject: [PATCH 1/4] Add missing return buffer argument in wasm import thunks --- .../DependencyAnalysis/ReadyToRun/WasmImportThunk.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs index b5f200735f9894..a614616a64b33d 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs @@ -128,6 +128,7 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr int[] offsets = new int[methodSignature.Length]; bool[] isIndirectStructArg = new bool[methodSignature.Length]; + bool hasRetBuffArg = _wasmSignature.SignatureString[0] == 'S'; int argIndex = 0; int argOffset; @@ -302,6 +303,13 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr wasmLocalIndex++; } + // Pass return buffer argument if needed + if (hasRetBuffArg) + { + expressions.Add(Local.Get(1)); + wasmLocalIndex++; + } + for (int i = 0; i < methodSignature.Length; i++) { TypeDesc paramType = methodSignature[i]; From 8f7f8bb678df3611616a3585b056225af5f92972 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 12 May 2026 16:02:44 -0700 Subject: [PATCH 2/4] Handle this ptr not being present --- .../Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs index a614616a64b33d..337552068f0015 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs @@ -306,7 +306,7 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr // Pass return buffer argument if needed if (hasRetBuffArg) { - expressions.Add(Local.Get(1)); + expressions.Add(Local.Get(hasThis ? 1 : 0)); wasmLocalIndex++; } From f8dedf865e828b01cc99f5dc1442896da77adced Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 12 May 2026 16:22:06 -0700 Subject: [PATCH 3/4] Checkpoint --- .../DependencyAnalysis/ReadyToRun/WasmImportThunk.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs index 337552068f0015..15c8d00be3b7ba 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs @@ -196,6 +196,12 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr wasmLocalIndex++; } + if (hasRetBuffArg) + { + // FIXME: What do I do here? + wasmLocalIndex++; + } + for (int i = 0; i < methodSignature.Length; i++) { TypeDesc paramType = methodSignature[i]; @@ -306,7 +312,7 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr // Pass return buffer argument if needed if (hasRetBuffArg) { - expressions.Add(Local.Get(hasThis ? 1 : 0)); + expressions.Add(Local.Get(wasmLocalIndex)); wasmLocalIndex++; } From 1d75523e33507d9e6955380074da124ac90b35f6 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 13 May 2026 10:39:08 -0700 Subject: [PATCH 4/4] Remove fixme comment --- .../Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs index 15c8d00be3b7ba..27b2d792466a6f 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs @@ -198,7 +198,6 @@ protected override void EmitCode(NodeFactory factory, ref Wasm.WasmEmitter instr if (hasRetBuffArg) { - // FIXME: What do I do here? wasmLocalIndex++; }