Skip to content

Commit 1361944

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 ecb8b29 commit 1361944

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");
@@ -205,3 +211,22 @@ fn set_cfg(cfg: &str) {
205211
}
206212
println!("cargo:rustc-cfg={}", cfg);
207213
}
214+
215+
fn is_musl_time64_abi() -> bool {
216+
match env::var("TARGET") {
217+
Ok(target) => match &target[..] {
218+
"arm-unknown-linux-musleabi"
219+
| "arm-unknown-linux-musleabihf"
220+
| "armv5te-unknown-linux-musleabi"
221+
| "armv7-unknown-linux-musleabi"
222+
| "armv7-unknown-linux-musleabihf"
223+
| "i586-unknown-linux-musl"
224+
| "i686-unknown-linux-musl"
225+
| "mips-unknown-linux-musl"
226+
| "mipsel-unknown-linux-musl"
227+
| "powerpc-unknown-linux-musl" => true,
228+
_ => false,
229+
},
230+
Err(_) => false,
231+
}
232+
}

libc-test/build.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,23 @@ fn test_linux(target: &str) {
32833283
// deprecated since glibc >= 2.29. This allows Rust binaries to link against
32843284
// glibc versions older than 2.29.
32853285
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);
3286+
// Some targets use time64 symbols so set the musl_time64_abi appropriately.
3287+
// See #2088 and #1848 for more information.
3288+
match target {
3289+
"arm-unknown-linux-musleabi"
3290+
| "arm-unknown-linux-musleabihf"
3291+
| "armv5te-unknown-linux-musleabi"
3292+
| "armv7-unknown-linux-musleabi"
3293+
| "armv7-unknown-linux-musleabihf"
3294+
| "i586-unknown-linux-musl"
3295+
| "i686-unknown-linux-musl"
3296+
| "mips-unknown-linux-musl"
3297+
| "mipsel-unknown-linux-musl"
3298+
| "powerpc-unknown-linux-musl" => {
3299+
cfg.cfg("musl_time64_abi", None);
3300+
}
3301+
_ => {}
3302+
}
32863303

32873304
headers! { cfg:
32883305
"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,
@@ -5315,10 +5315,7 @@ cfg_if! {
53155315
pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int;
53165316
pub fn aio_error(aiocbp: *const aiocb) -> ::c_int;
53175317
pub fn aio_return(aiocbp: *mut aiocb) -> ::ssize_t;
5318-
#[cfg_attr(
5319-
all(target_env = "musl", target_pointer_width = "32"),
5320-
link_name = "__aio_suspend_time64"
5321-
)]
5318+
#[cfg_attr(musl_time64_abi, link_name = "__aio_suspend_time64")]
53225319
pub fn aio_suspend(
53235320
aiocb_list: *const *const aiocb,
53245321
nitems: ::c_int,
@@ -5379,10 +5376,7 @@ cfg_if! {
53795376
riovcnt: ::c_ulong,
53805377
flags: ::c_ulong,
53815378
) -> isize;
5382-
#[cfg_attr(
5383-
all(target_env = "musl", target_pointer_width = "32"),
5384-
link_name = "__futimes_time64"
5385-
)]
5379+
#[cfg_attr(musl_time64_abi, link_name = "__futimes_time64")]
53865380
pub fn futimes(
53875381
fd: ::c_int,
53885382
times: *const ::timeval
@@ -5441,10 +5435,7 @@ extern "C" {
54415435
pub fn seed48(xseed: *mut ::c_ushort) -> *mut ::c_ushort;
54425436
pub fn lcong48(p: *mut ::c_ushort);
54435437

5444-
#[cfg_attr(
5445-
all(target_env = "musl", target_pointer_width = "32"),
5446-
link_name = "__lutimes_time64"
5447-
)]
5438+
#[cfg_attr(musl_time64_abi, link_name = "__lutimes_time64")]
54485439
pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int;
54495440

54505441
pub fn setpwent();
@@ -5540,15 +5531,9 @@ extern "C" {
55405531
pub fn fremovexattr(filedes: ::c_int, name: *const c_char) -> ::c_int;
55415532
pub fn signalfd(fd: ::c_int, mask: *const ::sigset_t, flags: ::c_int) -> ::c_int;
55425533
pub fn timerfd_create(clockid: ::clockid_t, flags: ::c_int) -> ::c_int;
5543-
#[cfg_attr(
5544-
all(target_env = "musl", target_pointer_width = "32"),
5545-
link_name = "__timerfd_gettime64"
5546-
)]
5534+
#[cfg_attr(musl_time64_abi, link_name = "__timerfd_gettime64")]
55475535
pub fn timerfd_gettime(fd: ::c_int, curr_value: *mut itimerspec) -> ::c_int;
5548-
#[cfg_attr(
5549-
all(target_env = "musl", target_pointer_width = "32"),
5550-
link_name = "__timerfd_settime64"
5551-
)]
5536+
#[cfg_attr(musl_time64_abi, link_name = "__timerfd_settime64")]
55525537
pub fn timerfd_settime(
55535538
fd: ::c_int,
55545539
flags: ::c_int,
@@ -5570,10 +5555,7 @@ extern "C" {
55705555
msg_len: ::size_t,
55715556
msg_prio: *mut ::c_uint,
55725557
) -> ::ssize_t;
5573-
#[cfg_attr(
5574-
all(target_env = "musl", target_pointer_width = "32"),
5575-
link_name = "__mq_timedreceive_time64"
5576-
)]
5558+
#[cfg_attr(musl_time64_abi, link_name = "__mq_timedreceive_time64")]
55775559
pub fn mq_timedreceive(
55785560
mqd: ::mqd_t,
55795561
msg_ptr: *mut ::c_char,
@@ -5587,10 +5569,7 @@ extern "C" {
55875569
msg_len: ::size_t,
55885570
msg_prio: ::c_uint,
55895571
) -> ::c_int;
5590-
#[cfg_attr(
5591-
all(target_env = "musl", target_pointer_width = "32"),
5592-
link_name = "__mq_timedsend_time64"
5593-
)]
5572+
#[cfg_attr(musl_time64_abi, link_name = "__mq_timedsend_time64")]
55945573
pub fn mq_timedsend(
55955574
mqd: ::mqd_t,
55965575
msg_ptr: *const ::c_char,
@@ -5610,10 +5589,7 @@ extern "C" {
56105589
pub fn dup3(oldfd: ::c_int, newfd: ::c_int, flags: ::c_int) -> ::c_int;
56115590
pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int;
56125591
pub fn mkostemps(template: *mut ::c_char, suffixlen: ::c_int, flags: ::c_int) -> ::c_int;
5613-
#[cfg_attr(
5614-
all(target_env = "musl", target_pointer_width = "32"),
5615-
link_name = "__sigtimedwait_time64"
5616-
)]
5592+
#[cfg_attr(musl_time64_abi, link_name = "__sigtimedwait_time64")]
56175593
pub fn sigtimedwait(
56185594
set: *const sigset_t,
56195595
info: *mut siginfo_t,
@@ -5727,10 +5703,7 @@ extern "C" {
57275703
pub fn umount(target: *const ::c_char) -> ::c_int;
57285704
pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int;
57295705
pub fn tee(fd_in: ::c_int, fd_out: ::c_int, len: ::size_t, flags: ::c_uint) -> ::ssize_t;
5730-
#[cfg_attr(
5731-
all(target_env = "musl", target_pointer_width = "32"),
5732-
link_name = "__settimeofday_time64"
5733-
)]
5706+
#[cfg_attr(musl_time64_abi, link_name = "__settimeofday_time64")]
57345707
pub fn settimeofday(tv: *const ::timeval, tz: *const ::timezone) -> ::c_int;
57355708
pub fn splice(
57365709
fd_in: ::c_int,
@@ -5744,15 +5717,9 @@ extern "C" {
57445717
pub fn eventfd_read(fd: ::c_int, value: *mut eventfd_t) -> ::c_int;
57455718
pub fn eventfd_write(fd: ::c_int, value: eventfd_t) -> ::c_int;
57465719

5747-
#[cfg_attr(
5748-
all(target_env = "musl", target_pointer_width = "32"),
5749-
link_name = "__sched_rr_get_interval_time64"
5750-
)]
5720+
#[cfg_attr(musl_time64_abi, link_name = "__sched_rr_get_interval_time64")]
57515721
pub fn sched_rr_get_interval(pid: ::pid_t, tp: *mut ::timespec) -> ::c_int;
5752-
#[cfg_attr(
5753-
all(target_env = "musl", target_pointer_width = "32"),
5754-
link_name = "__sem_timedwait_time64"
5755-
)]
5722+
#[cfg_attr(musl_time64_abi, link_name = "__sem_timedwait_time64")]
57565723
pub fn sem_timedwait(sem: *mut sem_t, abstime: *const ::timespec) -> ::c_int;
57575724
pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int;
57585725
pub fn sched_setparam(pid: ::pid_t, param: *const ::sched_param) -> ::c_int;
@@ -5774,10 +5741,7 @@ extern "C" {
57745741
pub fn personality(persona: ::c_ulong) -> ::c_int;
57755742
pub fn prctl(option: ::c_int, ...) -> ::c_int;
57765743
pub fn sched_getparam(pid: ::pid_t, param: *mut ::sched_param) -> ::c_int;
5777-
#[cfg_attr(
5778-
all(target_env = "musl", target_pointer_width = "32"),
5779-
link_name = "__ppoll_time64"
5780-
)]
5744+
#[cfg_attr(musl_time64_abi, link_name = "__ppoll_time64")]
57815745
pub fn ppoll(
57825746
fds: *mut ::pollfd,
57835747
nfds: nfds_t,
@@ -5793,10 +5757,7 @@ extern "C" {
57935757
protocol: ::c_int,
57945758
) -> ::c_int;
57955759
pub fn pthread_mutex_consistent(mutex: *mut pthread_mutex_t) -> ::c_int;
5796-
#[cfg_attr(
5797-
all(target_env = "musl", target_pointer_width = "32"),
5798-
link_name = "__pthread_mutex_timedlock_time64"
5799-
)]
5760+
#[cfg_attr(musl_time64_abi, link_name = "__pthread_mutex_timedlock_time64")]
58005761
pub fn pthread_mutex_timedlock(
58015762
lock: *mut pthread_mutex_t,
58025763
abstime: *const ::timespec,
@@ -5831,10 +5792,7 @@ extern "C" {
58315792
...
58325793
) -> ::c_int;
58335794
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;
5834-
#[cfg_attr(
5835-
all(target_env = "musl", target_pointer_width = "32"),
5836-
link_name = "__clock_nanosleep_time64"
5837-
)]
5795+
#[cfg_attr(musl_time64_abi, link_name = "__clock_nanosleep_time64")]
58385796
pub fn clock_nanosleep(
58395797
clk_id: ::clockid_t,
58405798
flags: ::c_int,
@@ -6104,15 +6062,9 @@ extern "C" {
61046062
) -> ::c_int;
61056063
pub fn timer_delete(timerid: ::timer_t) -> ::c_int;
61066064
pub fn timer_getoverrun(timerid: ::timer_t) -> ::c_int;
6107-
#[cfg_attr(
6108-
all(target_env = "musl", target_pointer_width = "32"),
6109-
link_name = "__timer_gettime64"
6110-
)]
6065+
#[cfg_attr(musl_time64_abi, link_name = "__timer_gettime64")]
61116066
pub fn timer_gettime(timerid: ::timer_t, curr_value: *mut ::itimerspec) -> ::c_int;
6112-
#[cfg_attr(
6113-
all(target_env = "musl", target_pointer_width = "32"),
6114-
link_name = "__timer_settime64"
6115-
)]
6067+
#[cfg_attr(musl_time64_abi, link_name = "__timer_settime64")]
61166068
pub fn timer_settime(
61176069
timerid: ::timer_t,
61186070
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,
@@ -822,7 +822,7 @@ extern "C" {
822822
old_limit: *mut ::rlimit,
823823
) -> ::c_int;
824824
pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
825-
#[cfg_attr(target_pointer_width = "32", link_name = "__gettimeofday_time64")]
825+
#[cfg_attr(musl_time64_abi, link_name = "__gettimeofday_time64")]
826826
pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
827827
pub fn ptrace(request: ::c_int, ...) -> ::c_long;
828828
pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int;
@@ -844,9 +844,9 @@ extern "C" {
844844
// Added in `musl` 1.2.2
845845
pub fn reallocarray(ptr: *mut ::c_void, nmemb: ::size_t, size: ::size_t) -> *mut ::c_void;
846846

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

852852
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)