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
29 changes: 6 additions & 23 deletions crates/cranelift/src/debug/gc.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::debug::Reader;
use crate::debug::transform::AddressTransform;
use crate::debug::{Compilation, Reader};
use gimli::UnitSectionOffset;
use gimli::constants;
use gimli::read;
use std::collections::{HashMap, HashSet};
use wasmtime_environ::{PrimaryMap, StaticModuleIndex};

#[derive(Debug)]
pub struct Dependencies {
Expand Down Expand Up @@ -68,43 +67,27 @@ impl Dependencies {
}

pub fn build_dependencies(
compilation: &mut Compilation<'_>,
dwp: &Option<read::DwarfPackage<Reader<'_>>>,
at: &PrimaryMap<StaticModuleIndex, AddressTransform>,
dwarf: &read::Dwarf<Reader<'_>>,
at: &AddressTransform,
) -> read::Result<Dependencies> {
let mut deps = Dependencies::new();
for (i, translation) in compilation.translations.iter() {
let dwarf = &translation.debuginfo.dwarf;
let mut units = dwarf.units();
while let Some(unit) = units.next()? {
build_unit_dependencies(unit, dwarf, dwp, &at[i], &mut deps)?;
}
let mut units = dwarf.units();
while let Some(unit) = units.next()? {
build_unit_dependencies(unit, dwarf, at, &mut deps)?;
}
Ok(deps)
}

fn build_unit_dependencies(
header: read::UnitHeader<Reader<'_>>,
dwarf: &read::Dwarf<Reader<'_>>,
dwp: &Option<read::DwarfPackage<Reader<'_>>>,
at: &AddressTransform,
deps: &mut Dependencies,
) -> read::Result<()> {
let unit = dwarf.unit(header)?;
let mut tree = unit.entries_tree(None)?;
let root = tree.root()?;
build_die_dependencies(root, dwarf, &unit, at, deps)?;

if let Some(dwarf_package) = dwp {
if let Some(dwo_id) = unit.dwo_id {
if let Some(cu) = dwarf_package.find_cu(dwo_id, dwarf)? {
if let Some(unit_header) = cu.debug_info.units().next()? {
build_unit_dependencies(unit_header, &cu, &None, at, deps)?;
}
}
}
}

Ok(())
}

Expand Down
19 changes: 11 additions & 8 deletions crates/cranelift/src/debug/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ pub fn transform_dwarf(
)
.flatten();

let reachable = build_dependencies(compilation, &dwarf_package, &transforms)?.get_reachable();

let out_encoding = gimli::Encoding {
format: gimli::Format::Dwarf32,
version: 4, // TODO: this should be configurable
Expand All @@ -185,9 +183,8 @@ pub fn transform_dwarf(

let addr_tr = &transforms[module];
let di = &translation.debuginfo;
let context = DebugInputContext {
reachable: &reachable,
};
let reachable = build_dependencies(&di.dwarf, addr_tr)?.get_reachable();

let out_module_synthetic_unit = ModuleSyntheticUnit::new(
module,
compilation,
Expand All @@ -202,25 +199,31 @@ pub fn transform_dwarf(
while let Some(header) = iter.next().unwrap_or(None) {
let unit = di.dwarf.unit(header)?;

let mut resolved_unit = None;
let mut split_unit = None;
let mut split_dwarf = None;
let mut split_reachable = None;

if unit.dwo_id.is_some() {
if let Some(dwarf_package) = &dwarf_package {
if let Some((fused, fused_dwarf)) =
replace_unit_from_split_dwarf(&unit, dwarf_package, &di.dwarf)
{
resolved_unit = Some(fused);
split_reachable =
Some(build_dependencies(&fused_dwarf, addr_tr)?.get_reachable());
split_unit = Some(fused);
split_dwarf = Some(fused_dwarf);
}
}
}
let context = DebugInputContext {
reachable: split_reachable.as_ref().unwrap_or(&reachable),
};

if let Some((id, ref_map, pending_refs)) = clone_unit(
compilation,
module,
&unit,
resolved_unit.as_ref(),
split_unit.as_ref(),
split_dwarf.as_ref(),
&context,
&addr_tr,
Expand Down