MCPcopy Create free account
hub / github.com/Rust-for-Linux/klint / new

Method new

src/binary_analysis/dwarf.rs:263–290  ·  view source on GitHub ↗
(object: &'file File<'data>)

Source from the content-addressed store, hash-verified

261
262impl<'file, 'data> DwarfLoader<'file, 'data> {
263 pub fn new(object: &'file File<'data>) -> Result<Self, Error> {
264 if !object.endianness().is_little_endian() {
265 Err(Error::UnexpectedElf(
266 "only little endian object files are supported",
267 ))?
268 }
269
270 let section_layout = SectionLayout::for_object(object)?;
271
272 let dwarf_sections = Arc::new(gimli::DwarfSections::load(|id| {
273 load_section(object, &section_layout, id.name())
274 })?);
275 // Also load `.eh_frame` which may be present in place of `.debug_frame`.
276 let eh_frame_section = load_section(object, &section_layout, ".eh_frame")?;
277
278 let dwarf =
279 dwarf_sections.borrow(|section| gimli::EndianSlice::new(section, gimli::LittleEndian));
280 // SAFETY: erase lifetime. This is fine as `dwarf` will be dropped before `dwarf_sections`.
281 let dwarf_transmute =
282 unsafe { std::mem::transmute::<Dwarf<ReaderTy<'_>>, Dwarf<ReaderTy<'_>>>(dwarf) };
283
284 Ok(Self {
285 section_layout,
286 dwarf: dwarf_transmute,
287 dwarf_sections,
288 eh_frame_section,
289 })
290 }
291
292 // This returns the correct lifetime instead of the hacked one.
293 fn dwarf(&self) -> &Dwarf<ReaderTy<'_>> {

Callers

nothing calls this directly

Calls 2

load_sectionFunction · 0.85
nameMethod · 0.80

Tested by

no test coverage detected