Move address maps to a section of the compiled image (#3240)

This commit moves the `address_map` field of `FunctionInfo` into a
custom-encoded section of the executable. The goal of this commit is, as
previous commits, to push less data through `bincode`. The `address_map`
field is actually extremely large and has huge benefits of not being
decoded when we load a module. This data is only used for traps and such
as well, so it's not overly important that it's massaged in to precise
data the runtime can extremely speedily use.

The `FunctionInfo` type does retain a tiny bit of information about the
function itself (it's start source location), but other than that the
`FunctionAddressMap` structure is moved from `wasmtime-environ` to
`wasmtime-cranelift` since it's now no longer needed outside of that
context.
This commit is contained in:
Alex Crichton
2021-08-26 23:06:41 -05:00
committed by GitHub
parent d12f1d77e6
commit fc91176685
10 changed files with 281 additions and 141 deletions

View File

@@ -34,6 +34,7 @@ use object::{
};
use std::collections::HashMap;
use std::convert::TryFrom;
use std::ops::Range;
use wasmtime_environ::obj;
use wasmtime_environ::{
DefinedFuncIndex, EntityRef, FuncIndex, Module, PrimaryMap, SignatureIndex,
@@ -157,7 +158,11 @@ impl<'a> ObjectBuilder<'a> {
}
}
fn append_func(&mut self, name: Vec<u8>, func: &'a CompiledFunction) -> SymbolId {
/// Appends the `func` specified named `name` to this object.
///
/// Returns the symbol associated with the function as well as the range
/// that the function resides within the text section.
fn append_func(&mut self, name: Vec<u8>, func: &'a CompiledFunction) -> (SymbolId, Range<u64>) {
let off = self
.obj
.append_section_data(self.text_section, &func.body, 1);
@@ -207,15 +212,22 @@ impl<'a> ObjectBuilder<'a> {
if !func.relocations.is_empty() {
self.pending_relocations.push((off, &func.relocations));
}
symbol_id
(symbol_id, off..off + func.body.len() as u64)
}
pub fn func(&mut self, index: DefinedFuncIndex, func: &'a CompiledFunction) {
/// Pushes a new defined function from the a wasm module into this object,
/// returning the range that the compiled code will live at relative in the
/// text section of the final executable.
///
/// Note that functions must be pushed in the order of their
/// `DefinedFuncIndex`.
pub fn func(&mut self, index: DefinedFuncIndex, func: &'a CompiledFunction) -> Range<u64> {
assert_eq!(self.jump_tables.push(&func.jt_offsets), index);
let index = self.module.func_index(index);
let name = obj::func_symbol_name(index);
let symbol_id = self.append_func(name.into_bytes(), func);
let (symbol_id, range) = self.append_func(name.into_bytes(), func);
assert_eq!(self.func_symbols.push(symbol_id), index);
range
}
pub fn trampoline(&mut self, sig: SignatureIndex, func: &'a CompiledFunction) {