Expand description
S3.X wasm32 link step: turn an LLVM-emitted relocatable wasm
object (\0asm with a linking custom section, undefined symbols,
no exports / no memory) into an instantiable wasm module.
LlvmAotEvaluator::emit_object_for_target(.., CodegenTarget::Wasm32)
writes a relocatable object — the LLVM WebAssembly backend emits the
same object-file shape clang -c --target=wasm32 produces. wasmtime
cannot instantiate that directly; it needs the linker pass that
materialises the memory, the globals (stack pointer), and the
function exports. We shell out to wasm-ld for that, mirroring how
a clang --target=wasm32 toolchain finishes the build.
wasm-ld is the LLVM linker shipped with the lld package; we probe
the common binary names (wasm-ld, wasm-ld-NN). The relocatable
wasm object format is stable across recent LLVM majors, so a system
wasm-ld-17 happily links an LLVM-18-emitted object.
Functions§
- find_
wasm_ ld - Locate a usable
wasm-ldonPATH. Returns the binary name (forCommand::new) orNonewhen no candidate responds to--version. - link_
wasm_ object - Link a relocatable wasm object (
obj_path) into an instantiable wasm module written toout_path, exportingentry_symboland the linearmemory.