Skip to content

Commit ddbc456

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 2f39477 commit ddbc456

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
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

+13-1
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)