Stream: rust-toolchain

Topic: ✔ rust mutable-global


view this post on Zulip Graydon Hoare (Aug 01 2023 at 00:55):

I notice rust 1.70 enabled the target features sign-ext and mutable-global by default. This is .. a little disruptive but we can adapt. I want to make a testcase that exhibits uses of both of these features, however, and am struggling a bit. I can do sign-ext by using some inline asm! to pick out the required instruction, but I'm wondering: is there a rust construct that causes a mutable global export? If I make a normal mut static and #[no_mangle] it, I think it exports an immutable global that has a linear-memory address of the mutable variable. Is the only viable approach here to write a module in .wat?

view this post on Zulip Graydon Hoare (Aug 01 2023 at 01:09):

I can't figure out anything to put in global_asm! that might work

view this post on Zulip Alex Crichton (Aug 01 2023 at 06:30):

Yeah rust and llvm have no native ability to export globals in wasm, so you'll need probably global asm to get the linking metadata to be present

view this post on Zulip Pat Hickey (Aug 01 2023 at 14:35):

https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi-preview1-component-adapter/build.rs

view this post on Zulip Pat Hickey (Aug 01 2023 at 14:35):

and when that fails you can roll your own object file

view this post on Zulip Graydon Hoare (Aug 01 2023 at 17:12):

@Alex Crichton I'm trying to find an example of global_asm with wasm and coming up short -- it doesn't look like I can jam arbitrary wat in there -- what's the supported syntax?

view this post on Zulip Graydon Hoare (Aug 01 2023 at 17:15):

oh geez I guess I can infer something by reading this https://llvm.org/doxygen/WebAssemblyAsmParser_8cpp_source.html

view this post on Zulip Alex Crichton (Aug 02 2023 at 06:41):

Yeah global_asm! has funky syntax and honestly I'm not so sure of it myself. I think last I checked I was poking around various test cases in LLVM to figure out what to do since I don't think it's documented anywhere. It's definitely not arbitrary s-expr wasm stuff

view this post on Zulip Graydon Hoare (Aug 02 2023 at 17:37):

ok. I wound up just using a utility crate we use to programmatically build wasms. who knows if any rust constructs actually correspond! haha

view this post on Zulip Notification Bot (Aug 03 2023 at 18:14):

Graydon Hoare has marked this topic as resolved.


Last updated: Dec 23 2024 at 13:07 UTC