-
Notifications
You must be signed in to change notification settings - Fork 191
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
What is the difference between wasi-sdk and emscripten? #222
Comments
/cc @sbc100 |
While Emscripten produces JS code to accompany the wasm files it produces, wasi-sdk doesn't produce any JS. Since wasi-sdk only produces wasm, it isn't affected by the issue that JS typed arrays are endianness-dependent in JS. WebAssembly and WASI are little-endian, so implementations on big-endian platforms need to perform byte-swapping under the covers, and several of the major implementations indeed do this. |
That't right. V8 is patched to reverse bytes on BE platforms when executing wasm itself. My only concern right now is related to runtime calls to functions outside of wasm, mainly libc. How are such calls to libc or Wasi API handled by wasi-sdk? Are they compiled to wasm as well? I'm just wondering if we need to apply any patches to make sure LE ordering is enforced to any outside calls. |
In wasi-sdk, libc itself is implemented entirely in wasm. There are calls to WASI APIs which may be implemented outside of wasm, but the expectation is that the implementations of those APIs behave as-if they are little-endian. And in practice, the major implementations indeed do run on big-endian platforms and do the byte-swapping as needed. |
Thanks for confirming. So how are WASI APIs outside of wasm compiled and handled? |
To my knowledge, V8 today does not have an implementation of WASI. In engines which do, such as Wasmtime, WASI is typically implemented in native host code, rather than wasm code, and it performs bytes-swapping on big-endian platforms so that it presents a little-endian API to wasm. |
I see, so by default it should handle bye swapping on BE to maintain LE ordering.
So then how should |
Node.js includes https://github.com/nodejs/uvwasi as its WASI implementation. |
Thanks for the link Richard, |
Hello,
I wanted to get more information on wasi-sdk and it's support on big endian platforms.
BE support was added to emscripten in this PR: emscripten-core/emscripten#13413
emscripten uses llvm/clang to generate wasm binaries. From my understanding it also compiles musl libc to wasm and glues it all together with a generated
js
file which can directly be called withNode js
, and it all gets executed by V8 runtime. Everything is little endian enforced by wasm standards and V8 is hard coded to reverse bytes accordingly on BE machines.What is the difference between the output of wasi-sdk and emscripten and where does it stand in terms of supporting BE machines as well as C runtime? Does it also make sure libc is LE enforced?
The text was updated successfully, but these errors were encountered: