diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index c5e18c7fae8..bb57fca74a2 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1090,11 +1090,12 @@ fn add_sanitizer_libraries(sess: &Session, crate_type: CrateType, linker: &mut d // both executables and dynamic shared objects. Everywhere else the runtimes // are currently distributed as static libraries which should be linked to // executables only. - let needs_runtime = match crate_type { - CrateType::Executable => true, - CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => sess.target.is_like_osx, - CrateType::Rlib | CrateType::Staticlib => false, - }; + let needs_runtime = !sess.target.is_like_android + && match crate_type { + CrateType::Executable => true, + CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => sess.target.is_like_osx, + CrateType::Rlib | CrateType::Staticlib => false, + }; if !needs_runtime { return; diff --git a/compiler/rustc_target/src/spec/android_base.rs b/compiler/rustc_target/src/spec/android_base.rs index 9f3e0bd5ef0..9c1df1a0677 100644 --- a/compiler/rustc_target/src/spec/android_base.rs +++ b/compiler/rustc_target/src/spec/android_base.rs @@ -1,10 +1,12 @@ -use crate::spec::TargetOptions; +use crate::spec::{SanitizerSet, TargetOptions}; pub fn opts() -> TargetOptions { let mut base = super::linux_base::opts(); base.os = "android".into(); + base.is_like_android = true; base.default_dwarf_version = 2; base.has_thread_local = false; + base.supported_sanitizers = SanitizerSet::ADDRESS; // This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867 // for context. (At that time, there was no `-C force-unwind-tables`, so the only solution // was to always emit `uwtable`). diff --git a/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs index 765803d1692..f62029c9067 100644 --- a/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs @@ -1,9 +1,10 @@ -use crate::spec::{LinkerFlavor, StackProbeType, Target}; +use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); + base.supported_sanitizers = SanitizerSet::ADDRESS; base.add_pre_link_args(LinkerFlavor::Gcc, &["-m32"]); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index f4960b26117..35b4cce50a0 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1381,6 +1381,8 @@ pub struct TargetOptions { pub is_like_msvc: bool, /// Whether a target toolchain is like WASM. pub is_like_wasm: bool, + /// Whether a target toolchain is like Android, implying a Linux kernel and a Bionic libc + pub is_like_android: bool, /// Default supported version of DWARF on this platform. /// Useful because some platforms (osx, bsd) only want up to DWARF2. pub default_dwarf_version: u32, @@ -1673,6 +1675,7 @@ impl Default for TargetOptions { is_like_windows: false, is_like_msvc: false, is_like_wasm: false, + is_like_android: false, default_dwarf_version: 4, allows_weak_linkage: true, has_rpath: false, @@ -2320,6 +2323,7 @@ impl Target { key!(is_like_windows, bool); key!(is_like_msvc, bool); key!(is_like_wasm, bool); + key!(is_like_android, bool); key!(default_dwarf_version, u32); key!(allows_weak_linkage, bool); key!(has_rpath, bool); @@ -2570,6 +2574,7 @@ impl ToJson for Target { target_option_val!(is_like_windows); target_option_val!(is_like_msvc); target_option_val!(is_like_wasm); + target_option_val!(is_like_android); target_option_val!(default_dwarf_version); target_option_val!(allows_weak_linkage); target_option_val!(has_rpath); diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index 9d047b63c85..e5ff0906be8 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -11,9 +11,15 @@ mod tests; pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[ "aarch64-apple-darwin", "aarch64-fuchsia", + "aarch64-linux-android", "aarch64-unknown-linux-gnu", + "arm-linux-androideabi", + "armv7-linux-androideabi", + "i686-linux-android", + "i686-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-fuchsia", + "x86_64-linux-android", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu", ];