Stream: git-wasmtime

Topic: wasmtime / issue #6546 preopendir not working with compon...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 09 2023 at 09:47):

hurae opened issue #6546:

Test Case

Simple read file metadata example, works fine with wasi preview1, but panic for component model.

// wit/see.wit
package plugin:see

world see {
  export run: func() -> result
}
// seesee/src/lib.rs
use std::fs::metadata;

wit_bindgen::generate!({
    path: "../wit/see.wit",
    world: "see",
});

struct Checks;

impl See for Checks {
    fn run() -> Result<(), ()> {
        let path = "/tmp/hello.txt";
        let metadata = metadata(path).unwrap();
        println!("metadata: {:?}", metadata);
        Ok(())
    }
}

export_see!(Checks);
// part of Cargo.toml
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-10.0.0", default-features = false, features = [
  "cranelift",
  "component-model",
  "async",
] }
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-10.0.0"}

Steps to Reproduce

The last step is just a copy of src/commands/run.rs which replaced all related things to component version.

Expected Results

print metadata of file to stdout.

Actual Results

└─>   cargo run ../rskyeye/seesee/seesee.component.wasm --dir /tmp
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/runner ../rskyeye/seesee/seesee.component.wasm --dir /tmp`
Error: error while executing at wasm backtrace:
    0: 0x16a4c - wit-component:adapter:wasi_snapshot_preview1!<core::result::Result<T,E> as wasi_preview1_component_adapter::TrappingUnwrap<T>>::trapping_unwrap::hf0327b60ad60be4c
    1: 0x1669b - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::descriptors::Descriptors::new::h128f28896896514d
    2: 0x1506b - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::State::descriptors::h5db82afb67da21a2
    3: 0x151f1 - wit-component:adapter:wasi_snapshot_preview1!fd_prestat_get
    4: 0x184c9 - wit-component:shim!adapt-wasi_snapshot_preview1-fd_prestat_get
    5: 0xcc34 - <unknown>!__wasi_fd_prestat_get
    6: 0xcf45 - <unknown>!__wasilibc_populate_preopens
    7:  0xa68 - <unknown>!__wasm_call_ctors
    8: 0x573e - <unknown>!run

Caused by:
    wasm trap: wasm `unreachable` instruction executed

Versions and Environment

Wasmtime version or commit:

Tried both branch "release-10.0.0" and commit "92024ad11728efa9b3b59b426ebc7cc817cebf6b" which is the last component type version 2 version.

component adapter:

Tried both commit 92024ad (component type version 2, with wasm-tools 1.0.34) and f7ae056 (component type version 3, with wasm-tools 1.0.35) with exactly the same commit of wasmtime and wasmtime_wasi.

Operating system: Linux fedora 6.2.14-300.fc38.x86_64

Architecture: AMD64

Extra Info

The same wasm file works before composing to component with adapter when run following command on all of version 8.0.0, 9.0.0, 9.0.3 and commit 92024ad11728efa9b3b59b426ebc7cc817cebf6b:

wasmtime run seesee.wasi.wasm --invoke run

view this post on Zulip Wasmtime GitHub notifications bot (Jun 09 2023 at 09:47):

hurae labeled issue #6546:

Test Case

Simple read file metadata example, works fine with wasi preview1, but panic for component model.

// wit/see.wit
package plugin:see

world see {
  export run: func() -> result
}
// seesee/src/lib.rs
use std::fs::metadata;

wit_bindgen::generate!({
    path: "../wit/see.wit",
    world: "see",
});

struct Checks;

impl See for Checks {
    fn run() -> Result<(), ()> {
        let path = "/tmp/hello.txt";
        let metadata = metadata(path).unwrap();
        println!("metadata: {:?}", metadata);
        Ok(())
    }
}

export_see!(Checks);
// part of Cargo.toml
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-10.0.0", default-features = false, features = [
  "cranelift",
  "component-model",
  "async",
] }
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-10.0.0"}

Steps to Reproduce

The last step is just a copy of src/commands/run.rs which replaced all related things to component version.

Expected Results

print metadata of file to stdout.

Actual Results

└─>   cargo run ../rskyeye/seesee/seesee.component.wasm --dir /tmp
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/runner ../rskyeye/seesee/seesee.component.wasm --dir /tmp`
Error: error while executing at wasm backtrace:
    0: 0x16a4c - wit-component:adapter:wasi_snapshot_preview1!<core::result::Result<T,E> as wasi_preview1_component_adapter::TrappingUnwrap<T>>::trapping_unwrap::hf0327b60ad60be4c
    1: 0x1669b - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::descriptors::Descriptors::new::h128f28896896514d
    2: 0x1506b - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::State::descriptors::h5db82afb67da21a2
    3: 0x151f1 - wit-component:adapter:wasi_snapshot_preview1!fd_prestat_get
    4: 0x184c9 - wit-component:shim!adapt-wasi_snapshot_preview1-fd_prestat_get
    5: 0xcc34 - <unknown>!__wasi_fd_prestat_get
    6: 0xcf45 - <unknown>!__wasilibc_populate_preopens
    7:  0xa68 - <unknown>!__wasm_call_ctors
    8: 0x573e - <unknown>!run

Caused by:
    wasm trap: wasm `unreachable` instruction executed

Versions and Environment

Wasmtime version or commit:

Tried both branch "release-10.0.0" and commit "92024ad11728efa9b3b59b426ebc7cc817cebf6b" which is the last component type version 2 version.

component adapter:

Tried both commit 92024ad (component type version 2, with wasm-tools 1.0.34) and f7ae056 (component type version 3, with wasm-tools 1.0.35) with exactly the same commit of wasmtime and wasmtime_wasi.

Operating system: Linux fedora 6.2.14-300.fc38.x86_64

Architecture: AMD64

Extra Info

The same wasm file works before composing to component with adapter when run following command on all of version 8.0.0, 9.0.0, 9.0.3 and commit 92024ad11728efa9b3b59b426ebc7cc817cebf6b:

wasmtime run seesee.wasi.wasm --invoke run

view this post on Zulip Wasmtime GitHub notifications bot (Jun 09 2023 at 15:00):

pchickey commented on issue #6546:

Can you please add RUST_LOG=wasmtime_wasi=trace and reproduce again? And initialize the default tracing subscriber at the start of your runner if it doesn't already have one.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 12 2023 at 03:13):

hurae commented on issue #6546:

RUST_LOG=wasmtime_wasi=trace didn't produce any log. By setting RUST_LOG=trace,cranelift_codegen=info,wasmtime_cranelift::compiler=info,cranelift_wasm::func_translator=info, I got this:

[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(3)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .wasmtime.engine
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .symtab
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .strtab
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .shstrtab
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] ====== Capturing Backtrace ======
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] === Tracing through contiguous sequence of Wasm frames ===
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] trampoline_sp = 0x00007f3b83873220
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace]    initial pc = 0x00007f3b83897e8f
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace]    initial fp = 0x00007f3b83872ff0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83897e8f
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83872ff0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b838976f2
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873090
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83894d60
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b838730e0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83895037
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873140
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b838994e6
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873170
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83890b4b
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873180
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b8389123d
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b838731d0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b8387501f
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b838731e0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83880889
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873210
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] === Done tracing contiguous sequence of Wasm frames ===
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] ====== Done Capturing Backtrace (reached end of activations) ======
Error: error while executing at wasm backtrace:
    0: 0x19db4 - wit-component:adapter:wasi_snapshot_preview1!<core::result::Result<T,E> as wasi_preview1_component_adapter::TrappingUnwrap<T>>::trapping_unwrap::hf0327b60ad60be4c
    1: 0x19a03 - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::descriptors::Descriptors::new::h128f28896896514d
    2: 0x183d3 - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::State::descriptors::h5db82afb67da21a2
    3: 0x18559 - wit-component:adapter:wasi_snapshot_preview1!fd_prestat_get
    4: 0x1b831 - wit-component:shim!adapt-wasi_snapshot_preview1-fd_prestat_get
    5: 0xec31 - <unknown>!__wasi_fd_prestat_get
    6: 0xef42 - <unknown>!__wasilibc_populate_preopens
    7:  0xabb - <unknown>!__wasm_call_ctors
    8: 0x622d - <unknown>!run

Caused by:
    wasm trap: wasm `unreachable` instruction executed

It seems not helpful either.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 12 2023 at 03:15):

hurae edited a comment on issue #6546:

RUST_LOG=wasmtime_wasi=trace didn't produce any log. By setting RUST_LOG=trace,cranelift_codegen=info,wasmtime_cranelift::compiler=info,cranelift_wasm::func_translator=info, I got this:

[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(3)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .wasmtime.engine
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .symtab
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .strtab
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .shstrtab
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] ====== Capturing Backtrace ======
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] === Tracing through contiguous sequence of Wasm frames ===
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] trampoline_sp = 0x00007f3b83873220
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace]    initial pc = 0x00007f3b83897e8f
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace]    initial fp = 0x00007f3b83872ff0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83897e8f
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83872ff0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b838976f2
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873090
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83894d60
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b838730e0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83895037
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873140
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b838994e6
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873170
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83890b4b
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873180
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b8389123d
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b838731d0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b8387501f
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b838731e0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83880889
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873210
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] === Done tracing contiguous sequence of Wasm frames ===
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] ====== Done Capturing Backtrace (reached end of activations) ======
Error: error while executing at wasm backtrace:
    0: 0x19db4 - wit-component:adapter:wasi_snapshot_preview1!<core::result::Result<T,E> as wasi_preview1_component_adapter::TrappingUnwrap<T>>::trapping_unwrap::hf0327b60ad60be4c
    1: 0x19a03 - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::descriptors::Descriptors::new::h128f28896896514d
    2: 0x183d3 - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::State::descriptors::h5db82afb67da21a2
    3: 0x18559 - wit-component:adapter:wasi_snapshot_preview1!fd_prestat_get
    4: 0x1b831 - wit-component:shim!adapt-wasi_snapshot_preview1-fd_prestat_get
    5: 0xec31 - <unknown>!__wasi_fd_prestat_get
    6: 0xef42 - <unknown>!__wasilibc_populate_preopens
    7:  0xabb - <unknown>!__wasm_call_ctors
    8: 0x622d - <unknown>!run

Caused by:
    wasm trap: wasm `unreachable` instruction executed

It seems not helpful either. By the way, here is my main function:

#[tokio::main(flavor = "multi_thread", worker_threads = 4)]
async fn main() -> Result<()> {
    // Initialize the default subscriber
    let subscriber = FmtSubscriber::builder().finish();

    // Set the default subscriber for the application
    tracing::subscriber::set_global_default(subscriber).expect("Failed to set default subscriber");
    env_logger::init();

    Command::try_parse()
        .unwrap_or_else(|e: Error| match e.kind() {
            ErrorKind::InvalidSubcommand | ErrorKind::UnknownArgument => {
                Command::Run(RunCommand::parse())
            },
            _ => e.exit(),
        })
        .execute()
        .await
}

Hope I didn't make anything wrong.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 12 2023 at 03:19):

hurae edited a comment on issue #6546:

Reproduced in branch "release-10.0.0".

RUST_LOG=wasmtime_wasi=trace didn't produce any log. By setting RUST_LOG=trace,cranelift_codegen=info,wasmtime_cranelift::compiler=info,cranelift_wasm::func_translator=info, I got this:

[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] creating instance InstanceId(3)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(2)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(0)
[2023-06-12T03:11:09Z TRACE wasmtime_environ::component::dfg] referencing export of InstanceId(1)
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .wasmtime.engine
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .symtab
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .strtab
[2023-06-12T03:11:11Z DEBUG wasmtime_jit::code_memory] ignoring section .shstrtab
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] ====== Capturing Backtrace ======
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] === Tracing through contiguous sequence of Wasm frames ===
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] trampoline_sp = 0x00007f3b83873220
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace]    initial pc = 0x00007f3b83897e8f
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace]    initial fp = 0x00007f3b83872ff0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83897e8f
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83872ff0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b838976f2
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873090
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83894d60
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b838730e0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83895037
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873140
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b838994e6
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873170
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83890b4b
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873180
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b8389123d
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b838731d0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b8387501f
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b838731e0
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] --- Tracing through one Wasm frame ---
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] pc = 0x7f3b83880889
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] fp = 0x7f3b83873210
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] === Done tracing contiguous sequence of Wasm frames ===
[2023-06-12T03:11:11Z TRACE wasmtime_runtime::traphandlers::backtrace] ====== Done Capturing Backtrace (reached end of activations) ======
Error: error while executing at wasm backtrace:
    0: 0x19db4 - wit-component:adapter:wasi_snapshot_preview1!<core::result::Result<T,E> as wasi_preview1_component_adapter::TrappingUnwrap<T>>::trapping_unwrap::hf0327b60ad60be4c
    1: 0x19a03 - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::descriptors::Descriptors::new::h128f28896896514d
    2: 0x183d3 - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::State::descriptors::h5db82afb67da21a2
    3: 0x18559 - wit-component:adapter:wasi_snapshot_preview1!fd_prestat_get
    4: 0x1b831 - wit-component:shim!adapt-wasi_snapshot_preview1-fd_prestat_get
    5: 0xec31 - <unknown>!__wasi_fd_prestat_get
    6: 0xef42 - <unknown>!__wasilibc_populate_preopens
    7:  0xabb - <unknown>!__wasm_call_ctors
    8: 0x622d - <unknown>!run

Caused by:
    wasm trap: wasm `unreachable` instruction executed

It seems not helpful either. By the way, here is my main function:

#[tokio::main(flavor = "multi_thread", worker_threads = 4)]
async fn main() -> Result<()> {
    // Initialize the default subscriber
    let subscriber = FmtSubscriber::builder().finish();

    // Set the default subscriber for the application
    tracing::subscriber::set_global_default(subscriber).expect("Failed to set default subscriber");
    env_logger::init();

    Command::try_parse()
        .unwrap_or_else(|e: Error| match e.kind() {
            ErrorKind::InvalidSubcommand | ErrorKind::UnknownArgument => {
                Command::Run(RunCommand::parse())
            },
            _ => e.exit(),
        })
        .execute()
        .await
}

Hope I didn't make anything wrong.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 12 2023 at 05:20):

hurae commented on issue #6546:

Is this the right combination?

use wasmtime::{
    Config, Engine, InstanceAllocationStrategy, OptLevel, ProfilingStrategy, Store,
    StoreLimits, StoreLimitsBuilder, Strategy,
};
use wasmtime::component::{Component, Linker};
use wasmtime::component::bindgen;
use wasmtime::StoreLimits;
use wasmtime_wasi::{ambient_authority, Dir};
use wasmtime_wasi::preview2::{DirPerms, FilePerms, Table, WasiCtxBuilder, WasiCtx, WasiView};
use wasmtime_wasi::preview2::wasi::command;

view this post on Zulip Wasmtime GitHub notifications bot (Jun 21 2023 at 02:53):

pchickey commented on issue #6546:

I was on vacation last week. Can you please provide a zip file with a complete reproduction, so I can investigate locally?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 21 2023 at 08:49):

hurae commented on issue #6546:

sure, here the full demo with plugin and runner, also bring with the wasm file and trace log.

demo.zip

view this post on Zulip Wasmtime GitHub notifications bot (Jun 22 2023 at 18:10):

pchickey commented on issue #6546:

The bug here is that you are throwing away the table used to initialize the WasiCtx, and creating a new one in your RunnerHostCtx.

The correct implementation is:

/// Populates the given `Linker` with WASI APIs.
fn populate_with_wasi(
    engine: &Engine,
    linker: &mut Linker<RunnerHostCtx>,
    preopen_dirs: Vec<(String, Dir)>,
    argv: &[String],
    env: &[(String, String)],
) -> Result<Store<RunnerHostCtx>> {
    // enable wasi preview2 support
    wasmtime_wasi::preview2::wasi::command::add_to_linker(linker)?;
    // enable host bindings support
    // Command::add_to_linker(linker, |host| host)?;

    // setup wasi context
    let mut builder = WasiCtxBuilder::new();
    builder = builder
        .inherit_stdout()
        .inherit_stderr()
        .set_args(argv)
        .set_env(env);
    for (name, dir) in preopen_dirs.into_iter() {
        builder = builder.push_preopened_dir(dir, DirPerms::all(), FilePerms::all(), name);
    }

    let mut table = Table::new();
    let wasi = builder.build(&mut table)?;
    let store = Store::new(
        engine,
        RunnerHostCtx {
            wasi,
            limits: StoreLimits::default(),
            table,
        },
    );

    Ok(store)
}

Also, tracing wasnt working properly, the correct invocation is apparently

use tracing_subscriber::{fmt, prelude::*, EnvFilter};
 ...
async fn main() -> Result<()> {
    tracing_subscriber::registry()
        .with(fmt::layer())
        .with(EnvFilter::from_default_env())
        .init();
...
}

and requires the features = [ "env-filter" ] in the dep on tracing-subscriber.

I expect this solves your other bug as well.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 25 2023 at 11:53):

hurae commented on issue #6546:

It worked, thanks.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 25 2023 at 11:53):

hurae closed issue #6546:

Test Case

Simple read file metadata example, works fine with wasi preview1, but panic for component model.

// wit/see.wit
package plugin:see

world see {
  export run: func() -> result
}
// seesee/src/lib.rs
use std::fs::metadata;

wit_bindgen::generate!({
    path: "../wit/see.wit",
    world: "see",
});

struct Checks;

impl See for Checks {
    fn run() -> Result<(), ()> {
        let path = "/tmp/hello.txt";
        let metadata = metadata(path).unwrap();
        println!("metadata: {:?}", metadata);
        Ok(())
    }
}

export_see!(Checks);
// part of Cargo.toml
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-10.0.0", default-features = false, features = [
  "cranelift",
  "component-model",
  "async",
] }
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-10.0.0"}

Steps to Reproduce

The last step is just a copy of src/commands/run.rs which replaced all related things to component version.

Expected Results

print metadata of file to stdout.

Actual Results

└─>   cargo run ../rskyeye/seesee/seesee.component.wasm --dir /tmp
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/runner ../rskyeye/seesee/seesee.component.wasm --dir /tmp`
Error: error while executing at wasm backtrace:
    0: 0x16a4c - wit-component:adapter:wasi_snapshot_preview1!<core::result::Result<T,E> as wasi_preview1_component_adapter::TrappingUnwrap<T>>::trapping_unwrap::hf0327b60ad60be4c
    1: 0x1669b - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::descriptors::Descriptors::new::h128f28896896514d
    2: 0x1506b - wit-component:adapter:wasi_snapshot_preview1!wasi_preview1_component_adapter::State::descriptors::h5db82afb67da21a2
    3: 0x151f1 - wit-component:adapter:wasi_snapshot_preview1!fd_prestat_get
    4: 0x184c9 - wit-component:shim!adapt-wasi_snapshot_preview1-fd_prestat_get
    5: 0xcc34 - <unknown>!__wasi_fd_prestat_get
    6: 0xcf45 - <unknown>!__wasilibc_populate_preopens
    7:  0xa68 - <unknown>!__wasm_call_ctors
    8: 0x573e - <unknown>!run

Caused by:
    wasm trap: wasm `unreachable` instruction executed

Versions and Environment

Wasmtime version or commit:

Tried both branch "release-10.0.0" and commit "92024ad11728efa9b3b59b426ebc7cc817cebf6b" which is the last component type version 2 version.

component adapter:

Tried both commit 92024ad (component type version 2, with wasm-tools 1.0.34) and f7ae056 (component type version 3, with wasm-tools 1.0.35) with exactly the same commit of wasmtime and wasmtime_wasi.

Operating system: Linux fedora 6.2.14-300.fc38.x86_64

Architecture: AMD64

Extra Info

The same wasm file works before composing to component with adapter when run following command on all of version 8.0.0, 9.0.0, 9.0.3 and commit 92024ad11728efa9b3b59b426ebc7cc817cebf6b:

wasmtime run seesee.wasi.wasm --invoke run

Last updated: Dec 23 2024 at 12:05 UTC