Stream: wasmtime

Topic: linking


view this post on Zulip cuberoo_ (Sep 02 2020 at 08:12):

Is it possible to create an instance that has the symbols for all added modules exposed? In particualar, I have modules that share an address space, but all have there own versions of the same API. I would like to be able to call them in sequence, one function, e.g. "compute", generating output for the next, and so on. However, when I link together ansd then create an instance it only has the final modules exports.

Here is the outline of code for building the instance:

  let mut linker = Linker::new(&store);
   linker.allow_shadowing(true);
    // add all but module 0 to the linker, ready for linking with module 0
    for i in 1..wasm_bytes.len() {
        let module = Module::new(store.engine(), &wasm_bytes[i][..])?;
        let module_name = [MODULE_PREFIX, &i.to_string()].join("_");
        linker.module(&module_name, &module)?;
    }
    // now link with module 0
    let module = Module::new(store.engine(), &wasm_bytes[0][..])?;
    let instance = linker.instantiate(&module)?;

and if we now enumerate the names we only get those from module 0:

    println!("printing names:");
    for e in instance.exports() {
        println!("name: {}", e.name());
    }

view this post on Zulip Alex Crichton (Sep 02 2020 at 15:31):

@cuberoo_ I don't think that's natively exposed right now, but you can always instantiate modules yourself and create a hash map of th exports

view this post on Zulip cuberoo_ (Sep 02 2020 at 15:43):

@Alex Crichton thanks. is it the case that if each module uses the same store that they will have a shared address space or is it possible that they might have buffers allocated at shared "addresses"? For example, if module A has a global AG and module B a global BG, can B write to AG, given an index provided by A, and so on?

view this post on Zulip Alex Crichton (Sep 02 2020 at 15:44):

that's up to you and how you set up the linear memories, wasmtime itself just does what you ask it

view this post on Zulip Alex Crichton (Sep 02 2020 at 15:44):

e.g. in this case it sounds like you want all the modules importing the same memory

view this post on Zulip cuberoo_ (Sep 02 2020 at 15:45):

ok cool. thanks


Last updated: Dec 23 2024 at 13:07 UTC