From 0f861e1035a64368494aa0d1381065f3bb1efede Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 3 Feb 2021 11:53:23 +0100 Subject: [PATCH] Update Cranelift --- Cargo.lock | 66 +++++---------------------- Cargo.toml | 2 +- src/debuginfo/mod.rs | 105 +++++++------------------------------------ 3 files changed, 29 insertions(+), 144 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5495cfa5eaa..99d9bbf1892 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,12 +29,6 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" -[[package]] -name = "cc" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" - [[package]] name = "cfg-if" version = "0.1.10" @@ -50,7 +44,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.69.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#986b5768f9e68f1564b43f32b8a4080a6582c8ca" +source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#256cc8a5185c8d2ee82838fe2b12c8672baa69a3" dependencies = [ "cranelift-entity", ] @@ -58,7 +52,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.69.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#986b5768f9e68f1564b43f32b8a4080a6582c8ca" +source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#256cc8a5185c8d2ee82838fe2b12c8672baa69a3" dependencies = [ "byteorder", "cranelift-bforest", @@ -76,7 +70,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.69.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#986b5768f9e68f1564b43f32b8a4080a6582c8ca" +source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#256cc8a5185c8d2ee82838fe2b12c8672baa69a3" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -85,17 +79,17 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.69.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#986b5768f9e68f1564b43f32b8a4080a6582c8ca" +source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#256cc8a5185c8d2ee82838fe2b12c8672baa69a3" [[package]] name = "cranelift-entity" version = "0.69.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#986b5768f9e68f1564b43f32b8a4080a6582c8ca" +source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#256cc8a5185c8d2ee82838fe2b12c8672baa69a3" [[package]] name = "cranelift-frontend" version = "0.69.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#986b5768f9e68f1564b43f32b8a4080a6582c8ca" +source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#256cc8a5185c8d2ee82838fe2b12c8672baa69a3" dependencies = [ "cranelift-codegen", "log", @@ -106,7 +100,7 @@ dependencies = [ [[package]] name = "cranelift-jit" version = "0.69.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#986b5768f9e68f1564b43f32b8a4080a6582c8ca" +source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#256cc8a5185c8d2ee82838fe2b12c8672baa69a3" dependencies = [ "anyhow", "cranelift-codegen", @@ -124,7 +118,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.69.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#986b5768f9e68f1564b43f32b8a4080a6582c8ca" +source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#256cc8a5185c8d2ee82838fe2b12c8672baa69a3" dependencies = [ "anyhow", "cranelift-codegen", @@ -136,17 +130,16 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.69.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#986b5768f9e68f1564b43f32b8a4080a6582c8ca" +source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#256cc8a5185c8d2ee82838fe2b12c8672baa69a3" dependencies = [ "cranelift-codegen", - "raw-cpuid", "target-lexicon", ] [[package]] name = "cranelift-object" version = "0.69.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#986b5768f9e68f1564b43f32b8a4080a6582c8ca" +source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#256cc8a5185c8d2ee82838fe2b12c8672baa69a3" dependencies = [ "anyhow", "cranelift-codegen", @@ -253,9 +246,9 @@ dependencies = [ [[package]] name = "object" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" +checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" dependencies = [ "crc32fast", "indexmap", @@ -279,17 +272,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "raw-cpuid" -version = "8.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fdf7d9dbd43f3d81d94a49c1c3df73cc2b3827995147e6cf7f89d4ec5483e73" -dependencies = [ - "bitflags", - "cc", - "rustc_version", -] - [[package]] name = "regalloc" version = "0.0.31" @@ -337,30 +319,6 @@ dependencies = [ "target-lexicon", ] -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "smallvec" version = "1.6.1" diff --git a/Cargo.toml b/Cargo.toml index 3820fce6d1e..41e23b51afa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime/", branch cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } target-lexicon = "0.11.0" gimli = { version = "0.23.0", default-features = false, features = ["write"]} -object = { version = "0.22.0", default-features = false, features = ["std", "read_core", "write", "coff", "elf", "macho", "pe"] } +object = { version = "0.23.0", default-features = false, features = ["std", "read_core", "write", "coff", "elf", "macho", "pe"] } ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.0.2" diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index a6f4ded41b6..28adbe2fdb6 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -9,7 +9,7 @@ use crate::prelude::*; use rustc_index::vec::IndexVec; use cranelift_codegen::entity::EntityRef; -use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc}; +use cranelift_codegen::ir::{LabelValueLoc, StackSlots, ValueLabel, ValueLoc}; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::ValueLocRange; @@ -39,7 +39,6 @@ pub(crate) struct DebugContext<'tcx> { dwarf: DwarfUnit, unit_range_list: RangeList, - clif_types: FxHashMap, types: FxHashMap, UnitEntryId>, } @@ -115,48 +114,10 @@ impl<'tcx> DebugContext<'tcx> { dwarf, unit_range_list: RangeList(Vec::new()), - clif_types: FxHashMap::default(), types: FxHashMap::default(), } } - fn dwarf_ty_for_clif_ty(&mut self, ty: Type) -> UnitEntryId { - if let Some(type_id) = self.clif_types.get(&ty) { - return *type_id; - } - - let new_entry = |dwarf: &mut DwarfUnit, tag| dwarf.unit.add(dwarf.unit.root(), tag); - - let primitive = |dwarf: &mut DwarfUnit, ate| { - let type_id = new_entry(dwarf, gimli::DW_TAG_base_type); - let type_entry = dwarf.unit.get_mut(type_id); - type_entry.set(gimli::DW_AT_encoding, AttributeValue::Encoding(ate)); - type_id - }; - - let type_id = if ty.is_bool() { - primitive(&mut self.dwarf, gimli::DW_ATE_boolean) - } else if ty.is_int() { - primitive(&mut self.dwarf, gimli::DW_ATE_address) - } else if ty.is_float() { - primitive(&mut self.dwarf, gimli::DW_ATE_float) - } else { - new_entry(&mut self.dwarf, gimli::DW_TAG_structure_type) - }; - - let type_entry = self.dwarf.unit.get_mut(type_id); - type_entry.set( - gimli::DW_AT_name, - AttributeValue::String(format!("{}", ty).replace('i', "u").into_bytes()), - ); - type_entry.set( - gimli::DW_AT_byte_size, - AttributeValue::Udata(u64::from(ty.bytes())), - ); - - type_id - } - fn dwarf_ty(&mut self, ty: Ty<'tcx>) -> UnitEntryId { if let Some(type_id) = self.types.get(ty) { return *type_id; @@ -312,51 +273,6 @@ impl<'tcx> DebugContext<'tcx> { // Using Udata for DW_AT_high_pc requires at least DWARF4 func_entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(u64::from(end))); - // FIXME Remove once actual debuginfo for locals works. - for (i, (param, &val)) in context - .func - .signature - .params - .iter() - .zip( - context - .func - .dfg - .block_params(context.func.layout.entry_block().unwrap()), - ) - .enumerate() - { - use cranelift_codegen::ir::ArgumentPurpose; - let base_name = match param.purpose { - ArgumentPurpose::Normal => "arg", - ArgumentPurpose::StructArgument(_) => "struct_arg", - ArgumentPurpose::StructReturn => "sret", - ArgumentPurpose::Link - | ArgumentPurpose::FramePointer - | ArgumentPurpose::CalleeSaved => continue, - ArgumentPurpose::VMContext - | ArgumentPurpose::SignatureId - | ArgumentPurpose::CallerTLS - | ArgumentPurpose::CalleeTLS - | ArgumentPurpose::StackLimit => unreachable!(), - }; - let name = format!("{}{}", base_name, i); - - let dw_ty = self.dwarf_ty_for_clif_ty(param.value_type); - let loc = - translate_loc(isa, context.func.locations[val], &context.func.stack_slots).unwrap(); - - let arg_id = self - .dwarf - .unit - .add(entry_id, gimli::DW_TAG_formal_parameter); - let var_entry = self.dwarf.unit.get_mut(arg_id); - - var_entry.set(gimli::DW_AT_name, AttributeValue::String(name.into_bytes())); - var_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty)); - var_entry.set(gimli::DW_AT_location, AttributeValue::Exprloc(loc)); - } - // FIXME make it more reliable and implement scopes before re-enabling this. if false { let value_labels_ranges = context.build_value_labels_ranges(isa).unwrap(); @@ -463,17 +379,17 @@ fn place_location<'tcx>( // Adapted from https://github.com/CraneStation/wasmtime/blob/5a1845b4caf7a5dba8eda1fef05213a532ed4259/crates/debug/src/transform/expression.rs#L59-L137 fn translate_loc( isa: &dyn TargetIsa, - loc: ValueLoc, + loc: LabelValueLoc, stack_slots: &StackSlots, ) -> Option { match loc { - ValueLoc::Reg(reg) => { + LabelValueLoc::ValueLoc( ValueLoc::Reg(reg)) => { let machine_reg = isa.map_dwarf_register(reg).unwrap(); let mut expr = Expression::new(); expr.op_reg(gimli::Register(machine_reg)); Some(expr) } - ValueLoc::Stack(ss) => { + LabelValueLoc::ValueLoc(ValueLoc::Stack(ss)) => { if let Some(ss_offset) = stack_slots[ss].offset { let mut expr = Expression::new(); expr.op_breg(X86_64::RBP, i64::from(ss_offset) + 16); @@ -482,6 +398,17 @@ fn translate_loc( None } } - _ => None, + LabelValueLoc::ValueLoc(ValueLoc::Unassigned) => unreachable!(), + LabelValueLoc::Reg(reg) => { + let machine_reg = isa.map_regalloc_reg_to_dwarf(reg).unwrap(); + let mut expr = Expression::new(); + expr.op_reg(gimli::Register(machine_reg)); + Some(expr) + } + LabelValueLoc::SPOffset(offset) => { + let mut expr = Expression::new(); + expr.op_breg(X86_64::RSP, offset); + Some(expr) + } } }