Skip to content

Commit baaf084

Browse files
committed
Add RUST_STD_FREEBSD_12_ABI env variable
Unfortunately, sanitizers do not support versioned symbols[1], so they break filesystem access via the legacy, pre-ino64 ABI. To use sanitizers on FreeBSD >= 12, we need to build the libc crate with LIBC_CI=1 to use the new ABI -- including the libc used for std. But that removes the st_lspare field std was expecting for the deprecated metadata extension. Add a way to skip that field to allow the build to work. [1]: google/sanitizers#628
1 parent b316642 commit baaf084

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Diff for: 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");

Diff for: 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
}

0 commit comments

Comments
 (0)