Skip to content

Commit

Permalink
Merge pull request #37 from afranchuk/remove-object
Browse files Browse the repository at this point in the history
Remove the optional `object` feature and related ModuleSectionInfo implementation
  • Loading branch information
mstange authored Jun 5, 2024
2 parents b7e1bcb + c6d3cf7 commit 4d517d5
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 52 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ exclude = ["/.github", "/.vscode", "/tests", "/fixtures", "/big-fixtures"]

[dependencies]
gimli = { version = "0.30", default-features = false, features = ["read"] }
object = { version = "0.36", default-features = false, features = ["read_core"], optional = true }
macho-unwind-info = { version = "0.4.0", optional = true }
pe-unwind-info = { version = "0.2.1", optional = true }
fallible-iterator = "0.3.0"
Expand Down
45 changes: 0 additions & 45 deletions src/unwinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,51 +936,6 @@ where
}
}

#[cfg(feature = "object")]
mod object {
use super::{ModuleSectionInfo, Range};
use object::read::{Object, ObjectSection, ObjectSegment};

impl<'data: 'file, 'file, O, D> ModuleSectionInfo<D> for &'file O
where
O: Object<'data>,
D: From<&'data [u8]>,
{
fn base_svma(&self) -> u64 {
if let Some(text_segment) = self.segments().find(|s| s.name() == Ok(Some("__TEXT"))) {
// This is a mach-O image. "Relative addresses" are relative to the
// vmaddr of the __TEXT segment.
return text_segment.address();
}

// For PE binaries, relative_address_base() returns the image base address.
// Otherwise it returns zero. This gives regular ELF images a base address of zero,
// which is what we want.
self.relative_address_base()
}

fn section_svma_range(&mut self, name: &[u8]) -> Option<Range<u64>> {
let section = self.section_by_name_bytes(name)?;
Some(section.address()..section.address() + section.size())
}

fn section_data(&mut self, name: &[u8]) -> Option<D> {
let section = self.section_by_name_bytes(name)?;
section.data().ok().map(|data| data.into())
}

fn segment_svma_range(&mut self, name: &[u8]) -> Option<Range<u64>> {
let segment = self.segments().find(|s| s.name_bytes() == Ok(Some(name)))?;
Some(segment.address()..segment.address() + segment.size())
}

fn segment_data(&mut self, name: &[u8]) -> Option<D> {
let segment = self.segments().find(|s| s.name_bytes() == Ok(Some(name)))?;
segment.data().ok().map(|data| data.into())
}
}
}

impl<D: Deref<Target = [u8]>> Module<D> {
pub fn new(
name: String,
Expand Down
7 changes: 1 addition & 6 deletions tests/integration_tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,11 @@ where
}
}

#[cfg(not(feature = "object"))]
let section_info = Module(file);
#[cfg(feature = "object")]
let section_info = &file;

let module = framehop::Module::new(
objpath.to_string_lossy().to_string(),
base_avma..(base_avma + buf.len() as u64),
base_avma,
section_info,
Module(file),
);
unwinder.add_module(module);
}
Expand Down

0 comments on commit 4d517d5

Please sign in to comment.