Commit c634137
committed
[wit-component] add shared-everything linking support
Per https://github.com/WebAssembly/component-model/blob/main/design/mvp/examples/SharedEverythingDynamicLinking.md and https://hackmd.io/IlY4lICRRNy9wQbNLdb2Wg.
This adds a new `component link` subcommand, which resembles `component new` but
accepts an arbitrary number of "dynamic library" modules (as defined by
https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md),
linking them together to create a component whose type is the union of the
component types found in the input modules (via the usual custom section
representation). This process can also be invoked programmatically via a new
`Linker` API.
`Linker` analyzes and topologically sorts the input modules, then sythesizes two
additional modules:
- `main`: hosts the component's single memory and function table and exports any
functions needed to break dependency cycles discovered in the input modules.
Those functions use `call.indirect` to invoke the real functions, references
to which are placed in the table by the `init` module.
- `init`: populates the function table as described above, initializes global
variables per the dynamic linking tool convention, and calls any static
constructors and/or link-time fixup functions
Finally, `Linker` generates a directed graph of modules and their instantiations
and passes it to `ComponentEncoder` to actually produce the component.
The implementation relies on a few modifications to the existing code in
`ComponentEncoder` and friends. Specifically, I've expanded the meaning of
"adapter" to include dynamic libraries as well as traditional adapters. The
former are distiguished from the latter by the presence of a new `LibraryInfo`
struct. This approach minimized the number of code changes in the interest of
keeping this PR comprehensible, but we will probably want to refactor
`ComponentEncoder` in the future to make the distinction between traditional
adapters and dynamic libraries clearer, possibly generalizing how we analyze and
instantiate modules of various flavors.
I've created a demo which ties everything together, for reference:
https://github.com/dicej/component-linking-demo. It includes `wasi-sdk` and
`wasi-libc` patches which have not yet been upstreamed; I'm planning to work on
that next.
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
skip wasmtime part of linking test under Wasm
Signed-off-by: Joel Dice <joel.dice@fermyon.com>1 parent 94ad03b commit c634137
File tree
11 files changed
+2557
-112
lines changed- crates
- fuzz-stats/src
- wit-component
- src
- encoding
- linking
- tests
- src/bin/wasm-tools
11 files changed
+2557
-112
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
43 | | - | |
| 41 | + | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
26 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | | - | |
| 35 | + | |
30 | 36 | | |
31 | | - | |
| 37 | + | |
32 | 38 | | |
33 | 39 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
18 | 24 | | |
19 | 25 | | |
20 | 26 | | |
| |||
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
31 | | - | |
| 37 | + | |
32 | 38 | | |
33 | 39 | | |
34 | 40 | | |
| |||
96 | 102 | | |
97 | 103 | | |
98 | 104 | | |
99 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
100 | 115 | | |
101 | 116 | | |
102 | 117 | | |
103 | | - | |
| 118 | + | |
104 | 119 | | |
105 | 120 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
111 | 146 | | |
112 | 147 | | |
113 | 148 | | |
| |||
173 | 208 | | |
174 | 209 | | |
175 | 210 | | |
176 | | - | |
| 211 | + | |
177 | 212 | | |
178 | 213 | | |
179 | 214 | | |
| |||
256 | 291 | | |
257 | 292 | | |
258 | 293 | | |
259 | | - | |
| 294 | + | |
260 | 295 | | |
261 | | - | |
| 296 | + | |
262 | 297 | | |
263 | 298 | | |
264 | 299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
0 commit comments