Upgrade gimli to 0.21 (#1819)

* Use gimli 0.21

* rm CFI w Expression

* Don't write .debug_frame twice
This commit is contained in:
Yury Delendik
2020-06-04 14:34:05 -05:00
committed by GitHub
parent 97c7fbbeb6
commit 6f37204f82
14 changed files with 45 additions and 74 deletions

View File

@@ -228,7 +228,7 @@ where
let mut found_expr: Option<write::Expression> = None;
for (_, _, expr) in &exprs {
if let Some(ref prev_expr) = found_expr {
if expr.0.eq(&prev_expr.0) {
if expr == prev_expr {
continue; // the same expression
}
found_expr = None;

View File

@@ -215,7 +215,7 @@ impl CompiledExpression {
pub fn build(&self) -> Option<write::Expression> {
if let [CompiledExpressionPart::Code(code)] = self.parts.as_slice() {
return Some(write::Expression(code.to_vec()));
return Some(write::Expression::raw(code.to_vec()));
}
// locals found, not supported
None
@@ -245,7 +245,7 @@ impl CompiledExpression {
BuildWithLocalsResult::Empty => None,
BuildWithLocalsResult::Simple(it, code) => it
.next()
.map(|(addr, len)| Ok((addr, len, write::Expression(code.to_vec())))),
.map(|(addr, len)| Ok((addr, len, write::Expression::raw(code.to_vec())))),
BuildWithLocalsResult::Ranges(it) => it.next().map(|r| {
r.map(|(func_index, start, end, code_buf)| {
(
@@ -254,7 +254,7 @@ impl CompiledExpression {
addend: start as i64,
},
(end - start) as u64,
write::Expression(code_buf),
write::Expression::raw(code_buf),
)
})
}),
@@ -415,7 +415,7 @@ where
});
} else {
let pos = pc.offset_from(&expr.0).into_u64() as usize;
let op = Operation::parse(&mut pc, &expr.0, encoding)?;
let op = Operation::parse(&mut pc, encoding)?;
match op {
Operation::FrameOffset { offset } => {
// Expand DW_OP_fpreg into frame location and DW_OP_plus_uconst.
@@ -435,7 +435,8 @@ where
code_chunk.extend(writer.into_vec());
continue;
}
Operation::Literal { .. }
Operation::UnsignedConstant { .. }
| Operation::SignedConstant { .. }
| Operation::PlusConstant { .. }
| Operation::Piece { .. } => (),
Operation::StackValue => {

View File

@@ -58,7 +58,7 @@ impl UnitRefsMap {
for (die_id, attr_name, offset) in refs.refs {
let die = comp_unit.get_mut(die_id);
if let Some(unit_id) = self.map.get(&offset) {
die.set(attr_name, write::AttributeValue::ThisUnitEntryRef(*unit_id));
die.set(attr_name, write::AttributeValue::UnitRef(*unit_id));
}
}
}
@@ -102,7 +102,9 @@ impl DebugInfoRefsMap {
if let Some((id, entry_id)) = self.map.get(&offset) {
die.set(
attr_name,
write::AttributeValue::AnyUnitEntryRef((*id, *entry_id)),
write::AttributeValue::DebugInfoRef(write::Reference::Entry(
*id, *entry_id,
)),
);
}
}

View File

@@ -262,7 +262,7 @@ fn generate_vars(
var.set(gimli::DW_AT_name, write::AttributeValue::StringRef(name_id));
var.set(
gimli::DW_AT_type,
write::AttributeValue::ThisUnitEntryRef(type_die_id),
write::AttributeValue::UnitRef(type_die_id),
);
var.set(
gimli::DW_AT_location,

View File

@@ -132,7 +132,7 @@ where
// Build DW_TAG_pointer_type for `WebAssemblyPtrWrapper<T>*`:
// .. DW_AT_type = <wrapper_die>
add_tag!(parent_id, gimli::DW_TAG_pointer_type => wrapper_ptr_type as wrapper_ptr_type_id {
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(wrapper_die_id)
gimli::DW_AT_type = write::AttributeValue::UnitRef(wrapper_die_id)
});
let base_type_id = pointer_type_entry.attr_value(gimli::DW_AT_type)?;
@@ -166,7 +166,7 @@ where
// .. DW_AT_location = 0
add_tag!(wrapper_die_id, gimli::DW_TAG_member => m_die as m_die_id {
gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("__ptr")),
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(wp_die_id),
gimli::DW_AT_type = write::AttributeValue::UnitRef(wp_die_id),
gimli::DW_AT_data_member_location = write::AttributeValue::Data1(0)
});
@@ -180,10 +180,10 @@ where
add_tag!(wrapper_die_id, gimli::DW_TAG_subprogram => deref_op_die as deref_op_die_id {
gimli::DW_AT_linkage_name = write::AttributeValue::StringRef(out_strings.add("resolve_vmctx_memory_ptr")),
gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("ptr")),
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(ptr_type_id)
gimli::DW_AT_type = write::AttributeValue::UnitRef(ptr_type_id)
});
add_tag!(deref_op_die_id, gimli::DW_TAG_formal_parameter => deref_op_this_param as deref_op_this_param_id {
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(wrapper_ptr_type_id),
gimli::DW_AT_type = write::AttributeValue::UnitRef(wrapper_ptr_type_id),
gimli::DW_AT_artificial = write::AttributeValue::Flag(true)
});
@@ -197,10 +197,10 @@ where
add_tag!(wrapper_die_id, gimli::DW_TAG_subprogram => deref_op_die as deref_op_die_id {
gimli::DW_AT_linkage_name = write::AttributeValue::StringRef(out_strings.add("resolve_vmctx_memory_ptr")),
gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("operator*")),
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(ref_type_id)
gimli::DW_AT_type = write::AttributeValue::UnitRef(ref_type_id)
});
add_tag!(deref_op_die_id, gimli::DW_TAG_formal_parameter => deref_op_this_param as deref_op_this_param_id {
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(wrapper_ptr_type_id),
gimli::DW_AT_type = write::AttributeValue::UnitRef(wrapper_ptr_type_id),
gimli::DW_AT_artificial = write::AttributeValue::Flag(true)
});
@@ -214,10 +214,10 @@ where
add_tag!(wrapper_die_id, gimli::DW_TAG_subprogram => deref_op_die as deref_op_die_id {
gimli::DW_AT_linkage_name = write::AttributeValue::StringRef(out_strings.add("resolve_vmctx_memory_ptr")),
gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("operator->")),
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(ptr_type_id)
gimli::DW_AT_type = write::AttributeValue::UnitRef(ptr_type_id)
});
add_tag!(deref_op_die_id, gimli::DW_TAG_formal_parameter => deref_op_this_param as deref_op_this_param_id {
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(wrapper_ptr_type_id),
gimli::DW_AT_type = write::AttributeValue::UnitRef(wrapper_ptr_type_id),
gimli::DW_AT_artificial = write::AttributeValue::Flag(true)
});

View File

@@ -56,7 +56,7 @@ pub(crate) fn add_internal_types(
// .. DW_AT_type = <memory_byte_die>
add_tag!(root_id, gimli::DW_TAG_pointer_type => memory_bytes_die as memory_bytes_die_id {
gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("u8*")),
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(memory_byte_die_id)
gimli::DW_AT_type = write::AttributeValue::UnitRef(memory_byte_die_id)
});
// Create artificial VMContext type and its reference for convinience viewing
@@ -87,7 +87,7 @@ pub(crate) fn add_internal_types(
// .. DW_AT_data_member_location = `memory_offset`
add_tag!(vmctx_die_id, gimli::DW_TAG_member => m_die as m_die_id {
gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("memory")),
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(memory_bytes_die_id),
gimli::DW_AT_type = write::AttributeValue::UnitRef(memory_bytes_die_id),
gimli::DW_AT_data_member_location = write::AttributeValue::Udata(memory_offset as u64)
});
}
@@ -102,7 +102,7 @@ pub(crate) fn add_internal_types(
// .. DW_AT_type = <vmctx_die>
add_tag!(root_id, gimli::DW_TAG_pointer_type => vmctx_ptr_die as vmctx_ptr_die_id {
gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("WasmtimeVMContext*")),
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(vmctx_die_id)
gimli::DW_AT_type = write::AttributeValue::UnitRef(vmctx_die_id)
});
// Build vmctx_die's DW_TAG_subprogram for `set` method:
@@ -116,7 +116,7 @@ pub(crate) fn add_internal_types(
gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("set"))
});
add_tag!(vmctx_set_id, gimli::DW_TAG_formal_parameter => vmctx_set_this_param as vmctx_set_this_param_id {
gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(vmctx_ptr_die_id),
gimli::DW_AT_type = write::AttributeValue::UnitRef(vmctx_ptr_die_id),
gimli::DW_AT_artificial = write::AttributeValue::Flag(true)
});
@@ -157,7 +157,7 @@ pub(crate) fn append_vmctx_info(
);
var_die.set(
gimli::DW_AT_type,
write::AttributeValue::ThisUnitEntryRef(vmctx_die_id),
write::AttributeValue::UnitRef(vmctx_die_id),
);
var_die.set(gimli::DW_AT_location, loc);

View File

@@ -1,6 +1,6 @@
use faerie::artifact::{Decl, SectionKind};
use faerie::*;
use gimli::write::{Address, DebugFrame, Dwarf, EndianVec, FrameTable, Result, Sections, Writer};
use gimli::write::{Address, Dwarf, EndianVec, FrameTable, Result, Sections, Writer};
use gimli::{RunTimeEndian, SectionId};
#[derive(Clone)]
@@ -30,6 +30,9 @@ pub fn emit_dwarf(
let mut sections = Sections::new(WriterRelocate::new(endian, symbol_resolver));
dwarf.write(&mut sections)?;
if let Some(frames) = frames {
frames.write_debug_frame(&mut sections.debug_frame)?;
}
sections.for_each_mut(|id, s| -> anyhow::Result<()> {
artifact.declare_with(
id.name(),
@@ -55,29 +58,6 @@ pub fn emit_dwarf(
Ok(())
})?;
if let Some(frames) = frames {
let mut debug_frame = DebugFrame::from(WriterRelocate::new(endian, symbol_resolver));
frames.write_debug_frame(&mut debug_frame).unwrap();
artifact.declare_with(
SectionId::DebugFrame.name(),
Decl::section(SectionKind::Debug),
debug_frame.writer.take(),
)?;
for reloc in &debug_frame.relocs {
artifact.link_with(
faerie::Link {
from: SectionId::DebugFrame.name(),
to: &reloc.name,
at: u64::from(reloc.offset),
},
faerie::Reloc::Debug {
size: reloc.size,
addend: reloc.addend as i32,
},
)?;
}
}
Ok(())
}