Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ path = "src/wasm2obj.rs"
[dependencies]
cranelift-codegen = { version = "0.38.0", features = ["enable-serde"] }
cranelift-native = "0.38.0"
cranelift-entity = { version = "0.38.0", features = ["enable-serde"] }
cranelift-wasm = { version = "0.38.0", features = ["enable-serde"] }
wasmtime-debug = { path = "wasmtime-debug" }
wasmtime-environ = { path = "wasmtime-environ" }
wasmtime-runtime = { path = "wasmtime-runtime" }
Expand Down
41 changes: 31 additions & 10 deletions src/wasm2obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
use cranelift_codegen::isa;
use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable;
use cranelift_entity::EntityRef;
use cranelift_native;
use cranelift_wasm::DefinedMemoryIndex;
use docopt::Docopt;
use faerie::Artifact;
use serde::Deserialize;
Expand All @@ -49,7 +51,9 @@ use std::str::FromStr;
use target_lexicon::Triple;
use wasmtime_debug::{emit_debugsections, read_debuginfo};
use wasmtime_environ::cache_conf;
use wasmtime_environ::{Compiler, Cranelift, ModuleEnvironment, Tunables};
use wasmtime_environ::{
Compiler, Cranelift, ModuleEnvironment, ModuleVmctxInfo, Tunables, VMOffsets,
};
use wasmtime_obj::emit_module;

mod utils;
Expand Down Expand Up @@ -183,13 +187,23 @@ fn handle_module(
)
};

let (compilation, relocations, address_transform) = Cranelift::compile_module(
&module,
lazy_function_body_inputs,
&*isa,
generate_debug_info,
)
.map_err(|e| e.to_string())?;
let (compilation, relocations, address_transform, value_ranges, stack_slots) =
Cranelift::compile_module(
&module,
lazy_function_body_inputs,
&*isa,
generate_debug_info,
)
.map_err(|e| e.to_string())?;

let module_vmctx_info = {
let ofs = VMOffsets::new(target_config.pointer_bytes(), &module);
let memory_offset = ofs.vmctx_vmmemory_definition_base(DefinedMemoryIndex::new(0)) as i64;
ModuleVmctxInfo {
memory_offset,
stack_slots,
}
};

emit_module(
&mut obj,
Expand All @@ -202,8 +216,15 @@ fn handle_module(

if generate_debug_info {
let debug_data = read_debuginfo(&data);
emit_debugsections(&mut obj, &target_config, &debug_data, &address_transform)
.map_err(|e| e.to_string())?;
emit_debugsections(
&mut obj,
&module_vmctx_info,
&target_config,
&debug_data,
&address_transform,
&value_ranges,
)
.map_err(|e| e.to_string())?;
}

// FIXME: Make the format a parameter.
Expand Down
158 changes: 0 additions & 158 deletions wasmtime-debug/src/address_transform.rs

This file was deleted.

2 changes: 1 addition & 1 deletion wasmtime-debug/src/gc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::address_transform::AddressTransform;
use crate::transform::AddressTransform;
use gimli::constants;
use gimli::read;
use gimli::{Reader, UnitSectionOffset};
Expand Down
13 changes: 8 additions & 5 deletions wasmtime-debug/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ use cranelift_codegen::isa::TargetFrontendConfig;
use faerie::{Artifact, Decl};
use failure::Error;
use target_lexicon::{BinaryFormat, Triple};
use wasmtime_environ::ModuleAddressMap;
use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges};

pub use crate::read_debuginfo::{read_debuginfo, DebugInfoData, WasmFileInfo};
pub use crate::transform::{transform_dwarf, ModuleVmctxInfo, ValueLabelsRanges};
pub use crate::transform::transform_dwarf;
pub use crate::write_debuginfo::{emit_dwarf, ResolvedSymbol, SymbolResolver};

mod address_transform;
mod gc;
mod read_debuginfo;
mod transform;
Expand All @@ -28,12 +27,14 @@ impl SymbolResolver for FunctionRelocResolver {

pub fn emit_debugsections(
obj: &mut Artifact,
vmctx_info: &ModuleVmctxInfo,
target_config: &TargetFrontendConfig,
debuginfo_data: &DebugInfoData,
at: &ModuleAddressMap,
ranges: &ValueLabelsRanges,
) -> Result<(), Error> {
let resolver = FunctionRelocResolver {};
let dwarf = transform_dwarf(target_config, debuginfo_data, at)?;
let dwarf = transform_dwarf(target_config, debuginfo_data, at, vmctx_info, ranges)?;
emit_dwarf(obj, dwarf, &resolver)?;
Ok(())
}
Expand All @@ -53,7 +54,9 @@ pub fn emit_debugsections_image(
triple: Triple,
target_config: &TargetFrontendConfig,
debuginfo_data: &DebugInfoData,
vmctx_info: &ModuleVmctxInfo,
at: &ModuleAddressMap,
ranges: &ValueLabelsRanges,
funcs: &Vec<(*const u8, usize)>,
) -> Result<Vec<u8>, Error> {
let ref func_offsets = funcs
Expand All @@ -62,7 +65,7 @@ pub fn emit_debugsections_image(
.collect::<Vec<u64>>();
let mut obj = Artifact::new(triple, String::from("module"));
let resolver = ImageRelocResolver { func_offsets };
let dwarf = transform_dwarf(target_config, debuginfo_data, at)?;
let dwarf = transform_dwarf(target_config, debuginfo_data, at, vmctx_info, ranges)?;

// Assuming all functions in the same code block, looking min/max of its range.
assert!(funcs.len() > 0);
Expand Down
13 changes: 0 additions & 13 deletions wasmtime-debug/src/read_debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub type Dwarf<'input> = gimli::Dwarf<gimli::EndianSlice<'input, LittleEndian>>;
#[derive(Debug)]
pub struct WasmFileInfo {
pub code_section_offset: u64,
pub function_offsets_and_sizes: Box<[(u64, u32)]>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -100,7 +99,6 @@ pub fn read_debuginfo(data: &[u8]) -> DebugInfoData {
let mut reader = ModuleReader::new(data).expect("reader");
let mut sections = HashMap::new();
let mut code_section_offset = 0;
let mut function_offsets_and_sizes = Vec::new();
while !reader.eof() {
let section = reader.read().expect("section");
if let SectionCode::Custom { name, .. } = section.code {
Expand All @@ -112,23 +110,12 @@ pub fn read_debuginfo(data: &[u8]) -> DebugInfoData {
}
if let SectionCode::Code = section.code {
code_section_offset = section.range().start as u64;
// TODO remove me later
let mut reader = section.get_code_section_reader().expect("code reader");
for _ in 0..reader.get_count() {
let body = reader.read().expect("function body read");
let range = body.range();
let fn_body_size = range.end - range.start;
let fn_body_offset = range.start;
function_offsets_and_sizes.push((fn_body_offset as u64, fn_body_size as u32));
}
}
}
let function_offsets_and_sizes = function_offsets_and_sizes.into_boxed_slice();
DebugInfoData {
dwarf: convert_sections(sections),
wasm_file: WasmFileInfo {
code_section_offset,
function_offsets_and_sizes,
},
}
}
Loading