Path: blob/main/crates/environ/src/module_artifacts.rs
1691 views
//! Definitions of runtime structures and metadata which are serialized into ELF1//! with `bincode` as part of a module's compilation process.23use crate::prelude::*;4use crate::{DefinedFuncIndex, FilePos, FuncIndex, Module, ModuleInternedTypeIndex, PrimaryMap};5use core::fmt;6use core::ops::Range;7use core::str;8use serde_derive::{Deserialize, Serialize};910/// Secondary in-memory results of function compilation.11#[derive(Clone, Serialize, Deserialize)]12pub struct CompiledFunctionInfo {13/// Where this function was found in the original wasm file.14pub start_srcloc: FilePos,15/// The [`FunctionLoc`] indicating the location of this function in the text16/// section of the competition artifact.17pub wasm_func_loc: FunctionLoc,18/// A trampoline for array callers (e.g. `Func::new`) calling into this function (if needed).19pub array_to_wasm_trampoline: Option<FunctionLoc>,20}2122/// Description of where a function is located in the text section of a23/// compiled image.24#[derive(Copy, Clone, Debug, Serialize, Deserialize)]25pub struct FunctionLoc {26/// The byte offset from the start of the text section where this27/// function starts.28pub start: u32,29/// The byte length of this function's function body.30pub length: u32,31}3233/// Secondary in-memory results of module compilation.34///35/// This opaque structure can be optionally passed back to36/// `CompiledModule::from_artifacts` to avoid decoding extra information there.37#[derive(Serialize, Deserialize)]38pub struct CompiledModuleInfo {39/// Type information about the compiled WebAssembly module.40pub module: Module,4142/// Metadata about each compiled function.43pub funcs: PrimaryMap<DefinedFuncIndex, CompiledFunctionInfo>,4445/// Sorted list, by function index, of names we have for this module.46pub func_names: Vec<FunctionName>,4748/// Metadata about wasm-to-array trampolines. Used when exposing a native49/// callee (e.g. `Func::wrap`) to a Wasm caller. Sorted by signature index.50pub wasm_to_array_trampolines: Vec<(ModuleInternedTypeIndex, FunctionLoc)>,5152/// General compilation metadata.53pub meta: Metadata,54}5556/// The name of a function stored in the57/// [`ELF_NAME_DATA`](crate::obj::ELF_NAME_DATA) section.58#[derive(Serialize, Deserialize)]59pub struct FunctionName {60/// The Wasm function index of this function.61pub idx: FuncIndex,62/// The offset of the name in the63/// [`ELF_NAME_DATA`](crate::obj::ELF_NAME_DATA) section.64pub offset: u32,65/// The length of the name in bytes.66pub len: u32,67}6869/// Metadata associated with a compiled ELF artifact.70#[derive(Serialize, Deserialize)]71pub struct Metadata {72/// Whether or not the original wasm module contained debug information that73/// we skipped and did not parse.74pub has_unparsed_debuginfo: bool,7576/// Offset in the original wasm file to the code section.77pub code_section_offset: u64,7879/// Whether or not custom wasm-specific dwarf sections were inserted into80/// the ELF image.81///82/// Note that even if this flag is `true` sections may be missing if they83/// weren't found in the original wasm module itself.84pub has_wasm_debuginfo: bool,8586/// Dwarf sections and the offsets at which they're stored in the87/// ELF_WASMTIME_DWARF88pub dwarf: Vec<(u8, Range<u64>)>,89}9091/// Value of a configured setting for a [`Compiler`](crate::Compiler)92#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]93pub enum FlagValue<'a> {94/// Name of the value that has been configured for this setting.95Enum(&'a str),96/// The numerical value of the configured settings.97Num(u8),98/// Whether the setting is on or off.99Bool(bool),100}101102impl fmt::Display for FlagValue<'_> {103fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {104match self {105Self::Enum(v) => v.fmt(f),106Self::Num(v) => v.fmt(f),107Self::Bool(v) => v.fmt(f),108}109}110}111112/// Types of objects that can be created by `Compiler::object`113pub enum ObjectKind {114/// A core wasm compilation artifact115Module,116/// A component compilation artifact117Component,118}119120121