Skip to content

Commit 0f861e1

Browse files
committed
Update Cranelift
1 parent 54523b8 commit 0f861e1

File tree

3 files changed

+29
-144
lines changed

3 files changed

+29
-144
lines changed

Cargo.lock

+12-54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime/", branch
1616
cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" }
1717
target-lexicon = "0.11.0"
1818
gimli = { version = "0.23.0", default-features = false, features = ["write"]}
19-
object = { version = "0.22.0", default-features = false, features = ["std", "read_core", "write", "coff", "elf", "macho", "pe"] }
19+
object = { version = "0.23.0", default-features = false, features = ["std", "read_core", "write", "coff", "elf", "macho", "pe"] }
2020

2121
ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" }
2222
indexmap = "1.0.2"

src/debuginfo/mod.rs

+16-89
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::prelude::*;
99
use rustc_index::vec::IndexVec;
1010

1111
use cranelift_codegen::entity::EntityRef;
12-
use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc};
12+
use cranelift_codegen::ir::{LabelValueLoc, StackSlots, ValueLabel, ValueLoc};
1313
use cranelift_codegen::isa::TargetIsa;
1414
use cranelift_codegen::ValueLocRange;
1515

@@ -39,7 +39,6 @@ pub(crate) struct DebugContext<'tcx> {
3939
dwarf: DwarfUnit,
4040
unit_range_list: RangeList,
4141

42-
clif_types: FxHashMap<Type, UnitEntryId>,
4342
types: FxHashMap<Ty<'tcx>, UnitEntryId>,
4443
}
4544

@@ -115,48 +114,10 @@ impl<'tcx> DebugContext<'tcx> {
115114
dwarf,
116115
unit_range_list: RangeList(Vec::new()),
117116

118-
clif_types: FxHashMap::default(),
119117
types: FxHashMap::default(),
120118
}
121119
}
122120

123-
fn dwarf_ty_for_clif_ty(&mut self, ty: Type) -> UnitEntryId {
124-
if let Some(type_id) = self.clif_types.get(&ty) {
125-
return *type_id;
126-
}
127-
128-
let new_entry = |dwarf: &mut DwarfUnit, tag| dwarf.unit.add(dwarf.unit.root(), tag);
129-
130-
let primitive = |dwarf: &mut DwarfUnit, ate| {
131-
let type_id = new_entry(dwarf, gimli::DW_TAG_base_type);
132-
let type_entry = dwarf.unit.get_mut(type_id);
133-
type_entry.set(gimli::DW_AT_encoding, AttributeValue::Encoding(ate));
134-
type_id
135-
};
136-
137-
let type_id = if ty.is_bool() {
138-
primitive(&mut self.dwarf, gimli::DW_ATE_boolean)
139-
} else if ty.is_int() {
140-
primitive(&mut self.dwarf, gimli::DW_ATE_address)
141-
} else if ty.is_float() {
142-
primitive(&mut self.dwarf, gimli::DW_ATE_float)
143-
} else {
144-
new_entry(&mut self.dwarf, gimli::DW_TAG_structure_type)
145-
};
146-
147-
let type_entry = self.dwarf.unit.get_mut(type_id);
148-
type_entry.set(
149-
gimli::DW_AT_name,
150-
AttributeValue::String(format!("{}", ty).replace('i', "u").into_bytes()),
151-
);
152-
type_entry.set(
153-
gimli::DW_AT_byte_size,
154-
AttributeValue::Udata(u64::from(ty.bytes())),
155-
);
156-
157-
type_id
158-
}
159-
160121
fn dwarf_ty(&mut self, ty: Ty<'tcx>) -> UnitEntryId {
161122
if let Some(type_id) = self.types.get(ty) {
162123
return *type_id;
@@ -312,51 +273,6 @@ impl<'tcx> DebugContext<'tcx> {
312273
// Using Udata for DW_AT_high_pc requires at least DWARF4
313274
func_entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(u64::from(end)));
314275

315-
// FIXME Remove once actual debuginfo for locals works.
316-
for (i, (param, &val)) in context
317-
.func
318-
.signature
319-
.params
320-
.iter()
321-
.zip(
322-
context
323-
.func
324-
.dfg
325-
.block_params(context.func.layout.entry_block().unwrap()),
326-
)
327-
.enumerate()
328-
{
329-
use cranelift_codegen::ir::ArgumentPurpose;
330-
let base_name = match param.purpose {
331-
ArgumentPurpose::Normal => "arg",
332-
ArgumentPurpose::StructArgument(_) => "struct_arg",
333-
ArgumentPurpose::StructReturn => "sret",
334-
ArgumentPurpose::Link
335-
| ArgumentPurpose::FramePointer
336-
| ArgumentPurpose::CalleeSaved => continue,
337-
ArgumentPurpose::VMContext
338-
| ArgumentPurpose::SignatureId
339-
| ArgumentPurpose::CallerTLS
340-
| ArgumentPurpose::CalleeTLS
341-
| ArgumentPurpose::StackLimit => unreachable!(),
342-
};
343-
let name = format!("{}{}", base_name, i);
344-
345-
let dw_ty = self.dwarf_ty_for_clif_ty(param.value_type);
346-
let loc =
347-
translate_loc(isa, context.func.locations[val], &context.func.stack_slots).unwrap();
348-
349-
let arg_id = self
350-
.dwarf
351-
.unit
352-
.add(entry_id, gimli::DW_TAG_formal_parameter);
353-
let var_entry = self.dwarf.unit.get_mut(arg_id);
354-
355-
var_entry.set(gimli::DW_AT_name, AttributeValue::String(name.into_bytes()));
356-
var_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty));
357-
var_entry.set(gimli::DW_AT_location, AttributeValue::Exprloc(loc));
358-
}
359-
360276
// FIXME make it more reliable and implement scopes before re-enabling this.
361277
if false {
362278
let value_labels_ranges = context.build_value_labels_ranges(isa).unwrap();
@@ -463,17 +379,17 @@ fn place_location<'tcx>(
463379
// Adapted from https://github.com/CraneStation/wasmtime/blob/5a1845b4caf7a5dba8eda1fef05213a532ed4259/crates/debug/src/transform/expression.rs#L59-L137
464380
fn translate_loc(
465381
isa: &dyn TargetIsa,
466-
loc: ValueLoc,
382+
loc: LabelValueLoc,
467383
stack_slots: &StackSlots,
468384
) -> Option<Expression> {
469385
match loc {
470-
ValueLoc::Reg(reg) => {
386+
LabelValueLoc::ValueLoc( ValueLoc::Reg(reg)) => {
471387
let machine_reg = isa.map_dwarf_register(reg).unwrap();
472388
let mut expr = Expression::new();
473389
expr.op_reg(gimli::Register(machine_reg));
474390
Some(expr)
475391
}
476-
ValueLoc::Stack(ss) => {
392+
LabelValueLoc::ValueLoc(ValueLoc::Stack(ss)) => {
477393
if let Some(ss_offset) = stack_slots[ss].offset {
478394
let mut expr = Expression::new();
479395
expr.op_breg(X86_64::RBP, i64::from(ss_offset) + 16);
@@ -482,6 +398,17 @@ fn translate_loc(
482398
None
483399
}
484400
}
485-
_ => None,
401+
LabelValueLoc::ValueLoc(ValueLoc::Unassigned) => unreachable!(),
402+
LabelValueLoc::Reg(reg) => {
403+
let machine_reg = isa.map_regalloc_reg_to_dwarf(reg).unwrap();
404+
let mut expr = Expression::new();
405+
expr.op_reg(gimli::Register(machine_reg));
406+
Some(expr)
407+
}
408+
LabelValueLoc::SPOffset(offset) => {
409+
let mut expr = Expression::new();
410+
expr.op_breg(X86_64::RSP, offset);
411+
Some(expr)
412+
}
486413
}
487414
}

0 commit comments

Comments
 (0)