Skip to content

Commit e5a7a26

Browse files
committed
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.
1 parent 7cf0329 commit e5a7a26

File tree

6 files changed

+95
-188
lines changed

6 files changed

+95
-188
lines changed

build.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ fn main() {
3535
Some(_) | None => println!("cargo:rustc-cfg=freebsd11"),
3636
}
3737

38+
// Some ABIs need to redirect time related symbols to their time64
39+
// equivalents. See #2088 and #1848 for more information.
40+
if is_musl_time64_abi() {
41+
println!("cargo:rustc-cfg=musl_time64_abi");
42+
}
43+
3844
// On CI: deny all warnings
3945
if libc_ci {
4046
println!("cargo:rustc-cfg=libc_deny_warnings");
@@ -176,3 +182,22 @@ fn which_freebsd() -> Option<i32> {
176182
_ => None,
177183
}
178184
}
185+
186+
fn is_musl_time64_abi() -> bool {
187+
match env::var("TARGET") {
188+
Ok(target) => match &target[..] {
189+
"arm-unknown-linux-musleabi"
190+
| "arm-unknown-linux-musleabihf"
191+
| "armv5te-unknown-linux-musleabi"
192+
| "armv7-unknown-linux-musleabi"
193+
| "armv7-unknown-linux-musleabihf"
194+
| "i586-unknown-linux-musl"
195+
| "i686-unknown-linux-musl"
196+
| "mips-unknown-linux-musl"
197+
| "mipsel-unknown-linux-musl"
198+
| "powerpc-unknown-linux-musl" => true,
199+
_ => false,
200+
},
201+
Err(_) => false,
202+
}
203+
}

libc-test/build.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,6 +3063,23 @@ fn test_linux(target: &str) {
30633063
// deprecated since glibc >= 2.29. This allows Rust binaries to link against
30643064
// glibc versions older than 2.29.
30653065
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);
3066+
// Some targets use time64 symbols so set the musl_time64_abi appropriately.
3067+
// See #2088 and #1848 for more information.
3068+
match target {
3069+
"arm-unknown-linux-musleabi"
3070+
| "arm-unknown-linux-musleabihf"
3071+
| "armv5te-unknown-linux-musleabi"
3072+
| "armv7-unknown-linux-musleabi"
3073+
| "armv7-unknown-linux-musleabihf"
3074+
| "i586-unknown-linux-musl"
3075+
| "i686-unknown-linux-musl"
3076+
| "mips-unknown-linux-musl"
3077+
| "mipsel-unknown-linux-musl"
3078+
| "powerpc-unknown-linux-musl" => {
3079+
cfg.cfg("musl_time64_abi", None);
3080+
}
3081+
_ => {}
3082+
}
30663083

30673084
headers! { cfg:
30683085
"ctype.h",

src/unix/linux_like/linux/mod.rs

Lines changed: 19 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ s! {
184184
}
185185

186186
pub struct input_event {
187-
#[cfg(all(target_env = "musl", target_pointer_width = "32"))]
187+
#[cfg(musl_time64_abi)]
188188
pub input_event_sec: ::c_ulong,
189-
#[cfg(all(target_env = "musl", target_pointer_width = "32"))]
189+
#[cfg(musl_time64_abi)]
190190
pub input_event_usec: ::c_ulong,
191-
#[cfg(not(all(target_env = "musl", target_pointer_width = "32")))]
191+
#[cfg(not(musl_time64_abi))]
192192
pub time: ::timeval,
193193
pub type_: ::__u16,
194194
pub code: ::__u16,
@@ -3757,10 +3757,7 @@ cfg_if! {
37573757
pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int;
37583758
pub fn aio_error(aiocbp: *const aiocb) -> ::c_int;
37593759
pub fn aio_return(aiocbp: *mut aiocb) -> ::ssize_t;
3760-
#[cfg_attr(
3761-
all(target_env = "musl", target_pointer_width = "32"),
3762-
link_name = "__aio_suspend_time64"
3763-
)]
3760+
#[cfg_attr(musl_time64_abi, link_name = "__aio_suspend_time64")]
37643761
pub fn aio_suspend(
37653762
aiocb_list: *const *const aiocb,
37663763
nitems: ::c_int,
@@ -3814,10 +3811,7 @@ cfg_if! {
38143811
riovcnt: ::c_ulong,
38153812
flags: ::c_ulong,
38163813
) -> isize;
3817-
#[cfg_attr(
3818-
all(target_env = "musl", target_pointer_width = "32"),
3819-
link_name = "__futimes_time64"
3820-
)]
3814+
#[cfg_attr(musl_time64_abi, link_name = "__futimes_time64")]
38213815
pub fn futimes(
38223816
fd: ::c_int,
38233817
times: *const ::timeval
@@ -3845,10 +3839,7 @@ extern "C" {
38453839
pub fn seed48(xseed: *mut ::c_ushort) -> *mut ::c_ushort;
38463840
pub fn lcong48(p: *mut ::c_ushort);
38473841

3848-
#[cfg_attr(
3849-
all(target_env = "musl", target_pointer_width = "32"),
3850-
link_name = "__lutimes_time64"
3851-
)]
3842+
#[cfg_attr(musl_time64_abi, link_name = "__lutimes_time64")]
38523843
pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int;
38533844

38543845
pub fn setpwent();
@@ -3966,15 +3957,9 @@ extern "C" {
39663957
pub fn fremovexattr(filedes: ::c_int, name: *const c_char) -> ::c_int;
39673958
pub fn signalfd(fd: ::c_int, mask: *const ::sigset_t, flags: ::c_int) -> ::c_int;
39683959
pub fn timerfd_create(clockid: ::clockid_t, flags: ::c_int) -> ::c_int;
3969-
#[cfg_attr(
3970-
all(target_env = "musl", target_pointer_width = "32"),
3971-
link_name = "__timerfd_gettime64"
3972-
)]
3960+
#[cfg_attr(musl_time64_abi, link_name = "__timerfd_gettime64")]
39733961
pub fn timerfd_gettime(fd: ::c_int, curr_value: *mut itimerspec) -> ::c_int;
3974-
#[cfg_attr(
3975-
all(target_env = "musl", target_pointer_width = "32"),
3976-
link_name = "__timerfd_settime64"
3977-
)]
3962+
#[cfg_attr(musl_time64_abi, link_name = "__timerfd_settime64")]
39783963
pub fn timerfd_settime(
39793964
fd: ::c_int,
39803965
flags: ::c_int,
@@ -3996,10 +3981,7 @@ extern "C" {
39963981
msg_len: ::size_t,
39973982
msg_prio: *mut ::c_uint,
39983983
) -> ::ssize_t;
3999-
#[cfg_attr(
4000-
all(target_env = "musl", target_pointer_width = "32"),
4001-
link_name = "__mq_timedreceive_time64"
4002-
)]
3984+
#[cfg_attr(musl_time64_abi, link_name = "__mq_timedreceive_time64")]
40033985
pub fn mq_timedreceive(
40043986
mqd: ::mqd_t,
40053987
msg_ptr: *mut ::c_char,
@@ -4013,10 +3995,7 @@ extern "C" {
40133995
msg_len: ::size_t,
40143996
msg_prio: ::c_uint,
40153997
) -> ::c_int;
4016-
#[cfg_attr(
4017-
all(target_env = "musl", target_pointer_width = "32"),
4018-
link_name = "__mq_timedsend_time64"
4019-
)]
3998+
#[cfg_attr(musl_time64_abi, link_name = "__mq_timedsend_time64")]
40203999
pub fn mq_timedsend(
40214000
mqd: ::mqd_t,
40224001
msg_ptr: *const ::c_char,
@@ -4036,10 +4015,7 @@ extern "C" {
40364015
pub fn dup3(oldfd: ::c_int, newfd: ::c_int, flags: ::c_int) -> ::c_int;
40374016
pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int;
40384017
pub fn mkostemps(template: *mut ::c_char, suffixlen: ::c_int, flags: ::c_int) -> ::c_int;
4039-
#[cfg_attr(
4040-
all(target_env = "musl", target_pointer_width = "32"),
4041-
link_name = "__sigtimedwait_time64"
4042-
)]
4018+
#[cfg_attr(musl_time64_abi, link_name = "__sigtimedwait_time64")]
40434019
pub fn sigtimedwait(
40444020
set: *const sigset_t,
40454021
info: *mut siginfo_t,
@@ -4155,10 +4131,7 @@ extern "C" {
41554131
pub fn umount(target: *const ::c_char) -> ::c_int;
41564132
pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int;
41574133
pub fn tee(fd_in: ::c_int, fd_out: ::c_int, len: ::size_t, flags: ::c_uint) -> ::ssize_t;
4158-
#[cfg_attr(
4159-
all(target_env = "musl", target_pointer_width = "32"),
4160-
link_name = "__settimeofday_time64"
4161-
)]
4134+
#[cfg_attr(musl_time64_abi, link_name = "__settimeofday_time64")]
41624135
pub fn settimeofday(tv: *const ::timeval, tz: *const ::timezone) -> ::c_int;
41634136
pub fn splice(
41644137
fd_in: ::c_int,
@@ -4169,15 +4142,9 @@ extern "C" {
41694142
flags: ::c_uint,
41704143
) -> ::ssize_t;
41714144
pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int;
4172-
#[cfg_attr(
4173-
all(target_env = "musl", target_pointer_width = "32"),
4174-
link_name = "__sched_rr_get_interval_time64"
4175-
)]
4145+
#[cfg_attr(musl_time64_abi, link_name = "__sched_rr_get_interval_time64")]
41764146
pub fn sched_rr_get_interval(pid: ::pid_t, tp: *mut ::timespec) -> ::c_int;
4177-
#[cfg_attr(
4178-
all(target_env = "musl", target_pointer_width = "32"),
4179-
link_name = "__sem_timedwait_time64"
4180-
)]
4147+
#[cfg_attr(musl_time64_abi, link_name = "__sem_timedwait_time64")]
41814148
pub fn sem_timedwait(sem: *mut sem_t, abstime: *const ::timespec) -> ::c_int;
41824149
pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int;
41834150
pub fn sched_setparam(pid: ::pid_t, param: *const ::sched_param) -> ::c_int;
@@ -4199,10 +4166,7 @@ extern "C" {
41994166
pub fn personality(persona: ::c_ulong) -> ::c_int;
42004167
pub fn prctl(option: ::c_int, ...) -> ::c_int;
42014168
pub fn sched_getparam(pid: ::pid_t, param: *mut ::sched_param) -> ::c_int;
4202-
#[cfg_attr(
4203-
all(target_env = "musl", target_pointer_width = "32"),
4204-
link_name = "__ppoll_time64"
4205-
)]
4169+
#[cfg_attr(musl_time64_abi, link_name = "__ppoll_time64")]
42064170
pub fn ppoll(
42074171
fds: *mut ::pollfd,
42084172
nfds: nfds_t,
@@ -4218,10 +4182,7 @@ extern "C" {
42184182
protocol: ::c_int,
42194183
) -> ::c_int;
42204184
pub fn pthread_mutex_consistent(mutex: *mut pthread_mutex_t) -> ::c_int;
4221-
#[cfg_attr(
4222-
all(target_env = "musl", target_pointer_width = "32"),
4223-
link_name = "__pthread_mutex_timedlock_time64"
4224-
)]
4185+
#[cfg_attr(musl_time64_abi, link_name = "__pthread_mutex_timedlock_time64")]
42254186
pub fn pthread_mutex_timedlock(
42264187
lock: *mut pthread_mutex_t,
42274188
abstime: *const ::timespec,
@@ -4239,10 +4200,7 @@ extern "C" {
42394200
...
42404201
) -> ::c_int;
42414202
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;
4242-
#[cfg_attr(
4243-
all(target_env = "musl", target_pointer_width = "32"),
4244-
link_name = "__clock_nanosleep_time64"
4245-
)]
4203+
#[cfg_attr(musl_time64_abi, link_name = "__clock_nanosleep_time64")]
42464204
pub fn clock_nanosleep(
42474205
clk_id: ::clockid_t,
42484206
flags: ::c_int,
@@ -4505,15 +4463,9 @@ extern "C" {
45054463
) -> ::c_int;
45064464
pub fn timer_delete(timerid: ::timer_t) -> ::c_int;
45074465
pub fn timer_getoverrun(timerid: ::timer_t) -> ::c_int;
4508-
#[cfg_attr(
4509-
all(target_env = "musl", target_pointer_width = "32"),
4510-
link_name = "__timer_gettime64"
4511-
)]
4466+
#[cfg_attr(musl_time64_abi, link_name = "__timer_gettime64")]
45124467
pub fn timer_gettime(timerid: ::timer_t, curr_value: *mut ::itimerspec) -> ::c_int;
4513-
#[cfg_attr(
4514-
all(target_env = "musl", target_pointer_width = "32"),
4515-
link_name = "__timer_settime64"
4516-
)]
4468+
#[cfg_attr(musl_time64_abi, link_name = "__timer_settime64")]
45174469
pub fn timer_settime(
45184470
timerid: ::timer_t,
45194471
flags: ::c_int,

src/unix/linux_like/linux/musl/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ extern "C" {
687687
vlen: ::c_uint,
688688
flags: ::c_uint,
689689
) -> ::c_int;
690-
#[cfg_attr(target_pointer_width = "32", link_name = "__recvmmsg_time64")]
690+
#[cfg_attr(musl_time64_abi, link_name = "__recvmmsg_time64")]
691691
pub fn recvmmsg(
692692
sockfd: ::c_int,
693693
msgvec: *mut ::mmsghdr,
@@ -714,7 +714,7 @@ extern "C" {
714714
) -> ::c_int;
715715

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

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

744744
pub fn ctermid(s: *mut ::c_char) -> *mut ::c_char;

src/unix/linux_like/mod.rs

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,20 +1637,11 @@ extern "C" {
16371637
pub fn fdatasync(fd: ::c_int) -> ::c_int;
16381638
pub fn mincore(addr: *mut ::c_void, len: ::size_t, vec: *mut ::c_uchar) -> ::c_int;
16391639

1640-
#[cfg_attr(
1641-
all(target_env = "musl", target_pointer_width = "32"),
1642-
link_name = "__clock_getres_time64"
1643-
)]
1640+
#[cfg_attr(musl_time64_abi, link_name = "__clock_getres_time64")]
16441641
pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
1645-
#[cfg_attr(
1646-
all(target_env = "musl", target_pointer_width = "32"),
1647-
link_name = "__clock_gettime64"
1648-
)]
1642+
#[cfg_attr(musl_time64_abi, link_name = "__clock_gettime64")]
16491643
pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
1650-
#[cfg_attr(
1651-
all(target_env = "musl", target_pointer_width = "32"),
1652-
link_name = "__clock_settime64"
1653-
)]
1644+
#[cfg_attr(musl_time64_abi, link_name = "__clock_settime64")]
16541645
pub fn clock_settime(clk_id: ::clockid_t, tp: *const ::timespec) -> ::c_int;
16551646
pub fn clock_getcpuclockid(pid: ::pid_t, clk_id: *mut ::clockid_t) -> ::c_int;
16561647

@@ -1680,15 +1671,9 @@ extern "C" {
16801671
len: ::off64_t,
16811672
advise: ::c_int,
16821673
) -> ::c_int;
1683-
#[cfg_attr(
1684-
all(target_env = "musl", target_pointer_width = "32"),
1685-
link_name = "__futimens_time64"
1686-
)]
1674+
#[cfg_attr(musl_time64_abi, link_name = "__futimens_time64")]
16871675
pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int;
1688-
#[cfg_attr(
1689-
all(target_env = "musl", target_pointer_width = "32"),
1690-
link_name = "__utimensat_time64"
1691-
)]
1676+
#[cfg_attr(musl_time64_abi, link_name = "__utimensat_time64")]
16921677
pub fn utimensat(
16931678
dirfd: ::c_int,
16941679
path: *const ::c_char,
@@ -1700,15 +1685,9 @@ extern "C" {
17001685
pub fn newlocale(mask: ::c_int, locale: *const ::c_char, base: ::locale_t) -> ::locale_t;
17011686
pub fn uselocale(loc: ::locale_t) -> ::locale_t;
17021687
pub fn creat64(path: *const c_char, mode: mode_t) -> ::c_int;
1703-
#[cfg_attr(
1704-
all(target_env = "musl", target_pointer_width = "32"),
1705-
link_name = "__fstat_time64"
1706-
)]
1688+
#[cfg_attr(musl_time64_abi, link_name = "__fstat_time64")]
17071689
pub fn fstat64(fildes: ::c_int, buf: *mut stat64) -> ::c_int;
1708-
#[cfg_attr(
1709-
all(target_env = "musl", target_pointer_width = "32"),
1710-
link_name = "__fstatat_time64"
1711-
)]
1690+
#[cfg_attr(musl_time64_abi, link_name = "__fstatat_time64")]
17121691
pub fn fstatat64(
17131692
dirfd: ::c_int,
17141693
pathname: *const c_char,
@@ -1717,10 +1696,7 @@ extern "C" {
17171696
) -> ::c_int;
17181697
pub fn ftruncate64(fd: ::c_int, length: off64_t) -> ::c_int;
17191698
pub fn lseek64(fd: ::c_int, offset: off64_t, whence: ::c_int) -> off64_t;
1720-
#[cfg_attr(
1721-
all(target_env = "musl", target_pointer_width = "32"),
1722-
link_name = "__lstat_time64"
1723-
)]
1699+
#[cfg_attr(musl_time64_abi, link_name = "__lstat_time64")]
17241700
pub fn lstat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
17251701
pub fn mmap64(
17261702
addr: *mut ::c_void,
@@ -1745,10 +1721,7 @@ extern "C" {
17451721
entry: *mut ::dirent64,
17461722
result: *mut *mut ::dirent64,
17471723
) -> ::c_int;
1748-
#[cfg_attr(
1749-
all(target_env = "musl", target_pointer_width = "32"),
1750-
link_name = "__stat_time64"
1751-
)]
1724+
#[cfg_attr(musl_time64_abi, link_name = "__stat_time64")]
17521725
pub fn stat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
17531726
pub fn truncate64(path: *const c_char, length: off64_t) -> ::c_int;
17541727

@@ -1792,10 +1765,7 @@ extern "C" {
17921765
pub fn vfork() -> ::pid_t;
17931766
pub fn setresgid(rgid: ::gid_t, egid: ::gid_t, sgid: ::gid_t) -> ::c_int;
17941767
pub fn setresuid(ruid: ::uid_t, euid: ::uid_t, suid: ::uid_t) -> ::c_int;
1795-
#[cfg_attr(
1796-
all(target_env = "musl", target_pointer_width = "32"),
1797-
link_name = "__wait4_time64"
1798-
)]
1768+
#[cfg_attr(musl_time64_abi, link_name = "__wait4_time64")]
17991769
pub fn wait4(
18001770
pid: ::pid_t,
18011771
status: *mut ::c_int,

0 commit comments

Comments
 (0)