Don't re-parse wasm for debuginfo (#2085)

* Don't re-parse wasm for debuginfo

This commit updates debuginfo parsing to happen during the main
translation of the original wasm module. This avoid re-parsing the wasm
module twice (at least the section-level headers). Additionally this
ties debuginfo directly to a `ModuleTranslation` which makes it easier
to process debuginfo for nested modules in the upcoming module linking
proposal.

The changes here are summarized by taking the `read_debuginfo` function
and merging it with the main module translation that happens which is
driven by cranelift. Some new hooks were added to the module environment
trait to support this, but most of it was integrating with existing hooks.

* Fix tests in debug crate
This commit is contained in:
Alex Crichton
2020-08-03 09:59:20 -05:00
committed by GitHub
parent e108f14620
commit 026fb8d388
18 changed files with 261 additions and 377 deletions

View File

@@ -5,12 +5,12 @@ use crate::object::{build_object, ObjectUnwindInfo};
use cranelift_codegen::ir;
use object::write::Object;
use std::hash::{Hash, Hasher};
use wasmtime_debug::{emit_dwarf, DebugInfoData, DwarfSection};
use wasmtime_debug::{emit_dwarf, DwarfSection};
use wasmtime_environ::entity::{EntityRef, PrimaryMap};
use wasmtime_environ::isa::{unwind::UnwindInfo, TargetFrontendConfig, TargetIsa};
use wasmtime_environ::wasm::{DefinedFuncIndex, DefinedMemoryIndex, MemoryIndex};
use wasmtime_environ::{
Compiler as _C, Module, ModuleAddressMap, ModuleMemoryOffset, ModuleTranslation,
Compiler as _C, DebugInfoData, Module, ModuleAddressMap, ModuleMemoryOffset, ModuleTranslation,
ModuleVmctxInfo, StackMaps, Traps, Tunables, VMOffsets, ValueLabelsRanges,
};
@@ -61,7 +61,7 @@ fn _assert_compiler_send_sync() {
fn transform_dwarf_data(
isa: &dyn TargetIsa,
module: &Module,
debug_data: DebugInfoData,
debug_data: &DebugInfoData,
address_transform: &ModuleAddressMap,
value_ranges: &ValueLabelsRanges,
stack_slots: PrimaryMap<DefinedFuncIndex, ir::StackSlots>,
@@ -86,7 +86,7 @@ fn transform_dwarf_data(
};
emit_dwarf(
isa,
&debug_data,
debug_data,
&address_transform,
&module_vmctx_info,
&value_ranges,
@@ -129,7 +129,6 @@ impl Compiler {
pub(crate) fn compile<'data>(
&self,
translation: &ModuleTranslation,
debug_data: Option<DebugInfoData>,
) -> Result<Compilation, SetupError> {
let (
compilation,
@@ -152,12 +151,12 @@ impl Compiler {
}
.map_err(SetupError::Compile)?;
let dwarf_sections = if debug_data.is_some() && !compilation.is_empty() {
let dwarf_sections = if translation.debuginfo.is_some() && !compilation.is_empty() {
let unwind_info = compilation.unwind_info();
transform_dwarf_data(
&*self.isa,
&translation.module,
debug_data.unwrap(),
translation.debuginfo.as_ref().unwrap(),
&address_transform,
&value_ranges,
stack_slots,

View File

@@ -15,7 +15,7 @@ use std::any::Any;
use std::collections::HashMap;
use std::sync::Arc;
use thiserror::Error;
use wasmtime_debug::{create_gdbjit_image, read_debuginfo};
use wasmtime_debug::create_gdbjit_image;
use wasmtime_environ::entity::{BoxedSlice, PrimaryMap};
use wasmtime_environ::isa::TargetIsa;
use wasmtime_environ::wasm::{DefinedFuncIndex, SignatureIndex};
@@ -89,21 +89,13 @@ impl CompilationArtifacts {
.translate(data)
.map_err(|error| SetupError::Compile(CompileError::Wasm(error)))?;
let debug_info = compiler.tunables().debug_info;
let mut debug_data = None;
if debug_info {
// TODO Do we want to ignore invalid DWARF data?
debug_data = Some(read_debuginfo(&data)?);
}
let Compilation {
obj,
unwind_info,
traps,
stack_maps,
address_transform,
} = compiler.compile(&translation, debug_data)?;
} = compiler.compile(&translation)?;
let ModuleTranslation {
module,
@@ -131,7 +123,7 @@ impl CompilationArtifacts {
traps,
stack_maps,
address_transform,
debug_info,
debug_info: compiler.tunables().debug_info,
})
}
}