Skip to content

Commit

Permalink
Debug info: two fixes in x64 backend.
Browse files Browse the repository at this point in the history
- 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 (bytecodealliance#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 bytecodealliance#2453 lands.
  • Loading branch information
cfallin committed Dec 2, 2020
1 parent 51c1d4b commit dadadcb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cranelift/codegen/src/machinst/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
}
}
Expand Down

0 comments on commit dadadcb

Please sign in to comment.