Stream: git-wasmtime

Topic: wasmtime / Issue #2198 infloop when static memory is disa...


view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2020 at 06:24):

ueno opened Issue #2198:

If static memory is disabled with --static-memory-maximum-size 0, certain programs run into an infinite loop, apparently in the compilation phase:

cargo new demo --bin
cd demo
echo 'rand = "*"' >> Cargo.toml
cat >src/main.rs <<EOF
use rand::prelude::*;

fn main() {
    let mut rng = rand::thread_rng();
    let number: u32 = rng.gen();
    println!("{:08x}", number);
}
EOF

cargo build --target wasm32-wasi
cd ../wasmtime
cargo run -- run --static-memory-maximum-size 0 ../demo/target/wasm32-wasi/debug/demo.wasm

The demo program is using the rand crate. If I replace the use of it with the getrandom crate as below, it works:

    let mut buf = [0u8; 4];
    let _ = getrandom::getrandom(&mut buf).unwrap();
    let number = u32::from_le_bytes(buf);

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2020 at 06:24):

ueno labeled Issue #2198:

If static memory is disabled with --static-memory-maximum-size 0, certain programs run into an infinite loop, apparently in the compilation phase:

cargo new demo --bin
cd demo
echo 'rand = "*"' >> Cargo.toml
cat >src/main.rs <<EOF
use rand::prelude::*;

fn main() {
    let mut rng = rand::thread_rng();
    let number: u32 = rng.gen();
    println!("{:08x}", number);
}
EOF

cargo build --target wasm32-wasi
cd ../wasmtime
cargo run -- run --static-memory-maximum-size 0 ../demo/target/wasm32-wasi/debug/demo.wasm

The demo program is using the rand crate. If I replace the use of it with the getrandom crate as below, it works:

    let mut buf = [0u8; 4];
    let _ = getrandom::getrandom(&mut buf).unwrap();
    let number = u32::from_le_bytes(buf);

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2020 at 07:36):

bjorn3 commented on Issue #2198:

Works for me

$ time wasmtime run --static-memory-maximum-size 0 ./target/wasm32-wasi/debug/demo.wasm
wasmtime run --static-memory-maximum-size 0   8,06s user 0,07s system 105% cpu 7,746 total
$ time wasmtime run --static-memory-maximum-size 0 ./target/wasm32-wasi/debug/demo.wasm
wasmtime run --static-memory-maximum-size 0   0,02s user 0,04s system 99% cpu 0,055 total
~~~

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2020 at 07:37):

bjorn3 edited a comment on Issue #2198:

Works for me

$ cargo build --target wasm32-wasi
   Compiling wasi v0.9.0+wasi-snapshot-preview1
   Compiling cfg-if v0.1.10
   Compiling ppv-lite86 v0.2.9
   Compiling getrandom v0.1.15
   Compiling rand_core v0.5.1
   Compiling rand_chacha v0.2.2
   Compiling rand v0.7.3
   Compiling demo v0.1.0 (/tmp/demo)
    Finished dev [unoptimized + debuginfo] target(s) in 3.08s
$ time wasmtime run --static-memory-maximum-size 0 ./target/wasm32-wasi/debug/demo.wasm
wasmtime run --static-memory-maximum-size 0   8,06s user 0,07s system 105% cpu 7,746 total
$ time wasmtime run --static-memory-maximum-size 0 ./target/wasm32-wasi/debug/demo.wasm
wasmtime run --static-memory-maximum-size 0   0,02s user 0,04s system 99% cpu 0,055 total
~~~

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2020 at 07:38):

bjorn3 commented on Issue #2198:

Try using a release mode wasmtime:

$ cargo run --release -- run --static-memory-maximum-size 0 ../demo/target/wasm32-wasi/debug/demo.wasm

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2020 at 07:50):

ueno commented on Issue #2198:

Thank you for taking a look! Indeed, using the release build helps, though it still hangs with the debug build.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2020 at 08:06):

bjorn3 commented on Issue #2198:

If you wait like 2 minutes with a debug build, does it finish? It may just be very slow.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2020 at 08:35):

ueno commented on Issue #2198:

You are right; indeed it finishes after ~3min:

$ time ~/devel/wasmtime/target/debug/wasmtime --static-memory-maximum-size 0 ./target/wasm32-wasi/debug/demo.wasm
4839175a
~/devel/wasmtime/target/debug/wasmtime --static-memory-maximum-size 0   167.70s user 0.14s system 103% cpu 2:41.38 total

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2020 at 08:36):

ueno closed Issue #2198:

If static memory is disabled with --static-memory-maximum-size 0, certain programs run into an infinite loop, apparently in the compilation phase:

cargo new demo --bin
cd demo
echo 'rand = "*"' >> Cargo.toml
cat >src/main.rs <<EOF
use rand::prelude::*;

fn main() {
    let mut rng = rand::thread_rng();
    let number: u32 = rng.gen();
    println!("{:08x}", number);
}
EOF

cargo build --target wasm32-wasi
cd ../wasmtime
cargo run -- run --static-memory-maximum-size 0 ../demo/target/wasm32-wasi/debug/demo.wasm

The demo program is using the rand crate. If I replace the use of it with the getrandom crate as below, it works:

    let mut buf = [0u8; 4];
    let _ = getrandom::getrandom(&mut buf).unwrap();
    let number = u32::from_le_bytes(buf);

Last updated: Nov 22 2024 at 16:03 UTC