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 simple cpp file #327

Closed
geloizi opened this issue Apr 5, 2019 · 13 comments · Fixed by #328
Closed

Can't run simple cpp file #327

geloizi opened this issue Apr 5, 2019 · 13 comments · Fixed by #328
Assignees
Labels
bug Something isn't working 📦 lib-emscripten About wasmer-emscripten

Comments

@geloizi
Copy link

geloizi commented Apr 5, 2019

A simple cpp program:

#include <iostream>
int main() {
    std::cout << "hello world\n";
}

Compiled with emscripten:

em++ -o cpp.js cpptest.cpp

Execution fails:

wasmer run cpp.wasm                                                                            
"Can\'t instantiate module: LinkError([ImportNotFound { namespace: \"env\", name: \"abortOnCannotGrowMemory\" }, ImportNotFound { namespace: \"env\", name: \"abortStackOverflow\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_ii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiid\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiid\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiij\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_v\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_vi\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_vii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viijii\" }, ImportNotFound { namespace: \"env\", name: \"___cxa_uncaught_exception\" }, ImportNotFound { namespace: \"env\", name: \"___lock\" }, ImportNotFound { namespace: \"env\", name: \"___map_file\" }, ImportNotFound { namespace: \"env\", name: \"___setErrNo\" }, ImportNotFound { namespace: \"env\", name: \"___syscall140\" }, ImportNotFound { namespace: \"env\", name: \"___syscall145\" }, ImportNotFound { namespace: \"env\", name: \"___syscall146\" }, ImportNotFound { namespace: \"env\", name: \"___syscall54\" }, ImportNotFound { namespace: \"env\", name: \"___syscall6\" }, ImportNotFound { namespace: \"env\", name: \"___syscall91\" }, ImportNotFound { namespace: \"env\", name: \"___unlock\" }, ImportNotFound { namespace: \"env\", name: \"_abort\" }, ImportNotFound { namespace: \"env\", name: \"_emscripten_get_heap_size\" }, ImportNotFound { namespace: \"env\", name: \"_emscripten_memcpy_big\" }, ImportNotFound { namespace: \"env\", name: \"_emscripten_resize_heap\" }, ImportNotFound { namespace: \"env\", name: \"_getenv\" }, ImportNotFound { namespace: \"env\", name: \"_llvm_stackrestore\" }, ImportNotFound { namespace: \"env\", name: \"_llvm_stacksave\" }, ImportNotFound { namespace: \"env\", name: \"_pthread_cond_wait\" }, ImportNotFound { namespace: \"env\", name: \"_strftime_l\" }, ImportNotFound { namespace: \"env\", name: \"memory\" }, ImportNotFound { namespace: \"env\", name: \"table\" }, ImportNotFound { namespace: \"env\", name: \"__memory_base\" }, ImportNotFound { namespace: \"env\", name: \"__table_base\" }, ImportNotFound { namespace: \"env\", name: \"DYNAMICTOP_PTR\" }, ImportNotFound { namespace: \"env\", name: \"tempDoublePtr\" }, ImportNotFound { namespace: \"global\", name: \"NaN\" }, ImportNotFound { namespace: \"global\", name: \"Infinity\" }])"
@geloizi geloizi added the bug Something isn't working label Apr 5, 2019
bors bot added a commit that referenced this issue Apr 5, 2019
328: fix master; add some emscripten calls r=MarkMcCaskey a=MarkMcCaskey

notified by #327 ;
that program when compiled now outputs 
`"RuntimeError: WebAssembly trap occured during runtime: memory out-of-bounds access"` ;

which may have been broken by #326 

Co-authored-by: Mark McCaskey <mark@wasmer.io>
@MarkMcCaskey
Copy link
Contributor

Thanks for reporting this! So there are two reasons this could have happened:

  • Master was broken for the past 11 hours and it was attempting to run Emscripten WASM files as WASI WASM files
  • If you're using a released version of Wasmer, then because we haven't released in a bit, it's missing a lot more emscripten syscalls. Once I fixed master, I noticed that it was still missing two which I implemented.

After those were fixed, I'm still having an issue running this program; I'm getting a "RuntimeError: WebAssembly trap occured during runtime: memory out-of-bounds access" -- which I'll start investigating now

@MarkMcCaskey MarkMcCaskey self-assigned this Apr 5, 2019
@syrusakbary
Copy link
Member

Yes, to add on top of what @MarkMcCaskey commented.

When running with released version 0.2.1 this is the output:

➜  wasmer run cpp.wasm
"Can\'t instantiate module: LinkError([ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiid\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiid\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiij\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viijii\" }, ImportNotFound { namespace: \"env\", name: \"___cxa_uncaught_exception\" }, ImportNotFound { namespace: \"env\", name: \"_strftime_l\" }])"

And when run with current master (your error):

➜  wasmer run cpp.wasm
"Can\'t instantiate module: LinkError([ImportNotFound { namespace: \"env\", name: \"abortStackOverflow\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_ii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiid\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiid\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_iiiiij\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_v\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_vi\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_vii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viiiiii\" }, ImportNotFound { namespace: \"env\", name: \"nullFunc_viijii\" }, ImportNotFound { namespace: \"env\", name: \"___cxa_uncaught_exception\" }, ImportNotFound { namespace: \"env\", name: \"___lock\" }, ImportNotFound { namespace: \"env\", name: \"___map_file\" }, ImportNotFound { namespace: \"env\", name: \"___setErrNo\" }, ImportNotFound { namespace: \"env\", name: \"___syscall140\" }, ImportNotFound { namespace: \"env\", name: \"___syscall145\" }, ImportNotFound { namespace: \"env\", name: \"___syscall146\" }, ImportNotFound { namespace: \"env\", name: \"___syscall54\" }, ImportNotFound { namespace: \"env\", name: \"___syscall6\" }, ImportNotFound { namespace: \"env\", name: \"___syscall91\" }, ImportNotFound { namespace: \"env\", name: \"___unlock\" }, ImportNotFound { namespace: \"env\", name: \"_abort\" }, ImportNotFound { namespace: \"env\", name: \"_emscripten_get_heap_size\" }, ImportNotFound { namespace: \"env\", name: \"_emscripten_memcpy_big\" }, ImportNotFound { namespace: \"env\", name: \"_emscripten_resize_heap\" }, ImportNotFound { namespace: \"env\", name: \"_getenv\" }, ImportNotFound { namespace: \"env\", name: \"_llvm_stackrestore\" }, ImportNotFound { namespace: \"env\", name: \"_llvm_stacksave\" }, ImportNotFound { namespace: \"env\", name: \"_pthread_cond_wait\" }, ImportNotFound { namespace: \"env\", name: \"_strftime_l\" }, ImportNotFound { namespace: \"env\", name: \"abortOnCannotGrowMemory\" }, ImportNotFound { namespace: \"env\", name: \"memory\" }, ImportNotFound { namespace: \"env\", name: \"table\" }, ImportNotFound { namespace: \"env\", name: \"__memory_base\" }, ImportNotFound { namespace: \"env\", name: \"__table_base\" }, ImportNotFound { namespace: \"env\", name: \"tempDoublePtr\" }, ImportNotFound { namespace: \"env\", name: \"DYNAMICTOP_PTR\" }, ImportNotFound { namespace: \"global\", name: \"NaN\" }, ImportNotFound { namespace: \"global\", name: \"Infinity\" }])"

We are working on investigating the issue and fixing it asap.

@MarkMcCaskey
Copy link
Contributor

We just found and are pushing a fix for C++! We're going to wrap it up with the other fixes and add it as a test.

It should be merged on to master soon!

bors bot added a commit that referenced this issue Apr 5, 2019
328: fix master; add some emscripten calls r=xmclark a=MarkMcCaskey

notified by #327 ;
that program when compiled now outputs 
`"RuntimeError: WebAssembly trap occured during runtime: memory out-of-bounds access"` ;

which may have been broken by #326 

Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Mackenzie Clark <mackenzie.a.z.c@gmail.com>
bors bot added a commit that referenced this issue Apr 5, 2019
328: fix master; add some emscripten calls r=MarkMcCaskey a=MarkMcCaskey

notified by #327 ;
that program when compiled now outputs 
`"RuntimeError: WebAssembly trap occured during runtime: memory out-of-bounds access"` ;

which may have been broken by #326 

Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Mackenzie Clark <mackenzie.a.z.c@gmail.com>
@syrusakbary syrusakbary changed the title cpp environment doesn Can't run simple cpp file Apr 5, 2019
@syrusakbary syrusakbary added the 📦 lib-emscripten About wasmer-emscripten label Apr 5, 2019
bors bot added a commit that referenced this issue Apr 5, 2019
328: fix master; add some emscripten calls r=MarkMcCaskey a=MarkMcCaskey

notified by #327 ;
that program when compiled now outputs 
`"RuntimeError: WebAssembly trap occured during runtime: memory out-of-bounds access"` ;

which may have been broken by #326 

resolves #327

Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Mackenzie Clark <mackenzie.a.z.c@gmail.com>
@syrusakbary
Copy link
Member

It seemed we were missing calling globalCtors (required for cpp files).
https://github.com/wasmerio/wasmer/pull/328/files#diff-6c1320db2af15a1d4083a7c5fab79cffR252
We just solved the issue on master with #328.

Here's the test file: https://github.com/wasmerio/wasmer/pull/328/files#diff-cbdacb4dc71f3c9fa01eb318ad62dda2R1
And the output that it should generate when running it with wasmer: https://github.com/wasmerio/wasmer/pull/328/files#diff-a302d4bac00cf38a4eccd6a4a85dccdfR1

We will make a wasmer release soon.

@geloizi
Copy link
Author

geloizi commented Apr 5, 2019

It still fails with

"RuntimeError: WebAssembly trap occured during runtime: memory out-of-bounds access"

BTW, there is a typo in error message. It should be " occurred".

@syrusakbary
Copy link
Member

syrusakbary commented Apr 5, 2019

Can you try with wasmer run cpp.wasm --disable-cache?
Also, if you can upload your wasm file here it would be awesome, and it would help us debug further.

This is the file we have been able to run successfully, in case you want to try locally: https://github.com/wasmerio/wasmer/blob/master/lib/emscripten/emtests/hello.wasm

(compiled from here)

@syrusakbary syrusakbary reopened this Apr 5, 2019
@geloizi
Copy link
Author

geloizi commented Apr 6, 2019

Confirmed. The issue has been fixed.

BTW, I've tried to build with latest-upstream version of emscripten (it's based on llbvm8), wasmer doesn't support it.

"Hello world" compiled with latest-upstream.
cpp.zip

@MarkMcCaskey
Copy link
Contributor

Thanks for following up @geloizi ; so I just ran the included hello.wasm in your zip file and it seems to be working on master for me. I'll look in to reproducing this and get back to you today

@MarkMcCaskey
Copy link
Contributor

@geloizi What OS are you running this on or if you could include the error output, that'd be very helpful!

@geloizi
Copy link
Author

geloizi commented Apr 8, 2019

What OS are you running this on

mac

@MarkMcCaskey
Copy link
Contributor

What OS are you running this on

mac

Hmm, I'm also running on a mac and am unable to reproduce with master and the cpp.wasm you posted.

@geloizi
Copy link
Author

geloizi commented Apr 8, 2019

never-mind. Emscripten latest-upstream isn't a stable release anyway.

@MarkMcCaskey
Copy link
Contributor

Okay! Well please let me know if you have any other issues or ideas for Wasmer and I'll look in to them! I'm going to close this issue for now

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-emscripten About wasmer-emscripten
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants