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

Can't run Golang with large binary #994

Closed
lucklove opened this issue Nov 21, 2019 · 12 comments
Closed

Can't run Golang with large binary #994

lucklove opened this issue Nov 21, 2019 · 12 comments
Labels
bug Something isn't working

Comments

@lucklove
Copy link

Describe the bug

wasmer hang when run large .wasm file compiled from Golang

echo "`wasmer -V` | `rustc -V` | `uname -m`"

wasmer 0.9.0 | | x86_64

Steps to reproduce

main.go:

package main

import (
        "fmt"
)

func main() {
        fmt.Println(len(xs))
}

var xs []int = []int{
        0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
        0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
        0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
        // many lines copy and paste from above
}

With go/wasi implementation, compile with
GOOS=wasi GOARCH=wasm go build -o main.wasm

Run with wasmer run main.wasm

When the xs is small, it's ok, but it take longer time when xs grows. And when the main.wasm is large (abount 50MB), the wamser will hang

Expected behavior

Actual behavior

Additional context

@lucklove lucklove added the bug Something isn't working label Nov 21, 2019
@syrusakbary
Copy link
Member

syrusakbary commented Nov 21, 2019

This means that the Clif backend is actually taking a lot of time compiling.

I think things should be faster if you run with the singlepass backend: wasmer run main.wasm --backend=singlepass. Let me know if that fixes your issue for now @lucklove

As a way to solve this generically, perhaps we can make singlepass the default backend when the provided binary file is larger than 10Mb... thoughts @bjfish @losfair @nlewycky ?

@lucklove
Copy link
Author

lucklove commented Nov 21, 2019

@syrusakbary Thanks for help, with --backend=singlepass, it can run, but with another error:

$ wasmer run main.wasm --backend=singlepass
Error: Can't instantiate WASI module: LinkError([Generic { message: "data segment does not fit" }])

I don't know if it's related to --backend=singlepass or the Golang compiler

@syrusakbary
Copy link
Member

Can you post here the wasm file? (you can compress it in a zip and send it in a comment). I'd like to debug a bit further

@lucklove
Copy link
Author

main.wasm.zip
thanks for help

@Hywan
Copy link
Contributor

Hywan commented Nov 29, 2019

Why are you closing the issue? The problem doesn't seem to be solved yet :-).

@lucklove
Copy link
Author

@Hywan Oh, sorry, I thought nobody cares about it.
Maybe it's the same problem with pingcap/tidb#13236

@lucklove lucklove reopened this Nov 29, 2019
@syrusakbary
Copy link
Member

@lucklove we debugged it further and it seem to be a bug on the go/wasi WebAssembly file.

The file generated is have an invalid data segment length. It should be an easy fix, but it should be done in the https://github.com/neelance/go/tree/wasi repo

Pinging @neelance, to see if he can help a bit on that!

@neelance
Copy link

neelance commented Dec 6, 2019

I believe this issue is already fixed on Go master. I need to rebase my branch. Will do so later.

@lucklove
Copy link
Author

lucklove commented Dec 9, 2019

I cherry-pick these commits and it works now:

142c002ee
1c50fcf85
9c384cc57
ecc7dd546
57662b157
30521d512
1c8e6077f
ecba83520
6dc740f09
d0f10a6e6
2686e7494
03bb3e9ad
e9c994954
ca70ada28
763d3ac75
e3c7ffcd9

@syrusakbary
Copy link
Member

That's awesome @lucklove. We just tested tidb on wasmer locally and it works great.

It seems there is an error on WebAssembly.sh that we are trying to debug now, once it's solved... you will be able to run tidb on the online WebAssembly browser shell as well!

@syrusakbary
Copy link
Member

Closing the issue as this appears to be an issue solved in the go/wasi repo.

We also have the PR #1004 that will use automatically the singlepass backend (when available) when the provided file is large (as both cranelift and llvm will take a lot of time compiling).

@neelance
Copy link

I've now rebased my fork for wasi at https://github.com/neelance/go/tree/wasi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants