]> git.lizzy.rs Git - rust.git/commitdiff
Add RUST_STD_FREEBSD_12_ABI env variable
authorGreg V <greg@unrelenting.technology>
Thu, 30 Jul 2020 23:55:12 +0000 (02:55 +0300)
committerGreg V <greg@unrelenting.technology>
Sun, 9 Aug 2020 14:52:00 +0000 (17:52 +0300)
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]: https://github.com/google/sanitizers/issues/628

library/std/build.rs
library/std/src/os/freebsd/fs.rs

index 83073cc77dd1a12354ce6b9e535804e83f33e27e..04bfed12153ec42a3f3e69893fd2a2ffe80a3a0e 100644 (file)
@@ -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");
index 6798e0d8f44fa146a337a8b8f7175863b5634e87..fa440548050783163770a897d5e3a34e556662fb 100644 (file)
@@ -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 @@ fn st_gen(&self) -> u32 {
     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
     }