From 430e7f9ba6b727b951eef2b0374d4dd4309ebb5c Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 13 May 2026 14:32:12 -0700 Subject: [PATCH 1/2] Detect wasm linker bug and handle instantiation failures better --- src/coreclr/hosts/corerun/wasm/libCorerun.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/coreclr/hosts/corerun/wasm/libCorerun.js b/src/coreclr/hosts/corerun/wasm/libCorerun.js index 683ec9241d45fb..8986f421c7a624 100644 --- a/src/coreclr/hosts/corerun/wasm/libCorerun.js +++ b/src/coreclr/hosts/corerun/wasm/libCorerun.js @@ -220,6 +220,9 @@ function libCoreRunFactory() { if (_posix_memalign(ptrPtr, 16, payloadSize)) { throw new Error("posix_memalign failed for Webcil payload"); } + if (typeof (wasmExports.__stack_pointer) === "undefined") { + throw new Error("__stack_pointer was not preserved by the linker or optimizer"); + } payloadPtr = HEAPU32[ptrPtr >>> 2 >>> 0]; wasmInstance = new WebAssembly.Instance(wasmModule, { webcil: { @@ -229,6 +232,9 @@ function libCoreRunFactory() { tableBase: new WebAssembly.Global({ value: "i32", mutable: false }, tableStartIndex), imageBase: new WebAssembly.Global({ value: "i32", mutable: false }, payloadPtr) }}); + } catch (e) { + const errorMessage = e instanceof Error ? e.message : String(e); + console.error("Failed to construct WebAssembly instance for Webcil image:", {wasmPath, errorMessage}); } finally { stackRestore(sp); } From d664d80518bc43b1c4f7639e08e018be6b774acf Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 13 May 2026 14:45:47 -0700 Subject: [PATCH 2/2] Thanks copilot --- src/coreclr/hosts/corerun/wasm/libCorerun.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/hosts/corerun/wasm/libCorerun.js b/src/coreclr/hosts/corerun/wasm/libCorerun.js index 8986f421c7a624..f803a5d1bcf70c 100644 --- a/src/coreclr/hosts/corerun/wasm/libCorerun.js +++ b/src/coreclr/hosts/corerun/wasm/libCorerun.js @@ -235,6 +235,7 @@ function libCoreRunFactory() { } catch (e) { const errorMessage = e instanceof Error ? e.message : String(e); console.error("Failed to construct WebAssembly instance for Webcil image:", {wasmPath, errorMessage}); + return false; } finally { stackRestore(sp); }