-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Wasm support #71
Comments
With the limitation of having a single submit in the whole program, I think this is not something I would want to make use of in this crate. |
Indeed it is a bummer, but I want to be precise, the limitation is not a single submit in the whole program. E.g. you can have a submit in a library, and a submit in a binary which depends on the library. The other limitation is that the library must either export a symbol with Hopefully wasm-ld can be fixed though, I don't have plans to work on it given there are workarounds. |
Thank you for clarifying the limitation. I missed that it is one per crate, not one per the whole program. It's clear from your PR description. Maybe it would be reasonable for inventory to use this, then? The reason I am not sure is: this adds build errors where there didn't used to be one. If I have a Wasm project that depends on some library that uses inventory in one part of its implementation, but in my project I never use that part, previously I'd still be able to use all the rest of the library; but if we add I am on board with trying it if someone wants to send a PR. We'll see how useful it ends up being in practice. I probably wouldn't do a pub struct Thing { ... }
pub struct Things(pub &'static [Thing]);
inventory::collect!(Things); |
Indeed, the compilation failures thing is a bit of a pickle, the even worse thing is just emitting this is going to lead to a bump of MSRV on wasm, and the old compilers are all going to get a compilation failure from rustc when just emitting I would be somewhat inclined to considering having a temporary I was going to wait until something has landed in the compiler before making a PR for this. |
Would love to use
Thanks in advance for any advice! |
@kwhitehouse Currently this only works if you have all of the following things:
These last two things are issues in the underlying I spent quite a bit of time debugging the |
For interested explorers: I have forked and modified LLVM to support multiple #[used]
#[link_section = ".init_array"]
pub static __CTOR: unsafe extern "C" fn() = __ctor1;
unsafe extern "C" fn __ctor1() {
VAL = VAL + 1;
}
#[used]
#[link_section = ".init_array"]
pub static __CTOR2: unsafe extern "C" fn() = __ctor2;
unsafe extern "C" fn __ctor2() {
VAL = VAL + 1;
}
static mut VAL: i32 = 0;
fn main() {
unsafe {
let val_ptr = &raw mut VAL;
println!("val = {}", *val_ptr);
}
}
Using a patch similar to the one in the OP of this thread,
I can now use the inventory package with the My patch to LLVM is here: llvm/llvm-project@8266ca5. |
@georgestagg Have you submitted your LLVM patch upstream, or is it just in your fork? Sounds like it would be worth upstreaming if possible, but not sure how big of a lift that is from your current patch. |
I'm working towards upstreaming, |
wasm-ld now seems to have rudimentary
.init_array
support.I posted a rustc patch here: rust-lang/rust#121533
While it does work to just add
This suffers from the limitation of wasm only supporting a single symbol in the link_section.
It would perhaps be nice if there was a
submit_many!()
macro which wouldI tested that this also works with
.init_array
at least on linux, on other platforms presumably it could justsubmit!
for eacharg to
submit_many!
.Probably not worth implementing until we see the rustc patch go in, but I figured it was worth mentioning since
wasm support has come up in the past. E.g. @matklad asked about it in #3
The text was updated successfully, but these errors were encountered: