Stream: git-wasmtime

Topic: wasmtime / issue #8432 Panic about missing trampolines wi...


view this post on Zulip Wasmtime GitHub notifications bot (Apr 22 2024 at 16:21):

alexcrichton added the bug label to Issue #8432.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 22 2024 at 16:21):

alexcrichton added the wasmtime:api label to Issue #8432.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 22 2024 at 16:21):

alexcrichton opened issue #8432:

This program:

use wasmtime::*;

fn main() {
    let engine = Engine::default();

    let module = Module::new(
        &engine,
        r#"
            (module
                (import "" "a" (func $a (result externref)))

                (func (export "a")
                    (drop (call $a))
                )
            )
        "#,
    )
    .unwrap();

    let mut linker = Linker::new(&engine);
    linker
        .func_wrap("", "a", |mut caller: Caller<'_, ()>| {
            ExternRef::new(&mut caller, 100)
        })
        .unwrap();

    let mut store = Store::new(&engine, ());
    let i = linker.instantiate(&mut store, &module).unwrap();
}

compiled against the main branch currently runs as:

$ cargo run -q
thread 'main' panicked at /home/alex/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/4b9f53a/crates/wasmtime/src/runtime/func.rs:1306:74:
must have a wasm-to-native trampoline for this signature if the Wasm module is importing a function of this signature
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

cc @fitzgen

view this post on Zulip Wasmtime GitHub notifications bot (Apr 22 2024 at 19:27):

fitzgen commented on issue #8432:

As discussed offline, we should look up the trampoline based on the import signature, not the wrapped function's type (which can be a subtype of the import signature).

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2024 at 08:27):

shamiao commented on issue #8432:

also happens when externref appeared as a func param.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 25 2024 at 06:09):

shamiao edited a comment on issue #8432:

also happens when externref appeared as a func param.

application note: unsafe fn Linker::func_new_unchecked can be used to bypass this panic.

view this post on Zulip Wasmtime GitHub notifications bot (May 01 2024 at 16:09):

fitzgen commented on issue #8432:

I started poking at this. Things are a bit hairy because we update FuncData based on whether we have found a trampoline for a host function or not yet, but we could update that to hold onto a trampoline for some supertype of the function which is compatible with that particular use but "incompatible" with some other use that uses the function as its precise type rather than the previous super type. I put "incompatible" in scare quotes because it isn't actually incompatible because the trampolines aren't doing anything with these values other than shuffling them around to different ABI argument/return registers and stack slots. So any trampoline we find would be valid for all future uses, at least as the system currently exists, but this is a pretty subtle invariant to rely upon almost by accident.

I think the best way to move forward is to center that invariant, and not make it an accidental after thought, by

view this post on Zulip Wasmtime GitHub notifications bot (May 06 2024 at 16:10):

alexcrichton commented on issue #8432:

I like the sound of that yeah and it makes sense to me!

view this post on Zulip Wasmtime GitHub notifications bot (May 06 2024 at 16:13):

fitzgen commented on issue #8432:

(I've been working on a patch, still have a few kinks to work out)

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2024 at 16:54):

fitzgen closed issue #8432:

This program:

use wasmtime::*;

fn main() {
    let engine = Engine::default();

    let module = Module::new(
        &engine,
        r#"
            (module
                (import "" "a" (func $a (result externref)))

                (func (export "a")
                    (drop (call $a))
                )
            )
        "#,
    )
    .unwrap();

    let mut linker = Linker::new(&engine);
    linker
        .func_wrap("", "a", |mut caller: Caller<'_, ()>| {
            ExternRef::new(&mut caller, 100)
        })
        .unwrap();

    let mut store = Store::new(&engine, ());
    let i = linker.instantiate(&mut store, &module).unwrap();
}

compiled against the main branch currently runs as:

$ cargo run -q
thread 'main' panicked at /home/alex/.cargo/git/checkouts/wasmtime-41807828cb3a7a7e/4b9f53a/crates/wasmtime/src/runtime/func.rs:1306:74:
must have a wasm-to-native trampoline for this signature if the Wasm module is importing a function of this signature
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

cc @fitzgen


Last updated: Nov 22 2024 at 16:03 UTC