diff options
author | bors <bors@rust-lang.org> | 2020-08-15 11:38:24 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2020-08-15 11:38:24 +0000 |
commit | 80fb3f3139c7dee7f211964c6a0b3ccb04b83d5e (patch) | |
tree | 75b4e6ba2a2080af0d2a6f36a64d7b52c0e8a20e | |
parent | 1e58871d25c9ef4d2edbc331dedcc7f0543eea15 (diff) | |
parent | ddbc45673b11f706e94fa17730eaa5c113f224d7 (diff) | |
download | rust-80fb3f3139c7dee7f211964c6a0b3ccb04b83d5e.tar.gz |
Auto merge of #74576 - myfreeweb:freebsd-sanitizers, r=oli-obk
Add sanitizer support on FreeBSD
Restarting #47337. Everything is better now, no more weird llvm problems, well not everything:
Unfortunately, the sanitizers don't have proper support for versioned symbols (https://github.com/google/sanitizers/issues/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?
-rw-r--r-- | library/std/build.rs | 3 | ||||
-rw-r--r-- | library/std/src/os/freebsd/fs.rs | 14 | ||||
-rw-r--r-- | src/bootstrap/native.rs | 1 | ||||
-rw-r--r-- | src/ci/docker/host-x86_64/dist-x86_64-freebsd/Dockerfile | 2 | ||||
-rw-r--r-- | src/librustc_codegen_ssa/back/link.rs | 1 | ||||
-rw-r--r-- | src/librustc_session/session.rs | 11 | ||||
-rw-r--r-- | src/tools/compiletest/src/util.rs | 11 |
7 files changed, 35 insertions, 8 deletions
diff --git a/library/std/build.rs b/library/std/build.rs index 83073cc77dd..04bfed12153 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 c6a00e179bd..1eda8690d5d 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 7d9b442e646..f1bc3d11d8b 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 766e6531c95..bfc768f9935 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 5de7ffbcfcb..bfcf979d125 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 9191f7e8d76..66dbe53bac3 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 ddd7941b114..a776bb0bfe4 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", |