From bb5aa64804d6ba83a768c7ed1c5d67435ddba53e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 12 May 2020 09:48:41 -0700 Subject: [PATCH] Enable gimli on all platforms 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. --- src/symbolize/gimli.rs | 16 +++++++++++++++- src/symbolize/gimli/elf.rs | 4 ++-- src/symbolize/mod.rs | 18 ++++++++---------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/symbolize/gimli.rs b/src/symbolize/gimli.rs index 3673e471b..36709761b 100644 --- a/src/symbolize/gimli.rs +++ b/src/symbolize/gimli.rs @@ -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. @@ -279,6 +282,7 @@ cfg_if::cfg_if! { use self::elf::Object; fn native_libraries() -> Vec { + wut(); let mut ret = Vec::new(); unsafe { libc::dl_iterate_phdr(Some(callback), &mut ret as *mut _ as *mut _); @@ -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 { + Vec::new() + } } } diff --git a/src/symbolize/gimli/elf.rs b/src/symbolize/gimli/elf.rs index e8dae3654..eb0ac88f5 100644 --- a/src/symbolize/gimli/elf.rs +++ b/src/symbolize/gimli/elf.rs @@ -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, diff --git a/src/symbolize/mod.rs b/src/symbolize/mod.rs index 90ef0caf8..acb90e4f9 100644 --- a/src/symbolize/mod.rs +++ b/src/symbolize/mod.rs @@ -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;