Skip to main content

Module wasm_link

Module wasm_link 

Source
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-ld on PATH. Returns the binary name (for Command::new) or None when no candidate responds to --version.
link_wasm_object
Link a relocatable wasm object (obj_path) into an instantiable wasm module written to out_path, exporting entry_symbol and the linear memory.