Skip to content

Commit

Permalink
Introduce musl_time64_abi cfg flag and set it from build.rs/libc-test
Browse files Browse the repository at this point in the history
Only some 32-bit targets use the time64 family of functions and that set
will not change going forward (new 32-bit targets added will use Y2038
compliant syscalls and types by default).

This patch introduces a cfg flag that controls when the time64 abi
related changes are enabled and sets that flag from libc and libc-tests'
build.rs files.
  • Loading branch information
wesleywiser committed Jan 12, 2023
1 parent 7cf0329 commit e5a7a26
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 188 deletions.
25 changes: 25 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ fn main() {
Some(_) | None => println!("cargo:rustc-cfg=freebsd11"),
}

// Some ABIs need to redirect time related symbols to their time64
// equivalents. See #2088 and #1848 for more information.
if is_musl_time64_abi() {
println!("cargo:rustc-cfg=musl_time64_abi");
}

// On CI: deny all warnings
if libc_ci {
println!("cargo:rustc-cfg=libc_deny_warnings");
Expand Down Expand Up @@ -176,3 +182,22 @@ fn which_freebsd() -> Option<i32> {
_ => None,
}
}

fn is_musl_time64_abi() -> bool {
match env::var("TARGET") {
Ok(target) => match &target[..] {
"arm-unknown-linux-musleabi"
| "arm-unknown-linux-musleabihf"
| "armv5te-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabihf"
| "i586-unknown-linux-musl"
| "i686-unknown-linux-musl"
| "mips-unknown-linux-musl"
| "mipsel-unknown-linux-musl"
| "powerpc-unknown-linux-musl" => true,
_ => false,
},
Err(_) => false,
}
}
17 changes: 17 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3063,6 +3063,23 @@ fn test_linux(target: &str) {
// deprecated since glibc >= 2.29. This allows Rust binaries to link against
// glibc versions older than 2.29.
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);
// Some targets use time64 symbols so set the musl_time64_abi appropriately.
// See #2088 and #1848 for more information.
match target {
"arm-unknown-linux-musleabi"
| "arm-unknown-linux-musleabihf"
| "armv5te-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabihf"
| "i586-unknown-linux-musl"
| "i686-unknown-linux-musl"
| "mips-unknown-linux-musl"
| "mipsel-unknown-linux-musl"
| "powerpc-unknown-linux-musl" => {
cfg.cfg("musl_time64_abi", None);
}
_ => {}
}

headers! { cfg:
"ctype.h",
Expand Down
86 changes: 19 additions & 67 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ s! {
}

pub struct input_event {
#[cfg(all(target_env = "musl", target_pointer_width = "32"))]
#[cfg(musl_time64_abi)]
pub input_event_sec: ::c_ulong,
#[cfg(all(target_env = "musl", target_pointer_width = "32"))]
#[cfg(musl_time64_abi)]
pub input_event_usec: ::c_ulong,
#[cfg(not(all(target_env = "musl", target_pointer_width = "32")))]
#[cfg(not(musl_time64_abi))]
pub time: ::timeval,
pub type_: ::__u16,
pub code: ::__u16,
Expand Down Expand Up @@ -3757,10 +3757,7 @@ cfg_if! {
pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int;
pub fn aio_error(aiocbp: *const aiocb) -> ::c_int;
pub fn aio_return(aiocbp: *mut aiocb) -> ::ssize_t;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__aio_suspend_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__aio_suspend_time64")]
pub fn aio_suspend(
aiocb_list: *const *const aiocb,
nitems: ::c_int,
Expand Down Expand Up @@ -3814,10 +3811,7 @@ cfg_if! {
riovcnt: ::c_ulong,
flags: ::c_ulong,
) -> isize;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__futimes_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__futimes_time64")]
pub fn futimes(
fd: ::c_int,
times: *const ::timeval
Expand Down Expand Up @@ -3845,10 +3839,7 @@ extern "C" {
pub fn seed48(xseed: *mut ::c_ushort) -> *mut ::c_ushort;
pub fn lcong48(p: *mut ::c_ushort);

#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__lutimes_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__lutimes_time64")]
pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int;

pub fn setpwent();
Expand Down Expand Up @@ -3966,15 +3957,9 @@ extern "C" {
pub fn fremovexattr(filedes: ::c_int, name: *const c_char) -> ::c_int;
pub fn signalfd(fd: ::c_int, mask: *const ::sigset_t, flags: ::c_int) -> ::c_int;
pub fn timerfd_create(clockid: ::clockid_t, flags: ::c_int) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__timerfd_gettime64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__timerfd_gettime64")]
pub fn timerfd_gettime(fd: ::c_int, curr_value: *mut itimerspec) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__timerfd_settime64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__timerfd_settime64")]
pub fn timerfd_settime(
fd: ::c_int,
flags: ::c_int,
Expand All @@ -3996,10 +3981,7 @@ extern "C" {
msg_len: ::size_t,
msg_prio: *mut ::c_uint,
) -> ::ssize_t;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__mq_timedreceive_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__mq_timedreceive_time64")]
pub fn mq_timedreceive(
mqd: ::mqd_t,
msg_ptr: *mut ::c_char,
Expand All @@ -4013,10 +3995,7 @@ extern "C" {
msg_len: ::size_t,
msg_prio: ::c_uint,
) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__mq_timedsend_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__mq_timedsend_time64")]
pub fn mq_timedsend(
mqd: ::mqd_t,
msg_ptr: *const ::c_char,
Expand All @@ -4036,10 +4015,7 @@ extern "C" {
pub fn dup3(oldfd: ::c_int, newfd: ::c_int, flags: ::c_int) -> ::c_int;
pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int;
pub fn mkostemps(template: *mut ::c_char, suffixlen: ::c_int, flags: ::c_int) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__sigtimedwait_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__sigtimedwait_time64")]
pub fn sigtimedwait(
set: *const sigset_t,
info: *mut siginfo_t,
Expand Down Expand Up @@ -4155,10 +4131,7 @@ extern "C" {
pub fn umount(target: *const ::c_char) -> ::c_int;
pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int;
pub fn tee(fd_in: ::c_int, fd_out: ::c_int, len: ::size_t, flags: ::c_uint) -> ::ssize_t;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__settimeofday_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__settimeofday_time64")]
pub fn settimeofday(tv: *const ::timeval, tz: *const ::timezone) -> ::c_int;
pub fn splice(
fd_in: ::c_int,
Expand All @@ -4169,15 +4142,9 @@ extern "C" {
flags: ::c_uint,
) -> ::ssize_t;
pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__sched_rr_get_interval_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__sched_rr_get_interval_time64")]
pub fn sched_rr_get_interval(pid: ::pid_t, tp: *mut ::timespec) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__sem_timedwait_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__sem_timedwait_time64")]
pub fn sem_timedwait(sem: *mut sem_t, abstime: *const ::timespec) -> ::c_int;
pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int;
pub fn sched_setparam(pid: ::pid_t, param: *const ::sched_param) -> ::c_int;
Expand All @@ -4199,10 +4166,7 @@ extern "C" {
pub fn personality(persona: ::c_ulong) -> ::c_int;
pub fn prctl(option: ::c_int, ...) -> ::c_int;
pub fn sched_getparam(pid: ::pid_t, param: *mut ::sched_param) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__ppoll_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__ppoll_time64")]
pub fn ppoll(
fds: *mut ::pollfd,
nfds: nfds_t,
Expand All @@ -4218,10 +4182,7 @@ extern "C" {
protocol: ::c_int,
) -> ::c_int;
pub fn pthread_mutex_consistent(mutex: *mut pthread_mutex_t) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__pthread_mutex_timedlock_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__pthread_mutex_timedlock_time64")]
pub fn pthread_mutex_timedlock(
lock: *mut pthread_mutex_t,
abstime: *const ::timespec,
Expand All @@ -4239,10 +4200,7 @@ extern "C" {
...
) -> ::c_int;
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__clock_nanosleep_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__clock_nanosleep_time64")]
pub fn clock_nanosleep(
clk_id: ::clockid_t,
flags: ::c_int,
Expand Down Expand Up @@ -4505,15 +4463,9 @@ extern "C" {
) -> ::c_int;
pub fn timer_delete(timerid: ::timer_t) -> ::c_int;
pub fn timer_getoverrun(timerid: ::timer_t) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__timer_gettime64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__timer_gettime64")]
pub fn timer_gettime(timerid: ::timer_t, curr_value: *mut ::itimerspec) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__timer_settime64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__timer_settime64")]
pub fn timer_settime(
timerid: ::timer_t,
flags: ::c_int,
Expand Down
8 changes: 4 additions & 4 deletions src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ extern "C" {
vlen: ::c_uint,
flags: ::c_uint,
) -> ::c_int;
#[cfg_attr(target_pointer_width = "32", link_name = "__recvmmsg_time64")]
#[cfg_attr(musl_time64_abi, link_name = "__recvmmsg_time64")]
pub fn recvmmsg(
sockfd: ::c_int,
msgvec: *mut ::mmsghdr,
Expand All @@ -714,7 +714,7 @@ extern "C" {
) -> ::c_int;

pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
#[cfg_attr(target_pointer_width = "32", link_name = "__gettimeofday_time64")]
#[cfg_attr(musl_time64_abi, link_name = "__gettimeofday_time64")]
pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
pub fn ptrace(request: ::c_int, ...) -> ::c_long;
pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int;
Expand All @@ -736,9 +736,9 @@ extern "C" {
// Added in `musl` 1.2.2
pub fn reallocarray(ptr: *mut ::c_void, nmemb: ::size_t, size: ::size_t) -> *mut ::c_void;

#[cfg_attr(target_pointer_width = "32", link_name = "__adjtimex_time64")]
#[cfg_attr(musl_time64_abi, link_name = "__adjtimex_time64")]
pub fn adjtimex(buf: *mut ::timex) -> ::c_int;
#[cfg_attr(target_pointer_width = "32", link_name = "__clock_adjtime64")]
#[cfg_attr(musl_time64_abi, link_name = "__clock_adjtime64")]
pub fn clock_adjtime(clk_id: ::clockid_t, buf: *mut ::timex) -> ::c_int;

pub fn ctermid(s: *mut ::c_char) -> *mut ::c_char;
Expand Down
50 changes: 10 additions & 40 deletions src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,20 +1637,11 @@ extern "C" {
pub fn fdatasync(fd: ::c_int) -> ::c_int;
pub fn mincore(addr: *mut ::c_void, len: ::size_t, vec: *mut ::c_uchar) -> ::c_int;

#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__clock_getres_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__clock_getres_time64")]
pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__clock_gettime64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__clock_gettime64")]
pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__clock_settime64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__clock_settime64")]
pub fn clock_settime(clk_id: ::clockid_t, tp: *const ::timespec) -> ::c_int;
pub fn clock_getcpuclockid(pid: ::pid_t, clk_id: *mut ::clockid_t) -> ::c_int;

Expand Down Expand Up @@ -1680,15 +1671,9 @@ extern "C" {
len: ::off64_t,
advise: ::c_int,
) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__futimens_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__futimens_time64")]
pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__utimensat_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__utimensat_time64")]
pub fn utimensat(
dirfd: ::c_int,
path: *const ::c_char,
Expand All @@ -1700,15 +1685,9 @@ extern "C" {
pub fn newlocale(mask: ::c_int, locale: *const ::c_char, base: ::locale_t) -> ::locale_t;
pub fn uselocale(loc: ::locale_t) -> ::locale_t;
pub fn creat64(path: *const c_char, mode: mode_t) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__fstat_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__fstat_time64")]
pub fn fstat64(fildes: ::c_int, buf: *mut stat64) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__fstatat_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__fstatat_time64")]
pub fn fstatat64(
dirfd: ::c_int,
pathname: *const c_char,
Expand All @@ -1717,10 +1696,7 @@ extern "C" {
) -> ::c_int;
pub fn ftruncate64(fd: ::c_int, length: off64_t) -> ::c_int;
pub fn lseek64(fd: ::c_int, offset: off64_t, whence: ::c_int) -> off64_t;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__lstat_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__lstat_time64")]
pub fn lstat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
pub fn mmap64(
addr: *mut ::c_void,
Expand All @@ -1745,10 +1721,7 @@ extern "C" {
entry: *mut ::dirent64,
result: *mut *mut ::dirent64,
) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__stat_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__stat_time64")]
pub fn stat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
pub fn truncate64(path: *const c_char, length: off64_t) -> ::c_int;

Expand Down Expand Up @@ -1792,10 +1765,7 @@ extern "C" {
pub fn vfork() -> ::pid_t;
pub fn setresgid(rgid: ::gid_t, egid: ::gid_t, sgid: ::gid_t) -> ::c_int;
pub fn setresuid(ruid: ::uid_t, euid: ::uid_t, suid: ::uid_t) -> ::c_int;
#[cfg_attr(
all(target_env = "musl", target_pointer_width = "32"),
link_name = "__wait4_time64"
)]
#[cfg_attr(musl_time64_abi, link_name = "__wait4_time64")]
pub fn wait4(
pid: ::pid_t,
status: *mut ::c_int,
Expand Down
Loading

0 comments on commit e5a7a26

Please sign in to comment.