Skip to content

Commit 8cecdbd

Browse files
committed
Auto 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 d629883 + e5e2616 commit 8cecdbd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

std/build.rs

Lines changed: 3 additions & 0 deletions
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");

std/src/os/freebsd/fs.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ pub trait MetadataExt {
7474
impl MetadataExt for Metadata {
7575
#[allow(deprecated)]
7676
fn as_raw_stat(&self) -> &raw::stat {
77-
unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const 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))]
82+
unsafe {
83+
&*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat)
84+
}
7885
}
7986
fn st_dev(&self) -> u64 {
8087
self.as_inner().as_inner().st_dev as u64
@@ -136,6 +143,11 @@ impl MetadataExt for Metadata {
136143
fn st_flags(&self) -> u32 {
137144
self.as_inner().as_inner().st_flags as u32
138145
}
146+
#[cfg(freebsd12)]
147+
fn st_lspare(&self) -> u32 {
148+
panic!("st_lspare not supported with FreeBSD 12 ABI");
149+
}
150+
#[cfg(not(freebsd12))]
139151
fn st_lspare(&self) -> u32 {
140152
self.as_inner().as_inner().st_lspare as u32
141153
}

0 commit comments

Comments
 (0)