Skip to content

Commit b3264b2

Browse files
androm3datgross35
authored andcommitted
hexagon: decouple time64 types from musl symbol redirects
The `musl32_time64` cfg previously conflated two distinct concepts: 1. Type definitions: `time_t` is `i64`, `suseconds_t` is `i64`, `timespec` has padding — applies to all 32-bit musl v1.2.3+ targets including hexagon. 2. Symbol redirects: `clock_gettime` → `__clock_gettime64` etc., corresponding to musl's `_REDIR_TIME64` — applies only to arm, mips, powerpc, and x86. Hexagon was added to musl after the time64 transition and never had a 32-bit `time_t`, so its libc exports `clock_gettime` directly with no `__*_time64` symbols. Applying the link-name redirects caused undefined symbol errors at link time (rust-lang/rust#154686). Introduce a new `musl_redir_time64` cfg for the symbol redirects and restrict it to arches that define `_REDIR_TIME64`. Keep `musl32_time64` for the type/struct meaning, now set generically for all 32-bit musl v1.2.3+ targets (removing explicit `target_arch = "hexagon"` conditions). (backport <#5040>) (cherry picked from commit a6b660c)
1 parent db1ebee commit b3264b2

9 files changed

Lines changed: 86 additions & 56 deletions

File tree

build.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ const ALLOWED_CFGS: &[&str] = &[
2828
// Corresponds to `__USE_TIME_BITS64` in UAPI
2929
"linux_time_bits64",
3030
"musl_v1_2_3",
31-
// Corresponds to `_REDIR_TIME64` in musl
31+
// musl v1.2.3+ && 32-bit: time_t is i64, struct layouts change
3232
"musl32_time64",
33+
// Corresponds to `_REDIR_TIME64` in musl: symbol redirects to __*_time64
34+
"musl_redir_time64",
3335
"vxworks_lt_25_09",
3436
];
3537

@@ -51,8 +53,9 @@ const CHECK_CFG_EXTRA: &[(&str, &[&str])] = &[
5153
),
5254
];
5355

54-
/// Musl architectures that set `#define _REDIR_TIME64 1`.
55-
const MUSL_REDIR_TIME64_ARCHES: &[&str] = &["arm", "hexagon", "mips", "powerpc", "x86"];
56+
/// Musl architectures that define `_REDIR_TIME64` (i.e. those that transitioned
57+
/// from 32-bit to 64-bit `time_t` and need `__*_time64` symbol redirects).
58+
const MUSL_REDIR_TIME64_ARCHES: &[&str] = &["arm", "mips", "powerpc", "x86"];
5659

5760
fn main() {
5861
// Avoid unnecessary re-building.
@@ -117,10 +120,13 @@ fn main() {
117120

118121
if musl && musl_v1_2_3 {
119122
set_cfg("musl_v1_2_3");
120-
if MUSL_REDIR_TIME64_ARCHES.contains(&target_arch.as_str()) {
123+
if target_ptr_width == "32" {
121124
set_cfg("musl32_time64");
122125
set_cfg("linux_time_bits64");
123126
}
127+
if MUSL_REDIR_TIME64_ARCHES.contains(&target_arch.as_str()) {
128+
set_cfg("musl_redir_time64");
129+
}
124130
}
125131

126132
let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok();

libc-test/build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3869,13 +3869,18 @@ fn test_linux(target: &str) {
38693869
}
38703870
let old_musl = musl && !musl_v1_2_3;
38713871

3872+
let b32 = arm || target.contains("hexagon") || mips32 || ppc32 || x86_32;
3873+
38723874
let mut cfg = ctest_cfg();
38733875
if (musl_v1_2_3 || loongarch64 || hexagon) && musl {
38743876
cfg.cfg("musl_v1_2_3", None);
3875-
if arm || hexagon || ppc32 || x86_32 || mips32 {
3877+
if b32 {
38763878
cfg.cfg("musl32_time64", None);
38773879
cfg.cfg("linux_time_bits64", None);
38783880
}
3881+
if arm || ppc32 || x86_32 || mips32 {
3882+
cfg.cfg("musl_redir_time64", None);
3883+
}
38793884
}
38803885
cfg.define("_GNU_SOURCE", None)
38813886
// This macro re-defines fscanf,scanf,sscanf to link to the symbols that are
@@ -4364,6 +4369,7 @@ fn test_linux(target: &str) {
43644369
|| name.starts_with("STATX_")
43654370
|| name.starts_with("SW_")
43664371
|| name.starts_with("SYS_")
4372+
|| name.starts_with("SYS3264_")
43674373
|| name.starts_with("TCP_")
43684374
|| name.starts_with("UINPUT_")
43694375
|| name.starts_with("VMADDR_")

src/new/common/posix/pthread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ extern "C" {
195195

196196
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
197197
#[cfg_attr(gnu_time_bits64, link_name = "__pthread_mutex_timedlock64")]
198-
#[cfg_attr(musl32_time64, link_name = "__pthread_mutex_timedlock_time64")]
198+
#[cfg_attr(musl_redir_time64, link_name = "__pthread_mutex_timedlock_time64")]
199199
pub fn pthread_mutex_timedlock(
200200
lock: *mut crate::pthread_mutex_t,
201201
abstime: *const crate::timespec,

src/new/musl/sys/socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern "C" {
4141
vlen: c_uint,
4242
flags: c_uint,
4343
) -> c_int;
44-
#[cfg_attr(musl32_time64, link_name = "__recvmmsg_time64")]
44+
#[cfg_attr(musl_redir_time64, link_name = "__recvmmsg_time64")]
4545
pub fn recvmmsg(
4646
sockfd: c_int,
4747
msgvec: *mut crate::mmsghdr,

src/unix/linux_like/linux/mod.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4046,7 +4046,7 @@ cfg_if! {
40464046
msg_prio: *mut c_uint,
40474047
) -> ssize_t;
40484048
#[cfg_attr(
4049-
any(gnu_time_bits64, musl32_time64),
4049+
any(gnu_time_bits64, musl_redir_time64),
40504050
link_name = "__mq_timedreceive_time64"
40514051
)]
40524052
pub fn mq_timedreceive(
@@ -4063,7 +4063,7 @@ cfg_if! {
40634063
msg_prio: c_uint,
40644064
) -> c_int;
40654065
#[cfg_attr(
4066-
any(gnu_time_bits64, musl32_time64),
4066+
any(gnu_time_bits64, musl_redir_time64),
40674067
link_name = "__mq_timedsend_time64"
40684068
)]
40694069
pub fn mq_timedsend(
@@ -4089,7 +4089,7 @@ extern "C" {
40894089
pub fn lcong48(p: *mut c_ushort);
40904090

40914091
#[cfg_attr(gnu_time_bits64, link_name = "__lutimes64")]
4092-
#[cfg_attr(musl32_time64, link_name = "__lutimes_time64")]
4092+
#[cfg_attr(musl_redir_time64, link_name = "__lutimes_time64")]
40934093
pub fn lutimes(file: *const c_char, times: *const crate::timeval) -> c_int;
40944094

40954095
pub fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t) -> c_int;
@@ -4165,9 +4165,15 @@ extern "C" {
41654165
pub fn fremovexattr(filedes: c_int, name: *const c_char) -> c_int;
41664166
pub fn signalfd(fd: c_int, mask: *const crate::sigset_t, flags: c_int) -> c_int;
41674167
pub fn timerfd_create(clockid: crate::clockid_t, flags: c_int) -> c_int;
4168-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__timerfd_gettime64")]
4168+
#[cfg_attr(
4169+
any(gnu_time_bits64, musl_redir_time64),
4170+
link_name = "__timerfd_gettime64"
4171+
)]
41694172
pub fn timerfd_gettime(fd: c_int, curr_value: *mut crate::itimerspec) -> c_int;
4170-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__timerfd_settime64")]
4173+
#[cfg_attr(
4174+
any(gnu_time_bits64, musl_redir_time64),
4175+
link_name = "__timerfd_settime64"
4176+
)]
41714177
pub fn timerfd_settime(
41724178
fd: c_int,
41734179
flags: c_int,
@@ -4184,7 +4190,7 @@ extern "C" {
41844190
) -> c_int;
41854191
pub fn dup3(oldfd: c_int, newfd: c_int, flags: c_int) -> c_int;
41864192
#[cfg_attr(gnu_time_bits64, link_name = "__sigtimedwait64")]
4187-
#[cfg_attr(musl32_time64, link_name = "__sigtimedwait_time64")]
4193+
#[cfg_attr(musl_redir_time64, link_name = "__sigtimedwait_time64")]
41884194
pub fn sigtimedwait(
41894195
set: *const sigset_t,
41904196
info: *mut siginfo_t,
@@ -4247,7 +4253,7 @@ extern "C" {
42474253
pub fn eventfd_write(fd: c_int, value: eventfd_t) -> c_int;
42484254

42494255
#[cfg_attr(gnu_time_bits64, link_name = "__sched_rr_get_interval64")]
4250-
#[cfg_attr(musl32_time64, link_name = "__sched_rr_get_interval_time64")]
4256+
#[cfg_attr(musl_redir_time64, link_name = "__sched_rr_get_interval_time64")]
42514257
pub fn sched_rr_get_interval(pid: crate::pid_t, tp: *mut crate::timespec) -> c_int;
42524258
pub fn sched_setparam(pid: crate::pid_t, param: *const crate::sched_param) -> c_int;
42534259
pub fn setns(fd: c_int, nstype: c_int) -> c_int;
@@ -4265,7 +4271,7 @@ extern "C" {
42654271
) -> c_int;
42664272
pub fn sched_getscheduler(pid: crate::pid_t) -> c_int;
42674273
#[cfg_attr(
4268-
any(gnu_time_bits64, musl32_time64),
4274+
any(gnu_time_bits64, musl_redir_time64),
42694275
link_name = "__clock_nanosleep_time64"
42704276
)]
42714277
pub fn clock_nanosleep(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ extern "C" {
765765
new_limit: *const crate::rlimit,
766766
old_limit: *mut crate::rlimit,
767767
) -> c_int;
768-
#[cfg_attr(musl32_time64, link_name = "__gettimeofday_time64")]
768+
#[cfg_attr(musl_redir_time64, link_name = "__gettimeofday_time64")]
769769
pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut c_void) -> c_int;
770770
pub fn ptrace(request: c_int, ...) -> c_long;
771771
pub fn getpriority(which: c_int, who: crate::id_t) -> c_int;
@@ -801,9 +801,9 @@ extern "C" {
801801
// Added in `musl` 1.2.2
802802
pub fn reallocarray(ptr: *mut c_void, nmemb: size_t, size: size_t) -> *mut c_void;
803803

804-
#[cfg_attr(musl32_time64, link_name = "__adjtimex_time64")]
804+
#[cfg_attr(musl_redir_time64, link_name = "__adjtimex_time64")]
805805
pub fn adjtimex(buf: *mut crate::timex) -> c_int;
806-
#[cfg_attr(musl32_time64, link_name = "__clock_adjtime64")]
806+
#[cfg_attr(musl_redir_time64, link_name = "__clock_adjtime64")]
807807
pub fn clock_adjtime(clk_id: crate::clockid_t, buf: *mut crate::timex) -> c_int;
808808

809809
pub fn ctermid(s: *mut c_char) -> *mut c_char;
@@ -871,7 +871,7 @@ extern "C" {
871871
pub fn utmpxname(file: *const c_char) -> c_int;
872872
pub fn pthread_tryjoin_np(thread: crate::pthread_t, retval: *mut *mut c_void) -> c_int;
873873
#[cfg_attr(
874-
all(musl32_time64, target_pointer_width = "32"),
874+
all(musl_redir_time64, target_pointer_width = "32"),
875875
link_name = "__pthread_timedjoin_np_time64"
876876
)]
877877
pub fn pthread_timedjoin_np(

src/unix/linux_like/linux_l4re_shared.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ pub const IPC_NOWAIT: c_int = 0o4000;
976976

977977
pub const IPC_RMID: c_int = 0;
978978
pub const IPC_SET: c_int = 1;
979-
pub const IPC_STAT: c_int = if cfg!(musl32_time64) { 0x102 } else { 2 };
979+
pub const IPC_STAT: c_int = if cfg!(musl_redir_time64) { 0x102 } else { 2 };
980980
pub const IPC_INFO: c_int = 3;
981981

982982
pub const SHM_R: c_int = 0o400;
@@ -1660,7 +1660,7 @@ cfg_if! {
16601660
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_return64")]
16611661
pub fn aio_return(aiocbp: *mut crate::aiocb) -> ssize_t;
16621662
#[cfg_attr(
1663-
any(musl32_time64, gnu_time_bits64),
1663+
any(musl_redir_time64, gnu_time_bits64),
16641664
link_name = "__aio_suspend_time64"
16651665
)]
16661666
pub fn aio_suspend(
@@ -1725,7 +1725,7 @@ cfg_if! {
17251725
flags: c_ulong,
17261726
) -> isize;
17271727
#[cfg_attr(gnu_time_bits64, link_name = "__futimes64")]
1728-
#[cfg_attr(musl32_time64, link_name = "__futimes_time64")]
1728+
#[cfg_attr(musl_redir_time64, link_name = "__futimes_time64")]
17291729
pub fn futimes(fd: c_int, times: *const crate::timeval) -> c_int;
17301730
}
17311731
}
@@ -1827,10 +1827,10 @@ extern "C" {
18271827
) -> c_int;
18281828
pub fn sched_get_priority_max(policy: c_int) -> c_int;
18291829
#[cfg_attr(gnu_time_bits64, link_name = "__settimeofday64")]
1830-
#[cfg_attr(musl32_time64, link_name = "__settimeofday_time64")]
1830+
#[cfg_attr(musl_redir_time64, link_name = "__settimeofday_time64")]
18311831
pub fn settimeofday(tv: *const crate::timeval, tz: *const crate::timezone) -> c_int;
18321832
#[cfg_attr(gnu_time_bits64, link_name = "__sem_timedwait64")]
1833-
#[cfg_attr(musl32_time64, link_name = "__sem_timedwait_time64")]
1833+
#[cfg_attr(musl_redir_time64, link_name = "__sem_timedwait_time64")]
18341834
pub fn sem_timedwait(sem: *mut crate::sem_t, abstime: *const crate::timespec) -> c_int;
18351835
pub fn sem_getvalue(sem: *mut crate::sem_t, sval: *mut c_int) -> c_int;
18361836
pub fn mount(
@@ -1843,7 +1843,7 @@ extern "C" {
18431843
#[cfg_attr(gnu_time_bits64, link_name = "__prctl_time64")]
18441844
pub fn prctl(option: c_int, ...) -> c_int;
18451845
#[cfg_attr(gnu_time_bits64, link_name = "__ppoll64")]
1846-
#[cfg_attr(musl32_time64, link_name = "__ppoll_time64")]
1846+
#[cfg_attr(musl_redir_time64, link_name = "__ppoll_time64")]
18471847
pub fn ppoll(
18481848
fds: *mut crate::pollfd,
18491849
nfds: crate::nfds_t,
@@ -1934,9 +1934,15 @@ extern "C" {
19341934
pub fn timer_delete(timerid: crate::timer_t) -> c_int;
19351935
#[cfg(not(target_os = "l4re"))]
19361936
pub fn timer_getoverrun(timerid: crate::timer_t) -> c_int;
1937-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__timer_gettime64")]
1937+
#[cfg_attr(
1938+
any(gnu_time_bits64, musl_redir_time64),
1939+
link_name = "__timer_gettime64"
1940+
)]
19381941
pub fn timer_gettime(timerid: crate::timer_t, curr_value: *mut crate::itimerspec) -> c_int;
1939-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__timer_settime64")]
1942+
#[cfg_attr(
1943+
any(gnu_time_bits64, musl_redir_time64),
1944+
link_name = "__timer_settime64"
1945+
)]
19401946
pub fn timer_settime(
19411947
timerid: crate::timer_t,
19421948
flags: c_int,

src/unix/linux_like/mod.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,20 +1873,26 @@ extern "C" {
18731873
pub fn mincore(addr: *mut c_void, len: size_t, vec: *mut c_uchar) -> c_int;
18741874

18751875
#[cfg_attr(gnu_time_bits64, link_name = "__clock_getres64")]
1876-
#[cfg_attr(musl32_time64, link_name = "__clock_getres_time64")]
1876+
#[cfg_attr(musl_redir_time64, link_name = "__clock_getres_time64")]
18771877
pub fn clock_getres(clk_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
1878-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__clock_gettime64")]
1878+
#[cfg_attr(
1879+
any(gnu_time_bits64, musl_redir_time64),
1880+
link_name = "__clock_gettime64"
1881+
)]
18791882
pub fn clock_gettime(clk_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
1880-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__clock_settime64")]
1883+
#[cfg_attr(
1884+
any(gnu_time_bits64, musl_redir_time64),
1885+
link_name = "__clock_settime64"
1886+
)]
18811887
pub fn clock_settime(clk_id: crate::clockid_t, tp: *const crate::timespec) -> c_int;
18821888
#[cfg(not(target_os = "l4re"))]
18831889
pub fn clock_getcpuclockid(pid: crate::pid_t, clk_id: *mut crate::clockid_t) -> c_int;
18841890

18851891
#[cfg_attr(gnu_time_bits64, link_name = "__getitimer64")]
1886-
#[cfg_attr(musl32_time64, link_name = "__getitimer_time64")]
1892+
#[cfg_attr(musl_redir_time64, link_name = "__getitimer_time64")]
18871893
pub fn getitimer(which: c_int, curr_value: *mut crate::itimerval) -> c_int;
18881894
#[cfg_attr(gnu_time_bits64, link_name = "__setitimer64")]
1889-
#[cfg_attr(musl32_time64, link_name = "__setitimer_time64")]
1895+
#[cfg_attr(musl_redir_time64, link_name = "__setitimer_time64")]
18901896
pub fn setitimer(
18911897
which: c_int,
18921898
new_value: *const crate::itimerval,
@@ -1907,11 +1913,11 @@ extern "C" {
19071913
#[cfg_attr(gnu_file_offset_bits64, link_name = "posix_fadvise64")]
19081914
pub fn posix_fadvise(fd: c_int, offset: off_t, len: off_t, advise: c_int) -> c_int;
19091915
#[cfg_attr(gnu_time_bits64, link_name = "__futimens64")]
1910-
#[cfg_attr(musl32_time64, link_name = "__futimens_time64")]
1916+
#[cfg_attr(musl_redir_time64, link_name = "__futimens_time64")]
19111917
#[cfg(not(target_os = "l4re"))]
19121918
pub fn futimens(fd: c_int, times: *const crate::timespec) -> c_int;
19131919
#[cfg_attr(gnu_time_bits64, link_name = "__utimensat64")]
1914-
#[cfg_attr(musl32_time64, link_name = "__utimensat_time64")]
1920+
#[cfg_attr(musl_redir_time64, link_name = "__utimensat_time64")]
19151921
pub fn utimensat(
19161922
dirfd: c_int,
19171923
path: *const c_char,
@@ -1963,7 +1969,7 @@ extern "C" {
19631969
pub fn setresgid(rgid: crate::gid_t, egid: crate::gid_t, sgid: crate::gid_t) -> c_int;
19641970
#[cfg(not(target_os = "l4re"))]
19651971
pub fn setresuid(ruid: crate::uid_t, euid: crate::uid_t, suid: crate::uid_t) -> c_int;
1966-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__wait4_time64")]
1972+
#[cfg_attr(any(gnu_time_bits64, musl_redir_time64), link_name = "__wait4_time64")]
19671973
#[cfg(not(target_os = "l4re"))]
19681974
pub fn wait4(
19691975
pid: crate::pid_t,

0 commit comments

Comments
 (0)