Skip to content

Commit

Permalink
Add RUST_STD_FREEBSD_12_ABI env variable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
valpackett committed Jul 31, 2020
1 parent b316642 commit baaf084
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions library/std/src/os/freebsd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ pub trait MetadataExt {
impl MetadataExt for Metadata {
#[allow(deprecated)]
fn as_raw_stat(&self) -> &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 {
Expand Down Expand Up @@ -137,6 +142,9 @@ impl MetadataExt for Metadata {
self.as_inner().as_inner().st_flags as u32
}
fn st_lspare(&self) -> u32 {
#[cfg(freebsd12)]
panic!("st_lspare not supported with FreeBSD 12 ABI");
#[cfg(not(freebsd12))]
self.as_inner().as_inner().st_lspare as u32
}
}

0 comments on commit baaf084

Please sign in to comment.