Skip to content

Commit 5e672e9

Browse files
wesleywisermyl7
authored andcommitted
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 030363e commit 5e672e9

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
@@ -67,6 +67,12 @@ fn main() {
6767
Some(_) | None => (),
6868
}
6969

70+
// Some ABIs need to redirect time related symbols to their time64
71+
// equivalents. See #2088 and #1848 for more information.
72+
if is_musl_time64_abi() {
73+
println!("cargo:rustc-cfg=musl_time64_abi");
74+
}
75+
7076
// On CI: deny all warnings
7177
if libc_ci {
7278
set_cfg("libc_deny_warnings");
@@ -213,3 +219,22 @@ fn set_cfg(cfg: &str) {
213219
}
214220
println!("cargo:rustc-cfg={}", cfg);
215221
}
222+
223+
fn is_musl_time64_abi() -> bool {
224+
match env::var("TARGET") {
225+
Ok(target) => match &target[..] {
226+
"arm-unknown-linux-musleabi"
227+
| "arm-unknown-linux-musleabihf"
228+
| "armv5te-unknown-linux-musleabi"
229+
| "armv7-unknown-linux-musleabi"
230+
| "armv7-unknown-linux-musleabihf"
231+
| "i586-unknown-linux-musl"
232+
| "i686-unknown-linux-musl"
233+
| "mips-unknown-linux-musl"
234+
| "mipsel-unknown-linux-musl"
235+
| "powerpc-unknown-linux-musl" => true,
236+
_ => false,
237+
},
238+
Err(_) => false,
239+
}
240+
}

libc-test/build.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,6 +3301,23 @@ fn test_linux(target: &str) {
33013301
// deprecated since glibc >= 2.29. This allows Rust binaries to link against
33023302
// glibc versions older than 2.29.
33033303
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);
3304+
// Some targets use time64 symbols so set the musl_time64_abi appropriately.
3305+
// See #2088 and #1848 for more information.
3306+
match target {
3307+
"arm-unknown-linux-musleabi"
3308+
| "arm-unknown-linux-musleabihf"
3309+
| "armv5te-unknown-linux-musleabi"
3310+
| "armv7-unknown-linux-musleabi"
3311+
| "armv7-unknown-linux-musleabihf"
3312+
| "i586-unknown-linux-musl"
3313+
| "i686-unknown-linux-musl"
3314+
| "mips-unknown-linux-musl"
3315+
| "mipsel-unknown-linux-musl"
3316+
| "powerpc-unknown-linux-musl" => {
3317+
cfg.cfg("musl_time64_abi", None);
3318+
}
3319+
_ => {}
3320+
}
33043321

33053322
headers! { cfg:
33063323
"ctype.h",

src/unix/linux_like/linux/mod.rs

Lines changed: 19 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ s! {
322322
}
323323

324324
pub struct input_event {
325-
#[cfg(all(target_env = "musl", target_pointer_width = "32"))]
325+
#[cfg(musl_time64_abi)]
326326
pub input_event_sec: ::c_ulong,
327-
#[cfg(all(target_env = "musl", target_pointer_width = "32"))]
327+
#[cfg(musl_time64_abi)]
328328
pub input_event_usec: ::c_ulong,
329-
#[cfg(not(all(target_env = "musl", target_pointer_width = "32")))]
329+
#[cfg(not(musl_time64_abi))]
330330
pub time: ::timeval,
331331
pub type_: ::__u16,
332332
pub code: ::__u16,
@@ -5350,10 +5350,7 @@ cfg_if! {
53505350
pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int;
53515351
pub fn aio_error(aiocbp: *const aiocb) -> ::c_int;
53525352
pub fn aio_return(aiocbp: *mut aiocb) -> ::ssize_t;
5353-
#[cfg_attr(
5354-
all(target_env = "musl", target_pointer_width = "32"),
5355-
link_name = "__aio_suspend_time64"
5356-
)]
5353+
#[cfg_attr(musl_time64_abi, link_name = "__aio_suspend_time64")]
53575354
pub fn aio_suspend(
53585355
aiocb_list: *const *const aiocb,
53595356
nitems: ::c_int,
@@ -5414,10 +5411,7 @@ cfg_if! {
54145411
riovcnt: ::c_ulong,
54155412
flags: ::c_ulong,
54165413
) -> isize;
5417-
#[cfg_attr(
5418-
all(target_env = "musl", target_pointer_width = "32"),
5419-
link_name = "__futimes_time64"
5420-
)]
5414+
#[cfg_attr(musl_time64_abi, link_name = "__futimes_time64")]
54215415
pub fn futimes(
54225416
fd: ::c_int,
54235417
times: *const ::timeval
@@ -5476,10 +5470,7 @@ extern "C" {
54765470
pub fn seed48(xseed: *mut ::c_ushort) -> *mut ::c_ushort;
54775471
pub fn lcong48(p: *mut ::c_ushort);
54785472

5479-
#[cfg_attr(
5480-
all(target_env = "musl", target_pointer_width = "32"),
5481-
link_name = "__lutimes_time64"
5482-
)]
5473+
#[cfg_attr(musl_time64_abi, link_name = "__lutimes_time64")]
54835474
pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int;
54845475

54855476
pub fn setpwent();
@@ -5575,15 +5566,9 @@ extern "C" {
55755566
pub fn fremovexattr(filedes: ::c_int, name: *const c_char) -> ::c_int;
55765567
pub fn signalfd(fd: ::c_int, mask: *const ::sigset_t, flags: ::c_int) -> ::c_int;
55775568
pub fn timerfd_create(clockid: ::clockid_t, flags: ::c_int) -> ::c_int;
5578-
#[cfg_attr(
5579-
all(target_env = "musl", target_pointer_width = "32"),
5580-
link_name = "__timerfd_gettime64"
5581-
)]
5569+
#[cfg_attr(musl_time64_abi, link_name = "__timerfd_gettime64")]
55825570
pub fn timerfd_gettime(fd: ::c_int, curr_value: *mut itimerspec) -> ::c_int;
5583-
#[cfg_attr(
5584-
all(target_env = "musl", target_pointer_width = "32"),
5585-
link_name = "__timerfd_settime64"
5586-
)]
5571+
#[cfg_attr(musl_time64_abi, link_name = "__timerfd_settime64")]
55875572
pub fn timerfd_settime(
55885573
fd: ::c_int,
55895574
flags: ::c_int,
@@ -5605,10 +5590,7 @@ extern "C" {
56055590
msg_len: ::size_t,
56065591
msg_prio: *mut ::c_uint,
56075592
) -> ::ssize_t;
5608-
#[cfg_attr(
5609-
all(target_env = "musl", target_pointer_width = "32"),
5610-
link_name = "__mq_timedreceive_time64"
5611-
)]
5593+
#[cfg_attr(musl_time64_abi, link_name = "__mq_timedreceive_time64")]
56125594
pub fn mq_timedreceive(
56135595
mqd: ::mqd_t,
56145596
msg_ptr: *mut ::c_char,
@@ -5622,10 +5604,7 @@ extern "C" {
56225604
msg_len: ::size_t,
56235605
msg_prio: ::c_uint,
56245606
) -> ::c_int;
5625-
#[cfg_attr(
5626-
all(target_env = "musl", target_pointer_width = "32"),
5627-
link_name = "__mq_timedsend_time64"
5628-
)]
5607+
#[cfg_attr(musl_time64_abi, link_name = "__mq_timedsend_time64")]
56295608
pub fn mq_timedsend(
56305609
mqd: ::mqd_t,
56315610
msg_ptr: *const ::c_char,
@@ -5645,10 +5624,7 @@ extern "C" {
56455624
pub fn dup3(oldfd: ::c_int, newfd: ::c_int, flags: ::c_int) -> ::c_int;
56465625
pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int;
56475626
pub fn mkostemps(template: *mut ::c_char, suffixlen: ::c_int, flags: ::c_int) -> ::c_int;
5648-
#[cfg_attr(
5649-
all(target_env = "musl", target_pointer_width = "32"),
5650-
link_name = "__sigtimedwait_time64"
5651-
)]
5627+
#[cfg_attr(musl_time64_abi, link_name = "__sigtimedwait_time64")]
56525628
pub fn sigtimedwait(
56535629
set: *const sigset_t,
56545630
info: *mut siginfo_t,
@@ -5762,10 +5738,7 @@ extern "C" {
57625738
pub fn umount(target: *const ::c_char) -> ::c_int;
57635739
pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int;
57645740
pub fn tee(fd_in: ::c_int, fd_out: ::c_int, len: ::size_t, flags: ::c_uint) -> ::ssize_t;
5765-
#[cfg_attr(
5766-
all(target_env = "musl", target_pointer_width = "32"),
5767-
link_name = "__settimeofday_time64"
5768-
)]
5741+
#[cfg_attr(musl_time64_abi, link_name = "__settimeofday_time64")]
57695742
pub fn settimeofday(tv: *const ::timeval, tz: *const ::timezone) -> ::c_int;
57705743
pub fn splice(
57715744
fd_in: ::c_int,
@@ -5779,15 +5752,9 @@ extern "C" {
57795752
pub fn eventfd_read(fd: ::c_int, value: *mut eventfd_t) -> ::c_int;
57805753
pub fn eventfd_write(fd: ::c_int, value: eventfd_t) -> ::c_int;
57815754

5782-
#[cfg_attr(
5783-
all(target_env = "musl", target_pointer_width = "32"),
5784-
link_name = "__sched_rr_get_interval_time64"
5785-
)]
5755+
#[cfg_attr(musl_time64_abi, link_name = "__sched_rr_get_interval_time64")]
57865756
pub fn sched_rr_get_interval(pid: ::pid_t, tp: *mut ::timespec) -> ::c_int;
5787-
#[cfg_attr(
5788-
all(target_env = "musl", target_pointer_width = "32"),
5789-
link_name = "__sem_timedwait_time64"
5790-
)]
5757+
#[cfg_attr(musl_time64_abi, link_name = "__sem_timedwait_time64")]
57915758
pub fn sem_timedwait(sem: *mut sem_t, abstime: *const ::timespec) -> ::c_int;
57925759
pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int;
57935760
pub fn sched_setparam(pid: ::pid_t, param: *const ::sched_param) -> ::c_int;
@@ -5809,10 +5776,7 @@ extern "C" {
58095776
pub fn personality(persona: ::c_ulong) -> ::c_int;
58105777
pub fn prctl(option: ::c_int, ...) -> ::c_int;
58115778
pub fn sched_getparam(pid: ::pid_t, param: *mut ::sched_param) -> ::c_int;
5812-
#[cfg_attr(
5813-
all(target_env = "musl", target_pointer_width = "32"),
5814-
link_name = "__ppoll_time64"
5815-
)]
5779+
#[cfg_attr(musl_time64_abi, link_name = "__ppoll_time64")]
58165780
pub fn ppoll(
58175781
fds: *mut ::pollfd,
58185782
nfds: nfds_t,
@@ -5828,10 +5792,7 @@ extern "C" {
58285792
protocol: ::c_int,
58295793
) -> ::c_int;
58305794
pub fn pthread_mutex_consistent(mutex: *mut pthread_mutex_t) -> ::c_int;
5831-
#[cfg_attr(
5832-
all(target_env = "musl", target_pointer_width = "32"),
5833-
link_name = "__pthread_mutex_timedlock_time64"
5834-
)]
5795+
#[cfg_attr(musl_time64_abi, link_name = "__pthread_mutex_timedlock_time64")]
58355796
pub fn pthread_mutex_timedlock(
58365797
lock: *mut pthread_mutex_t,
58375798
abstime: *const ::timespec,
@@ -5866,10 +5827,7 @@ extern "C" {
58665827
...
58675828
) -> ::c_int;
58685829
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;
5869-
#[cfg_attr(
5870-
all(target_env = "musl", target_pointer_width = "32"),
5871-
link_name = "__clock_nanosleep_time64"
5872-
)]
5830+
#[cfg_attr(musl_time64_abi, link_name = "__clock_nanosleep_time64")]
58735831
pub fn clock_nanosleep(
58745832
clk_id: ::clockid_t,
58755833
flags: ::c_int,
@@ -6139,15 +6097,9 @@ extern "C" {
61396097
) -> ::c_int;
61406098
pub fn timer_delete(timerid: ::timer_t) -> ::c_int;
61416099
pub fn timer_getoverrun(timerid: ::timer_t) -> ::c_int;
6142-
#[cfg_attr(
6143-
all(target_env = "musl", target_pointer_width = "32"),
6144-
link_name = "__timer_gettime64"
6145-
)]
6100+
#[cfg_attr(musl_time64_abi, link_name = "__timer_gettime64")]
61466101
pub fn timer_gettime(timerid: ::timer_t, curr_value: *mut ::itimerspec) -> ::c_int;
6147-
#[cfg_attr(
6148-
all(target_env = "musl", target_pointer_width = "32"),
6149-
link_name = "__timer_settime64"
6150-
)]
6102+
#[cfg_attr(musl_time64_abi, link_name = "__timer_settime64")]
61516103
pub fn timer_settime(
61526104
timerid: ::timer_t,
61536105
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
@@ -804,7 +804,7 @@ extern "C" {
804804
vlen: ::c_uint,
805805
flags: ::c_uint,
806806
) -> ::c_int;
807-
#[cfg_attr(target_pointer_width = "32", link_name = "__recvmmsg_time64")]
807+
#[cfg_attr(musl_time64_abi, link_name = "__recvmmsg_time64")]
808808
pub fn recvmmsg(
809809
sockfd: ::c_int,
810810
msgvec: *mut ::mmsghdr,
@@ -821,7 +821,7 @@ extern "C" {
821821
new_limit: *const ::rlimit,
822822
old_limit: *mut ::rlimit,
823823
) -> ::c_int;
824-
#[cfg_attr(target_pointer_width = "32", link_name = "__gettimeofday_time64")]
824+
#[cfg_attr(musl_time64_abi, link_name = "__gettimeofday_time64")]
825825
pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
826826
pub fn ptrace(request: ::c_int, ...) -> ::c_long;
827827
pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int;
@@ -843,9 +843,9 @@ extern "C" {
843843
// Added in `musl` 1.2.2
844844
pub fn reallocarray(ptr: *mut ::c_void, nmemb: ::size_t, size: ::size_t) -> *mut ::c_void;
845845

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

851851
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
@@ -1675,20 +1675,11 @@ extern "C" {
16751675
pub fn fdatasync(fd: ::c_int) -> ::c_int;
16761676
pub fn mincore(addr: *mut ::c_void, len: ::size_t, vec: *mut ::c_uchar) -> ::c_int;
16771677

1678-
#[cfg_attr(
1679-
all(target_env = "musl", target_pointer_width = "32"),
1680-
link_name = "__clock_getres_time64"
1681-
)]
1678+
#[cfg_attr(musl_time64_abi, link_name = "__clock_getres_time64")]
16821679
pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
1683-
#[cfg_attr(
1684-
all(target_env = "musl", target_pointer_width = "32"),
1685-
link_name = "__clock_gettime64"
1686-
)]
1680+
#[cfg_attr(musl_time64_abi, link_name = "__clock_gettime64")]
16871681
pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
1688-
#[cfg_attr(
1689-
all(target_env = "musl", target_pointer_width = "32"),
1690-
link_name = "__clock_settime64"
1691-
)]
1682+
#[cfg_attr(musl_time64_abi, link_name = "__clock_settime64")]
16921683
pub fn clock_settime(clk_id: ::clockid_t, tp: *const ::timespec) -> ::c_int;
16931684
pub fn clock_getcpuclockid(pid: ::pid_t, clk_id: *mut ::clockid_t) -> ::c_int;
16941685

@@ -1713,15 +1704,9 @@ extern "C" {
17131704
len: ::off64_t,
17141705
advise: ::c_int,
17151706
) -> ::c_int;
1716-
#[cfg_attr(
1717-
all(target_env = "musl", target_pointer_width = "32"),
1718-
link_name = "__futimens_time64"
1719-
)]
1707+
#[cfg_attr(musl_time64_abi, link_name = "__futimens_time64")]
17201708
pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int;
1721-
#[cfg_attr(
1722-
all(target_env = "musl", target_pointer_width = "32"),
1723-
link_name = "__utimensat_time64"
1724-
)]
1709+
#[cfg_attr(musl_time64_abi, link_name = "__utimensat_time64")]
17251710
pub fn utimensat(
17261711
dirfd: ::c_int,
17271712
path: *const ::c_char,
@@ -1733,15 +1718,9 @@ extern "C" {
17331718
pub fn newlocale(mask: ::c_int, locale: *const ::c_char, base: ::locale_t) -> ::locale_t;
17341719
pub fn uselocale(loc: ::locale_t) -> ::locale_t;
17351720
pub fn creat64(path: *const c_char, mode: mode_t) -> ::c_int;
1736-
#[cfg_attr(
1737-
all(target_env = "musl", target_pointer_width = "32"),
1738-
link_name = "__fstat_time64"
1739-
)]
1721+
#[cfg_attr(musl_time64_abi, link_name = "__fstat_time64")]
17401722
pub fn fstat64(fildes: ::c_int, buf: *mut stat64) -> ::c_int;
1741-
#[cfg_attr(
1742-
all(target_env = "musl", target_pointer_width = "32"),
1743-
link_name = "__fstatat_time64"
1744-
)]
1723+
#[cfg_attr(musl_time64_abi, link_name = "__fstatat_time64")]
17451724
pub fn fstatat64(
17461725
dirfd: ::c_int,
17471726
pathname: *const c_char,
@@ -1750,10 +1729,7 @@ extern "C" {
17501729
) -> ::c_int;
17511730
pub fn ftruncate64(fd: ::c_int, length: off64_t) -> ::c_int;
17521731
pub fn lseek64(fd: ::c_int, offset: off64_t, whence: ::c_int) -> off64_t;
1753-
#[cfg_attr(
1754-
all(target_env = "musl", target_pointer_width = "32"),
1755-
link_name = "__lstat_time64"
1756-
)]
1732+
#[cfg_attr(musl_time64_abi, link_name = "__lstat_time64")]
17571733
pub fn lstat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
17581734
pub fn mmap64(
17591735
addr: *mut ::c_void,
@@ -1778,10 +1754,7 @@ extern "C" {
17781754
entry: *mut ::dirent64,
17791755
result: *mut *mut ::dirent64,
17801756
) -> ::c_int;
1781-
#[cfg_attr(
1782-
all(target_env = "musl", target_pointer_width = "32"),
1783-
link_name = "__stat_time64"
1784-
)]
1757+
#[cfg_attr(musl_time64_abi, link_name = "__stat_time64")]
17851758
pub fn stat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
17861759
pub fn truncate64(path: *const c_char, length: off64_t) -> ::c_int;
17871760

@@ -1820,10 +1793,7 @@ extern "C" {
18201793
pub fn sbrk(increment: ::intptr_t) -> *mut ::c_void;
18211794
pub fn setresgid(rgid: ::gid_t, egid: ::gid_t, sgid: ::gid_t) -> ::c_int;
18221795
pub fn setresuid(ruid: ::uid_t, euid: ::uid_t, suid: ::uid_t) -> ::c_int;
1823-
#[cfg_attr(
1824-
all(target_env = "musl", target_pointer_width = "32"),
1825-
link_name = "__wait4_time64"
1826-
)]
1796+
#[cfg_attr(musl_time64_abi, link_name = "__wait4_time64")]
18271797
pub fn wait4(
18281798
pid: ::pid_t,
18291799
status: *mut ::c_int,

0 commit comments

Comments
 (0)