-
Notifications
You must be signed in to change notification settings - Fork 715
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
Emscripten main.c file? #1434
Emscripten main.c file? #1434
Conversation
Looks nice! I think this is reasonable to have here, though I worry a little about version skew with emscripten. It would be nice to have some basic tests, but I'm not sure we'd want to run the full emscripten testsuite here. |
@sbc100 wdyt? |
I'm currently working on the WASI implementation which should allow STANDALONE_WASM binaries to run the wasm-interp. Eventually it would be nice to unify those two things. Specifically, in my implementation I use uvwasi, which is very nice way to expose the wasi APIs entry points and is cross platform and fairly well tested. it does add a small sandbox layer out course which wasm2c users might not want. I think there are a few questions we need to ask:
I worry in particular about the duplicate work and maintance cost of maintaining our own WASI implementation over time as it evolves. It would be nice to combine efforts with uvwasi and be able to benefit from their work. |
Personally, I don't think we want to be pulling emscripten-specific stuff into wabt. Testing emscripten under wasm2c would be something we could do in the emscripten repro and report bugs back here. |
It could also enable wasm-interp to run binaries produced by wasi-sdk.
Just as there isn't a way to have a completely un-sandboxed core wasm module, even though some users would find it useful because it'd make it easier to share memory between wasm and host, I encourage wabt to not provide a completely unsandboxed API either, even though some users may find it useful. An API sandbox is sometimes inconvenient, as is the core sandbox, but if we focus on finding solutions to problems that work with the sandbox instead of making it easy to disable the sandbox, we can make the whole ecosystem better for people who do need the sandbox. |
I think both routes are important. In emscripten we have |
Yes! Indeed, as of #1430 we can pass all the wask-sdk micro-tests (not say much I know but milestone non-the-less).
I believe the wasm2c already has an unsandboxed-memory mode, which is mostly interesting for experimenting and bench-marking I guess. I would agree that we don't want to encourage such things in the wild but I do think its reasonable to have flags that we can use to turn these things on and off. I mean even chrome itself has a |
Do you have a sense of what features, specifically, are useful, that are unsupported? It would be great to learn more about how current sandboxing mechanisms are insufficient for real-world use cases.
A great way to push the sandboxing approach as far as we can take it is to enable it and find out where it's insufficient. 😄 |
Thinking about this some more, I agree. This is pretty useful for
If we're generating bindings for wasm-interp, we should be able to do it for wasm2c too. Using uvwasi as a base seems like a good way to go.
If we do, we definitely should encourage it. As @sbc100 said, I think it's useful for benchmarking (memory checking overhead, etc.). But I'm not sure if this usage translates to a completely unsandboxed WASI too.
emscripten would be convenient, but it does feel a bit odd to include here given that the emscripten API isn't standardized. |
@kripken is it possible for this to live in the emscripten-repo for now? Seems like that makes for sense (at least for now). |
Sure, here is my main use case: Right now emscripten ships an emsdk to users with binary builds for 3 platforms, windows, mac, and linux. That includes LLVM, Binaryen, and on some platforms Python and other stuff. Those builds cover most but not all users, since some people's linux distro can't run our linux builds, or they are on BSD, or whatever. We suggest those people build from source, but instead, how about if we gave them a build that runs in node.js, or a big C file? Both are those are likely to work for many users and be much simpler than building themselves. Another benefit of such builds is we can use newer compilers. It would be nice if binaryen could use c++20 or maybe be a mixture of various languages, some of which use very new compilers. It's easier to do that if we have more easy ways for users to get builds from us, so they aren't stuck. For such builds to be feasible, they must be of similar performance and capability to our normal builds. It looks like node.js is not currently viable as code caching of wasm worked in node 12, but fails in node 14 (due to v8 APIs changing, I am told). Recompiling clang on every invocation would not be fun! That's why I'm more focused on wasm2c atm (but long-term, I think node - or deno 😉 - is better). For wasm2c to work, I need:
I think that covers it. Currently we already have direct node.js access to some things like files, and maybe the same flag could cover wasm2c. As I find the specific APIs, I can let you know what's missing from WASI in more detail.
Definitely! I hope I didn't come across as negative in any way about that. I look forward to a future where practically everything is sandboxed! Yeah, I'm happy for this to live in emscripten. Whatever people prefer. Sounds like we are agreed there, so I'll close this. |
This is the
main()
file I've used in my emscripten testing so far. It's now at the point where it can run the whole benchmark suite, which includes file handling (some tests read a file, and sqlite also does seeks and writes), setjmp/longjmp, and a few other nontrivial things.I'm a little unsure which repo it should live in, so I just opened a draft PR here. Do people think it would make sense here, or in the emscripten repo?
A related question might be where to test the emscripten+wasm2c mode. Getting it passing the emscripten test suite seems useful. Or maybe we should add some emcc tests here?