Skip to content

Commit aacf321

Browse files
committed
Add sanitizer support for modern iOS platforms
asan and tsan generally support iOS, but that previously wasn't configured in rust. This only adds support for the simulator architectures, and arm64 device architecture, not the older 32 bit architectures.
1 parent 5b8f284 commit aacf321

File tree

6 files changed

+49
-10
lines changed

6 files changed

+49
-10
lines changed

compiler/rustc_target/src/spec/aarch64_apple_ios.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use super::apple_base::{ios_llvm_target, opts, Arch};
2-
use crate::spec::{FramePointer, Target, TargetOptions};
2+
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let arch = Arch::Arm64;
6+
let mut base = opts("ios", arch);
7+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;
8+
69
Target {
710
// Clang automatically chooses a more specific target based on
811
// IPHONEOS_DEPLOYMENT_TARGET.
@@ -28,7 +31,7 @@ pub fn target() -> Target {
2831
darwinpcs\0\
2932
-Os\0"
3033
.into(),
31-
..opts("ios", arch)
34+
..base
3235
},
3336
}
3437
}

compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use super::apple_base::{ios_sim_llvm_target, opts, Arch};
2-
use crate::spec::{FramePointer, Target, TargetOptions};
2+
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let arch = Arch::Arm64_sim;
6+
let mut base = opts("ios", arch);
7+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;
8+
69
Target {
710
// Clang automatically chooses a more specific target based on
811
// IPHONEOS_DEPLOYMENT_TARGET.
@@ -28,7 +31,7 @@ pub fn target() -> Target {
2831
darwinpcs\0\
2932
-Os\0"
3033
.into(),
31-
..opts("ios", arch)
34+
..base
3235
},
3336
}
3437
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use super::apple_base::{ios_sim_llvm_target, opts, Arch};
2-
use crate::spec::{StackProbeType, Target, TargetOptions};
2+
use crate::spec::{SanitizerSet, StackProbeType, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let arch = Arch::X86_64_sim;
6+
let mut base = opts("ios", arch);
7+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;
8+
69
Target {
710
llvm_target: ios_sim_llvm_target(arch).into(),
811
pointer_width: 64,
@@ -12,7 +15,7 @@ pub fn target() -> Target {
1215
options: TargetOptions {
1316
max_atomic_width: Some(64),
1417
stack_probes: StackProbeType::X86,
15-
..opts("ios", arch)
18+
..base
1619
},
1720
}
1821
}

src/bootstrap/compile.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,12 @@ fn copy_sanitizers(
467467
let dst = libdir.join(&runtime.name);
468468
builder.copy(&runtime.path, &dst);
469469

470-
if target == "x86_64-apple-darwin" || target == "aarch64-apple-darwin" {
470+
if target == "x86_64-apple-darwin"
471+
|| target == "aarch64-apple-darwin"
472+
|| target == "aarch64-apple-ios"
473+
|| target == "aarch64-apple-ios-sim"
474+
|| target == "x86_64-apple-ios"
475+
{
471476
// Update the library’s install name to reflect that it has been renamed.
472477
apple_darwin_update_library_name(&dst, &format!("@rpath/{}", &runtime.name));
473478
// Upon renaming the install name, the code signature of the file will invalidate,

src/bootstrap/native.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ impl Step for Llvm {
483483
cfg.define("LLVM_VERSION_SUFFIX", suffix);
484484
}
485485

486-
configure_cmake(builder, target, &mut cfg, true, ldflags);
486+
configure_cmake(builder, target, &mut cfg, true, ldflags, &[]);
487487
configure_llvm(builder, target, &mut cfg);
488488

489489
for (key, val) in &builder.config.llvm_build_config {
@@ -574,6 +574,7 @@ fn configure_cmake(
574574
cfg: &mut cmake::Config,
575575
use_compiler_launcher: bool,
576576
mut ldflags: LdFlags,
577+
extra_compiler_flags: &[&str],
577578
) {
578579
// Do not print installation messages for up-to-date files.
579580
// LLVM and LLD builds can produce a lot of those and hit CI limits on log size.
@@ -714,6 +715,9 @@ fn configure_cmake(
714715
if builder.config.llvm_clang_cl.is_some() {
715716
cflags.push(&format!(" --target={}", target));
716717
}
718+
for flag in extra_compiler_flags {
719+
cflags.push(&format!(" {}", flag));
720+
}
717721
cfg.define("CMAKE_C_FLAGS", cflags);
718722
let mut cxxflags: OsString = builder.cflags(target, GitRepo::Llvm, CLang::Cxx).join(" ").into();
719723
if let Some(ref s) = builder.config.llvm_cxxflags {
@@ -723,6 +727,9 @@ fn configure_cmake(
723727
if builder.config.llvm_clang_cl.is_some() {
724728
cxxflags.push(&format!(" --target={}", target));
725729
}
730+
for flag in extra_compiler_flags {
731+
cxxflags.push(&format!(" {}", flag));
732+
}
726733
cfg.define("CMAKE_CXX_FLAGS", cxxflags);
727734
if let Some(ar) = builder.ar(target) {
728735
if ar.is_absolute() {
@@ -864,7 +871,7 @@ impl Step for Lld {
864871
}
865872
}
866873

867-
configure_cmake(builder, target, &mut cfg, true, ldflags);
874+
configure_cmake(builder, target, &mut cfg, true, ldflags, &[]);
868875
configure_llvm(builder, target, &mut cfg);
869876

870877
// Re-use the same flags as llvm to control the level of debug information
@@ -1028,7 +1035,16 @@ impl Step for Sanitizers {
10281035
// Unfortunately sccache currently lacks support to build them successfully.
10291036
// Disable compiler launcher on Darwin targets to avoid potential issues.
10301037
let use_compiler_launcher = !self.target.contains("apple-darwin");
1031-
configure_cmake(builder, self.target, &mut cfg, use_compiler_launcher, LdFlags::default());
1038+
let extra_compiler_flags: &[&str] =
1039+
if self.target.contains("apple") { &["-fembed-bitcode=off"] } else { &[] };
1040+
configure_cmake(
1041+
builder,
1042+
self.target,
1043+
&mut cfg,
1044+
use_compiler_launcher,
1045+
LdFlags::default(),
1046+
extra_compiler_flags,
1047+
);
10321048

10331049
t!(fs::create_dir_all(&out_dir));
10341050
cfg.out_dir(out_dir);
@@ -1084,12 +1100,15 @@ fn supported_sanitizers(
10841100

10851101
match &*target.triple {
10861102
"aarch64-apple-darwin" => darwin_libs("osx", &["asan", "lsan", "tsan"]),
1103+
"aarch64-apple-ios" => darwin_libs("ios", &["asan", "tsan"]),
1104+
"aarch64-apple-ios-sim" => darwin_libs("iossim", &["asan", "tsan"]),
10871105
"aarch64-unknown-fuchsia" => common_libs("fuchsia", "aarch64", &["asan"]),
10881106
"aarch64-unknown-linux-gnu" => {
10891107
common_libs("linux", "aarch64", &["asan", "lsan", "msan", "tsan", "hwasan"])
10901108
}
10911109
"x86_64-apple-darwin" => darwin_libs("osx", &["asan", "lsan", "tsan"]),
10921110
"x86_64-unknown-fuchsia" => common_libs("fuchsia", "x86_64", &["asan"]),
1111+
"x86_64-apple-ios" => darwin_libs("iossim", &["asan", "tsan"]),
10931112
"x86_64-unknown-freebsd" => common_libs("freebsd", "x86_64", &["asan", "msan", "tsan"]),
10941113
"x86_64-unknown-netbsd" => {
10951114
common_libs("netbsd", "x86_64", &["asan", "lsan", "msan", "tsan"])

src/tools/compiletest/src/util.rs

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ mod tests;
1111

1212
pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[
1313
"aarch64-apple-darwin",
14+
"aarch64-apple-ios",
15+
"aarch64-apple-ios-sim",
1416
"aarch64-unknown-fuchsia",
1517
"aarch64-linux-android",
1618
"aarch64-unknown-linux-gnu",
@@ -19,6 +21,7 @@ pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[
1921
"i686-linux-android",
2022
"i686-unknown-linux-gnu",
2123
"x86_64-apple-darwin",
24+
"x86_64-apple-ios",
2225
"x86_64-unknown-fuchsia",
2326
"x86_64-linux-android",
2427
"x86_64-unknown-freebsd",
@@ -63,8 +66,11 @@ pub const MSAN_SUPPORTED_TARGETS: &[&str] = &[
6366

6467
pub const TSAN_SUPPORTED_TARGETS: &[&str] = &[
6568
"aarch64-apple-darwin",
69+
"aarch64-apple-ios",
70+
"aarch64-apple-ios-sim",
6671
"aarch64-unknown-linux-gnu",
6772
"x86_64-apple-darwin",
73+
"x86_64-apple-ios",
6874
"x86_64-unknown-freebsd",
6975
"x86_64-unknown-linux-gnu",
7076
"s390x-unknown-linux-gnu",

0 commit comments

Comments
 (0)