Skip to content

Commit 7aa65fa

Browse files
authored
Rollup merge of rust-lang#73058 - tmiasko:aarch64-san, r=nagisa
Support sanitizers on aarch64-unknown-linux-gnu
2 parents 52e8dcb + 66e7a14 commit 7aa65fa

File tree

6 files changed

+60
-49
lines changed

6 files changed

+60
-49
lines changed

src/bootstrap/native.rs

+30-37
Original file line numberDiff line numberDiff line change
@@ -689,48 +689,41 @@ fn supported_sanitizers(
689689
target: Interned<String>,
690690
channel: &str,
691691
) -> Vec<SanitizerRuntime> {
692-
let mut result = Vec::new();
692+
let darwin_libs = |os: &str, components: &[&str]| -> Vec<SanitizerRuntime> {
693+
components
694+
.into_iter()
695+
.map(move |c| SanitizerRuntime {
696+
cmake_target: format!("clang_rt.{}_{}_dynamic", c, os),
697+
path: out_dir
698+
.join(&format!("build/lib/darwin/libclang_rt.{}_{}_dynamic.dylib", c, os)),
699+
name: format!("librustc-{}_rt.{}.dylib", channel, c),
700+
})
701+
.collect()
702+
};
703+
704+
let common_libs = |os: &str, arch: &str, components: &[&str]| -> Vec<SanitizerRuntime> {
705+
components
706+
.into_iter()
707+
.map(move |c| SanitizerRuntime {
708+
cmake_target: format!("clang_rt.{}-{}", c, arch),
709+
path: out_dir.join(&format!("build/lib/{}/libclang_rt.{}-{}.a", os, c, arch)),
710+
name: format!("librustc-{}_rt.{}.a", channel, c),
711+
})
712+
.collect()
713+
};
714+
693715
match &*target {
694-
"x86_64-apple-darwin" => {
695-
for s in &["asan", "lsan", "tsan"] {
696-
result.push(SanitizerRuntime {
697-
cmake_target: format!("clang_rt.{}_osx_dynamic", s),
698-
path: out_dir
699-
.join(&format!("build/lib/darwin/libclang_rt.{}_osx_dynamic.dylib", s)),
700-
name: format!("librustc-{}_rt.{}.dylib", channel, s),
701-
});
702-
}
716+
"aarch64-fuchsia" => common_libs("fuchsia", "aarch64", &["asan"]),
717+
"aarch64-unknown-linux-gnu" => {
718+
common_libs("linux", "aarch64", &["asan", "lsan", "msan", "tsan"])
703719
}
720+
"x86_64-apple-darwin" => darwin_libs("osx", &["asan", "lsan", "tsan"]),
721+
"x86_64-fuchsia" => common_libs("fuchsia", "x86_64", &["asan"]),
704722
"x86_64-unknown-linux-gnu" => {
705-
for s in &["asan", "lsan", "msan", "tsan"] {
706-
result.push(SanitizerRuntime {
707-
cmake_target: format!("clang_rt.{}-x86_64", s),
708-
path: out_dir.join(&format!("build/lib/linux/libclang_rt.{}-x86_64.a", s)),
709-
name: format!("librustc-{}_rt.{}.a", channel, s),
710-
});
711-
}
712-
}
713-
"x86_64-fuchsia" => {
714-
for s in &["asan"] {
715-
result.push(SanitizerRuntime {
716-
cmake_target: format!("clang_rt.{}-x86_64", s),
717-
path: out_dir.join(&format!("build/lib/fuchsia/libclang_rt.{}-x86_64.a", s)),
718-
name: format!("librustc-{}_rt.{}.a", channel, s),
719-
});
720-
}
721-
}
722-
"aarch64-fuchsia" => {
723-
for s in &["asan"] {
724-
result.push(SanitizerRuntime {
725-
cmake_target: format!("clang_rt.{}-aarch64", s),
726-
path: out_dir.join(&format!("build/lib/fuchsia/libclang_rt.{}-aarch64.a", s)),
727-
name: format!("librustc-{}_rt.{}.a", channel, s),
728-
});
729-
}
723+
common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
730724
}
731-
_ => {}
725+
_ => Vec::new(),
732726
}
733-
result
734727
}
735728

736729
struct HashStamp {

src/ci/docker/dist-aarch64-linux/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ ENV HOSTS=aarch64-unknown-linux-gnu
3535
ENV RUST_CONFIGURE_ARGS \
3636
--enable-full-tools \
3737
--enable-profiler \
38+
--enable-sanitizers \
3839
--disable-docs
3940
ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS

src/librustc_codegen_ssa/back/link.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,10 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
804804
linker.args(&["-Wl,-rpath", "-Xlinker", rpath]);
805805
linker.link_dylib(Symbol::intern(&libname));
806806
}
807-
"x86_64-unknown-linux-gnu" | "x86_64-fuchsia" | "aarch64-fuchsia" => {
807+
"aarch64-fuchsia"
808+
| "aarch64-unknown-linux-gnu"
809+
| "x86_64-fuchsia"
810+
| "x86_64-unknown-linux-gnu" => {
808811
let filename = format!("librustc{}_rt.{}.a", channel, name);
809812
let path = default_tlib.join(&filename);
810813
linker.link_whole_rlib(&path);

src/librustc_session/session.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -1349,11 +1349,19 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
13491349
);
13501350
}
13511351

1352-
const ASAN_SUPPORTED_TARGETS: &[&str] =
1353-
&["aarch64-fuchsia", "x86_64-apple-darwin", "x86_64-fuchsia", "x86_64-unknown-linux-gnu"];
1354-
const LSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
1355-
const MSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"];
1356-
const TSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
1352+
const ASAN_SUPPORTED_TARGETS: &[&str] = &[
1353+
"aarch64-fuchsia",
1354+
"aarch64-unknown-linux-gnu",
1355+
"x86_64-apple-darwin",
1356+
"x86_64-fuchsia",
1357+
"x86_64-unknown-linux-gnu",
1358+
];
1359+
const LSAN_SUPPORTED_TARGETS: &[&str] =
1360+
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
1361+
const MSAN_SUPPORTED_TARGETS: &[&str] =
1362+
&["aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu"];
1363+
const TSAN_SUPPORTED_TARGETS: &[&str] =
1364+
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
13571365

13581366
// Sanitizers can only be used on some tested platforms.
13591367
for s in sess.opts.debugging_opts.sanitizer {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `-Zsanitizer=leak` only works with targets: x86_64-apple-darwin, x86_64-unknown-linux-gnu
1+
error: `-Zsanitizer=leak` only works with targets: aarch64-unknown-linux-gnu, x86_64-apple-darwin, x86_64-unknown-linux-gnu
22

33
error: aborting due to previous error
44

src/tools/compiletest/src/util.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,22 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
8282
("xcore", "xcore"),
8383
];
8484

85-
pub const ASAN_SUPPORTED_TARGETS: &'static [&'static str] =
86-
&["aarch64-fuchsia", "x86_64-apple-darwin", "x86_64-fuchsia", "x86_64-unknown-linux-gnu"];
85+
pub const ASAN_SUPPORTED_TARGETS: &'static [&'static str] = &[
86+
"aarch64-fuchsia",
87+
"aarch64-unknown-linux-gnu",
88+
"x86_64-apple-darwin",
89+
"x86_64-fuchsia",
90+
"x86_64-unknown-linux-gnu",
91+
];
8792

8893
pub const LSAN_SUPPORTED_TARGETS: &'static [&'static str] =
89-
&["x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
94+
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
9095

91-
pub const MSAN_SUPPORTED_TARGETS: &'static [&'static str] = &["x86_64-unknown-linux-gnu"];
96+
pub const MSAN_SUPPORTED_TARGETS: &'static [&'static str] =
97+
&["aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu"];
9298

9399
pub const TSAN_SUPPORTED_TARGETS: &'static [&'static str] =
94-
&["x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
100+
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
95101

96102
pub fn matches_os(triple: &str, name: &str) -> bool {
97103
// For the wasm32 bare target we ignore anything also ignored on emscripten

0 commit comments

Comments
 (0)