about summary refs log tree commit diff
path: root/library/std/src/sys/pal/unix/time.rs
diff options
context:
space:
mode:
authorBastian Kersting <bkersting@google.com>2025-03-04 14:31:03 +0000
committerBastian Kersting <bkersting@google.com>2025-03-10 08:51:04 +0000
commit02bb2d4410d4db07c40bed308f8ba0d2af28d069 (patch)
tree97fb3aef92817f4f48d15a852731e34ebc87d6b5 /library/std/src/sys/pal/unix/time.rs
parent2c6a12ec44d0426c8939123c2f2cf27d2217de13 (diff)
downloadrust-02bb2d4410d4db07c40bed308f8ba0d2af28d069.tar.gz
rust-02bb2d4410d4db07c40bed308f8ba0d2af28d069.zip
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::weak 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.
Diffstat (limited to 'library/std/src/sys/pal/unix/time.rs')
-rw-r--r--library/std/src/sys/pal/unix/time.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/library/std/src/sys/pal/unix/time.rs b/library/std/src/sys/pal/unix/time.rs
index 0271626380c..fc60c307f34 100644
--- a/library/std/src/sys/pal/unix/time.rs
+++ b/library/std/src/sys/pal/unix/time.rs
@@ -96,6 +96,15 @@ impl Timespec {
         }
     }
 
+    #[cfg_attr(
+        all(
+            target_os = "linux",
+            target_env = "gnu",
+            target_pointer_width = "32",
+            not(target_arch = "riscv32")
+        ),
+        no_sanitize(cfi)
+    )]
     pub fn now(clock: libc::clockid_t) -> Timespec {
         use crate::mem::MaybeUninit;
         use crate::sys::cvt;