wabt icon indicating copy to clipboard operation
wabt copied to clipboard

wasm-concat ?

Open munrocket opened this issue 5 years ago • 3 comments

Current problems:

  • wasm sandbox interoperability is slow
  • wasm can be written in different languages

So it will be useful to add one .wasm from another .wasm

Solution:

What if will try to disassemble .wasm -> .wat, contact table of functions as a string and assemble it back .wat -> .wasm? The problem with function names can be solved by tool itself, main file will be the same, each function in dependency can be numerated by dependency id, so name collision will be not possible.

Should we change .wasm design by itself to make this sandbox fusion possible?

munrocket avatar Oct 28 '20 06:10 munrocket

The biggest issue with concatenating wasm modules is that there can be at most one table and one memory, so the concatenated module would have to share them. This is impossible to do without having additional information (e.g. relocations), which is essentially what the wasm-ld linker does (although it is also solving a more constrained problem).

Another approach would be to allow modules to be linked ahead-of-time into its own module, which is more-or-less what the module-linking proposal does.

binji avatar Oct 29 '20 00:10 binji

Library with linear algebra, complex numbers and other math works without WebAssembly.Memory. Usually they have ridiculous amount of interoperability operations and simply useless as wasm libraries in current design. So we need to copy paste that code from one library to another and translate to another languages. Either way it becomes slower than javascript. Am I right that this cases can be covered by simple concatenation or exist some another barrier currently?

munrocket avatar Oct 29 '20 02:10 munrocket

Seamless module merges would be a great property. Technically, the issues with memories and tables ought to be solved soon with the proposals for multi-memories and for reference types, respectively. After that, the one remaining culprit is the start function, which can be worked around, though a change to allow multiple start functions would be nicer.

rossberg avatar Oct 29 '20 06:10 rossberg

I'm guessing this is unlikely to be included in WABT anytime soon, but we have built this tool out-of-tree using WABT. Available here: https://github.com/fix-project/wasm-tools/tree/main/src/module-combiner

keithw avatar Sep 18 '22 06:09 keithw