Skip to content

Commit

Permalink
Update object dependency to 0.24.0
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed May 2, 2021
1 parent 9ba86eb commit ca5ec39
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cpp_demangle = { default-features = false, version = "0.3.0", optional = true }
addr2line = { version = "0.15.1", optional = true, default-features = false }
miniz_oxide = { version = "0.4.0", optional = true, default-features = false }
[dependencies.object]
version = "0.23"
version = "0.24"
optional = true
default-features = false
features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive']
Expand Down
2 changes: 1 addition & 1 deletion crates/as-if-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ addr2line = { version = "0.15.1", default-features = false }
miniz_oxide = { version = "0.4.0", default-features = false }

[dependencies.object]
version = "0.22"
version = "0.24"
default-features = false
features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive']

Expand Down
17 changes: 8 additions & 9 deletions src/symbolize/gimli/coff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::convert::TryFrom;
use object::pe::{ImageDosHeader, ImageSymbol};
use object::read::pe::{ImageNtHeaders, ImageOptionalHeader, SectionTable};
use object::read::StringTable;
use object::{Bytes, LittleEndian as LE};
use object::LittleEndian as LE;

#[cfg(target_pointer_width = "32")]
type Pe = object::pe::ImageNtHeaders32;
Expand All @@ -18,25 +18,25 @@ impl Mapping {
}

pub struct Object<'a> {
data: Bytes<'a>,
data: &'a [u8],
sections: SectionTable<'a>,
symbols: Vec<(usize, &'a ImageSymbol)>,
strings: StringTable<'a>,
}

pub fn get_image_base(data: &[u8]) -> Option<usize> {
let data = Bytes(data);
let dos_header = ImageDosHeader::parse(data).ok()?;
let (nt_headers, _, _) = dos_header.nt_headers::<Pe>(data).ok()?;
let mut offset = dos_header.nt_headers_offset().into();
let (nt_headers, _) = Pe::parse(data, &mut offset).ok()?;
usize::try_from(nt_headers.optional_header().image_base()).ok()
}

impl<'a> Object<'a> {
fn parse(data: &'a [u8]) -> Option<Object<'a>> {
let data = Bytes(data);
let dos_header = ImageDosHeader::parse(data).ok()?;
let (nt_headers, _, nt_tail) = dos_header.nt_headers::<Pe>(data).ok()?;
let sections = nt_headers.sections(nt_tail).ok()?;
let mut offset = dos_header.nt_headers_offset().into();
let (nt_headers, _) = Pe::parse(data, &mut offset).ok()?;
let sections = nt_headers.sections(data, offset).ok()?;
let symtab = nt_headers.symbols(data).ok()?;
let strings = symtab.strings();
let image_base = usize::try_from(nt_headers.optional_header().image_base()).ok()?;
Expand Down Expand Up @@ -78,8 +78,7 @@ impl<'a> Object<'a> {
.section_by_name(self.strings, name.as_bytes())?
.1
.pe_data(self.data)
.ok()?
.0,
.ok()?,
)
}

Expand Down
7 changes: 3 additions & 4 deletions src/symbolize/gimli/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct Object<'a> {
/// We could use a literal instead, but this helps ensure correctness.
endian: NativeEndian,
/// The entire file data.
data: Bytes<'a>,
data: &'a [u8],
sections: SectionTable<'a, Elf>,
strings: StringTable<'a>,
/// List of pre-parsed and sorted symbols by base address.
Expand All @@ -38,7 +38,6 @@ pub struct Object<'a> {

impl<'a> Object<'a> {
fn parse(data: &'a [u8]) -> Option<Object<'a>> {
let data = object::Bytes(data);
let elf = Elf::parse(data).ok()?;
let endian = elf.endian().ok()?;
let sections = elf.sections(endian, data).ok()?;
Expand Down Expand Up @@ -90,7 +89,7 @@ impl<'a> Object<'a> {

pub fn section(&self, stash: &'a Stash, name: &str) -> Option<&'a [u8]> {
if let Some(section) = self.section_header(name) {
let mut data = section.data(self.endian, self.data).ok()?;
let mut data = Bytes(section.data(self.endian, self.data).ok()?);

// Check for DWARF-standard (gABI) compression, i.e., as generated
// by ld's `--compress-debug-sections=zlib-gabi` flag.
Expand Down Expand Up @@ -131,7 +130,7 @@ impl<'a> Object<'a> {
}
})
.next()?;
let mut data = compressed_section.data(self.endian, self.data).ok()?;
let mut data = Bytes(compressed_section.data(self.endian, self.data).ok()?);
if data.read_bytes(8).ok()?.0 != b"ZLIB\0\0\0\0" {
return None;
}
Expand Down
6 changes: 3 additions & 3 deletions src/symbolize/gimli/libs_macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(super) fn native_libraries() -> Vec<Library> {
fn native_library(i: u32) -> Option<Library> {
use object::macho;
use object::read::macho::{MachHeader, Segment};
use object::{Bytes, NativeEndian};
use object::NativeEndian;

// Fetch the name of this library which corresponds to the path of
// where to load it as well.
Expand Down Expand Up @@ -47,7 +47,7 @@ fn native_library(i: u32) -> Option<Library> {
header as *const _ as *const u8,
mem::size_of_val(header) + header.sizeofcmds.get(endian) as usize,
);
(header.load_commands(endian, Bytes(data)).ok()?, endian)
(header.load_commands(endian, data).ok()?, endian)
}
macho::MH_MAGIC_64 => {
let endian = NativeEndian;
Expand All @@ -56,7 +56,7 @@ fn native_library(i: u32) -> Option<Library> {
header as *const _ as *const u8,
mem::size_of_val(header) + header.sizeofcmds.get(endian) as usize,
);
(header.load_commands(endian, Bytes(data)).ok()?, endian)
(header.load_commands(endian, data).ok()?, endian)
}
_ => return None,
}
Expand Down
37 changes: 19 additions & 18 deletions src/symbolize/gimli/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Mapping {
// First up we need to load the unique UUID which is stored in the macho
// header of the file we're reading, specified at `path`.
let map = super::mmap(path)?;
let (macho, data) = find_header(Bytes(&map))?;
let (macho, data) = find_header(&map)?;
let endian = macho.endian().ok()?;
let uuid = macho.uuid(endian, data).ok()??;

Expand All @@ -40,7 +40,7 @@ impl Mapping {
// file. This should have the symbol table for at least some
// symbolication purposes.
Mapping::mk(map, |data, stash| {
let (macho, data) = find_header(Bytes(data))?;
let (macho, data) = find_header(data)?;
let endian = macho.endian().ok()?;
let obj = Object::parse(macho, endian, data)?;
Context::new(stash, obj)
Expand Down Expand Up @@ -73,7 +73,7 @@ impl Mapping {
let entry = entry.ok()?;
let map = super::mmap(&entry.path())?;
let candidate = Mapping::mk(map, |data, stash| {
let (macho, data) = find_header(Bytes(data))?;
let (macho, data) = find_header(data)?;
let endian = macho.endian().ok()?;
let entry_uuid = macho.uuid(endian, data).ok()??;
if entry_uuid != uuid {
Expand All @@ -91,7 +91,7 @@ impl Mapping {
}
}

fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
fn find_header(mut data: &[u8]) -> Option<(&'_ Mach, &[u8])> {
use object::endian::BigEndian;

let desired_cpu = || {
Expand All @@ -108,16 +108,15 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
}
};

match data
.clone()
match Bytes(data)
.read::<object::endian::U32<NativeEndian>>()
.ok()?
.get(NativeEndian)
{
macho::MH_MAGIC_64 | macho::MH_CIGAM_64 | macho::MH_MAGIC | macho::MH_CIGAM => {}

macho::FAT_MAGIC | macho::FAT_CIGAM => {
let mut header_data = data;
let mut header_data = Bytes(data);
let endian = BigEndian;
let header = header_data.read::<macho::FatHeader>().ok()?;
let nfat = header.nfat_arch.get(endian);
Expand All @@ -126,13 +125,14 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
.find(|arch| desired_cpu() == Some(arch.cputype.get(endian)))?;
let offset = arch.offset.get(endian);
let size = arch.size.get(endian);
data = data
data = Bytes(data)
.read_bytes_at(offset.try_into().ok()?, size.try_into().ok()?)
.ok()?;
.ok()?
.0;
}

macho::FAT_MAGIC_64 | macho::FAT_CIGAM_64 => {
let mut header_data = data;
let mut header_data = Bytes(data);
let endian = BigEndian;
let header = header_data.read::<macho::FatHeader>().ok()?;
let nfat = header.nfat_arch.get(endian);
Expand All @@ -141,9 +141,10 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
.find(|arch| desired_cpu() == Some(arch.cputype.get(endian)))?;
let offset = arch.offset.get(endian);
let size = arch.size.get(endian);
data = data
data = Bytes(data)
.read_bytes_at(offset.try_into().ok()?, size.try_into().ok()?)
.ok()?;
.ok()?
.0;
}

_ => return None,
Expand All @@ -155,7 +156,7 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
// This is used both for executables/libraries and source object files.
pub struct Object<'a> {
endian: NativeEndian,
data: Bytes<'a>,
data: &'a [u8],
dwarf: Option<&'a [MachSection]>,
syms: Vec<(&'a [u8], u64)>,
syms_sort_by_name: bool,
Expand All @@ -166,7 +167,7 @@ pub struct Object<'a> {
}

impl<'a> Object<'a> {
fn parse(mach: &'a Mach, endian: NativeEndian, data: Bytes<'a>) -> Option<Object<'a>> {
fn parse(mach: &'a Mach, endian: NativeEndian, data: &'a [u8]) -> Option<Object<'a>> {
let is_object = mach.filetype(endian) == object::macho::MH_OBJECT;
let mut dwarf = None;
let mut syms = Vec::new();
Expand All @@ -181,7 +182,7 @@ impl<'a> Object<'a> {
dwarf = segment.sections(endian, section_data).ok();
}
} else if let Some(symtab) = command.symtab().ok()? {
let symbols = symtab.symbols::<Mach>(endian, data).ok()?;
let symbols = symtab.symbols::<Mach, _>(endian, data).ok()?;
syms = symbols
.iter()
.filter_map(|nlist: &MachNlist| {
Expand Down Expand Up @@ -230,7 +231,7 @@ impl<'a> Object<'a> {
&& &section_name[2..] == &name[1..]
}
})?;
Some(section.data(self.endian, self.data).ok()?.0)
Some(section.data(self.endian, self.data).ok()?)
}

pub fn search_symtab<'b>(&'b self, addr: u64) -> Option<&'b [u8]> {
Expand Down Expand Up @@ -299,9 +300,9 @@ fn object_mapping(path: &[u8]) -> Option<Mapping> {
.members()
.filter_map(Result::ok)
.find(|m| m.name() == member_name)?;
Bytes(member.data())
member.data(data).ok()?
}
None => Bytes(data),
None => data,
};
let (macho, data) = find_header(data)?;
let endian = macho.endian().ok()?;
Expand Down

0 comments on commit ca5ec39

Please sign in to comment.