It seems like there's two different ways to add a module to a linker and get the _start
symbol in it:
// Using module + get_default
linker.module(&mut store, "", &module)?;
let func = linker.get_default(&mut store, "")?.typed::<(), ()>(&store);
// Using instantiate + get_typed_func
let instance = linker.instantiate(&mut store, &module)?;
let func = instance.get_typed_func::<(), ()>(&mut store, "_start")?;
However, the first option resets the module's memory before every func.call()
(meaning all globals are reset to their initial values each time), whereas the second doesn't. What's the difference between these and how can I change this behaviour for each of them?
In wasi you are only allowed to call _start once.
Wasi programs that export a _start are so-called “commands” - they can be instantiated and run once, and should not run multiple times. This restriction exists to get things working with libc. the linker get_default knows about this pattern and enforces it for you, but the instantiate & func call does not.
if you want to use wasi in a program that has multiple export funcs called on the same instantance, you want to compile the wasi program differently - use the -mexec-model=reactor
cflag in wasi-sdk, or crate type cdylib
on a rust program
Last updated: Nov 22 2024 at 16:03 UTC