about summary refs log tree commit diff
path: root/library/std/src/sys/fs
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-03-11 19:35:28 +0100
committerGitHub <noreply@github.com>2025-03-11 19:35:28 +0100
commit9746ac5c2f59b557e15b3c48e2b2b0cf4e17b64a (patch)
tree06987bf348c8ff552f92f753047b389c2bc12aa7 /library/std/src/sys/fs
parent8a2e3acb450ccbd361394c31334d5b361b28b8fa (diff)
parente5dc1e378619b11b296a953ca08abb2cdf38f9e0 (diff)
Rollup merge of #138002 - 1c3t3a:fix-std-cfi-violation, r=rcvalle
Disable CFI for weakly linked syscalls

Currently, when enabling CFI via -Zsanitizer=cfi and executing e.g. std::sys::random::getrandom, we can observe a CFI violation. This is the case for all consumers of the std::sys::pal::weak::syscall macro, as it is defining weak functions which don't show up in LLVM IR metadata. CFI fails for all these functions.

Similar to other such cases in
https://github.com/rust-lang/rust/issues/115199, this change stops emitting the CFI typecheck for consumers of the macro via the `#[no_sanitize(cfi)]` attribute.

r? ``````@rcvalle``````
Diffstat (limited to 'library/std/src/sys/fs')
-rw-r--r--library/std/src/sys/fs/unix.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/library/std/src/sys/fs/unix.rs b/library/std/src/sys/fs/unix.rs
index 914971934bf..d944bc9c9a2 100644
--- a/library/std/src/sys/fs/unix.rs
+++ b/library/std/src/sys/fs/unix.rs
@@ -1454,6 +1454,20 @@ impl File {
         Ok(())
     }
 
+    // FIXME(#115199): Rust currently omits weak function definitions
+    // and its metadata from LLVM IR.
+    #[cfg_attr(
+        any(
+            target_os = "android",
+            all(
+                target_os = "linux",
+                target_env = "gnu",
+                target_pointer_width = "32",
+                not(target_arch = "riscv32")
+            )
+        ),
+        no_sanitize(cfi)
+    )]
     pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
         #[cfg(not(any(
             target_os = "redox",