Skip to content

Commit 3467c35

Browse files
committed
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).
1 parent b6ab1fb commit 3467c35

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
@@ -3723,13 +3723,18 @@ fn test_linux(target: &str) {
37233723
}
37243724
let old_musl = musl && !musl_v1_2_3;
37253725

3726+
let b32 = arm || target.contains("hexagon") || mips32 || ppc32 || x86_32;
3727+
37263728
let mut cfg = ctest_cfg();
37273729
if (musl_v1_2_3 || loongarch64 || hexagon) && musl {
37283730
cfg.cfg("musl_v1_2_3", None);
3729-
if arm || hexagon || ppc32 || x86_32 || mips32 {
3731+
if b32 {
37303732
cfg.cfg("musl32_time64", None);
37313733
cfg.cfg("linux_time_bits64", None);
37323734
}
3735+
if arm || ppc32 || x86_32 || mips32 {
3736+
cfg.cfg("musl_redir_time64", None);
3737+
}
37333738
}
37343739
cfg.define("_GNU_SOURCE", None)
37353740
// This macro re-defines fscanf,scanf,sscanf to link to the symbols that are
@@ -4215,6 +4220,7 @@ fn test_linux(target: &str) {
42154220
|| name.starts_with("STATX_")
42164221
|| name.starts_with("SW_")
42174222
|| name.starts_with("SYS_")
4223+
|| name.starts_with("SYS3264_")
42184224
|| name.starts_with("TCP_")
42194225
|| name.starts_with("UINPUT_")
42204226
|| 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
@@ -4010,7 +4010,7 @@ cfg_if! {
40104010
msg_prio: *mut c_uint,
40114011
) -> ssize_t;
40124012
#[cfg_attr(
4013-
any(gnu_time_bits64, musl32_time64),
4013+
any(gnu_time_bits64, musl_redir_time64),
40144014
link_name = "__mq_timedreceive_time64"
40154015
)]
40164016
pub fn mq_timedreceive(
@@ -4027,7 +4027,7 @@ cfg_if! {
40274027
msg_prio: c_uint,
40284028
) -> c_int;
40294029
#[cfg_attr(
4030-
any(gnu_time_bits64, musl32_time64),
4030+
any(gnu_time_bits64, musl_redir_time64),
40314031
link_name = "__mq_timedsend_time64"
40324032
)]
40334033
pub fn mq_timedsend(
@@ -4053,7 +4053,7 @@ extern "C" {
40534053
pub fn lcong48(p: *mut c_ushort);
40544054

40554055
#[cfg_attr(gnu_time_bits64, link_name = "__lutimes64")]
4056-
#[cfg_attr(musl32_time64, link_name = "__lutimes_time64")]
4056+
#[cfg_attr(musl_redir_time64, link_name = "__lutimes_time64")]
40574057
pub fn lutimes(file: *const c_char, times: *const crate::timeval) -> c_int;
40584058

40594059
pub fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t) -> c_int;
@@ -4129,9 +4129,15 @@ extern "C" {
41294129
pub fn fremovexattr(filedes: c_int, name: *const c_char) -> c_int;
41304130
pub fn signalfd(fd: c_int, mask: *const crate::sigset_t, flags: c_int) -> c_int;
41314131
pub fn timerfd_create(clockid: crate::clockid_t, flags: c_int) -> c_int;
4132-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__timerfd_gettime64")]
4132+
#[cfg_attr(
4133+
any(gnu_time_bits64, musl_redir_time64),
4134+
link_name = "__timerfd_gettime64"
4135+
)]
41334136
pub fn timerfd_gettime(fd: c_int, curr_value: *mut crate::itimerspec) -> c_int;
4134-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__timerfd_settime64")]
4137+
#[cfg_attr(
4138+
any(gnu_time_bits64, musl_redir_time64),
4139+
link_name = "__timerfd_settime64"
4140+
)]
41354141
pub fn timerfd_settime(
41364142
fd: c_int,
41374143
flags: c_int,
@@ -4148,7 +4154,7 @@ extern "C" {
41484154
) -> c_int;
41494155
pub fn dup3(oldfd: c_int, newfd: c_int, flags: c_int) -> c_int;
41504156
#[cfg_attr(gnu_time_bits64, link_name = "__sigtimedwait64")]
4151-
#[cfg_attr(musl32_time64, link_name = "__sigtimedwait_time64")]
4157+
#[cfg_attr(musl_redir_time64, link_name = "__sigtimedwait_time64")]
41524158
pub fn sigtimedwait(
41534159
set: *const sigset_t,
41544160
info: *mut siginfo_t,
@@ -4211,7 +4217,7 @@ extern "C" {
42114217
pub fn eventfd_write(fd: c_int, value: eventfd_t) -> c_int;
42124218

42134219
#[cfg_attr(gnu_time_bits64, link_name = "__sched_rr_get_interval64")]
4214-
#[cfg_attr(musl32_time64, link_name = "__sched_rr_get_interval_time64")]
4220+
#[cfg_attr(musl_redir_time64, link_name = "__sched_rr_get_interval_time64")]
42154221
pub fn sched_rr_get_interval(pid: crate::pid_t, tp: *mut crate::timespec) -> c_int;
42164222
pub fn sched_setparam(pid: crate::pid_t, param: *const crate::sched_param) -> c_int;
42174223
pub fn setns(fd: c_int, nstype: c_int) -> c_int;
@@ -4229,7 +4235,7 @@ extern "C" {
42294235
) -> c_int;
42304236
pub fn sched_getscheduler(pid: crate::pid_t) -> c_int;
42314237
#[cfg_attr(
4232-
any(gnu_time_bits64, musl32_time64),
4238+
any(gnu_time_bits64, musl_redir_time64),
42334239
link_name = "__clock_nanosleep_time64"
42344240
)]
42354241
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
@@ -1922,20 +1922,26 @@ extern "C" {
19221922
pub fn mincore(addr: *mut c_void, len: size_t, vec: *mut c_uchar) -> c_int;
19231923

19241924
#[cfg_attr(gnu_time_bits64, link_name = "__clock_getres64")]
1925-
#[cfg_attr(musl32_time64, link_name = "__clock_getres_time64")]
1925+
#[cfg_attr(musl_redir_time64, link_name = "__clock_getres_time64")]
19261926
pub fn clock_getres(clk_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
1927-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__clock_gettime64")]
1927+
#[cfg_attr(
1928+
any(gnu_time_bits64, musl_redir_time64),
1929+
link_name = "__clock_gettime64"
1930+
)]
19281931
pub fn clock_gettime(clk_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
1929-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__clock_settime64")]
1932+
#[cfg_attr(
1933+
any(gnu_time_bits64, musl_redir_time64),
1934+
link_name = "__clock_settime64"
1935+
)]
19301936
pub fn clock_settime(clk_id: crate::clockid_t, tp: *const crate::timespec) -> c_int;
19311937
#[cfg(not(target_os = "l4re"))]
19321938
pub fn clock_getcpuclockid(pid: crate::pid_t, clk_id: *mut crate::clockid_t) -> c_int;
19331939

19341940
#[cfg_attr(gnu_time_bits64, link_name = "__getitimer64")]
1935-
#[cfg_attr(musl32_time64, link_name = "__getitimer_time64")]
1941+
#[cfg_attr(musl_redir_time64, link_name = "__getitimer_time64")]
19361942
pub fn getitimer(which: c_int, curr_value: *mut crate::itimerval) -> c_int;
19371943
#[cfg_attr(gnu_time_bits64, link_name = "__setitimer64")]
1938-
#[cfg_attr(musl32_time64, link_name = "__setitimer_time64")]
1944+
#[cfg_attr(musl_redir_time64, link_name = "__setitimer_time64")]
19391945
pub fn setitimer(
19401946
which: c_int,
19411947
new_value: *const crate::itimerval,
@@ -1956,11 +1962,11 @@ extern "C" {
19561962
#[cfg_attr(gnu_file_offset_bits64, link_name = "posix_fadvise64")]
19571963
pub fn posix_fadvise(fd: c_int, offset: off_t, len: off_t, advise: c_int) -> c_int;
19581964
#[cfg_attr(gnu_time_bits64, link_name = "__futimens64")]
1959-
#[cfg_attr(musl32_time64, link_name = "__futimens_time64")]
1965+
#[cfg_attr(musl_redir_time64, link_name = "__futimens_time64")]
19601966
#[cfg(not(target_os = "l4re"))]
19611967
pub fn futimens(fd: c_int, times: *const crate::timespec) -> c_int;
19621968
#[cfg_attr(gnu_time_bits64, link_name = "__utimensat64")]
1963-
#[cfg_attr(musl32_time64, link_name = "__utimensat_time64")]
1969+
#[cfg_attr(musl_redir_time64, link_name = "__utimensat_time64")]
19641970
pub fn utimensat(
19651971
dirfd: c_int,
19661972
path: *const c_char,
@@ -2007,7 +2013,7 @@ extern "C" {
20072013
pub fn setresgid(rgid: crate::gid_t, egid: crate::gid_t, sgid: crate::gid_t) -> c_int;
20082014
#[cfg(not(target_os = "l4re"))]
20092015
pub fn setresuid(ruid: crate::uid_t, euid: crate::uid_t, suid: crate::uid_t) -> c_int;
2010-
#[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__wait4_time64")]
2016+
#[cfg_attr(any(gnu_time_bits64, musl_redir_time64), link_name = "__wait4_time64")]
20112017
#[cfg(not(target_os = "l4re"))]
20122018
pub fn wait4(
20132019
pid: crate::pid_t,

0 commit comments

Comments
 (0)