-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Compiled wasm32-wasip2 component from simple code requires excessive WASI interfaces #133235
Comments
EDIT: Nevermind I read the zulip thread, so this is T-libs
|
This comment has been minimized.
This comment has been minimized.
Ah right we have a wasi ping group now |
Hey WASI notification group! This issue or PR could use some WASI-specific guidance. (In case it's useful, here are some instructions for tackling these sorts of |
My guess would be that format is pulling in the entire panic machinery which includes a lot more string formatting. You could try compiling the wasm binary and std with panic immediate abort (I don’t know the exact flags by heart) and see if that removes those extraneous environmental dependencies. |
Based on rust-lang/wg-cargo-std-aware#29 it might be something like |
Those look correct - you might also need |
Alright, I changed my build command to error[E0152]: duplicate lang item in crate `core`: `sized`
|
= note: the lang item is first defined in crate `core` (which `implementation` depends on)
= note: first definition in `core` loaded from /Users/zhiqiu/offline_code/opensource/wit_issue/implementation/target/wasm32-wasip2/release/deps/libcore-55d3ecbce88cf86e.rlib, /Users/zhiqiu/offline_code/opensource/wit_issue/implementation/target/wasm32-wasip2/release/deps/libcore-55d3ecbce88cf86e.rmeta
= note: second definition in `core` loaded from /Users/zhiqiu/.rustup/toolchains/nightly-2024-11-19-aarch64-apple-darwin/lib/rustlib/wasm32-wasip2/lib/libcore-65e53cbf30438bae.rlib
This is out of my mind and I don't know if it's another solvable issue or bug....... Kind of reminds me of the horrible building errors in C. I think you can reproduce this in this branch of my repo. |
Maybe using |
@bjorn3 Thanks, I tried this error[E0152]: duplicate lang item in crate `core`: `sized`
|
= note: the lang item is first defined in crate `core` (which `implementation` depends on)
= note: first definition in `core` loaded from /Users/zhiqiu/offline_code/opensource/wit_issue/implementation/target/wasm32-wasip2/release/deps/libcore-65b8a47a5d02d391.rlib, /Users/zhiqiu/offline_code/opensource/wit_issue/implementation/target/wasm32-wasip2/release/deps/libcore-65b8a47a5d02d391.rmeta
= note: second definition in `core` loaded from /Users/zhiqiu/.rustup/toolchains/nightly-2024-11-19-aarch64-apple-darwin/lib/rustlib/wasm32-wasip2/lib/libcore-65e53cbf30438bae.rlib
For more information about this error, try `rustc --explain E0152` And I don't quite understand the explanation given by |
I believe the command you want is:
Notably
which I believe is what you want |
@alexcrichton Wow! That works like a charm. Thanks a lot! As a Rust application developer and a WASI newbie, that long command has a lot to take in. I have a few questions (not trying to push anything but for discussion):
Do you guys think those questions are hard to answer? I might just write up a blog or actually try to solve these issues if they are not like rabbit-hole hard. |
Yes, if you use any libstd api that needs those interfaces, they will automatically be imported.
The standard library has what is effectively1 a call to: bindgen!({
path: "/path/to/wasip2/cli/imports.wat",
world: "wasi:cli/imports",
}); which causes all interfaces in the Footnotes
|
Thst's.......... a lot of information and clears out most of the mist in my mind. Thanks a lot! @bjorn3 I'd like to ask a few more questions, if you don't mind.
This partially explains why
Take Taking a step back, I think the information you provided is really valuable and useful for understanding how WASI generally works in Rust. Can you please put that in the rustc book? I could make a PR, but I think it's not appropriate for me to do that. |
It only imports the get-environment method of the wasi_cli/environment interface (+ other interfaces used by the panic handler if it is possible to panic). |
OK, the problem is conceptually clear to me. Thanks! So, the behavior of the default panic handler is documented here
I tried Maybe I should use |
If a panic happens before the
That won't have any effect. It only sets a flag and doesn't enable any optimization opportunities. |
OK then. Are we stuck? I don't know anything else to set the panic handler globally. I found |
The easiest solution is to provide the full wasip2 interface to the wasm component, so using |
By "stuck" I mean stuck in solving this issue, not making this program run. I did implement We see in the case of But in the case of
I want to know if there's a way to configure panic handler globally ahead of compilation, so the panic handler does not brings in excessive interface requirements other than |
It is not possible to replace the panic handler when using libstd. There can only be a single panic handler in the whole program and libstd always defines a panic handler. |
OK........ So, it seems we have to turn to I think it is definitely an issue to be resolved because: No ways to replace the panic handler when using libstd -> No ways to prune interfaces requirements when a component uses libstd -> A host must grant all interfaces required by the panic handler of libstd to run an untrustable guest -> Potentially compromised security guarantees of WASIp2 |
The default permissions |
OK, I see your points. The host can provide random stubs even if a component requires excessive interfaces. My feeling is that there is some inconsistency: Conceptually, a host opts in capabilities that it chooses to offer to a component, e.g., implementing Besides, I did some search, I guess for custom panic handler, we'll have to wait for #59222 and #32837 ........... |
During my learning and experiments of wasip2, I tried this simple code and compiled it to a wasip2 component:
and
The host code, which runs the component, is:
The block with a note binds many interfaces to avoid runtime errors that says something like
component imports instance wasi:cli/[email protected], but a matching implementation was not found in the linker.
Removing any one of the lines in the block will result in a runtime error.I expect this compiled component requires none of these WASI interfaces to run, since it has nothing to do with io, cli, etc. Binding these unnecessary interfaces may raise security concerns.
The full minimized code is here.
As a kind person pointed out on ByteAlliance Zulip, these interfaces are required by
std
.Probably there's a way to minimize or prune the interface requirements in the compilation? I think rustc has all the information of which effects are used by any one of functions/macros that is used by a user.
At the very lease, I think we should document these requirements somewhere, so there are no hidden/dark interface dependencies that are not specified and unknown in WIT files.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: