-
Notifications
You must be signed in to change notification settings - Fork 89
[Documentation] static core linking #239
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
Comments
You can then transform a core wasm module into a component using a tool such as All of these things happen ahead of time, before the component is loaded into a runtime for instantiation. |
So what is the relationship between |
I'm not aware of any specific documentation myself, but these tools are quite low-level so it's sort of similar to asking what the relationship is between
The |
@pchickey made a reference to I know what |
wasm-ld is not used by any of the wit tools or runtimes. On our call last night I described the process by which which you can statically link programs prior to getting involved with any component runtime. If you desire a component which contains a single statically linked core module, you should create that core module using whatever wasm-object file (meaning, in almost all cases, llvm) based toolchain, and use You can then take that core module and transform it into a component by using At this time there is no mechanism to take already-existing components (meaning, any set of components containing more than one core module) and change their representation into a single core module using a single linear memory. If you wanted to create such a thing, merging the core modules into a single linear memory would have to implement its own page table / virtual addressing scheme internal to wasm, which would be slower than letting a wasm runtime do that translation on your behalf to implement multiple linear memories, since the runtime can leverage actual virtual memory and an internal-to-wasm implementation cannot. |
OK, I guess I completely misunderstood that. So if the linking is going to be done the same way it is done today, does it interface with component model, i.e. does component model encode any of the core module composition? There is this example in mvp/Explainer.md:
This would not mean that |
@penzn That example is admittedly a bit synthetic; if you were able to generate that component, you might as well have statically linked (component
(core module $AB
... $A and $B linked together via wasm-ld
)
(core instance $ab (instantiate $AB))
) This simple example doesn't have any imports/exports, but in a more realistic example, the core module produced by wasm-ld would contain imports for all symbols annotated with That being said, if you did leave |
I see, how this integrates with components is similar to how we currently use 'external' functions, with the linking staying pretty much the same (difference is in how the interfaces are really produced). Can we add this to the docs, maybe changing this particular example? I can try to help. |
Yes, that's a good idea; it seems like how static linking fits into the component model is a generally pretty hot topic these days :) Maybe the best way would be a new StaticLinking.md example (linked to from within the main explainer in the relevant points like the example you're looking at) so that this StaticLinking.md can better introduce the problem from scratch and explain how it all works. That'd be awesome to have your help writing it up, otherwise I'm happy to take a crack at it some time after WasmCon. |
I started this diagram to try to capture the different phases of linking that we've been talking about and how they fit together in the overall developer workflow. I'm imagining a new |
@lukewagner that looks right, thank you for putting it together! I think this diagram is great, though I think there is another angle that can be useful (this might need a diagram, maybe just a note in the text), specifically how would this work from 'using a component' point of view. Say I have a WIT file, implementation of that component, and a consumer of that component - I can compile both the implementation and consumer into a bunch of .o/.a files, but would I be able to link them together, or would that be tricky due to the need to maintain memory boundaries? |
@penzn Using core wasm multi-memory (which it looks like is in both Firefox and Chrome now), it's always possible to take an arbitrary component and "fuse" it into a single core wasm module that imports/exports the Canonical ABI of the original WIT. Is that what you're asking about, or something else? |
I am just trying to understand where the boundaries are, and looks like this picture is all that is needed to describe the main flow anyway, multi-memory case can live in a separate picture, though it is possible to add to this one too, I suppose. There is not a tool for this multi-memory fusing yet anyway, right? |
Gotcha; I suppose I could add a final branch to the existing flow, showing that you could either run directly on a component-enabled runtime or fuse to run on a pure-core-wasm runtime that speaks the CABI.
Correct. @alexcrichton should check me on this but, iirc, wasmtime's compilation of components internally fuses components into core wasm, compiling component-level concepts like |
This is correct, more-or-less. There's engine-specific stuff not represented in core wasm such as resource tables some other state like MAY_{ENTER,LEAVE}. This can all theoretically become core wasm, however, but it was easier to put in the engine currently.
To add my own thinking to this, there's no tool that does this today and I don't think that this would be an easy lift. That being said I also don't think it would necessarily be overly difficult either. The concerns here that make this difficult are:
AFAIK no one's planning such tooling like this just yet too. |
Just to check my assumption here: if you have a fixed world in the host, then I think that implies fixed core function signatures for all imports/exports, so the only extra bits of metadata the runtime needs are the |
@lukewagner I got a questions about the diagram. There are two blocks named "wit-component". The above one "combined" two core modules together and output one component. It looks like |
Indeed!
I'll snipe this question from Luke while I'm here; |
Thanks Alex! Just to append to that fine answer, regarding the question
since there are a variety of possible interpretations of "link ... ahead of time", I'd like to expand to say that the component binary produced by |
Does it mean this PR #1133 ? |
@lum1n0us Yes, that is a new part of the dynamic linking story: IIRC, that PR emulates |
Heh, it took a while, but I finally got back to this documentation request. See #367 |
@pchickey @lukewagner, we had a discussion of static linking in context of WebAssembly/WASI#549, and I just wanted to make sure I understood it correctly:
Currently static core linking works by shipping static libs or wasm 'object files' in the component binary and then running
wasm-ld
in the runtime during component instantiation.Is this an accurate description? Can you please point me to where this is currently documented?
The text was updated successfully, but these errors were encountered: