Skip to content

Commit 4a722b8

Browse files
authored
Fix calculation of reachable DWARF (#11338)
A single dependency graph indexed by `gimli::UnitSectionOffset` was used to contain the dependencies from every `gimli::Dwarf`. However, this is not correct because a `gimli::UnitSectionOffset` is only unique within its associated `gimli::Dwarf`. Fix by using one graph per `gimli::Dwarf`.
1 parent 6047d27 commit 4a722b8

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

crates/cranelift/src/debug/gc.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
use crate::debug::Reader;
12
use crate::debug::transform::AddressTransform;
2-
use crate::debug::{Compilation, Reader};
33
use gimli::UnitSectionOffset;
44
use gimli::constants;
55
use gimli::read;
66
use std::collections::{HashMap, HashSet};
7-
use wasmtime_environ::{PrimaryMap, StaticModuleIndex};
87

98
#[derive(Debug)]
109
pub struct Dependencies {
@@ -68,43 +67,27 @@ impl Dependencies {
6867
}
6968

7069
pub fn build_dependencies(
71-
compilation: &mut Compilation<'_>,
72-
dwp: &Option<read::DwarfPackage<Reader<'_>>>,
73-
at: &PrimaryMap<StaticModuleIndex, AddressTransform>,
70+
dwarf: &read::Dwarf<Reader<'_>>,
71+
at: &AddressTransform,
7472
) -> read::Result<Dependencies> {
7573
let mut deps = Dependencies::new();
76-
for (i, translation) in compilation.translations.iter() {
77-
let dwarf = &translation.debuginfo.dwarf;
78-
let mut units = dwarf.units();
79-
while let Some(unit) = units.next()? {
80-
build_unit_dependencies(unit, dwarf, dwp, &at[i], &mut deps)?;
81-
}
74+
let mut units = dwarf.units();
75+
while let Some(unit) = units.next()? {
76+
build_unit_dependencies(unit, dwarf, at, &mut deps)?;
8277
}
8378
Ok(deps)
8479
}
8580

8681
fn build_unit_dependencies(
8782
header: read::UnitHeader<Reader<'_>>,
8883
dwarf: &read::Dwarf<Reader<'_>>,
89-
dwp: &Option<read::DwarfPackage<Reader<'_>>>,
9084
at: &AddressTransform,
9185
deps: &mut Dependencies,
9286
) -> read::Result<()> {
9387
let unit = dwarf.unit(header)?;
9488
let mut tree = unit.entries_tree(None)?;
9589
let root = tree.root()?;
9690
build_die_dependencies(root, dwarf, &unit, at, deps)?;
97-
98-
if let Some(dwarf_package) = dwp {
99-
if let Some(dwo_id) = unit.dwo_id {
100-
if let Some(cu) = dwarf_package.find_cu(dwo_id, dwarf)? {
101-
if let Some(unit_header) = cu.debug_info.units().next()? {
102-
build_unit_dependencies(unit_header, &cu, &None, at, deps)?;
103-
}
104-
}
105-
}
106-
}
107-
10891
Ok(())
10992
}
11093

crates/cranelift/src/debug/transform/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ pub fn transform_dwarf(
163163
)
164164
.flatten();
165165

166-
let reachable = build_dependencies(compilation, &dwarf_package, &transforms)?.get_reachable();
167-
168166
let out_encoding = gimli::Encoding {
169167
format: gimli::Format::Dwarf32,
170168
version: 4, // TODO: this should be configurable
@@ -185,9 +183,8 @@ pub fn transform_dwarf(
185183

186184
let addr_tr = &transforms[module];
187185
let di = &translation.debuginfo;
188-
let context = DebugInputContext {
189-
reachable: &reachable,
190-
};
186+
let reachable = build_dependencies(&di.dwarf, addr_tr)?.get_reachable();
187+
191188
let out_module_synthetic_unit = ModuleSyntheticUnit::new(
192189
module,
193190
compilation,
@@ -202,25 +199,31 @@ pub fn transform_dwarf(
202199
while let Some(header) = iter.next().unwrap_or(None) {
203200
let unit = di.dwarf.unit(header)?;
204201

205-
let mut resolved_unit = None;
202+
let mut split_unit = None;
206203
let mut split_dwarf = None;
204+
let mut split_reachable = None;
207205

208206
if unit.dwo_id.is_some() {
209207
if let Some(dwarf_package) = &dwarf_package {
210208
if let Some((fused, fused_dwarf)) =
211209
replace_unit_from_split_dwarf(&unit, dwarf_package, &di.dwarf)
212210
{
213-
resolved_unit = Some(fused);
211+
split_reachable =
212+
Some(build_dependencies(&fused_dwarf, addr_tr)?.get_reachable());
213+
split_unit = Some(fused);
214214
split_dwarf = Some(fused_dwarf);
215215
}
216216
}
217217
}
218+
let context = DebugInputContext {
219+
reachable: split_reachable.as_ref().unwrap_or(&reachable),
220+
};
218221

219222
if let Some((id, ref_map, pending_refs)) = clone_unit(
220223
compilation,
221224
module,
222225
&unit,
223-
resolved_unit.as_ref(),
226+
split_unit.as_ref(),
224227
split_dwarf.as_ref(),
225228
&context,
226229
&addr_tr,

0 commit comments

Comments
 (0)