diff --git a/library/std/build.rs b/library/std/build.rs index 83073cc77dd1a..04bfed12153ec 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -16,6 +16,9 @@ fn main() { } else if target.contains("freebsd") { println!("cargo:rustc-link-lib=execinfo"); println!("cargo:rustc-link-lib=pthread"); + if env::var("RUST_STD_FREEBSD_12_ABI").is_ok() { + println!("cargo:rustc-cfg=freebsd12"); + } } else if target.contains("netbsd") { println!("cargo:rustc-link-lib=pthread"); println!("cargo:rustc-link-lib=rt"); diff --git a/library/std/src/os/freebsd/fs.rs b/library/std/src/os/freebsd/fs.rs index c6a00e179bd7f..1eda8690d5d1b 100644 --- a/library/std/src/os/freebsd/fs.rs +++ b/library/std/src/os/freebsd/fs.rs @@ -74,7 +74,14 @@ pub trait MetadataExt { impl MetadataExt for Metadata { #[allow(deprecated)] fn as_raw_stat(&self) -> &raw::stat { - unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) } + // The methods below use libc::stat, so they work fine when libc is built with FreeBSD 12 ABI. + // This method would just return nonsense. + #[cfg(freebsd12)] + panic!("as_raw_stat not supported with FreeBSD 12 ABI"); + #[cfg(not(freebsd12))] + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) + } } fn st_dev(&self) -> u64 { self.as_inner().as_inner().st_dev as u64 @@ -136,6 +143,11 @@ impl MetadataExt for Metadata { fn st_flags(&self) -> u32 { self.as_inner().as_inner().st_flags as u32 } + #[cfg(freebsd12)] + fn st_lspare(&self) -> u32 { + panic!("st_lspare not supported with FreeBSD 12 ABI"); + } + #[cfg(not(freebsd12))] fn st_lspare(&self) -> u32 { self.as_inner().as_inner().st_lspare as u32 } diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 7d9b442e6468b..f1bc3d11d8b77 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -794,6 +794,7 @@ fn supported_sanitizers( } "x86_64-apple-darwin" => darwin_libs("osx", &["asan", "lsan", "tsan"]), "x86_64-fuchsia" => common_libs("fuchsia", "x86_64", &["asan"]), + "x86_64-unknown-freebsd" => common_libs("freebsd", "x86_64", &["asan", "msan", "tsan"]), "x86_64-unknown-linux-gnu" => { common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"]) } diff --git a/src/ci/docker/host-x86_64/dist-x86_64-freebsd/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-freebsd/Dockerfile index 766e6531c9507..bfc768f993512 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-freebsd/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-x86_64-freebsd/Dockerfile @@ -29,5 +29,5 @@ ENV \ ENV HOSTS=x86_64-unknown-freebsd -ENV RUST_CONFIGURE_ARGS --enable-extended --enable-profiler --disable-docs +ENV RUST_CONFIGURE_ARGS --enable-extended --enable-profiler --enable-sanitizers --disable-docs ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 5de7ffbcfcbfb..bfcf979d12548 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -822,6 +822,7 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) { "aarch64-fuchsia" | "aarch64-unknown-linux-gnu" | "x86_64-fuchsia" + | "x86_64-unknown-freebsd" | "x86_64-unknown-linux-gnu" => { let filename = format!("librustc{}_rt.{}.a", channel, name); let path = default_tlib.join(&filename); diff --git a/src/librustc_session/session.rs b/src/librustc_session/session.rs index 9191f7e8d76be..66dbe53bac387 100644 --- a/src/librustc_session/session.rs +++ b/src/librustc_session/session.rs @@ -1453,14 +1453,19 @@ fn validate_commandline_args_with_session_available(sess: &Session) { "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-fuchsia", + "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu", ]; const LSAN_SUPPORTED_TARGETS: &[&str] = &["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]; const MSAN_SUPPORTED_TARGETS: &[&str] = - &["aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu"]; - const TSAN_SUPPORTED_TARGETS: &[&str] = - &["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]; + &["aarch64-unknown-linux-gnu", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"]; + const TSAN_SUPPORTED_TARGETS: &[&str] = &[ + "aarch64-unknown-linux-gnu", + "x86_64-apple-darwin", + "x86_64-unknown-freebsd", + "x86_64-unknown-linux-gnu", + ]; // Sanitizers can only be used on some tested platforms. for s in sess.opts.debugging_opts.sanitizer { diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index ddd7941b11469..a776bb0bfe481 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -87,6 +87,7 @@ pub const ASAN_SUPPORTED_TARGETS: &'static [&'static str] = &[ "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-fuchsia", + "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu", ]; @@ -94,10 +95,14 @@ pub const LSAN_SUPPORTED_TARGETS: &'static [&'static str] = &["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]; pub const MSAN_SUPPORTED_TARGETS: &'static [&'static str] = - &["aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu"]; + &["aarch64-unknown-linux-gnu", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"]; -pub const TSAN_SUPPORTED_TARGETS: &'static [&'static str] = - &["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]; +pub const TSAN_SUPPORTED_TARGETS: &'static [&'static str] = &[ + "aarch64-unknown-linux-gnu", + "x86_64-apple-darwin", + "x86_64-unknown-freebsd", + "x86_64-unknown-linux-gnu", +]; const BIG_ENDIAN: &'static [&'static str] = &[ "armebv7r",