about summary refs log tree commit diff
path: root/src/debuginfo
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2020-05-01 19:21:29 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2020-05-01 19:21:29 +0200
commit4da6488d95cec9709bf77a28913c8040cc0508ee (patch)
tree82255543011592d38ee9c883441c4f607d4d369b /src/debuginfo
parent485e52e1539d7fb1916c201a73f3d467a18646bf (diff)
downloadrust-4da6488d95cec9709bf77a28913c8040cc0508ee.tar.gz
rust-4da6488d95cec9709bf77a28913c8040cc0508ee.zip
Always emit .eh_frame section
Diffstat (limited to 'src/debuginfo')
-rw-r--r--src/debuginfo/emit.rs29
-rw-r--r--src/debuginfo/mod.rs18
-rw-r--r--src/debuginfo/unwind.rs56
3 files changed, 57 insertions, 46 deletions
diff --git a/src/debuginfo/emit.rs b/src/debuginfo/emit.rs
index e49e13a5be5..af93620fa8a 100644
--- a/src/debuginfo/emit.rs
+++ b/src/debuginfo/emit.rs
@@ -1,6 +1,6 @@
 use rustc_data_structures::fx::FxHashMap;
 
-use gimli::write::{Address, AttributeValue, EhFrame, EndianVec, Result, Sections, Writer, Section};
+use gimli::write::{Address, AttributeValue, EndianVec, Result, Sections, Writer};
 use gimli::{RunTimeEndian, SectionId};
 
 use crate::backend::WriteDebugInfo;
@@ -17,12 +17,9 @@ impl DebugContext<'_> {
             AttributeValue::RangeListRef(unit_range_list_id),
         );
 
-        let mut sections = Sections::new(WriterRelocate::new(self));
+        let mut sections = Sections::new(WriterRelocate::new(self.endian));
         self.dwarf.write(&mut sections).unwrap();
 
-        let mut eh_frame = EhFrame::from(WriterRelocate::new(self));
-        self.frame_table.write_eh_frame(&mut eh_frame).unwrap();
-
         let mut section_map = FxHashMap::default();
         let _: Result<()> = sections.for_each_mut(|id, section| {
             if !section.writer.slice().is_empty() {
@@ -35,21 +32,11 @@ impl DebugContext<'_> {
         let _: Result<()> = sections.for_each(|id, section| {
             if let Some(section_id) = section_map.get(&id) {
                 for reloc in &section.relocs {
-                    product.add_debug_reloc(&section_map, &self.symbols, section_id, reloc);
+                    product.add_debug_reloc(&section_map, section_id, reloc);
                 }
             }
             Ok(())
         });
-
-        if !eh_frame.0.writer.slice().is_empty() {
-            let id = eh_frame.id();
-            let section_id = product.add_debug_section(id, eh_frame.0.writer.into_vec());
-            section_map.insert(id, section_id);
-
-            for reloc in &eh_frame.0.relocs {
-                product.add_debug_reloc(&section_map, &self.symbols, &section_id, reloc);
-            }
-        }
     }
 }
 
@@ -68,16 +55,16 @@ pub(crate) enum DebugRelocName {
 }
 
 #[derive(Clone)]
-struct WriterRelocate {
-    relocs: Vec<DebugReloc>,
-    writer: EndianVec<RunTimeEndian>,
+pub(super) struct WriterRelocate {
+    pub(super) relocs: Vec<DebugReloc>,
+    pub(super) writer: EndianVec<RunTimeEndian>,
 }
 
 impl WriterRelocate {
-    fn new(ctx: &DebugContext<'_>) -> Self {
+    pub(super) fn new(endian: RunTimeEndian) -> Self {
         WriterRelocate {
             relocs: Vec::new(),
-            writer: EndianVec::new(ctx.endian),
+            writer: EndianVec::new(endian),
         }
     }
 }
diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs
index fdc6cc911c7..2a360dd00c2 100644
--- a/src/debuginfo/mod.rs
+++ b/src/debuginfo/mod.rs
@@ -11,12 +11,13 @@ use cranelift_codegen::isa::TargetIsa;
 use cranelift_codegen::ValueLocRange;
 
 use gimli::write::{
-    self, Address, AttributeValue, CieId, DwarfUnit, Expression, FrameTable, LineProgram,
+    self, Address, AttributeValue, DwarfUnit, Expression, LineProgram,
     LineString, Location, LocationList, Range, RangeList, UnitEntryId, Writer,
 };
 use gimli::{Encoding, Format, LineEncoding, RunTimeEndian, X86_64};
 
 pub(crate) use emit::{DebugReloc, DebugRelocName};
+pub(crate) use unwind::UnwindContext;
 
 fn target_endian(tcx: TyCtxt<'_>) -> RunTimeEndian {
     use rustc_target::abi::Endian;
@@ -31,13 +32,10 @@ pub(crate) struct DebugContext<'tcx> {
     tcx: TyCtxt<'tcx>,
 
     endian: RunTimeEndian,
-    symbols: indexmap::IndexMap<FuncId, String>,
 
     dwarf: DwarfUnit,
     unit_range_list: RangeList,
-    frame_table: FrameTable,
 
-    cie: CieId,
     clif_types: FxHashMap<Type, UnitEntryId>,
     types: FxHashMap<Ty<'tcx>, UnitEntryId>,
 }
@@ -111,20 +109,14 @@ impl<'tcx> DebugContext<'tcx> {
             );
         }
 
-        let mut frame_table = FrameTable::default();
-        let cie = frame_table.add_cie(isa.create_systemv_cie().expect("SystemV unwind info CIE"));
-
         DebugContext {
             tcx,
 
             endian: target_endian(tcx),
-            symbols: indexmap::IndexMap::new(),
 
             dwarf,
             unit_range_list: RangeList(Vec::new()),
-            frame_table,
 
-            cie,
             clif_types: FxHashMap::default(),
             types: FxHashMap::default(),
         }
@@ -267,8 +259,6 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
     ) -> Self {
         let mir = debug_context.tcx.instance_mir(instance.def);
 
-        let (symbol, _) = debug_context.symbols.insert_full(func_id, name.to_string());
-
         // FIXME: add to appropriate scope intead of root
         let scope = debug_context.dwarf.unit.root();
 
@@ -291,7 +281,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
         FunctionDebugContext {
             debug_context,
             entry_id,
-            symbol,
+            symbol: func_id.as_u32() as usize,
             instance,
             mir,
         }
@@ -320,8 +310,6 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
         source_info_set: &indexmap::IndexSet<SourceInfo>,
         local_map: FxHashMap<mir::Local, CPlace<'tcx>>,
     ) {
-        self.create_unwind_info(context, isa);
-
         let end = self.create_debug_lines(context, isa, source_info_set);
 
         self.debug_context
diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs
index c0d4eb5c0ed..987c4d8f3e8 100644
--- a/src/debuginfo/unwind.rs
+++ b/src/debuginfo/unwind.rs
@@ -1,15 +1,35 @@
 use crate::prelude::*;
 
-use cranelift_codegen::isa::unwind::UnwindInfo;
+use cranelift_codegen::isa::{TargetIsa, unwind::UnwindInfo};
 
-use gimli::write::Address;
+use gimli::write::{Address, CieId, EhFrame, FrameTable, Section};
 
-impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
-    pub(super) fn create_unwind_info(
-        &mut self,
-        context: &Context,
-        isa: &dyn cranelift_codegen::isa::TargetIsa,
-    ) {
+use crate::backend::WriteDebugInfo;
+
+pub(crate) struct UnwindContext<'tcx> {
+    tcx: TyCtxt<'tcx>,
+    frame_table: FrameTable,
+    cie_id: CieId,
+}
+
+impl<'tcx> UnwindContext<'tcx> {
+    pub(crate) fn new(
+        tcx: TyCtxt<'tcx>,
+        module: &mut Module<impl Backend>,
+    ) -> Self {
+        let mut frame_table = FrameTable::default();
+        let cie = module.isa().create_systemv_cie().expect("SystemV unwind info CIE");
+
+        let cie_id = frame_table.add_cie(cie);
+
+        UnwindContext {
+            tcx,
+            frame_table,
+            cie_id,
+        }
+    }
+
+    pub(crate) fn add_function(&mut self, func_id: FuncId, context: &Context, isa: &dyn TargetIsa) {
         let unwind_info = if let Some(unwind_info) = context.create_unwind_info(isa).unwrap() {
             unwind_info
         } else {
@@ -18,8 +38,8 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
 
         match unwind_info {
             UnwindInfo::SystemV(unwind_info) => {
-                self.debug_context.frame_table.add_fde(self.debug_context.cie, unwind_info.to_fde(Address::Symbol {
-                    symbol: self.symbol,
+                self.frame_table.add_fde(self.cie_id, unwind_info.to_fde(Address::Symbol {
+                    symbol: func_id.as_u32() as usize,
                     addend: 0,
                 }));
             },
@@ -28,4 +48,20 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
             }
         }
     }
+
+    pub(crate) fn emit<P: WriteDebugInfo>(self, product: &mut P) {
+        let mut eh_frame = EhFrame::from(super::emit::WriterRelocate::new(super::target_endian(self.tcx)));
+        self.frame_table.write_eh_frame(&mut eh_frame).unwrap();
+
+        if !eh_frame.0.writer.slice().is_empty() {
+            let id = eh_frame.id();
+            let section_id = product.add_debug_section(id, eh_frame.0.writer.into_vec());
+            let mut section_map = FxHashMap::default();
+            section_map.insert(id, section_id);
+
+            for reloc in &eh_frame.0.relocs {
+                product.add_debug_reloc(&section_map, &section_id, reloc);
+            }
+        }
+    }
 }