-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support multiple versions of wasmtime
in the same crate
#6673
Support multiple versions of wasmtime
in the same crate
#6673
Conversation
Subscribe to Label Actioncc @peterhuene
This issue or pull request has been labeled: "wasmtime:api"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
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.
Thanks for working on this!
One suggestion I might have though is that instead of changing the literal identifier used in Rust code to one with a version appended I think this would be a good use for #[export_name = "foo"]
or #[link_name = "foo"]
(depending on context). That way the symbol in Rust wouldn't change, but only the symbol at the binary level (which is what we care about the most here)
This is a really great suggestion, thank you! I did not know this was possible, but it simplifies things considerably. |
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.
Nice! I like how this simplified things well. If you're up for it as well it'd be awesome to include this dependency in the wasmtime-fiber
crate as well which would allow removing the links
attribute there and enable multi-version linkage.
I started tackling this in e085825. I still need to handle the |
This all looks great to me, thanks again! If you're up for handling s390x that'd be much appreciated, but if not then I think as long as it's not broken it's ok to land this and that's ok too. |
Thanks for all of your help reviewing! I attempted handling s390x in ff81d02. I tried to pass the suffix with the |
I sent adampetro#1 to avoid the need to copy files around, IIRC I dealt with voodoo like that a long time ago, but I'm not sure that's the simplest it can be. This reminded me though that there's one more location at |
Thanks! I added versioned symbols for Would I also need to do something similar in |
Ah yes I forgot about that! I think though that's the last one and this should be good to go once that's updated 👍 |
I'll add the new crate to |
Yeah I think it's fine to keep the same strategy as |
a7331b1
to
2c45991
Compare
^ force push to rebase latest main and resolve merge conflict |
Drive-by clarifying thought that I just worked out: I was contemplating the non-composability of POSIX signals (as one does...) and wondering how multiple runtimes in one process would fare if each is trying to handle traps from its own respective instances. It turns out that Wasmtime chains to previous signal handlers if it wasn't active (TLS slot was null). I think this mostly works, except I haven't been able to convince myself yet that it's safe if a Wasm instance in wasmtime-1 calls to host code which then calls a Wasm instance in wasmtime-2 which traps. Then both TLS slots are active; if wasmtime-1 catches the signal (registered its handlers last), will it properly chain to wasmtime-2? If so, we should probably document somewhere how this interaction is expected to work. |
Good questions! Ones I had forgotten to consider with this... I think though we should be good in theory. If you've got wasmtime-1 and wasmtime-2 both on the stack then if one faults and the others' handler ends up running first the handler should end up determining that the signal should not be caught and defer to the next handler. This is more-or-less falling out of the "we don't catch signals not caused by wasm" and the signals from wasmtime-1 appear like non-wasm signals to wasmtime-2 because the faulting address won't be in any known region. I do agree though it'd be good to document this! It'd be better yet to even test it, although that part is sort of hard. As for where to document this I'm not entirely sure other than perhaps in the code along the lines of "this should be written to work when multiple wasmtimes are in the same process" |
In theory we could have a test (maybe an integration test to avoid overhead in the usual Or: if we wrapped some globals into a context struct (at least the signal handlers and the allocated tls-slot) we could do something like let ctx1 = wasmtime::ProcessContext::new();
let ctx2 = wasmtime::ProcessContext::new();
let engine1 = wasmtime::Engine::new_with_context(&ctx1);
let engine2 = wasmtime::Engine::new_with_context(&ctx2);
// ... test with instances calling each other via host code and |
…and it is uses `weak` linkage
Ah sorry I'm new to this as well so I'm trying to remember what's going on here. I think the issue may be that [[wildcard-audits.wasmtime]]
who = "Bobby Holley <bobbyholley@gmail.com>"
criteria = "safe-to-deploy"
user-id = 73222 # wasmtime-publish
start = "2021-10-29"
end = "2024-06-26"
notes = "The Bytecode Alliance is the author of this crate." (to copy an existing entry) This is a "trusted file" though which we typically audit carefully in PRs and contributors typically don't modify. For example when existing crates are updated we as project authors will send a PR with audits which a contributor then rebases on top of to get In lieu of that can you add this entry? [[wildcard-audits.wasmtime-versioned-export-macros]]
who = "Alex Crichton <alex@alexcrichton.com>"
criteria = "safe-to-deploy"
user-id = 1 # Alex Crichton (alexcrichton)
start = "2023-07-05"
end = "2024-07-05"
notes = "The Bytecode Alliance is the author of this crate." |
Even with the suggested
With |
Hm ok sorry for the runaround here! I think in this situation let's set @bholley you might be interested in some of the above, but I think this boils down to we're adding a new crate to this repository and I think it may not be playing well with |
@mystor can you figure out what's going on here? |
No worries, sounds good and thanks for the help! |
Yes, it is required that all crates marked as Once there is a published version of the crate you can switch to |
Ok thanks for the clarification! In that case @adampetro this all looks good to me, so happy to merge when you feel it's ready |
+1, thanks!
👍 I think it's ready. Thanks for all your help @alexcrichton! |
@alexcrichton If this crate isn't published, it shouldn't need an |
True! This will be published soon though, it just hasn't been included in any release prior yet. |
issue #6660
This change enables support for including multiple versions of
wasmtime
in a crate by adding suffixes to the symbols produced to assembly that currently producemultiple definition
errors when attempting to use multiplewasmtime
versions.Starting this in draft to get feedback on the general approach before adding tests, tackling removing
links
from thefiber
crate, and other refinements.