Stream: rust-toolchain

Topic: Rust cdylib


view this post on Zulip Dan Gohman (Mar 04 2024 at 23:47):

In C:

In Rust:

Should we be thinking about a plan to add shared-everything dynamic linking support for Rust? I don't know of anyone that urgently needs it, but if we will eventually need it, perhaps we should start thinking about how we'll get there?

view this post on Zulip Alex Crichton (Mar 04 2024 at 23:50):

I think it'd be fine to redefine cdylib on the wasm32-wasip2 target and beyond, but beyond that I don't know of a great way to deal with -mexec-model.

The closest equivalent I can think of is #![windows_subsystem = "..."] at the crate level

view this post on Zulip Dan Gohman (Mar 04 2024 at 23:52):

How hard would it be to add a new crate-type?

view this post on Zulip Joel Dice (Mar 04 2024 at 23:55):

Dan Gohman said:

...

Should we be thinking about a plan to add shared-everything dynamic linking support for Rust? I don't know of anyone that urgently needs it, but if we will eventually need it, perhaps we should start thinking about how we'll get there?

You can do it today with some black magic, e.g.: RUSTFLAGS="-C relocation-model=pic" cargo +nightly build -Zbuild-std=panic_abort,std --release --target=wasm32-wasi and crate-type = [ "staticlib" ] to build a PIC .a file, which you can then run through clang -shared -Wl,--whole-archive <name>.a --Wl,--no-whole-archive. What could be easier? :)

view this post on Zulip Joel Dice (Mar 04 2024 at 23:57):

Just making "-C relocation-model=pic" the default for wasm32-wasip2 would be a big step forward

view this post on Zulip Dan Gohman (Mar 04 2024 at 23:58):

To do even that though, we should have something to migrate existing users to.

view this post on Zulip Alex Crichton (Mar 04 2024 at 23:59):

I suspect adding a new crate type would be a very big ask

view this post on Zulip Alex Crichton (Mar 04 2024 at 23:59):

that's integrated in tons and tons of rust tooling

view this post on Zulip Alex Crichton (Mar 04 2024 at 23:59):

alternatively we could make #![no_main] work for executables perhaps

view this post on Zulip Alex Crichton (Mar 05 2024 at 00:00):

to map to the "reactor" case

view this post on Zulip Dan Gohman (Mar 05 2024 at 00:00):

Ooh, that's an interesting idea.

view this post on Zulip Dan Gohman (Mar 05 2024 at 00:28):

Hmm, no_start means something subtly different on other architectures. It looks like what we might want is the #![no_entry] proposal.

This allows people to write their own entry point, without needing to manually link or create a .cargo/config with target-specific linker arguments.

view this post on Zulip Alex Crichton (Mar 05 2024 at 00:38):

it might be best to have #![wasm_something = "something"] perhaps to sidestep portability concerns

view this post on Zulip Alex Crichton (Mar 05 2024 at 00:38):

we don't really want to force any other platform to worry about this

view this post on Zulip Alex Crichton (Mar 05 2024 at 00:39):

I'm not sure if we want to persist the "command" and "reactor" terminology though?

view this post on Zulip Alex Crichton (Mar 05 2024 at 00:39):

perhaps #![wasm_no_start] on the crate

view this post on Zulip Dan Gohman (Mar 05 2024 at 00:39):

Yeah, I was never a huge fan of "reactor", and would be happy to use some other term.

view this post on Zulip Alex Crichton (Mar 05 2024 at 00:40):

with wasm_no_start we perhaps wouldn't have to give it a name even

view this post on Zulip Alex Crichton (Mar 05 2024 at 00:40):

it's all just wasm binaries with or without a start

view this post on Zulip Dan Gohman (Mar 05 2024 at 00:42):

What about #![wasm_exec = "exports"], which is sort of short for "the way you execute the code is, you call the exports"?

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:40):

I like the idea of the terminology, but reading #![wasm_exec = "exports"] as a standalone thing doesn't do a great job of conveying that, so we might want some wordsmithing there

view this post on Zulip Dan Gohman (Mar 05 2024 at 01:40):

"world"?

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:40):

#![wasm_entry = "exports"] maybe? defaulted to "main"?

view this post on Zulip Dan Gohman (Mar 05 2024 at 01:41):

Or maybe we can do some more magic and infer this from the world the bindings are generated from.

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:41):

hm I think we need knowledge before that

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:42):

b/c right now wasm-component-ld picks the adapter based on _start or not

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:42):

e.g. this

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:42):

so I think rustc needs to know about the shape of generated code

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:42):

and rustc won't have total knowledge of linked libraries for example

view this post on Zulip Dan Gohman (Mar 05 2024 at 01:43):

All we really need to know is if you have wasi:cli/run@0.2.0

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:43):

that's part of the adapter though, so rustc will never see that

view this post on Zulip Dan Gohman (Mar 05 2024 at 01:44):

I'd be ok waiting on these changes until we don't have an adapter anymore

view this post on Zulip Dan Gohman (Mar 05 2024 at 01:44):

If that makes it simpler

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:44):

but even then where would wasi:cli/run@0.2.0 be referenced?

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:44):

e.g. as a rust programmer you're "just" doing fn main() {}

view this post on Zulip Alex Crichton (Mar 05 2024 at 01:45):

so I feel like we need a source-level annotation of whether that's expected or not for the compiler

view this post on Zulip Dan Gohman (Mar 05 2024 at 01:45):

Hmm, yeah.


Last updated: Dec 23 2024 at 13:07 UTC