diff --git a/Cargo.lock b/Cargo.lock index e21e11d9..ab3ce82c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,7 +36,6 @@ name = "backtrace" version = "0.3.73" dependencies = [ "addr2line", - "cc", "cfg-if", "cpp_demangle", "dylib-dep", diff --git a/Cargo.toml b/Cargo.toml index f456d269..182d8872 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ name = "backtrace" version = "0.3.73" authors = ["The Rust Project Developers"] -build = "build.rs" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/rust-lang/backtrace-rs" @@ -49,11 +48,6 @@ version = "0.36.0" default-features = false features = ['read_core', 'elf', 'macho', 'pe', 'xcoff', 'unaligned', 'archive'] -[build-dependencies] -# Only needed for Android, but cannot be target dependent -# https://github.com/rust-lang/cargo/issues/4932 -cc = "1.0.97" - [dev-dependencies] dylib-dep = { path = "crates/dylib-dep" } libloading = "0.7" @@ -74,7 +68,6 @@ serialize-serde = ["serde"] # purposes. New code should use none of these features. coresymbolication = [] dbghelp = [] -dl_iterate_phdr = [] dladdr = [] kernel32 = [] libunwind = [] diff --git a/build.rs b/build.rs deleted file mode 100644 index 2a3da849..00000000 --- a/build.rs +++ /dev/null @@ -1,55 +0,0 @@ -extern crate cc; - -use std::env; -use std::path::Path; - -// Must be public so the build script of `std` can call it. -pub fn main() { - match env::var("CARGO_CFG_TARGET_OS").unwrap_or_default().as_str() { - "android" => build_android(), - _ => {} - } -} - -// Used to detect the value of the `__ANDROID_API__` -// builtin #define -const MARKER: &str = "BACKTRACE_RS_ANDROID_APIVERSION"; -const ANDROID_API_C: &str = " -BACKTRACE_RS_ANDROID_APIVERSION __ANDROID_API__ -"; - -fn build_android() { - // Create `android-api.c` on demand. - // Required to support calling this from the `std` build script. - let out_dir = env::var_os("OUT_DIR").unwrap(); - let android_api_c = Path::new(&out_dir).join("android-api.c"); - std::fs::write(&android_api_c, ANDROID_API_C).unwrap(); - - let expansion = match cc::Build::new().file(&android_api_c).try_expand() { - Ok(result) => result, - Err(e) => { - eprintln!("warning: android version detection failed while running C compiler: {e}"); - return; - } - }; - let expansion = match std::str::from_utf8(&expansion) { - Ok(s) => s, - Err(_) => return, - }; - eprintln!("expanded android version detection:\n{expansion}"); - let i = match expansion.find(MARKER) { - Some(i) => i, - None => return, - }; - let version = match expansion[i + MARKER.len() + 1..].split_whitespace().next() { - Some(s) => s, - None => return, - }; - let version = match version.parse::() { - Ok(n) => n, - Err(_) => return, - }; - if version >= 21 { - println!("cargo:rustc-cfg=feature=\"dl_iterate_phdr\""); - } -} diff --git a/crates/as-if-std/build.rs b/crates/as-if-std/build.rs index 7669f555..7018b101 100644 --- a/crates/as-if-std/build.rs +++ b/crates/as-if-std/build.rs @@ -1,11 +1,3 @@ -// backtrace-rs requires a feature check on Android targets, so -// we need to run its build.rs as well. -#[allow(unused_extern_crates)] -#[path = "../../build.rs"] -mod backtrace_build_rs; - fn main() { println!("cargo:rustc-cfg=backtrace_in_libstd"); - - backtrace_build_rs::main(); } diff --git a/src/symbolize/gimli.rs b/src/symbolize/gimli.rs index 7465f755..684705e2 100644 --- a/src/symbolize/gimli.rs +++ b/src/symbolize/gimli.rs @@ -100,7 +100,7 @@ impl Mapping { // only borrow `map` and `stash` and we're preserving them below. cx: unsafe { core::mem::transmute::, Context<'static>>(cx) }, _map: data, - stash: stash, + stash, }) } } @@ -122,13 +122,11 @@ impl<'data> Context<'data> { if cfg!(not(target_os = "aix")) { let data = object.section(stash, id.name()).unwrap_or(&[]); Ok(EndianSlice::new(data, Endian)) + } else if let Some(name) = id.xcoff_name() { + let data = object.section(stash, name).unwrap_or(&[]); + Ok(EndianSlice::new(data, Endian)) } else { - if let Some(name) = id.xcoff_name() { - let data = object.section(stash, name).unwrap_or(&[]); - Ok(EndianSlice::new(data, Endian)) - } else { - Ok(EndianSlice::new(&[], Endian)) - } + Ok(EndianSlice::new(&[], Endian)) } }) .ok()?; @@ -226,7 +224,7 @@ cfg_if::cfg_if! { target_os = "hurd", target_os = "openbsd", target_os = "netbsd", - all(target_os = "android", feature = "dl_iterate_phdr"), + target_os = "android", ), not(target_env = "uclibc"), ))] {