Skip to content

Commit

Permalink
Enable gimli on all platforms
Browse files Browse the repository at this point in the history
This commit updates `#[cfg]` and organization to ensure that the
gimli-symbolize feature compiles on all platforms. The main thing to
implement will be loading native libraries which currently doesn't have
an implementation for platforms like FreeBSD.
  • Loading branch information
alexcrichton committed May 12, 2020
1 parent 67ccecb commit bb5aa64
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
16 changes: 15 additions & 1 deletion src/symbolize/gimli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ cfg_if::cfg_if! {
bias: slide,
})
}
} else {
} else if #[cfg(any(
target_os = "linux",
target_os = "fuchsia",
))] {
// Other Unix (e.g. Linux) platforms use ELF as an object file format
// and typically implement an API called `dl_iterate_phdr` to load
// native libraries.
Expand All @@ -279,6 +282,7 @@ cfg_if::cfg_if! {
use self::elf::Object;

fn native_libraries() -> Vec<Library> {
wut();
let mut ret = Vec::new();
unsafe {
libc::dl_iterate_phdr(Some(callback), &mut ret as *mut _ as *mut _);
Expand Down Expand Up @@ -316,6 +320,16 @@ cfg_if::cfg_if! {
});
0
}
} else {
// Everything else should use ELF, but doesn't know how to load native
// libraries.

mod elf;
use self::elf::Object;

fn native_libraries() -> Vec<Library> {
Vec::new()
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/symbolize/gimli/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ impl<'a> Object<'a> {
// symbolicating with locally defined functions.
.filter(|sym| sym.st_shndx(endian) != object::elf::SHN_UNDEF)
.map(|sym| {
let address = sym.st_value(endian);
let size = sym.st_size(endian);
let address = sym.st_value(endian).into();
let size = sym.st_size(endian).into();
let name = sym.st_name(endian);
ParsedSym {
address,
Expand Down
18 changes: 8 additions & 10 deletions src/symbolize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,21 +463,19 @@ cfg_if::cfg_if! {
unsafe fn clear_symbol_cache_imp() {}
} else if #[cfg(all(
feature = "gimli-symbolize",
any(
target_os = "linux",
target_os = "macos",
windows,
),
not(target_os = "emscripten"),
))] {
mod gimli;
use self::gimli::resolve as resolve_imp;
use self::gimli::Symbol as SymbolImp;
use self::gimli::clear_symbol_cache as clear_symbol_cache_imp;
} else if #[cfg(all(feature = "libbacktrace",
any(unix, all(windows, not(target_vendor = "uwp"), target_env = "gnu")),
not(target_os = "fuchsia"),
not(target_os = "emscripten"),
not(target_env = "uclibc")))] {
} else if #[cfg(all(
feature = "libbacktrace",
any(unix, all(windows, not(target_vendor = "uwp"), target_env = "gnu")),
not(target_os = "fuchsia"),
not(target_os = "emscripten"),
not(target_env = "uclibc"),
))] {
mod libbacktrace;
use self::libbacktrace::resolve as resolve_imp;
use self::libbacktrace::Symbol as SymbolImp;
Expand Down

0 comments on commit bb5aa64

Please sign in to comment.