(
&self,
obj: &mut Object<'_>,
translations: &'a PrimaryMap<StaticModuleIndex, ModuleTranslation<'a>>,
get_func: &'a dyn Fn(
StaticModuleIndex,
| 855 | } |
| 856 | |
| 857 | fn append_dwarf<'a>( |
| 858 | &self, |
| 859 | obj: &mut Object<'_>, |
| 860 | translations: &'a PrimaryMap<StaticModuleIndex, ModuleTranslation<'a>>, |
| 861 | get_func: &'a dyn Fn( |
| 862 | StaticModuleIndex, |
| 863 | DefinedFuncIndex, |
| 864 | ) -> (SymbolId, &'a (dyn Any + Send + Sync)), |
| 865 | dwarf_package_bytes: Option<&'a [u8]>, |
| 866 | tunables: &'a Tunables, |
| 867 | ) -> Result<()> { |
| 868 | log::trace!("appending DWARF debug info"); |
| 869 | |
| 870 | let get_func = move |m, f| { |
| 871 | let (sym, any) = get_func(m, f); |
| 872 | log::trace!("get_func({m:?}, {f:?}) -> ({sym:?}, {any:#p})"); |
| 873 | debug_assert!(!any.is::<Option<CompilerContext>>()); |
| 874 | debug_assert!(any.is::<CompiledFunction>()); |
| 875 | ( |
| 876 | sym, |
| 877 | any.downcast_ref::<CompiledFunction>().unwrap().metadata(), |
| 878 | ) |
| 879 | }; |
| 880 | |
| 881 | let mut compilation = crate::debug::Compilation::new( |
| 882 | &*self.isa, |
| 883 | translations, |
| 884 | &get_func, |
| 885 | dwarf_package_bytes, |
| 886 | tunables, |
| 887 | ); |
| 888 | let dwarf_sections = crate::debug::emit_dwarf(&*self.isa, &mut compilation) |
| 889 | .with_context(|| "failed to emit DWARF debug information")?; |
| 890 | |
| 891 | let (debug_bodies, debug_relocs): (Vec<_>, Vec<_>) = dwarf_sections |
| 892 | .iter() |
| 893 | .map(|s| ((s.name, &s.body), (s.name, &s.relocs))) |
| 894 | .unzip(); |
| 895 | let mut dwarf_sections_ids = HashMap::new(); |
| 896 | for (name, body) in debug_bodies { |
| 897 | let segment = obj.segment_name(StandardSegment::Debug).to_vec(); |
| 898 | let section_id = obj.add_section(segment, name.as_bytes().to_vec(), SectionKind::Debug); |
| 899 | dwarf_sections_ids.insert(name, section_id); |
| 900 | obj.append_section_data(section_id, &body, 1); |
| 901 | } |
| 902 | |
| 903 | // Write all debug data relocations. |
| 904 | for (name, relocs) in debug_relocs { |
| 905 | let section_id = *dwarf_sections_ids.get(name).unwrap(); |
| 906 | for reloc in relocs { |
| 907 | let target_symbol = match reloc.target { |
| 908 | DwarfSectionRelocTarget::Func(id) => compilation.symbol_id(id), |
| 909 | DwarfSectionRelocTarget::Section(name) => { |
| 910 | obj.section_symbol(dwarf_sections_ids[name]) |
| 911 | } |
| 912 | }; |
| 913 | obj.add_relocation( |
| 914 | section_id, |
nothing calls this directly
no test coverage detected