Skip to content

Commit

Permalink
X: Try to change code size.
Browse files Browse the repository at this point in the history
  • Loading branch information
detly committed Aug 27, 2023
1 parent 11fc8a0 commit ed82e86
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 93 deletions.
9 changes: 0 additions & 9 deletions src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,6 @@ impl BacktraceFrameFmt<'_, '_, '_> {
lineno: Option<u32>,
colno: Option<u32>,
) -> fmt::Result {
// Fuchsia is unable to symbolize within a process so it has a special
// format which can be used to symbolize later. Print that instead of
// printing addresses in our own format here.
if cfg!(target_os = "fuchsia") {
self.print_raw_fuchsia(frame_ip)?;
} else {
self.print_raw_generic(frame_ip, symbol_name, filename, lineno, colno)?;
}
self.symbol_index += 1;
Ok(())
}

Expand Down
62 changes: 3 additions & 59 deletions src/symbolize/gimli/coff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,71 +37,15 @@ pub fn get_image_base(data: &[u8]) -> Option<usize> {

impl<'a> Object<'a> {
fn parse(data: &'a [u8]) -> Option<Object<'a>> {
let dos_header = ImageDosHeader::parse(data).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()?;

// Collect all the symbols into a local vector which is sorted
// by address and contains enough data to learn about the symbol
// name. Note that we only look at function symbols and also
// note that the sections are 1-indexed because the zero section
// is special (apparently).
let mut symbols = Vec::new();
let mut i = 0;
let len = symtab.len();
while i < len {
let sym = symtab.symbol(i).ok()?;
i += 1 + sym.number_of_aux_symbols as usize;
let section_number = sym.section_number.get(LE);
if sym.derived_type() != object::pe::IMAGE_SYM_DTYPE_FUNCTION || section_number == 0 {
continue;
}
let addr = usize::try_from(sym.value.get(LE)).ok()?;
let section = sections
.section(usize::try_from(section_number).ok()?)
.ok()?;
let va = usize::try_from(section.virtual_address.get(LE)).ok()?;
symbols.push((addr + va + image_base, sym));
}
symbols.sort_unstable_by_key(|x| x.0);
Some(Object {
data,
sections,
strings,
symbols,
})
None
}

pub fn section(&self, _: &Stash, name: &str) -> Option<&'a [u8]> {
Some(
self.sections
.section_by_name(self.strings, name.as_bytes())?
.1
.pe_data(self.data)
.ok()?,
)
None
}

pub fn search_symtab<'b>(&'b self, addr: u64) -> Option<&'b [u8]> {
// Note that unlike other formats COFF doesn't embed the size of
// each symbol. As a last ditch effort search for the *closest*
// symbol to a particular address and return that one. This gets
// really wonky once symbols start getting removed because the
// symbols returned here can be totally incorrect, but we have
// no idea of knowing how to detect that.
let addr = usize::try_from(addr).ok()?;
let i = match self.symbols.binary_search_by_key(&addr, |p| p.0) {
Ok(i) => i,
// typically `addr` isn't in the array, but `i` is where
// we'd insert it, so the previous position must be the
// greatest less than `addr`
Err(i) => i.checked_sub(1)?,
};
self.symbols[i].1.name(self.strings).ok()
None
}

pub(super) fn search_object_map(&self, _addr: u64) -> Option<(&Context<'_>, u64)> {
Expand Down
26 changes: 1 addition & 25 deletions src/symbolize/gimli/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,7 @@ impl Mapping {

/// Load debuginfo from an external debug file.
fn new_debug(original_path: &Path, path: PathBuf, crc: Option<u32>) -> Option<Mapping> {
let map = super::mmap(&path)?;
Mapping::mk(map, |map, stash| {
let object = Object::parse(&map)?;

if let Some(_crc) = crc {
// TODO: check crc
}

// Try to locate a supplementary object file.
let mut sup = None;
if let Some((path_sup, build_id_sup)) = object.gnu_debugaltlink_path(&path) {
if let Some(map_sup) = super::mmap(&path_sup) {
let map_sup = stash.cache_mmap(map_sup);
if let Some(sup_) = Object::parse(map_sup) {
if sup_.build_id() == Some(build_id_sup) {
sup = Some(sup_);
}
}
}
}

let dwp = Mapping::load_dwarf_package(original_path, stash);

Context::new(stash, object, sup, dwp)
})
None
}

/// Try to locate a DWARF package file.
Expand Down

0 comments on commit ed82e86

Please sign in to comment.