-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add libc-backing support for WASI-SDK (v8) #19
Conversation
These simply call the externally linked instruction_memory_grow and instruction_memory_size functions in the runtime. Once connected, these runtime functions can use the existing expand_memory logic that is specific to each runtime-memory implementation.
Note this is only needed when incrementally compiling, which we don't do because of LTO.
- Removed wasmception integration for now - Consistent readv/writev implementation - Changed some magic numbers to enums - Added predeclaration of (get|set)_(i8|16|32|64|f32|f64) stubs - Consistent offset type in get/set stubs - Moved env_(sin|cos) to runtime/libc/env.c
These aren't needed to pass code_benches, but may be used depending on what functions the wasm binary uses (unlink -> wasi_unstable_path_unlink_file for example). Note this the WASI API backing is still not exhaustive.
These were emitted by wasi-sdk-8.0.
And some cleanup around wasm-libc selection
Sorry about the delay on this. This PR has a number of different changes in it, let me know if you want me to split it into multiple PRs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a clean, easy addition to me. @Others you agree?
This isn't solving all problems, but it is certainly adding some great support.
runtime/memory/cortex_m_wrapping.c
Outdated
return memory_size / WASM_PAGE_SIZE; | ||
} | ||
|
||
i32 instruction_memory_grow(i32 count) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels pretty generic, but is replicated across backends. I wonder if there's an opportunity for more code sharing. Perhaps a future issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can address in this PR. Maybe @geky can lift these to runtime.c
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming expand_memory, memory_size, and WASM_PAGE_SIZE are all available globally I can move these to runtime.c.
Though I wonder if memory_grow/memory_size would be a better interface than expand_memory/memory_size. They are isomorphic to expand_memory/memory_size, but are closer the Wasm specification.
SILVERFISH_PATH, = bestpath([ | ||
(SILVERFISH_RELEASE_PATH, args.release), | ||
(SILVERFISH_DEBUG_PATH, args.debug), | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if someone passes in both --release
and --debug
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno. Probably breaks.
I didn't think it was worth enforcing, but I can look into how to enforce exclusivity if you think it is worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know of an argparse option that would help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still don't want to merge with out an explicit check for this edge case.
Also can you clean up the name and documentation of the "best path" function? It's a little more specific than the name let's on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this documentation should help with this: https://docs.python.org/3/library/argparse.html#mutual-exclusion
runtime/memory/cortex_m_wrapping.c
Outdated
return memory_size / WASM_PAGE_SIZE; | ||
} | ||
|
||
i32 instruction_memory_grow(i32 count) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can address in this PR. Maybe @geky can lift these to runtime.c
?
Currently: - code_benches/run.py --polybench - code_benches/run.py --app - code_benches/run.py --custom
The memory instruction implementation is just a thing wrapper around the memory_size/memory_expand API in aWsm.
Ok, sorry about being slow to update this! I've just pushed some changes based on your guys feedback:
Also added a small bit of test filtering so you can run a subset of the code_benches. This is useful for sanity checking minor changes without needing to run the whole bench-suite: ./code_benches/run.py --polybench |
Here is what needs done to merge this:
|
|
Had a go trying to rebase this, and very quickly ran into problems.
And there is no |
Ah, it looks like I didn't update the instructions. You need to download wasi-sdk outside of git: WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-8/wasi-sdk-8.0-linux.tar.gz
wget $WASI_SDK_URL -O wasi-sdk.tar.gz
mkdir -p wasi-sdk
tar xvfz wasi-sdk.tar.gz --strip-components=1 -C wasi-sdk (I have this in the CI script, but I just realized it's nowhere else.) This raises an interesting question of if the wasi-sdk should be available as a submodule. One of the benefits of moving to wasi-sdk is you don't need to compile LLVM thanks to the prebuilt binaries, but these aren't available as a git repo. It may be valuable to also include wasi-sdk as a submodule, in which case this is the release/hash I was using for wasi-sdk: Though not you would need to compile this before it would be usable, you also may need to tweak the paths to point to the compiled binaries correctly since I think the binary paths in the source differ from the prebuilt-binaries. |
Currently fixed as WASI-SDK v8, downloads and untars if --wasi-sdk is specified and WASI_SDK_PATH does not exist.
We can merge this, but it is totally broken on Mac.
|
I got this working on my machine with the following diff: https://gist.github.com/Others/49f7201c707edbe84dd0898ae17a185a I think we can either apply this diff + do something smarter to pick the wasi release to download, or ship this PR, and I can follow up with a patch to fix it on mac. |
The intent of this PR is to add initial support for WASI SDK. WASI SDK has a few benefits for Cortex-M development, such as allowing garbage collection of the libc-hooks. WASI SDK also provides prebuilt libc binaries, which is very nice for first time users. Also Wasmception has been deprecated in favor of WASI SDK, so would be a good idea to eventually migrate.
This PR has a few concessions:
if
instructions, which aWsm currently doesn't support, and I'm not confident enough with the inner-workings of aWsm to implement branching instructions :)Changes:
memory.size
andmemory.grow
instructions. WASI SDK uses these instead of a mmap hook.copysign/ceil/nearest
float instructions. The updated LLVM Wasm backend started emitting these. I tried to mirror the implementation of similar float instructions.Note for posterity:
The WASI API is actually very frustrating to use with the expectations of stability. Marking the entire API as "unstable" is technically correct, but practically: unhelpful. However, the WASI-SDK (separate repo) does have easy to navigate releases.
This leads to a bit of a strange situation where the best resource for the state of the WASI API at WASI-SDK v8 is this file at this hash:
https://github.com/WebAssembly/wasi-libc/blob/ec3ee5e98541a89b9db016005fa0e9f0287fd755/libc-bottom-half/headers/public/wasi/core.h
Anyways, @Others, let me know how this looks