diff --git a/src/coreclr/hosts/corerun/wasm/libCorerun.js b/src/coreclr/hosts/corerun/wasm/libCorerun.js index 683ec9241d45fb..f803a5d1bcf70c 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,10 @@ 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}); + return false; } finally { stackRestore(sp); }