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

Panic in the singlepass compiler #2347

Closed
matklad opened this issue May 26, 2021 · 4 comments · Fixed by #2391
Closed

Panic in the singlepass compiler #2347

matklad opened this issue May 26, 2021 · 4 comments · Fixed by #2391
Labels
bug Something isn't working 📦 lib-compiler-singlepass About wasmer-compiler-singlepass

Comments

@matklad
Copy link
Contributor

matklad commented May 26, 2021

fn main() {
    let jit = wasmer::JIT::new(wasmer::Singlepass::new());
    let store = wasmer::Store::new(&jit.engine());
    let bytes = vec![
        0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 124, 1, 127, 2, 1, 0, 3, 3, 2, 0, 0, 10, 20,
        2, 3, 0, 0, 11, 14, 0, 65, 255, 135, 140, 120, 183, 155, 155, 32, 0, 166, 0, 11,
    ];
    let _ = wasmer::Module::new(&store, bytes);
}

This results in

thread 'tests::error_cases::test_simple_contract' panicked at 'called `Option::unwrap()` on a `None` value', /home/matklad/.cargo/git/checkouts/wasmer-0210ff4327f3d2ae/a98937b/lib/compiler-singlepass/src/codegen_x64.rs:513:60

wasmer "1.0.2"

@matklad matklad added the bug Something isn't working label May 26, 2021
@olonho
Copy link

olonho commented May 27, 2021

Minimalized contract looks like that:

 (module
  (type (;0;) (func (param f64) (result i32)))
  (func (;1;) (type 0) (param f64) (result i32)
    f64.const 0
    f64.ceil
    local.get 0
    f64.copysign
    unreachable))

removing f64.ceil or f64.copysign makes bug to go away. Crash happens here:

           at /Users/nike/.rustup/toolchains/1.51.0-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:386:21
   4: wasmer_compiler_singlepass::codegen_x64::FuncGen::emit_relaxed_binop
             at /Users/nike/.cargo/git/checkouts/wasmer-0210ff4327f3d2ae/a98937b/lib/compiler-singlepass/src/codegen_x64.rs:513:28
   5: wasmer_compiler_singlepass::codegen_x64::FuncGen::canonicalize_nan
             at /Users/nike/.cargo/git/checkouts/wasmer-0210ff4327f3d2ae/a98937b/lib/compiler-singlepass/src/codegen_x64.rs:341:9
   6: wasmer_compiler_singlepass::codegen_x64::FuncGen::feed_operator
             at /Users/nike/.cargo/git/checkouts/wasmer-0210ff4327f3d2ae/a98937b/lib/compiler-singlepass/src/codegen_x64.rs:3570:33

Seems ad-hoc register allocator in Singlepass runs out of registers.

@Hywan Hywan added the 📦 lib-compiler-singlepass About wasmer-compiler-singlepass label Jun 1, 2021
@Hywan
Copy link
Contributor

Hywan commented Jun 1, 2021

Thank you for the bug report!

@syrusakbary
Copy link
Member

Tested and reproduced the bug. It seems was introduced in Wasmer 1.0

@chenyukang
Copy link
Contributor

I'm fixing this.

chenyukang added a commit to chenyukang/wasmer that referenced this issue Jun 5, 2021
bors bot added a commit that referenced this issue Jun 8, 2021
2391: Fix Singlepass issue #2347 r=Hywan a=chenyukang

# Description
Fix Singlepass compiler issue: #2347 

I'm not sure whether the unit test case added to a suitable file. 
Any better suggestion?
@syrusakbary 

Edit by @Hywan: Close #2347, close #2159.


Co-authored-by: yukang <[email protected]>
Co-authored-by: Yukang <[email protected]>
@bors bors bot closed this as completed in e6c8fcd Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-compiler-singlepass About wasmer-compiler-singlepass
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants