Skip to content

Commit b36a10a

Browse files
authored
Rollup merge of #101598 - chriswailes:sanitizers, r=nagisa,eholk
Update rustc's information on Android's sanitizers This patch updates sanitizer 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.
2 parents c10f7d7 + 3d5a417 commit b36a10a

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
@@ -1381,6 +1381,8 @@ pub struct TargetOptions {
13811381
pub is_like_msvc: bool,
13821382
/// Whether a target toolchain is like WASM.
13831383
pub is_like_wasm: bool,
1384+
/// Whether a target toolchain is like Android, implying a Linux kernel and a Bionic libc
1385+
pub is_like_android: bool,
13841386
/// Default supported version of DWARF on this platform.
13851387
/// Useful because some platforms (osx, bsd) only want up to DWARF2.
13861388
pub default_dwarf_version: u32,
@@ -1673,6 +1675,7 @@ impl Default for TargetOptions {
16731675
is_like_windows: false,
16741676
is_like_msvc: false,
16751677
is_like_wasm: false,
1678+
is_like_android: false,
16761679
default_dwarf_version: 4,
16771680
allows_weak_linkage: true,
16781681
has_rpath: false,
@@ -2320,6 +2323,7 @@ impl Target {
23202323
key!(is_like_windows, bool);
23212324
key!(is_like_msvc, bool);
23222325
key!(is_like_wasm, bool);
2326+
key!(is_like_android, bool);
23232327
key!(default_dwarf_version, u32);
23242328
key!(allows_weak_linkage, bool);
23252329
key!(has_rpath, bool);
@@ -2570,6 +2574,7 @@ impl ToJson for Target {
25702574
target_option_val!(is_like_windows);
25712575
target_option_val!(is_like_msvc);
25722576
target_option_val!(is_like_wasm);
2577+
target_option_val!(is_like_android);
25732578
target_option_val!(default_dwarf_version);
25742579
target_option_val!(allows_weak_linkage);
25752580
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)