Patch a Wasm binary for use in a thread instance (shared memory).
In LLVM's shared-memory Wasm model:
The Start function (section id=8) is __wasm_init_memory — it initializes
passive data segments with an atomic guard. Threads must NOT re-run this.
A separate constructor function (__wasm_call_ctors) runs C++ global
constructors. LLVM inserts a call to this function at the beginning of
every exported function. Threads must NOT re-run constructors either, as
they would clobber shared global state (e.g. resetting LOGGER::file_log_handler
to NULL in MariaDB).
This function:
Removes the Start section so __wasm_init_memory doesn't auto-run.
Finds the constructor function by scanning the known LLVM helper exports
for their common call target and replaces that function body with a no-op.
Patch a Wasm binary for use in a thread instance (shared memory).
In LLVM's shared-memory Wasm model:
__wasm_init_memory— it initializes passive data segments with an atomic guard. Threads must NOT re-run this.__wasm_call_ctors) runs C++ global constructors. LLVM inserts acallto this function at the beginning of every exported function. Threads must NOT re-run constructors either, as they would clobber shared global state (e.g. resetting LOGGER::file_log_handler to NULL in MariaDB).This function:
__wasm_init_memorydoesn't auto-run.