Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chasm 0.9.3: execution fails with MissingStackFrame on exception handling #77

Open
illarionov opened this issue Jan 11, 2025 · 3 comments

Comments

@illarionov
Copy link

Given the following Kotlin/WASI code compiled with Kotlin/WASM 2.1.0 and -Xwasm-use-new-exception-proposal:

suspend fun main() {
    println("test")
    try {
        try { error("Test exception") } catch (ise: RuntimeException) { }
        test()
    } catch (ex: Throwable) {
    }
}

suspend fun test() {}

The execution of this code with Chasm fails with ExecutionError(error=MissingStackFrame).

Reproduction example: https://github.com/illarionov/wehdemo/tree/exceptionBug

Steps to reproduce:

git clone https://github.com/illarionov/wehdemo.git -b exceptionBug
cd wehdemo
./gradlew chasm-runner:jvmRun

Run on Github Actions: https://github.com/illarionov/wehdemo/actions/runs/12721599169

Just in case, I also attach the generated WASM binary files : wasm-binaries.zip

This error is reproduced on both debug and production optimized files.

@CharlieTap
Copy link
Owner

Hey @illarionov 👋🏼

When I run the repro locally it seems to work:

Weh Demo Results
wehdemo on  exceptionBug via 🅶 v8.12 via ☕ v23.0.1 via 🅺 v2.1.0 via 💎 v3.2.2 
❯ ./gradlew chasm-runner:jvmRun

Welcome to Gradle 8.12!

Here are the highlights of this release:
- Enhanced error and warning reporting with the Problems API
- File-system watching support on Alpine Linux
- Build and test Swift 6 libraries and apps

For more details see https://docs.gradle.org/8.12/release-notes.html

Starting a Gradle Daemon, 1 busy Daemon could not be reused, use --status for details

> Task :chasm-runner:jvmRun
Hello from Kotlin via WASI
Current 'realtime' timestamp is: 1736584599455000000
Current 'monotonic' timestamp is: 148771049690166
Day 1
14808
0

Day 2
2
2

Day 3
96225
96225

Day 4
2
0

Day 5
22
30

Day 6
3
0

Day 7
26936
26936


BUILD SUCCESSFUL in 2m 11s
6 actionable tasks: 6 executed

I also tried using the binary you provided with the latest chasm snapshot injecting my own stub functions like this:

        val imports = imports(store) {
            function {
                moduleName = "wasi_snapshot_preview1"
                entityName = "fd_write"
                type {
                    params {
                        i32()
                        i32()
                        i32()
                        i32()
                    }
                    results {
                        i32()
                    }
                }
                reference { values ->
                    listOf(NumberValue.I32(0))
                }
            }
            function {
                moduleName = "wasi_snapshot_preview1"
                entityName = "random_get"
                type {
                    params {
                        i32()
                        i32()
                    }
                    results {
                        i32()
                    }
                }
                reference { values ->
                    listOf(NumberValue.I32(0))
                }
            }
        }
        invoke(store, instance, "_initialize", emptyList())

And this also returned a Success. What does the exceptionBug branch of the wah demo produce for you?

@illarionov
Copy link
Author

This is strange, because in the exceptionBug branch the code that outputs such results has been completely removed.
That is WASM source: https://github.com/illarionov/wehdemo/blob/exceptionBug/wasm-code/src/wasmWasiMain/kotlin/Main.kt
And this is CHASm runner: https://github.com/illarionov/wehdemo/blob/exceptionBug/chasm-runner/src/jvmMain/kotlin/JvmMain.kt

My local output is the same as here: https://github.com/illarionov/wehdemo/actions/runs/12721599169/job/35464696333#step:5:59

I'll check with with the latest chasm snapshot later too.

@illarionov
Copy link
Author

I updated the Chasm to 0.9.4 and this is still reproducible.

I also simplified the code a bit to reduce the binary size.

Given the following code:

import kotlin.wasm.unsafe.UnsafeWasmMemoryApi
import kotlin.wasm.unsafe.withScopedMemoryAllocator

@OptIn(UnsafeWasmMemoryApi::class)
suspend fun main() {
    withScopedMemoryAllocator { }
    try {
        try { error("Test exception") } catch (ise: RuntimeException) { }
        test()
    } catch (ex: Throwable) {
    }
}

suspend fun test() {}

Fails with ExecutionError(error=MissingStackLabel).

Updates are on the exceptionBug branch (https://github.com/illarionov/wehdemo/tree/exceptionBug).

Run on Github Actions: https://github.com/illarionov/wehdemo/actions/runs/12762622996/job/35571430113#step:5:57

Generated binaries: https://github.com/illarionov/wehdemo/actions/runs/12762622996/artifacts/2426529411

productionExecutable/optimized/wehdemo-wasm-code-wasm-wasi.wasm in archive is now 9154 bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants