Function rustc_codegen_ssa::back::metadata::create_metadata_file_for_wasm
source · pub fn create_metadata_file_for_wasm(
sess: &Session,
data: &[u8],
section_name: &str,
) -> Vec<u8>
Expand description
Creates a simple WebAssembly object file, which is itself a wasm module,
that contains a custom section of the name section_name
with contents
data
.
NB: the object
crate does not yet have support for writing the wasm
object file format. In lieu of that the wasm-encoder
crate is used to
build a wasm file by hand.
The wasm object file format is defined at
https://github.com/WebAssembly/tool-conventions/blob/main/Linking.md
and mainly consists of a linking
custom section. In this case the custom
section there is empty except for a version marker indicating what format
it’s in.
The main purpose of this is to contain a custom section with section_name
,
which is then appended after linking
.
As a further detail the object needs to have a 64-bit memory if wasm64
is
the target or otherwise it’s interpreted as a 32-bit object which is
incompatible with 64-bit ones.