Move wasm data/debuginfo into the ELF compilation image (#3235)
* Move wasm data/debuginfo into the ELF compilation image This commit moves existing allocations of `Box<[u8]>` stored separately from compilation's final ELF image into the ELF image itself. The goal of this commit is to reduce the amount of data which `bincode` will need to process in the future. DWARF debugging information and wasm data segments can be quite large, and they're relatively rarely read, so there's typically no need to copy them around. Instead by moving them into the ELF image this opens up the opportunity in the future to eliminate copies and use data directly as-found in the image itself. For information accessed possibly-multiple times, such as the wasm data ranges, the indexes of the data within the ELF image are computed when a `CompiledModule` is created. These indexes are then used to directly index into the image without having to root around in the ELF file each time they're accessed. One other change located here is that the symbolication context previously cloned the debug information into it to adhere to the `'static` lifetime safely, but this isn't actually ever used in `wasmtime` right now so the unsafety around this has been removed and instead borrowed data is returned (no more clones, yay!). * Fix lightbeam
This commit is contained in:
@@ -38,14 +38,13 @@ impl Drop for CodeMemoryEntry {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CodeMemoryObjectAllocation<'a, 'b> {
|
||||
pub struct CodeMemoryObjectAllocation<'a> {
|
||||
pub code_range: &'a mut [u8],
|
||||
funcs: BTreeMap<FuncIndex, (usize, usize)>,
|
||||
trampolines: BTreeMap<SignatureIndex, (usize, usize)>,
|
||||
pub obj: ObjectFile<'b>,
|
||||
}
|
||||
|
||||
impl<'a> CodeMemoryObjectAllocation<'a, '_> {
|
||||
impl<'a> CodeMemoryObjectAllocation<'a> {
|
||||
pub fn funcs_len(&self) -> usize {
|
||||
self.funcs.len()
|
||||
}
|
||||
@@ -140,14 +139,22 @@ impl CodeMemory {
|
||||
unsafe { &mut *body_ptr }
|
||||
}
|
||||
|
||||
/// Alternative to `allocate_for_object`, but when the object file isn't
|
||||
/// already parsed.
|
||||
pub fn allocate_for_object_unparsed<'a>(
|
||||
&'a mut self,
|
||||
obj: &[u8],
|
||||
) -> Result<CodeMemoryObjectAllocation<'a>> {
|
||||
let obj = ObjectFile::parse(obj)?;
|
||||
self.allocate_for_object(&obj)
|
||||
}
|
||||
|
||||
/// Allocates and copies the ELF image code section into CodeMemory.
|
||||
/// Returns references to functions and trampolines defined there.
|
||||
pub fn allocate_for_object<'a, 'b>(
|
||||
pub fn allocate_for_object<'a>(
|
||||
&'a mut self,
|
||||
obj: &'b [u8],
|
||||
) -> Result<CodeMemoryObjectAllocation<'a, 'b>> {
|
||||
let obj = ObjectFile::parse(obj)
|
||||
.with_context(|| "failed to parse internal ELF compilation artifact")?;
|
||||
obj: &ObjectFile,
|
||||
) -> Result<CodeMemoryObjectAllocation<'a>> {
|
||||
let text_section = obj.section_by_name(".text").unwrap();
|
||||
let text_section_size = text_section.size() as usize;
|
||||
|
||||
@@ -157,7 +164,6 @@ impl CodeMemory {
|
||||
code_range: &mut [],
|
||||
funcs: BTreeMap::new(),
|
||||
trampolines: BTreeMap::new(),
|
||||
obj,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -212,7 +218,6 @@ impl CodeMemory {
|
||||
code_range: &mut entry.mmap.as_mut_slice()[..text_section_size],
|
||||
funcs,
|
||||
trampolines,
|
||||
obj,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user