Skip to content

Commit 3d5a417

Browse files
committed
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.
1 parent 11bb80a commit 3d5a417

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1090,11 +1090,12 @@ fn add_sanitizer_libraries(sess: &Session, crate_type: CrateType, linker: &mut d
10901090
// both executables and dynamic shared objects. Everywhere else the runtimes
10911091
// are currently distributed as static libraries which should be linked to
10921092
// executables only.
1093-
let needs_runtime = match crate_type {
1094-
CrateType::Executable => true,
1095-
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => sess.target.is_like_osx,
1096-
CrateType::Rlib | CrateType::Staticlib => false,
1097-
};
1093+
let needs_runtime = !sess.target.is_like_android
1094+
&& match crate_type {
1095+
CrateType::Executable => true,
1096+
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => sess.target.is_like_osx,
1097+
CrateType::Rlib | CrateType::Staticlib => false,
1098+
};
10981099

10991100
if !needs_runtime {
11001101
return;

compiler/rustc_target/src/spec/android_base.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::spec::TargetOptions;
1+
use crate::spec::{SanitizerSet, TargetOptions};
22

33
pub fn opts() -> TargetOptions {
44
let mut base = super::linux_base::opts();
55
base.os = "android".into();
6+
base.is_like_android = true;
67
base.default_dwarf_version = 2;
78
base.has_thread_local = false;
9+
base.supported_sanitizers = SanitizerSet::ADDRESS;
810
// This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867
911
// for context. (At that time, there was no `-C force-unwind-tables`, so the only solution
1012
// was to always emit `uwtable`).

compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use crate::spec::{LinkerFlavor, StackProbeType, Target};
1+
use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target};
22

33
pub fn target() -> Target {
44
let mut base = super::linux_gnu_base::opts();
55
base.cpu = "pentium4".into();
66
base.max_atomic_width = Some(64);
7+
base.supported_sanitizers = SanitizerSet::ADDRESS;
78
base.add_pre_link_args(LinkerFlavor::Gcc, &["-m32"]);
89
// don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved
910
base.stack_probes = StackProbeType::Call;

compiler/rustc_target/src/spec/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,8 @@ pub struct TargetOptions {
13791379
pub is_like_msvc: bool,
13801380
/// Whether a target toolchain is like WASM.
13811381
pub is_like_wasm: bool,
1382+
/// Whether a target toolchain is like Android, implying a Linux kernel and a Bionic libc
1383+
pub is_like_android: bool,
13821384
/// Default supported version of DWARF on this platform.
13831385
/// Useful because some platforms (osx, bsd) only want up to DWARF2.
13841386
pub default_dwarf_version: u32,
@@ -1671,6 +1673,7 @@ impl Default for TargetOptions {
16711673
is_like_windows: false,
16721674
is_like_msvc: false,
16731675
is_like_wasm: false,
1676+
is_like_android: false,
16741677
default_dwarf_version: 4,
16751678
allows_weak_linkage: true,
16761679
has_rpath: false,
@@ -2318,6 +2321,7 @@ impl Target {
23182321
key!(is_like_windows, bool);
23192322
key!(is_like_msvc, bool);
23202323
key!(is_like_wasm, bool);
2324+
key!(is_like_android, bool);
23212325
key!(default_dwarf_version, u32);
23222326
key!(allows_weak_linkage, bool);
23232327
key!(has_rpath, bool);
@@ -2568,6 +2572,7 @@ impl ToJson for Target {
25682572
target_option_val!(is_like_windows);
25692573
target_option_val!(is_like_msvc);
25702574
target_option_val!(is_like_wasm);
2575+
target_option_val!(is_like_android);
25712576
target_option_val!(default_dwarf_version);
25722577
target_option_val!(allows_weak_linkage);
25732578
target_option_val!(has_rpath);

src/tools/compiletest/src/util.rs

+6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ mod tests;
1111
pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[
1212
"aarch64-apple-darwin",
1313
"aarch64-fuchsia",
14+
"aarch64-linux-android",
1415
"aarch64-unknown-linux-gnu",
16+
"arm-linux-androideabi",
17+
"armv7-linux-androideabi",
18+
"i686-linux-android",
19+
"i686-unknown-linux-gnu",
1520
"x86_64-apple-darwin",
1621
"x86_64-fuchsia",
22+
"x86_64-linux-android",
1723
"x86_64-unknown-freebsd",
1824
"x86_64-unknown-linux-gnu",
1925
];

0 commit comments

Comments
 (0)