Skip to content

Commit 9fdc807

Browse files
authored
Rollup merge of rust-lang#74576 - myfreeweb:freebsd-sanitizers, r=oli-obk
Add sanitizer support on FreeBSD Restarting rust-lang#47337. Everything is better now, no more weird llvm problems, well not everything: Unfortunately, the sanitizers don't have proper support for versioned symbols (google/sanitizers#628), so `libc`'s usage of `stat@FBSD_1.0` and so on explodes, e.g. in calling `std::fs::metadata`. Building std (now easy thanks to cargo `-Zbuild-std`) and libc with `freebsd12/13` config via the `LIBC_CI=1` env variable is a good workaround… ``` LIBC_CI=1 RUSTFLAGS="-Z sanitizer=address" cargo +san-test -Zbuild-std run --target x86_64-unknown-freebsd --verbose ``` …*except* std won't build because there's no `st_lspare` in the ino64 version of the struct, so an std patch is required: ```diff --- i/src/libstd/os/freebsd/fs.rs +++ w/src/libstd/os/freebsd/fs.rs @@ -66,8 +66,6 @@ pub trait MetadataExt { fn st_flags(&self) -> u32; #[stable(feature = "metadata_ext2", since = "1.8.0")] fn st_gen(&self) -> u32; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_lspare(&self) -> u32; } #[stable(feature = "metadata_ext", since = "1.1.0")] @@ -136,7 +134,4 @@ impl MetadataExt for Metadata { fn st_flags(&self) -> u32 { self.as_inner().as_inner().st_flags as u32 } - fn st_lspare(&self) -> u32 { - self.as_inner().as_inner().st_lspare as u32 - } } ``` I guess std could like.. detect that `libc` isn't built for the old ABI, and replace the implementation of `st_lspare` with a panic?
2 parents 62f9aa9 + baaf084 commit 9fdc807

File tree

7 files changed

+30
-7
lines changed

7 files changed

+30
-7
lines changed

library/std/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ fn main() {
1616
} else if target.contains("freebsd") {
1717
println!("cargo:rustc-link-lib=execinfo");
1818
println!("cargo:rustc-link-lib=pthread");
19+
if env::var("RUST_STD_FREEBSD_12_ABI").is_ok() {
20+
println!("cargo:rustc-cfg=freebsd12");
21+
}
1922
} else if target.contains("netbsd") {
2023
println!("cargo:rustc-link-lib=pthread");
2124
println!("cargo:rustc-link-lib=rt");

library/std/src/os/freebsd/fs.rs

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ pub trait MetadataExt {
7474
impl MetadataExt for Metadata {
7575
#[allow(deprecated)]
7676
fn as_raw_stat(&self) -> &raw::stat {
77+
// The methods below use libc::stat, so they work fine when libc is built with FreeBSD 12 ABI.
78+
// This method would just return nonsense.
79+
#[cfg(freebsd12)]
80+
panic!("as_raw_stat not supported with FreeBSD 12 ABI");
81+
#[cfg(not(freebsd12))]
7782
unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) }
7883
}
7984
fn st_dev(&self) -> u64 {
@@ -137,6 +142,9 @@ impl MetadataExt for Metadata {
137142
self.as_inner().as_inner().st_flags as u32
138143
}
139144
fn st_lspare(&self) -> u32 {
145+
#[cfg(freebsd12)]
146+
panic!("st_lspare not supported with FreeBSD 12 ABI");
147+
#[cfg(not(freebsd12))]
140148
self.as_inner().as_inner().st_lspare as u32
141149
}
142150
}

src/bootstrap/native.rs

+1
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ fn supported_sanitizers(
786786
}
787787
"x86_64-apple-darwin" => darwin_libs("osx", &["asan", "lsan", "tsan"]),
788788
"x86_64-fuchsia" => common_libs("fuchsia", "x86_64", &["asan"]),
789+
"x86_64-unknown-freebsd" => common_libs("freebsd", "x86_64", &["asan", "msan", "tsan"]),
789790
"x86_64-unknown-linux-gnu" => {
790791
common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
791792
}

src/ci/docker/host-x86_64/dist-x86_64-freebsd/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ ENV \
2929

3030
ENV HOSTS=x86_64-unknown-freebsd
3131

32-
ENV RUST_CONFIGURE_ARGS --enable-extended --enable-profiler --disable-docs
32+
ENV RUST_CONFIGURE_ARGS --enable-extended --enable-profiler --enable-sanitizers --disable-docs
3333
ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS

src/librustc_codegen_ssa/back/link.rs

+1
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
818818
"aarch64-fuchsia"
819819
| "aarch64-unknown-linux-gnu"
820820
| "x86_64-fuchsia"
821+
| "x86_64-unknown-freebsd"
821822
| "x86_64-unknown-linux-gnu" => {
822823
let filename = format!("librustc{}_rt.{}.a", channel, name);
823824
let path = default_tlib.join(&filename);

src/librustc_session/session.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1376,14 +1376,19 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
13761376
"aarch64-unknown-linux-gnu",
13771377
"x86_64-apple-darwin",
13781378
"x86_64-fuchsia",
1379+
"x86_64-unknown-freebsd",
13791380
"x86_64-unknown-linux-gnu",
13801381
];
13811382
const LSAN_SUPPORTED_TARGETS: &[&str] =
13821383
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
13831384
const MSAN_SUPPORTED_TARGETS: &[&str] =
1384-
&["aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu"];
1385-
const TSAN_SUPPORTED_TARGETS: &[&str] =
1386-
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
1385+
&["aarch64-unknown-linux-gnu", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"];
1386+
const TSAN_SUPPORTED_TARGETS: &[&str] = &[
1387+
"aarch64-unknown-linux-gnu",
1388+
"x86_64-apple-darwin",
1389+
"x86_64-unknown-freebsd",
1390+
"x86_64-unknown-linux-gnu",
1391+
];
13871392

13881393
// Sanitizers can only be used on some tested platforms.
13891394
for s in sess.opts.debugging_opts.sanitizer {

src/tools/compiletest/src/util.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,22 @@ pub const ASAN_SUPPORTED_TARGETS: &'static [&'static str] = &[
8787
"aarch64-unknown-linux-gnu",
8888
"x86_64-apple-darwin",
8989
"x86_64-fuchsia",
90+
"x86_64-unknown-freebsd",
9091
"x86_64-unknown-linux-gnu",
9192
];
9293

9394
pub const LSAN_SUPPORTED_TARGETS: &'static [&'static str] =
9495
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
9596

9697
pub const MSAN_SUPPORTED_TARGETS: &'static [&'static str] =
97-
&["aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu"];
98+
&["aarch64-unknown-linux-gnu", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"];
9899

99-
pub const TSAN_SUPPORTED_TARGETS: &'static [&'static str] =
100-
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
100+
pub const TSAN_SUPPORTED_TARGETS: &'static [&'static str] = &[
101+
"aarch64-unknown-linux-gnu",
102+
"x86_64-apple-darwin",
103+
"x86_64-unknown-freebsd",
104+
"x86_64-unknown-linux-gnu",
105+
];
101106

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

0 commit comments

Comments
 (0)