Skip to content

Disable CFI for weakly linked syscalls #138002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions library/std/src/sys/fs/unix.rs
Original file line number Diff line number Diff line change
@@ -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",
3 changes: 3 additions & 0 deletions library/std/src/sys/pal/unix/fd.rs
Original file line number Diff line number Diff line change
@@ -251,6 +251,9 @@ impl FileDesc {
}

#[cfg(all(target_os = "android", target_pointer_width = "32"))]
// FIXME(#115199): Rust currently omits weak function definitions
// and its metadata from LLVM IR.
#[no_sanitize(cfi)]
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
super::weak::weak!(fn preadv64(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);

3 changes: 3 additions & 0 deletions library/std/src/sys/pal/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
@@ -434,6 +434,9 @@ impl Command {
target_os = "nto",
target_vendor = "apple",
))]
// FIXME(#115199): Rust currently omits weak function definitions
// and its metadata from LLVM IR.
#[cfg_attr(target_os = "linux", no_sanitize(cfi))]
fn posix_spawn(
&mut self,
stdio: &ChildPipes,
3 changes: 3 additions & 0 deletions library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
@@ -188,6 +188,9 @@ impl Thread {
}

#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "nto"))]
// FIXME(#115199): Rust currently omits weak function definitions
// and its metadata from LLVM IR.
#[no_sanitize(cfi)]
pub fn set_name(name: &CStr) {
weak! {
fn pthread_setname_np(
11 changes: 11 additions & 0 deletions library/std/src/sys/pal/unix/time.rs
Original file line number Diff line number Diff line change
@@ -96,6 +96,17 @@ impl Timespec {
}
}

// FIXME(#115199): Rust currently omits weak function definitions
// and its metadata from LLVM IR.
#[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;
3 changes: 3 additions & 0 deletions library/std/src/sys/pal/unix/weak.rs
Original file line number Diff line number Diff line change
@@ -144,6 +144,9 @@ unsafe fn fetch(name: &str) -> *mut libc::c_void {
#[cfg(not(any(target_os = "linux", target_os = "android")))]
pub(crate) macro syscall {
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
// FIXME(#115199): Rust currently omits weak function definitions
// and its metadata from LLVM IR.
#[no_sanitize(cfi)]
unsafe fn $name($($arg_name: $t),*) -> $ret {
weak! { fn $name($($t),*) -> $ret }