Debug info: two fixes in x64 backend.

- Sort by generated-code offset to maintain invariant and avoid gimli
  panic.
- Fix srcloc interaction with branch peephole optimization in
  MachBuffer: if a srcloc range overlaps with a branch that is
  truncated, remove that srcloc range.

These issues were found while fuzzing the new backend (#2453); I suspect
that they arise with the new backend because we can sink instructions
(e.g. loads or extends) in more interesting ways than before, but I'm
not entirely sure.

Test coverage will be via the fuzz corpus once #2453 lands.
This commit is contained in:
Chris Fallin
2020-12-01 17:01:38 -08:00
parent d1662a5d6e
commit 60d7f7de0a

View File

@@ -674,6 +674,12 @@ impl<I: VCodeInst> MachBuffer<I> {
// (end of buffer)
self.data.truncate(b.start as usize);
self.fixup_records.truncate(b.fixup);
while let Some(last_srcloc) = self.srclocs.last() {
if last_srcloc.end <= b.start {
break;
}
self.srclocs.pop();
}
// State:
// [PRE CODE]
// cur_off, Offset b.start, b.labels_at_this_branch:
@@ -1184,12 +1190,15 @@ impl<I: VCodeInst> MachBuffer<I> {
// incorrect.
assert!(self.fixup_records.is_empty());
let mut srclocs = self.srclocs;
srclocs.sort_by_key(|entry| entry.start);
MachBufferFinalized {
data: self.data,
relocs: self.relocs,
traps: self.traps,
call_sites: self.call_sites,
srclocs: self.srclocs,
srclocs,
stack_maps: self.stack_maps,
}
}