From 3d5a41724bd72c228a9e26a44a55337672c7dee3 Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Thu, 8 Sep 2022 16:33:44 -0700 Subject: [PATCH] Update rustc's information on Android's sanitizers This patch updates sanitizier support definitions for Android inside the compiler. It also adjusts the logic to make sure no pre-built sanitizer runtime libraries are emitted as these are instead provided dynamically on Android targets. --- compiler/rustc_codegen_ssa/src/back/link.rs | 11 ++++++----- compiler/rustc_target/src/spec/android_base.rs | 4 +++- .../rustc_target/src/spec/i686_unknown_linux_gnu.rs | 3 ++- compiler/rustc_target/src/spec/mod.rs | 5 +++++ src/tools/compiletest/src/util.rs | 6 ++++++ 5 files changed, 22 insertions(+), 7 deletions(-) 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 dc16739bd56..24d2f3f43f1 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1379,6 +1379,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, @@ -1671,6 +1673,7 @@ fn default() -> 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, @@ -2318,6 +2321,7 @@ macro_rules! key { 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); @@ -2568,6 +2572,7 @@ macro_rules! target_option_val { 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 @@ 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", ];