From fe4fb81173a682fe051d0829465775f9c0e5b5b0 Mon Sep 17 00:00:00 2001 From: Daniel Frampton Date: Fri, 5 Aug 2022 10:27:46 -0700 Subject: [PATCH 01/12] ci: install-musl: upgrade to 1.2.3 --- ci/install-musl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/install-musl.sh b/ci/install-musl.sh index 036a369631c0e..2bf7879baf211 100644 --- a/ci/install-musl.sh +++ b/ci/install-musl.sh @@ -5,7 +5,7 @@ set -ex -MUSL_VERSION=1.1.24 +MUSL_VERSION=1.2.3 MUSL="musl-${MUSL_VERSION}" # Download, configure, build, and install musl: From 5002716d97a3e9018218eaaca94f421d1822b67a Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sun, 28 Feb 2021 15:31:22 +0000 Subject: [PATCH 02/12] musl: define time_t as i64 type. musl 1.1 maintenance has for all practical purposes ended. Accordingly, there is no point in supporting both 1.1 and 1.2 in the libc crate, so follow the time_t type transition to 64-bit. --- src/unix/linux_like/linux/musl/mod.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 2a894a602502e..1fc8e960e9622 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -1,15 +1,6 @@ pub type pthread_t = *mut ::c_void; pub type clock_t = c_long; -#[cfg_attr( - not(feature = "rustc-dep-of-std"), - deprecated( - since = "0.2.80", - note = "This type is changed to 64-bit in musl 1.2.0, \ - we'll follow that change in the future release. \ - See #1848 for more info." - ) -)] -pub type time_t = c_long; +pub type time_t = i64; pub type suseconds_t = c_long; pub type ino_t = u64; pub type off_t = i64; From c462dd1e9a6cd4cfa2aa80c3bf09a6981cc39cc4 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sun, 28 Feb 2021 15:36:29 +0000 Subject: [PATCH 03/12] musl: fix utmpx struct layout - add padding members for musl 1.2 - ensure the padding members have an appropriate type (always c_int) --- src/unix/linux_like/linux/musl/mod.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 1fc8e960e9622..a616b82086c10 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -276,14 +276,9 @@ s_no_extra_traits! { pub __reserved: [::c_char; 256], } - // FIXME: musl added paddings and adjusted - // layout in 1.2.0 but our CI is still 1.1.24. - // So, I'm leaving some fields as comments for now. - // ref. https://github.com/bminor/musl/commit/ - // 1e7f0fcd7ff2096904fd93a2ee6d12a2392be392 pub struct utmpx { pub ut_type: ::c_short, - //__ut_pad1: ::c_short, + __ut_pad1: ::c_short, pub ut_pid: ::pid_t, pub ut_line: [::c_char; 32], pub ut_id: [::c_char; 4], @@ -291,15 +286,15 @@ s_no_extra_traits! { pub ut_host: [::c_char; 256], pub ut_exit: __exit_status, - //#[cfg(target_endian = "little")] - pub ut_session: ::c_long, - //#[cfg(target_endian = "little")] - //__ut_pad2: ::c_long, + #[cfg(target_endian = "little")] + pub ut_session: ::c_int, + #[cfg(target_endian = "little")] + __ut_pad2: ::c_int, - //#[cfg(not(target_endian = "little"))] - //__ut_pad2: ::c_int, - //#[cfg(not(target_endian = "little"))] - //pub ut_session: ::c_int, + #[cfg(not(target_endian = "little"))] + __ut_pad2: ::c_int, + #[cfg(not(target_endian = "little"))] + pub ut_session: ::c_int, pub ut_tv: ::timeval, pub ut_addr_v6: [::c_uint; 4], From 2242535f293aa4044e07e928171eb2fda70fc966 Mon Sep 17 00:00:00 2001 From: Daniel Frampton Date: Fri, 18 Mar 2022 11:10:58 -0700 Subject: [PATCH 04/12] Redirecting to musl time64 symbols --- src/unix/linux_like/linux/mod.rs | 69 ++++++++++++++++++++ src/unix/linux_like/linux/musl/mod.rs | 4 ++ src/unix/linux_like/mod.rs | 24 +++++++ src/unix/mod.rs | 93 ++++++++++++++++++++++----- 4 files changed, 174 insertions(+), 16 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index d3d627234ceea..ecd6b24bbacb6 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -184,6 +184,11 @@ s! { } pub struct input_event { + #[cfg(all(target_env = "musl", target_pointer_width = "32"))] + pub input_event_sec: ::c_ulong, + #[cfg(all(target_env = "musl", target_pointer_width = "32"))] + pub input_event_usec: ::c_ulong, + #[cfg(not(all(target_env = "musl", target_pointer_width = "32")))] pub time: ::timeval, pub type_: ::__u16, pub code: ::__u16, @@ -3752,6 +3757,10 @@ 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" + )] pub fn aio_suspend( aiocb_list: *const *const aiocb, nitems: ::c_int, @@ -3805,6 +3814,10 @@ cfg_if! { riovcnt: ::c_ulong, flags: ::c_ulong, ) -> isize; + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__futimes_time64" + )] pub fn futimes( fd: ::c_int, times: *const ::timeval @@ -3832,6 +3845,10 @@ 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" + )] pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int; pub fn setpwent(); @@ -3949,7 +3966,15 @@ 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" + )] 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" + )] pub fn timerfd_settime( fd: ::c_int, flags: ::c_int, @@ -3971,6 +3996,10 @@ 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" + )] pub fn mq_timedreceive( mqd: ::mqd_t, msg_ptr: *mut ::c_char, @@ -3984,6 +4013,10 @@ 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" + )] pub fn mq_timedsend( mqd: ::mqd_t, msg_ptr: *const ::c_char, @@ -4003,6 +4036,10 @@ 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" + )] pub fn sigtimedwait( set: *const sigset_t, info: *mut siginfo_t, @@ -4118,6 +4155,10 @@ 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" + )] pub fn settimeofday(tv: *const ::timeval, tz: *const ::timezone) -> ::c_int; pub fn splice( fd_in: ::c_int, @@ -4128,7 +4169,15 @@ 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" + )] 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" + )] 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; @@ -4150,6 +4199,10 @@ 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" + )] pub fn ppoll( fds: *mut ::pollfd, nfds: nfds_t, @@ -4165,6 +4218,10 @@ 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" + )] pub fn pthread_mutex_timedlock( lock: *mut pthread_mutex_t, abstime: *const ::timespec, @@ -4182,6 +4239,10 @@ 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" + )] pub fn clock_nanosleep( clk_id: ::clockid_t, flags: ::c_int, @@ -4444,7 +4505,15 @@ 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" + )] 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" + )] pub fn timer_settime( timerid: ::timer_t, flags: ::c_int, diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index a616b82086c10..48b721f926e45 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -687,6 +687,7 @@ extern "C" { vlen: ::c_uint, flags: ::c_uint, ) -> ::c_int; + #[cfg_attr(target_pointer_width = "32", link_name = "__recvmmsg_time64")] pub fn recvmmsg( sockfd: ::c_int, msgvec: *mut ::mmsghdr, @@ -713,6 +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")] 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; @@ -734,7 +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")] pub fn adjtimex(buf: *mut ::timex) -> ::c_int; + #[cfg_attr(target_pointer_width = "32", 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; diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 45a1dee554b4c..ad3a32337949d 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -1637,8 +1637,20 @@ 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" + )] 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" + )] 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" + )] 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; @@ -1668,7 +1680,15 @@ extern "C" { len: ::off64_t, advise: ::c_int, ) -> ::c_int; + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + 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" + )] pub fn utimensat( dirfd: ::c_int, path: *const ::c_char, @@ -1756,6 +1776,10 @@ 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" + )] pub fn wait4( pid: ::pid_t, status: *mut ::c_int, diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 826b835182a82..ded2608000859 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -730,6 +730,10 @@ extern "C" { all(target_os = "freebsd", any(freebsd11, freebsd10)), link_name = "fstat@FBSD_1.0" )] + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__fstat_time64" + )] pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; pub fn mkdir(path: *const c_char, mode: mode_t) -> ::c_int; @@ -743,6 +747,10 @@ extern "C" { all(target_os = "freebsd", any(freebsd11, freebsd10)), link_name = "stat@FBSD_1.0" )] + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__stat_time64" + )] pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; pub fn pclose(stream: *mut ::FILE) -> ::c_int; @@ -827,6 +835,10 @@ extern "C" { all(target_os = "freebsd", any(freebsd11, freebsd10)), link_name = "fstatat@FBSD_1.1" )] + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__fstatat_time64" + )] pub fn fstatat( dirfd: ::c_int, pathname: *const ::c_char, @@ -933,6 +945,10 @@ extern "C" { link_name = "nanosleep$UNIX2003" )] #[cfg_attr(target_os = "netbsd", link_name = "__nanosleep50")] + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__nanosleep_time64" + )] pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> ::c_int; pub fn tcgetpgrp(fd: ::c_int) -> pid_t; pub fn tcsetpgrp(fd: ::c_int, pgrp: ::pid_t) -> ::c_int; @@ -972,6 +988,10 @@ extern "C" { pub fn umask(mask: mode_t) -> mode_t; #[cfg_attr(target_os = "netbsd", link_name = "__utime50")] + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__utime64" + )] pub fn utime(file: *const c_char, buf: *const utimbuf) -> ::c_int; #[cfg_attr( @@ -1020,6 +1040,10 @@ extern "C" { all(target_os = "freebsd", any(freebsd11, freebsd10)), link_name = "lstat@FBSD_1.0" )] + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__lstat_time64" + )] pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int; #[cfg_attr( @@ -1047,6 +1071,10 @@ extern "C" { pub fn signal(signum: ::c_int, handler: sighandler_t) -> sighandler_t; #[cfg_attr(target_os = "netbsd", link_name = "__getrusage50")] + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__getrusage_time64" + )] pub fn getrusage(resource: ::c_int, usage: *mut rusage) -> ::c_int; #[cfg_attr( @@ -1118,6 +1146,10 @@ extern "C" { all(target_os = "macos", target_arch = "x86"), link_name = "pthread_cond_timedwait$UNIX2003" )] + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__pthread_cond_timedwait_time64" + )] pub fn pthread_cond_timedwait( cond: *mut pthread_cond_t, lock: *mut pthread_mutex_t, @@ -1181,9 +1213,17 @@ extern "C" { pub fn raise(signum: ::c_int) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__utimes50")] + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__utimes_time64" + )] pub fn utimes(filename: *const ::c_char, times: *const ::timeval) -> ::c_int; pub fn dlopen(filename: *const ::c_char, flag: ::c_int) -> *mut ::c_void; pub fn dlerror() -> *mut ::c_char; + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__dlsym_time64" + )] pub fn dlsym(handle: *mut ::c_void, symbol: *const ::c_char) -> *mut ::c_void; pub fn dlclose(handle: *mut ::c_void) -> ::c_int; pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int; @@ -1231,40 +1271,56 @@ extern "C" { pub fn res_init() -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__gmtime_r50")] - #[cfg_attr(target_env = "musl", allow(deprecated))] - // FIXME: for `time_t` + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__gmtime64_r" + )] pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; #[cfg_attr(target_os = "netbsd", link_name = "__localtime_r50")] - #[cfg_attr(target_env = "musl", allow(deprecated))] - // FIXME: for `time_t` + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__localtime64_r" + )] pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; #[cfg_attr( all(target_os = "macos", target_arch = "x86"), link_name = "mktime$UNIX2003" )] #[cfg_attr(target_os = "netbsd", link_name = "__mktime50")] - #[cfg_attr(target_env = "musl", allow(deprecated))] - // FIXME: for `time_t` + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__mktime64" + )] pub fn mktime(tm: *mut tm) -> time_t; #[cfg_attr(target_os = "netbsd", link_name = "__time50")] - #[cfg_attr(target_env = "musl", allow(deprecated))] - // FIXME: for `time_t` + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__time64" + )] pub fn time(time: *mut time_t) -> time_t; #[cfg_attr(target_os = "netbsd", link_name = "__gmtime50")] - #[cfg_attr(target_env = "musl", allow(deprecated))] - // FIXME: for `time_t` + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__gmtime64" + )] pub fn gmtime(time_p: *const time_t) -> *mut tm; #[cfg_attr(target_os = "netbsd", link_name = "__locatime50")] - #[cfg_attr(target_env = "musl", allow(deprecated))] - // FIXME: for `time_t` + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__localtime64" + )] pub fn localtime(time_p: *const time_t) -> *mut tm; #[cfg_attr(target_os = "netbsd", link_name = "__difftime50")] - #[cfg_attr(target_env = "musl", allow(deprecated))] - // FIXME: for `time_t` + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__difftime64" + )] pub fn difftime(time1: time_t, time0: time_t) -> ::c_double; #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")] - #[cfg_attr(target_env = "musl", allow(deprecated))] - // FIXME: for `time_t` + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__timegm_time64" + )] pub fn timegm(tm: *mut ::tm) -> time_t; #[cfg_attr(target_os = "netbsd", link_name = "__mknod50")] @@ -1319,6 +1375,10 @@ extern "C" { link_name = "select$UNIX2003" )] #[cfg_attr(target_os = "netbsd", link_name = "__select50")] + #[cfg_attr( + all(target_env = "musl", target_pointer_width = "32"), + link_name = "__select_time64" + )] pub fn select( nfds: ::c_int, readfds: *mut fd_set, @@ -1509,6 +1569,7 @@ cfg_if! { link_name = "pselect$UNIX2003" )] #[cfg_attr(target_os = "netbsd", link_name = "__pselect50")] + #[cfg_attr(all(target_env = "musl", target_pointer_width = "32"), link_name = "__pselect_time64")] pub fn pselect( nfds: ::c_int, readfds: *mut fd_set, From 7cf03293d976941b4257b42d46bc447fcebcf295 Mon Sep 17 00:00:00 2001 From: Daniel Frampton Date: Fri, 6 May 2022 14:07:12 -0700 Subject: [PATCH 05/12] Update stat structures and redirect all stat functions. --- src/unix/linux_like/linux/musl/b32/arm/mod.rs | 32 ++++++----------- .../linux_like/linux/musl/b32/mips/mod.rs | 35 ++++++------------- src/unix/linux_like/linux/musl/b32/powerpc.rs | 31 ++++++---------- .../linux_like/linux/musl/b32/riscv32/mod.rs | 23 +----------- src/unix/linux_like/linux/musl/b32/x86/mod.rs | 32 ++++++----------- .../linux_like/linux/musl/b64/aarch64/mod.rs | 23 +----------- src/unix/linux_like/linux/musl/b64/mips64.rs | 25 +------------ .../linux_like/linux/musl/b64/powerpc64.rs | 22 +----------- .../linux_like/linux/musl/b64/riscv64/mod.rs | 23 +----------- src/unix/linux_like/linux/musl/b64/s390x.rs | 21 +---------- .../linux_like/linux/musl/b64/x86_64/mod.rs | 22 +----------- src/unix/linux_like/mod.rs | 16 +++++++++ 12 files changed, 64 insertions(+), 241 deletions(-) diff --git a/src/unix/linux_like/linux/musl/b32/arm/mod.rs b/src/unix/linux_like/linux/musl/b32/arm/mod.rs index c47fa2c4cfda9..3d8d1a8d8d273 100644 --- a/src/unix/linux_like/linux/musl/b32/arm/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/arm/mod.rs @@ -1,5 +1,6 @@ pub type c_char = u8; pub type wchar_t = u32; +pub type stat64 = ::stat; s! { pub struct stat { @@ -15,35 +16,22 @@ s! { pub st_size: ::off_t, pub st_blksize: ::blksize_t, pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, + __st_atime32: ::c_long, + __st_atime32_nsec: ::c_long, + __st_mtime32: ::c_long, + __st_mtime32_nsec: ::c_long, + __st_ctime32: ::c_long, + __st_ctime32_nsec: ::c_long, pub st_ino: ::ino_t, - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __st_dev_padding: ::c_int, - __st_ino_truncated: ::c_long, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_int, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, pub st_atime: ::time_t, pub st_atime_nsec: ::c_long, + __st_atime_nsec_padding: ::c_long, pub st_mtime: ::time_t, pub st_mtime_nsec: ::c_long, + __st_mtime_nsec_padding: ::c_long, pub st_ctime: ::time_t, pub st_ctime_nsec: ::c_long, - pub st_ino: ::ino_t, + __st_ctime_nsec_padding: ::c_long, } pub struct stack_t { diff --git a/src/unix/linux_like/linux/musl/b32/mips/mod.rs b/src/unix/linux_like/linux/musl/b32/mips/mod.rs index 40b507bcd0633..ee6957212c3c4 100644 --- a/src/unix/linux_like/linux/musl/b32/mips/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/mips/mod.rs @@ -1,5 +1,6 @@ pub type c_char = i8; pub type wchar_t = ::c_int; +pub type stat64 = ::stat; s! { pub struct stat { @@ -13,39 +14,25 @@ s! { pub st_rdev: ::dev_t, __st_padding2: [::c_long; 2], pub st_size: ::off_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, + __st_atime32: ::c_long, + __st_atime32_nsec: ::c_long, + __st_mtime32: ::c_long, + __st_mtime32_nsec: ::c_long, + __st_ctime32: ::c_long, + __st_ctime32_nsec: ::c_long, pub st_blksize: ::blksize_t, __st_padding3: ::c_long, pub st_blocks: ::blkcnt_t, - __st_padding4: [::c_long; 14], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __st_padding1: [::c_long; 2], - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_padding2: [::c_long; 2], - pub st_size: ::off_t, pub st_atime: ::time_t, pub st_atime_nsec: ::c_long, + __st_atime_nsec_padding: ::c_long, pub st_mtime: ::time_t, pub st_mtime_nsec: ::c_long, + __st_mtime_nsec_padding: ::c_long, pub st_ctime: ::time_t, pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - __st_padding3: ::c_long, - pub st_blocks: ::blkcnt64_t, - __st_padding4: [::c_long; 14], + __st_ctime_nsec_padding: ::c_long, + __st_padding4: [::c_long; 2], } pub struct stack_t { diff --git a/src/unix/linux_like/linux/musl/b32/powerpc.rs b/src/unix/linux_like/linux/musl/b32/powerpc.rs index 5b1bf17ed8c22..3a4ee89cc5412 100644 --- a/src/unix/linux_like/linux/musl/b32/powerpc.rs +++ b/src/unix/linux_like/linux/musl/b32/powerpc.rs @@ -1,5 +1,6 @@ pub type c_char = u8; pub type wchar_t = i32; +pub type stat64 = ::stat; s! { pub struct stat { @@ -14,34 +15,22 @@ s! { pub st_size: ::off_t, pub st_blksize: ::blksize_t, pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, + __st_atime32: ::c_long, + __st_atime32_nsec: ::c_long, + __st_mtime32: ::c_long, + __st_mtime32_nsec: ::c_long, + __st_ctime32: ::c_long, + __st_ctime32_nsec: ::c_long, __unused: [::c_long; 2], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_short, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, pub st_atime: ::time_t, pub st_atime_nsec: ::c_long, + __st_atime_nsec_padding: ::c_long, pub st_mtime: ::time_t, pub st_mtime_nsec: ::c_long, + __st_mtime_nsec_padding: ::c_long, pub st_ctime: ::time_t, pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 2], + __st_ctime_nsec_padding: ::c_long, } pub struct stack_t { diff --git a/src/unix/linux_like/linux/musl/b32/riscv32/mod.rs b/src/unix/linux_like/linux/musl/b32/riscv32/mod.rs index 573624620728a..d662af943c312 100644 --- a/src/unix/linux_like/linux/musl/b32/riscv32/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/riscv32/mod.rs @@ -2,6 +2,7 @@ pub type c_char = u8; pub type wchar_t = ::c_int; +pub type stat64 = ::stat; s! { pub struct pthread_attr_t { @@ -30,28 +31,6 @@ s! { __unused: [::c_int; 2usize], } - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub __pad1: ::dev_t, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - pub __pad2: ::c_int, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_int; 2], - } - pub struct statfs { pub f_type: ::c_long, pub f_bsize: ::c_long, diff --git a/src/unix/linux_like/linux/musl/b32/x86/mod.rs b/src/unix/linux_like/linux/musl/b32/x86/mod.rs index c319b91b61434..fbd9bcfbb1510 100644 --- a/src/unix/linux_like/linux/musl/b32/x86/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/x86/mod.rs @@ -1,5 +1,6 @@ pub type c_char = i8; pub type wchar_t = i32; +pub type stat64 = ::stat; s! { pub struct stat { @@ -15,35 +16,22 @@ s! { pub st_size: ::off_t, pub st_blksize: ::blksize_t, pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, + __st_atime32: ::c_long, + __st_atime32_nsec: ::c_long, + __st_mtime32: ::c_long, + __st_mtime32_nsec: ::c_long, + __st_ctime32: ::c_long, + __st_ctime32_nsec: ::c_long, pub st_ino: ::ino_t, - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __st_dev_padding: ::c_int, - __st_ino_truncated: ::c_long, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_int, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, pub st_atime: ::time_t, pub st_atime_nsec: ::c_long, + __st_atime_nsec_padding: ::c_long, pub st_mtime: ::time_t, pub st_mtime_nsec: ::c_long, + __st_mtime_nsec_padding: ::c_long, pub st_ctime: ::time_t, pub st_ctime_nsec: ::c_long, - pub st_ino: ::ino_t, + __st_ctime_nsec_padding: ::c_long, } pub struct stack_t { diff --git a/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs b/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs index 14b4bc6d68b87..96f2e289f43e6 100644 --- a/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs @@ -4,6 +4,7 @@ pub type __s64 = ::c_longlong; pub type wchar_t = u32; pub type nlink_t = u32; pub type blksize_t = ::c_int; +pub type stat64 = ::stat; s! { pub struct stat { @@ -28,28 +29,6 @@ s! { __unused: [::c_uint; 2], } - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad0: ::c_ulong, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - __pad1: ::c_int, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_uint; 2], - } - pub struct user_regs_struct { pub regs: [::c_ulonglong; 31], pub sp: ::c_ulonglong, diff --git a/src/unix/linux_like/linux/musl/b64/mips64.rs b/src/unix/linux_like/linux/musl/b64/mips64.rs index 22ac916909346..a5252f785b983 100644 --- a/src/unix/linux_like/linux/musl/b64/mips64.rs +++ b/src/unix/linux_like/linux/musl/b64/mips64.rs @@ -4,6 +4,7 @@ pub type __u64 = ::c_ulong; pub type __s64 = ::c_long; pub type nlink_t = u64; pub type blksize_t = i64; +pub type stat64 = ::stat; s! { pub struct stat { @@ -30,30 +31,6 @@ s! { __pad5: [::c_int; 14], } - pub struct stat64 { - pub st_dev: ::dev_t, - __pad1: [::c_int; 3], - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad2: [::c_uint; 2], - pub st_size: ::off_t, - __pad3: ::c_int, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - __pad4: ::c_uint, - pub st_blocks: ::blkcnt_t, - __pad5: [::c_int; 14], - } - pub struct statfs { pub f_type: ::c_ulong, pub f_bsize: ::c_ulong, diff --git a/src/unix/linux_like/linux/musl/b64/powerpc64.rs b/src/unix/linux_like/linux/musl/b64/powerpc64.rs index 0bb4cf837d268..8596770a51240 100644 --- a/src/unix/linux_like/linux/musl/b64/powerpc64.rs +++ b/src/unix/linux_like/linux/musl/b64/powerpc64.rs @@ -4,6 +4,7 @@ pub type __u64 = ::c_ulong; pub type __s64 = ::c_long; pub type nlink_t = u64; pub type blksize_t = ::c_long; +pub type stat64 = ::stat; s! { pub struct stat { @@ -27,27 +28,6 @@ s! { __unused: [::c_long; 3], } - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __reserved: [::c_long; 3], - } - pub struct ipc_perm { pub __ipc_perm_key: ::key_t, pub uid: ::uid_t, diff --git a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs index f354293e0d05c..bb67418dbd7d5 100644 --- a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs @@ -9,6 +9,7 @@ pub type fsblkcnt64_t = ::c_ulong; pub type fsfilcnt64_t = ::c_ulong; pub type __u64 = ::c_ulonglong; pub type __s64 = ::c_longlong; +pub type stat64 = ::stat; s! { pub struct pthread_attr_t { @@ -37,28 +38,6 @@ s! { __unused: [::c_int; 2usize], } - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub __pad1: ::dev_t, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - pub __pad2: ::c_int, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_int; 2], - } - pub struct statfs { pub f_type: ::c_long, pub f_bsize: ::c_long, diff --git a/src/unix/linux_like/linux/musl/b64/s390x.rs b/src/unix/linux_like/linux/musl/b64/s390x.rs index 60bfc8d3e0b24..55e8094f98f68 100644 --- a/src/unix/linux_like/linux/musl/b64/s390x.rs +++ b/src/unix/linux_like/linux/musl/b64/s390x.rs @@ -5,6 +5,7 @@ pub type wchar_t = i32; pub type greg_t = u64; pub type __u64 = u64; pub type __s64 = i64; +pub type stat64 = ::stat; s! { pub struct ipc_perm { @@ -39,26 +40,6 @@ s! { __unused: [::c_long; 3], } - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - __unused: [::c_long; 3], - } - pub struct statfs { pub f_type: ::c_ulong, pub f_bsize: ::c_ulong, diff --git a/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs b/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs index 8198dc2f35168..d3779ce9c863b 100644 --- a/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs @@ -5,6 +5,7 @@ pub type blksize_t = ::c_long; pub type __u64 = ::c_ulonglong; pub type __s64 = ::c_longlong; pub type greg_t = i64; +pub type stat64 = ::stat; s! { pub struct stat { @@ -28,27 +29,6 @@ s! { __unused: [::c_long; 3], } - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __reserved: [::c_long; 3], - } - pub struct user_regs_struct { pub r15: ::c_ulong, pub r14: ::c_ulong, diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index ad3a32337949d..057f3e60dcb51 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -1700,7 +1700,15 @@ 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" + )] 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" + )] pub fn fstatat64( dirfd: ::c_int, pathname: *const c_char, @@ -1709,6 +1717,10 @@ 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" + )] pub fn lstat64(path: *const c_char, buf: *mut stat64) -> ::c_int; pub fn mmap64( addr: *mut ::c_void, @@ -1733,6 +1745,10 @@ 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" + )] pub fn stat64(path: *const c_char, buf: *mut stat64) -> ::c_int; pub fn truncate64(path: *const c_char, length: off64_t) -> ::c_int; From e5a7a26272bdfb9aeeade65cd612e48bfceb46b3 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Thu, 25 Aug 2022 13:29:42 -0400 Subject: [PATCH 06/12] Introduce musl_time64_abi cfg flag and set it from build.rs/libc-test 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. --- build.rs | 25 +++++++ libc-test/build.rs | 17 +++++ src/unix/linux_like/linux/mod.rs | 86 ++++++------------------ src/unix/linux_like/linux/musl/mod.rs | 8 +-- src/unix/linux_like/mod.rs | 50 +++----------- src/unix/mod.rs | 97 ++++++--------------------- 6 files changed, 95 insertions(+), 188 deletions(-) diff --git a/build.rs b/build.rs index bbee2d28a1789..2ff4149960fc5 100644 --- a/build.rs +++ b/build.rs @@ -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"); @@ -176,3 +182,22 @@ fn which_freebsd() -> Option { _ => 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, + } +} diff --git a/libc-test/build.rs b/libc-test/build.rs index 602bb89ffbb85..99e91a9f49de2 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -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", diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index ecd6b24bbacb6..04f58fe8f270a 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -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, @@ -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, @@ -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 @@ -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(); @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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; @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 48b721f926e45..b8414a459f7a8 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -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, @@ -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; @@ -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; diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 057f3e60dcb51..64dd667264437 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -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; @@ -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, @@ -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, @@ -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, @@ -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; @@ -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, diff --git a/src/unix/mod.rs b/src/unix/mod.rs index ded2608000859..d283bdf0bcf02 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -730,10 +730,7 @@ extern "C" { all(target_os = "freebsd", any(freebsd11, freebsd10)), link_name = "fstat@FBSD_1.0" )] - #[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 fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; pub fn mkdir(path: *const c_char, mode: mode_t) -> ::c_int; @@ -747,10 +744,7 @@ extern "C" { all(target_os = "freebsd", any(freebsd11, freebsd10)), link_name = "stat@FBSD_1.0" )] - #[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 stat(path: *const c_char, buf: *mut stat) -> ::c_int; pub fn pclose(stream: *mut ::FILE) -> ::c_int; @@ -835,10 +829,7 @@ extern "C" { all(target_os = "freebsd", any(freebsd11, freebsd10)), link_name = "fstatat@FBSD_1.1" )] - #[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 fstatat( dirfd: ::c_int, pathname: *const ::c_char, @@ -945,10 +936,7 @@ extern "C" { link_name = "nanosleep$UNIX2003" )] #[cfg_attr(target_os = "netbsd", link_name = "__nanosleep50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__nanosleep_time64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__nanosleep_time64")] pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> ::c_int; pub fn tcgetpgrp(fd: ::c_int) -> pid_t; pub fn tcsetpgrp(fd: ::c_int, pgrp: ::pid_t) -> ::c_int; @@ -988,10 +976,7 @@ extern "C" { pub fn umask(mask: mode_t) -> mode_t; #[cfg_attr(target_os = "netbsd", link_name = "__utime50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__utime64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__utime64")] pub fn utime(file: *const c_char, buf: *const utimbuf) -> ::c_int; #[cfg_attr( @@ -1040,10 +1025,7 @@ extern "C" { all(target_os = "freebsd", any(freebsd11, freebsd10)), link_name = "lstat@FBSD_1.0" )] - #[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 lstat(path: *const c_char, buf: *mut stat) -> ::c_int; #[cfg_attr( @@ -1071,10 +1053,7 @@ extern "C" { pub fn signal(signum: ::c_int, handler: sighandler_t) -> sighandler_t; #[cfg_attr(target_os = "netbsd", link_name = "__getrusage50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__getrusage_time64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__getrusage_time64")] pub fn getrusage(resource: ::c_int, usage: *mut rusage) -> ::c_int; #[cfg_attr( @@ -1146,10 +1125,7 @@ extern "C" { all(target_os = "macos", target_arch = "x86"), link_name = "pthread_cond_timedwait$UNIX2003" )] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__pthread_cond_timedwait_time64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__pthread_cond_timedwait_time64")] pub fn pthread_cond_timedwait( cond: *mut pthread_cond_t, lock: *mut pthread_mutex_t, @@ -1213,17 +1189,11 @@ extern "C" { pub fn raise(signum: ::c_int) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__utimes50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__utimes_time64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__utimes_time64")] pub fn utimes(filename: *const ::c_char, times: *const ::timeval) -> ::c_int; pub fn dlopen(filename: *const ::c_char, flag: ::c_int) -> *mut ::c_void; pub fn dlerror() -> *mut ::c_char; - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__dlsym_time64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__dlsym_time64")] pub fn dlsym(handle: *mut ::c_void, symbol: *const ::c_char) -> *mut ::c_void; pub fn dlclose(handle: *mut ::c_void) -> ::c_int; pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int; @@ -1271,56 +1241,32 @@ extern "C" { pub fn res_init() -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__gmtime_r50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__gmtime64_r" - )] + #[cfg_attr(musl_time64_abi, link_name = "__gmtime64_r")] pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; #[cfg_attr(target_os = "netbsd", link_name = "__localtime_r50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__localtime64_r" - )] + #[cfg_attr(musl_time64_abi, link_name = "__localtime64_r")] pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; #[cfg_attr( all(target_os = "macos", target_arch = "x86"), link_name = "mktime$UNIX2003" )] #[cfg_attr(target_os = "netbsd", link_name = "__mktime50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__mktime64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__mktime64")] pub fn mktime(tm: *mut tm) -> time_t; #[cfg_attr(target_os = "netbsd", link_name = "__time50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__time64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__time64")] pub fn time(time: *mut time_t) -> time_t; #[cfg_attr(target_os = "netbsd", link_name = "__gmtime50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__gmtime64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__gmtime64")] pub fn gmtime(time_p: *const time_t) -> *mut tm; #[cfg_attr(target_os = "netbsd", link_name = "__locatime50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__localtime64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__localtime64")] pub fn localtime(time_p: *const time_t) -> *mut tm; #[cfg_attr(target_os = "netbsd", link_name = "__difftime50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__difftime64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__difftime64")] pub fn difftime(time1: time_t, time0: time_t) -> ::c_double; #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__timegm_time64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__timegm_time64")] pub fn timegm(tm: *mut ::tm) -> time_t; #[cfg_attr(target_os = "netbsd", link_name = "__mknod50")] @@ -1375,10 +1321,7 @@ extern "C" { link_name = "select$UNIX2003" )] #[cfg_attr(target_os = "netbsd", link_name = "__select50")] - #[cfg_attr( - all(target_env = "musl", target_pointer_width = "32"), - link_name = "__select_time64" - )] + #[cfg_attr(musl_time64_abi, link_name = "__select_time64")] pub fn select( nfds: ::c_int, readfds: *mut fd_set, @@ -1569,7 +1512,7 @@ cfg_if! { link_name = "pselect$UNIX2003" )] #[cfg_attr(target_os = "netbsd", link_name = "__pselect50")] - #[cfg_attr(all(target_env = "musl", target_pointer_width = "32"), link_name = "__pselect_time64")] + #[cfg_attr(musl_time64_abi, link_name = "__pselect_time64")] pub fn pselect( nfds: ::c_int, readfds: *mut fd_set, From 61178cf152ebfc041d36bc1232a007734022f5fb Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 26 Aug 2022 13:33:24 -0400 Subject: [PATCH 07/12] Update x86 musl to 1.2.3 --- src/unix/linux_like/linux/arch/generic/mod.rs | 27 ++++++++++---- src/unix/linux_like/linux/musl/b32/x86/mod.rs | 36 +++++++++++-------- src/unix/linux_like/linux/musl/mod.rs | 2 +- src/unix/linux_like/mod.rs | 22 +++++++++--- src/unix/mod.rs | 3 ++ 5 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/unix/linux_like/linux/arch/generic/mod.rs b/src/unix/linux_like/linux/arch/generic/mod.rs index 40bc30a4f336b..64fc8f58468f6 100644 --- a/src/unix/linux_like/linux/arch/generic/mod.rs +++ b/src/unix/linux_like/linux/arch/generic/mod.rs @@ -37,8 +37,25 @@ pub const SO_PASSCRED: ::c_int = 16; pub const SO_PEERCRED: ::c_int = 17; pub const SO_RCVLOWAT: ::c_int = 18; pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; + +cfg_if! { + if #[cfg(not(musl_time64_abi))] { + pub const SO_RCVTIMEO: ::c_int = 20; + pub const SO_SNDTIMEO: ::c_int = 21; + pub const SO_TIMESTAMP: ::c_int = 29; + pub const SO_TIMESTAMPNS: ::c_int = 35; + pub const SO_TIMESTAMPING: ::c_int = 37; + pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING; + } else { + pub const SO_RCVTIMEO: ::c_int = 66; + pub const SO_SNDTIMEO: ::c_int = 67; + pub const SO_TIMESTAMP: ::c_int = 63; + pub const SO_TIMESTAMPNS: ::c_int = 64; + pub const SO_TIMESTAMPING: ::c_int = 65; + pub const SCM_TIMESTAMPING: ::c_int = 65; + } +} + // pub const SO_RCVTIMEO_OLD: ::c_int = 20; // pub const SO_SNDTIMEO_OLD: ::c_int = 21; pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22; @@ -49,17 +66,14 @@ pub const SO_ATTACH_FILTER: ::c_int = 26; pub const SO_DETACH_FILTER: ::c_int = 27; pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER; pub const SO_PEERNAME: ::c_int = 28; -pub const SO_TIMESTAMP: ::c_int = 29; // pub const SO_TIMESTAMP_OLD: ::c_int = 29; pub const SO_ACCEPTCONN: ::c_int = 30; pub const SO_PEERSEC: ::c_int = 31; pub const SO_SNDBUFFORCE: ::c_int = 32; pub const SO_RCVBUFFORCE: ::c_int = 33; pub const SO_PASSSEC: ::c_int = 34; -pub const SO_TIMESTAMPNS: ::c_int = 35; // pub const SO_TIMESTAMPNS_OLD: ::c_int = 35; pub const SO_MARK: ::c_int = 36; -pub const SO_TIMESTAMPING: ::c_int = 37; // pub const SO_TIMESTAMPING_OLD: ::c_int = 37; pub const SO_PROTOCOL: ::c_int = 38; pub const SO_DOMAIN: ::c_int = 39; @@ -119,7 +133,6 @@ cfg_if! { // Defined in unix/linux_like/mod.rs // pub const SCM_TIMESTAMP: ::c_int = SO_TIMESTAMP; pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS; -pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING; // Ioctl Constants @@ -270,7 +283,7 @@ cfg_if! { pub const RLIMIT_NICE: ::c_int = 13; pub const RLIMIT_RTPRIO: ::c_int = 14; pub const RLIMIT_RTTIME: ::c_int = 15; - pub const RLIM_NLIMITS: ::c_int = 15; + pub const RLIM_NLIMITS: ::c_int = 16; pub const RLIMIT_NLIMITS: ::c_int = RLIM_NLIMITS; } } diff --git a/src/unix/linux_like/linux/musl/b32/x86/mod.rs b/src/unix/linux_like/linux/musl/b32/x86/mod.rs index fbd9bcfbb1510..722e007617d6c 100644 --- a/src/unix/linux_like/linux/musl/b32/x86/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/x86/mod.rs @@ -55,34 +55,40 @@ s! { pub struct shmid_ds { pub shm_perm: ::ipc_perm, pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - __unused1: ::c_int, - pub shm_dtime: ::time_t, - __unused2: ::c_int, - pub shm_ctime: ::time_t, - __unused3: ::c_int, + __shm_atime_lo: ::c_ulong, + __shm_atime_hi: ::c_ulong, + __shm_dtime_lo: ::c_ulong, + __shm_dtime_hi: ::c_ulong, + __shm_ctime_lo: ::c_ulong, + __shm_ctime_hi: ::c_ulong, pub shm_cpid: ::pid_t, pub shm_lpid: ::pid_t, pub shm_nattch: ::c_ulong, __pad1: ::c_ulong, __pad2: ::c_ulong, + __pad3: ::c_ulong, + pub shm_atime: ::time_t, + pub shm_dtime: ::time_t, + pub shm_ctime: ::time_t, } pub struct msqid_ds { pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - __unused1: ::c_int, - pub msg_rtime: ::time_t, - __unused2: ::c_int, - pub msg_ctime: ::time_t, - __unused3: ::c_int, - __msg_cbytes: ::c_ulong, + __msg_stime_lo: ::c_ulong, + __msg_stime_hi: ::c_ulong, + __msg_rtime_lo: ::c_ulong, + __msg_rtime_hi: ::c_ulong, + __msg_ctime_lo: ::c_ulong, + __msg_ctime_hi: ::c_ulong, + pub msg_cbytes: ::c_ulong, pub msg_qnum: ::msgqnum_t, pub msg_qbytes: ::msglen_t, pub msg_lspid: ::pid_t, pub msg_lrpid: ::pid_t, - __pad1: ::c_ulong, - __pad2: ::c_ulong, + __unused: [::c_ulong; 2], + pub msg_stime: ::time_t, + pub msg_rtime: ::time_t, + pub msg_ctime: ::time_t, } pub struct statfs { diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index b8414a459f7a8..4db01269f5838 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -1,7 +1,7 @@ pub type pthread_t = *mut ::c_void; pub type clock_t = c_long; pub type time_t = i64; -pub type suseconds_t = c_long; +pub type suseconds_t = i64; pub type ino_t = u64; pub type off_t = i64; pub type blkcnt_t = i64; diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 64dd667264437..3974488e07f8f 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -108,14 +108,28 @@ s! { pub struct sched_param { pub sched_priority: ::c_int, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] + #[cfg(target_env = "musl")] + __reserved1: ::c_int, + #[cfg(target_os = "emscripten")] pub sched_ss_low_priority: ::c_int, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] + #[cfg(target_os = "emscripten")] pub sched_ss_repl_period: ::timespec, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] + #[cfg(target_os = "emscripten")] pub sched_ss_init_budget: ::timespec, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] + #[cfg(target_os = "emscripten")] pub sched_ss_max_repl: ::c_int, + #[cfg(musl_time64_abi)] + __reserved2: [::c_long; 4], + #[cfg(all(target_env = "musl", not(musl_time64_abi)))] + __reserved2_1: time_t, + #[cfg(all(target_env = "musl", not(musl_time64_abi)))] + __reserved2_2: ::c_long, + #[cfg(all(target_env = "musl", not(musl_time64_abi)))] + __reserved2_3: time_t, + #[cfg(all(target_env = "musl", not(musl_time64_abi)))] + __reserved2_4: ::c_long, + #[cfg(target_env = "musl")] + __reserved3: ::c_int, } pub struct Dl_info { diff --git a/src/unix/mod.rs b/src/unix/mod.rs index d283bdf0bcf02..f17693aed858b 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -77,6 +77,8 @@ s! { pub tv_nsec: i64, #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] pub tv_nsec: ::c_long, + #[cfg(musl_time64_abi)] + __pad0: u32 } pub struct rlimit { @@ -1413,6 +1415,7 @@ cfg_if! { target_os = "haiku", target_os = "nto")))] { extern "C" { + #[cfg_attr(musl_time64_abi, link_name = "__adjtime64")] pub fn adjtime(delta: *const timeval, olddelta: *mut timeval) -> ::c_int; pub fn stpncpy(dst: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char; } From af75803c70ea809d8ca87aab3ef7e25126d2e878 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 26 Aug 2022 16:03:00 -0400 Subject: [PATCH 08/12] Update libc-test/build.rs testing for musl 1.2.3 symbols --- libc-test/build.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 99e91a9f49de2..7c28fcbd23c3c 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3272,8 +3272,8 @@ fn test_linux(target: &str) { t if t.ends_with("_t") => t.to_string(), - // In MUSL `flock64` is a typedef to `flock`. - "flock64" if musl => format!("struct {}", ty), + // In MUSL, `flock64` is a typedef to `flock` and `stat64` is a typedef to `stat`. + "flock64" | "stat64" if musl => format!("struct {}", ty), // put `struct` in front of all structs:. t if is_struct => format!("struct {}", t), @@ -3492,6 +3492,9 @@ fn test_linux(target: &str) { // - these constants are used by the glibc implementation. n if musl && n.contains("__SIZEOF_PTHREAD") => true, + // FIXME: ctest reports incorrect values for both Rust/libc and C/musl. + "IPC_STAT" if musl => true, + // FIXME: It was extended to 4096 since glibc 2.31 (Linux 5.4). // We should do so after a while. "SOMAXCONN" if gnu => true, From 1cf8128adf982bc53735b6ed776dd3c93e44c528 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 26 Aug 2022 17:59:24 -0400 Subject: [PATCH 09/12] Update arm to musl 1.2.3 --- src/unix/linux_like/linux/musl/b32/arm/mod.rs | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/unix/linux_like/linux/musl/b32/arm/mod.rs b/src/unix/linux_like/linux/musl/b32/arm/mod.rs index 3d8d1a8d8d273..a9cd5f50e6ccf 100644 --- a/src/unix/linux_like/linux/musl/b32/arm/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/arm/mod.rs @@ -55,34 +55,40 @@ s! { pub struct shmid_ds { pub shm_perm: ::ipc_perm, pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - __unused1: ::c_int, - pub shm_dtime: ::time_t, - __unused2: ::c_int, - pub shm_ctime: ::time_t, - __unused3: ::c_int, + __shm_atime_lo: ::c_ulong, + __shm_atime_hi: ::c_ulong, + __shm_dtime_lo: ::c_ulong, + __shm_dtime_hi: ::c_ulong, + __shm_ctime_lo: ::c_ulong, + __shm_ctime_hi: ::c_ulong, pub shm_cpid: ::pid_t, pub shm_lpid: ::pid_t, pub shm_nattch: ::c_ulong, __pad1: ::c_ulong, __pad2: ::c_ulong, + __pad3: ::c_ulong, + pub shm_atime: ::time_t, + pub shm_dtime: ::time_t, + pub shm_ctime: ::time_t, } pub struct msqid_ds { pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - __unused1: ::c_int, - pub msg_rtime: ::time_t, - __unused2: ::c_int, - pub msg_ctime: ::time_t, - __unused3: ::c_int, - __msg_cbytes: ::c_ulong, + __msg_stime_lo: ::c_ulong, + __msg_stime_hi: ::c_ulong, + __msg_rtime_lo: ::c_ulong, + __msg_rtime_hi: ::c_ulong, + __msg_ctime_lo: ::c_ulong, + __msg_ctime_hi: ::c_ulong, + pub msg_cbytes: ::c_ulong, pub msg_qnum: ::msgqnum_t, pub msg_qbytes: ::msglen_t, pub msg_lspid: ::pid_t, pub msg_lrpid: ::pid_t, - __pad1: ::c_ulong, - __pad2: ::c_ulong, + __unused: [::c_ulong; 2], + pub msg_stime: ::time_t, + pub msg_rtime: ::time_t, + pub msg_ctime: ::time_t, } pub struct statfs { From 909edf6e432b7bc94584a802b9ffd1ef09fe0429 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 26 Aug 2022 18:51:41 -0400 Subject: [PATCH 10/12] Update mips to musl 1.2.3 --- ci/docker/mips-unknown-linux-musl/Dockerfile | 10 ++-- src/unix/linux_like/linux/arch/mips/mod.rs | 27 +++++++--- .../linux_like/linux/musl/b32/mips/mod.rs | 52 +++++++------------ src/unix/mod.rs | 4 +- 4 files changed, 48 insertions(+), 45 deletions(-) diff --git a/ci/docker/mips-unknown-linux-musl/Dockerfile b/ci/docker/mips-unknown-linux-musl/Dockerfile index 6fbd284fb9ba3..c01d9b597df0f 100644 --- a/ci/docker/mips-unknown-linux-musl/Dockerfile +++ b/ci/docker/mips-unknown-linux-musl/Dockerfile @@ -10,16 +10,16 @@ RUN mkdir /toolchain # See build_dir/target-mips_24kc_musl/linux-ath79_generic/linux-5.4.154 # Musl version: 1.1.24 # See staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/info.mk -RUN curl --retry 5 -L https://downloads.openwrt.org/releases/21.02.1/targets/ath79/generic/openwrt-sdk-21.02.1-ath79-generic_gcc-8.4.0_musl.Linux-x86_64.tar.xz | \ +RUN curl --retry 5 -L https://downloads.openwrt.org/releases/22.03.0-rc6/targets/ath79/generic/openwrt-sdk-22.03.0-rc6-ath79-generic_gcc-11.2.0_musl.Linux-x86_64.tar.xz | \ tar xJf - -C /toolchain --strip-components=1 # See https://lkml.org/lkml/2014/3/14/269 COPY sysinfo_guard.patch /toolchain -RUN patch /toolchain/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/include/linux/kernel.h Date: Sun, 28 Aug 2022 20:29:32 -0400 Subject: [PATCH 11/12] Update mipsel to musl 1.2.3 --- ci/docker/mipsel-unknown-linux-musl/Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ci/docker/mipsel-unknown-linux-musl/Dockerfile b/ci/docker/mipsel-unknown-linux-musl/Dockerfile index dad215abf5601..9e664885b4674 100644 --- a/ci/docker/mipsel-unknown-linux-musl/Dockerfile +++ b/ci/docker/mipsel-unknown-linux-musl/Dockerfile @@ -8,18 +8,18 @@ RUN mkdir /toolchain # Linux kernel version: 5.4.154 # See build_dir/target-mipsel_mips32_musl/linux-brcm47xx_generic/linux-5.4.154 -# Musl version: 1.1.24 +# Musl version: 1.2.3 # See staging_dir/toolchain-mipsel_mips32_gcc-8.4.0_musl/info.mk -RUN curl --retry 5 -L https://downloads.openwrt.org/releases/21.02.1/targets/bcm47xx/generic/openwrt-sdk-21.02.1-bcm47xx-generic_gcc-8.4.0_musl.Linux-x86_64.tar.xz | \ +RUN curl --retry 5 -L https://downloads.openwrt.org/releases/22.03.0-rc6/targets/bcm47xx/generic/openwrt-sdk-22.03.0-rc6-bcm47xx-generic_gcc-11.2.0_musl.Linux-x86_64.tar.xz | \ tar xJf - -C /toolchain --strip-components=1 # See https://lkml.org/lkml/2014/3/14/269 COPY sysinfo_guard.patch /toolchain -RUN patch /toolchain/staging_dir/toolchain-mipsel_mips32_gcc-8.4.0_musl/include/linux/kernel.h Date: Sun, 28 Aug 2022 21:18:01 -0400 Subject: [PATCH 12/12] Update x86_64 to musl 1.2.3 --- src/unix/linux_like/linux/musl/b64/x86_64/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs b/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs index d3779ce9c863b..dc91f0797b3db 100644 --- a/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs @@ -651,7 +651,7 @@ pub const MAP_32BIT: ::c_int = 0x0040; pub const O_APPEND: ::c_int = 1024; pub const O_DIRECT: ::c_int = 0x4000; pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_LARGEFILE: ::c_int = 0; +pub const O_LARGEFILE: ::c_int = 0x8000; pub const O_NOFOLLOW: ::c_int = 0x20000; pub const O_CREAT: ::c_int = 64; pub const O_EXCL: ::c_int = 128;