Skip to content

Update gimli dependencies #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- run: cargo build
- run: cargo test
- run: cargo test --features "gimli-symbolize"
- run: cargo test --features "libbacktrace"
# run: cargo test --features "libbacktrace"
- run: cargo check --features "libbacktrace gimli-symbolize"
- run: cargo test --features "serialize-rustc"
- run: cargo test --features "serialize-serde"
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ cpp_demangle = { default-features = false, version = "0.3.0", optional = true }

# Optional dependencies enabled through the `gimli-symbolize` feature, do not
# use these features directly.
addr2line = { version = "0.14.1", optional = true, default-features = false }
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
4 changes: 2 additions & 2 deletions crates/as-if-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ bench = false
cfg-if = "1.0"
rustc-demangle = "0.1.4"
libc = { version = "0.2.45", default-features = false }
addr2line = { version = "0.14.1", default-features = false }
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
26 changes: 6 additions & 20 deletions src/symbolize/gimli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,13 @@ struct Context<'a> {

impl<'data> Context<'data> {
fn new(stash: &'data Stash, object: Object<'data>) -> Option<Context<'data>> {
fn load_section<'data, S>(stash: &'data Stash, obj: &Object<'data>) -> S
where
S: gimli::Section<gimli::EndianSlice<'data, Endian>>,
{
let data = obj.section(stash, S::section_name()).unwrap_or(&[]);
S::from(EndianSlice::new(data, Endian))
}

let dwarf = addr2line::Context::from_sections(
load_section(stash, &object),
load_section(stash, &object),
load_section(stash, &object),
load_section(stash, &object),
load_section(stash, &object),
load_section(stash, &object),
load_section(stash, &object),
load_section(stash, &object),
load_section(stash, &object),
gimli::EndianSlice::new(&[], Endian),
)
let sections = gimli::Dwarf::load(|id| -> Result<_, ()> {
let data = object.section(stash, id.name()).unwrap_or(&[]);
Ok(EndianSlice::new(data, Endian))
})
.ok()?;
let dwarf = addr2line::Context::from_dwarf(sections).ok()?;

Some(Context { dwarf, object })
}
}
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
23 changes: 12 additions & 11 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(data: &'_ [u8]) -> Option<(&'_ Mach, &'_ [u8])> {
use object::endian::BigEndian;

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

let mut data = Bytes(data);
match data
.clone()
.read::<object::endian::U32<NativeEndian>>()
Expand Down Expand Up @@ -149,13 +150,13 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
_ => return None,
}

Mach::parse(data).ok().map(|h| (h, data))
Mach::parse(data.0).ok().map(|h| (h, data.0))
}

// 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