Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade musl supported version to 1.2.3 #3068

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
25 changes: 25 additions & 0 deletions build.rs
Expand Up @@ -35,6 +35,12 @@ fn main() {
Some(_) | None => println!("cargo:rustc-cfg=freebsd11"),
}

// Some ABIs need to redirect time related symbols to their time64
// equivalents. See #2088 and #1848 for more information.
if is_musl_time64_abi() {
println!("cargo:rustc-cfg=musl_time64_abi");
}

// On CI: deny all warnings
if libc_ci {
println!("cargo:rustc-cfg=libc_deny_warnings");
Expand Down Expand Up @@ -176,3 +182,22 @@ fn which_freebsd() -> Option<i32> {
_ => None,
}
}

fn is_musl_time64_abi() -> bool {
match env::var("TARGET") {
Ok(target) => match &target[..] {
"arm-unknown-linux-musleabi"
| "arm-unknown-linux-musleabihf"
| "armv5te-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabihf"
| "i586-unknown-linux-musl"
| "i686-unknown-linux-musl"
| "mips-unknown-linux-musl"
| "mipsel-unknown-linux-musl"
| "powerpc-unknown-linux-musl" => true,
Copy link

@kanavin kanavin Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work for custom targets, e.g. yocto is defining them like 'i686-poky-linux-musl'. It's better to split TARGET into parts and match against them, e.g. first check for presence of 'musl, and then against a list of affected 32 bit architectures. Same comment for libc-test/build.rs.

Here's how a similar issue was fixed (by me :) in crossbeam: all custom vendors (e.g. poky, gentoo, etc.) were converted to '-unknown-' and then matching against the standard list would work:
crossbeam-rs/crossbeam#922

_ => false,
},
Err(_) => false,
}
}
10 changes: 5 additions & 5 deletions ci/docker/mips-unknown-linux-musl/Dockerfile
Expand Up @@ -10,16 +10,16 @@ RUN mkdir /toolchain
# See build_dir/target-mips_24kc_musl/linux-ath79_generic/linux-5.4.154
# Musl version: 1.1.24
# See staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/info.mk
RUN curl --retry 5 -L https://downloads.openwrt.org/releases/21.02.1/targets/ath79/generic/openwrt-sdk-21.02.1-ath79-generic_gcc-8.4.0_musl.Linux-x86_64.tar.xz | \
RUN curl --retry 5 -L https://downloads.openwrt.org/releases/22.03.0-rc6/targets/ath79/generic/openwrt-sdk-22.03.0-rc6-ath79-generic_gcc-11.2.0_musl.Linux-x86_64.tar.xz | \
tar xJf - -C /toolchain --strip-components=1

# See https://lkml.org/lkml/2014/3/14/269
COPY sysinfo_guard.patch /toolchain
RUN patch /toolchain/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/include/linux/kernel.h </toolchain/sysinfo_guard.patch
RUN patch /toolchain/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/include/linux/kernel.h </toolchain/sysinfo_guard.patch

ENV PATH=$PATH:/rust/bin:/toolchain/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/bin \
ENV PATH=$PATH:/rust/bin:/toolchain/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/bin \
STAGING_DIR=/toolchain/staging_dir \
CC_mips_unknown_linux_musl=mips-openwrt-linux-musl-gcc \
CARGO_TARGET_MIPS_UNKNOWN_LINUX_MUSL_LINKER=mips-openwrt-linux-musl-gcc \
CARGO_TARGET_MIPS_UNKNOWN_LINUX_MUSL_RUNNER="qemu-mips -L /toolchain/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl" \
RUSTFLAGS="-L /toolchain/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/lib"
CARGO_TARGET_MIPS_UNKNOWN_LINUX_MUSL_RUNNER="qemu-mips -L /toolchain/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl" \
RUSTFLAGS="-L /toolchain/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/lib"
12 changes: 6 additions & 6 deletions ci/docker/mipsel-unknown-linux-musl/Dockerfile
Expand Up @@ -8,18 +8,18 @@ RUN mkdir /toolchain

# Linux kernel version: 5.4.154
# See build_dir/target-mipsel_mips32_musl/linux-brcm47xx_generic/linux-5.4.154
# Musl version: 1.1.24
# Musl version: 1.2.3
# See staging_dir/toolchain-mipsel_mips32_gcc-8.4.0_musl/info.mk
RUN curl --retry 5 -L https://downloads.openwrt.org/releases/21.02.1/targets/bcm47xx/generic/openwrt-sdk-21.02.1-bcm47xx-generic_gcc-8.4.0_musl.Linux-x86_64.tar.xz | \
RUN curl --retry 5 -L https://downloads.openwrt.org/releases/22.03.0-rc6/targets/bcm47xx/generic/openwrt-sdk-22.03.0-rc6-bcm47xx-generic_gcc-11.2.0_musl.Linux-x86_64.tar.xz | \
tar xJf - -C /toolchain --strip-components=1

# See https://lkml.org/lkml/2014/3/14/269
COPY sysinfo_guard.patch /toolchain
RUN patch /toolchain/staging_dir/toolchain-mipsel_mips32_gcc-8.4.0_musl/include/linux/kernel.h </toolchain/sysinfo_guard.patch
RUN patch /toolchain/staging_dir/toolchain-mipsel_mips32_gcc-11.2.0_musl/include/linux/kernel.h </toolchain/sysinfo_guard.patch

ENV PATH=$PATH:/rust/bin:/toolchain/staging_dir/toolchain-mipsel_mips32_gcc-8.4.0_musl/bin \
ENV PATH=$PATH:/rust/bin:/toolchain/staging_dir/toolchain-mipsel_mips32_gcc-11.2.0_musl/bin \
STAGING_DIR=/toolchain/staging_dir \
CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-musl-gcc \
CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_MUSL_LINKER=mipsel-openwrt-linux-musl-gcc \
CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_MUSL_RUNNER="qemu-mipsel -L /toolchain/staging_dir/toolchain-mipsel_mips32_gcc-8.4.0_musl" \
RUSTFLAGS="-L /toolchain/staging_dir/toolchain-mipsel_mips32_gcc-8.4.0_musl/lib"
CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_MUSL_RUNNER="qemu-mipsel -L /toolchain/staging_dir/toolchain-mipsel_mips32_gcc-11.2.0_musl" \
RUSTFLAGS="-L /toolchain/staging_dir/toolchain-mipsel_mips32_gcc-11.2.0_musl/lib"
2 changes: 1 addition & 1 deletion ci/install-musl.sh
Expand Up @@ -5,7 +5,7 @@

set -ex

MUSL_VERSION=1.1.24
MUSL_VERSION=1.2.3
MUSL="musl-${MUSL_VERSION}"

# Download, configure, build, and install musl:
Expand Down
24 changes: 22 additions & 2 deletions libc-test/build.rs
Expand Up @@ -3063,6 +3063,23 @@ fn test_linux(target: &str) {
// deprecated since glibc >= 2.29. This allows Rust binaries to link against
// glibc versions older than 2.29.
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);
// Some targets use time64 symbols so set the musl_time64_abi appropriately.
// See #2088 and #1848 for more information.
match target {
"arm-unknown-linux-musleabi"
| "arm-unknown-linux-musleabihf"
| "armv5te-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabihf"
| "i586-unknown-linux-musl"
| "i686-unknown-linux-musl"
| "mips-unknown-linux-musl"
| "mipsel-unknown-linux-musl"
| "powerpc-unknown-linux-musl" => {
cfg.cfg("musl_time64_abi", None);
}
_ => {}
}

headers! { cfg:
"ctype.h",
Expand Down Expand Up @@ -3255,8 +3272,8 @@ fn test_linux(target: &str) {

t if t.ends_with("_t") => t.to_string(),

// In MUSL `flock64` is a typedef to `flock`.
"flock64" if musl => format!("struct {}", ty),
// In MUSL, `flock64` is a typedef to `flock` and `stat64` is a typedef to `stat`.
"flock64" | "stat64" if musl => format!("struct {}", ty),

// put `struct` in front of all structs:.
t if is_struct => format!("struct {}", t),
Expand Down Expand Up @@ -3475,6 +3492,9 @@ fn test_linux(target: &str) {
// - these constants are used by the glibc implementation.
n if musl && n.contains("__SIZEOF_PTHREAD") => true,

// FIXME: ctest reports incorrect values for both Rust/libc and C/musl.
"IPC_STAT" if musl => true,

// FIXME: It was extended to 4096 since glibc 2.31 (Linux 5.4).
// We should do so after a while.
"SOMAXCONN" if gnu => true,
Expand Down
27 changes: 20 additions & 7 deletions src/unix/linux_like/linux/arch/generic/mod.rs
Expand Up @@ -37,8 +37,25 @@ pub const SO_PASSCRED: ::c_int = 16;
pub const SO_PEERCRED: ::c_int = 17;
pub const SO_RCVLOWAT: ::c_int = 18;
pub const SO_SNDLOWAT: ::c_int = 19;
pub const SO_RCVTIMEO: ::c_int = 20;
pub const SO_SNDTIMEO: ::c_int = 21;

cfg_if! {
if #[cfg(not(musl_time64_abi))] {
pub const SO_RCVTIMEO: ::c_int = 20;
pub const SO_SNDTIMEO: ::c_int = 21;
pub const SO_TIMESTAMP: ::c_int = 29;
pub const SO_TIMESTAMPNS: ::c_int = 35;
pub const SO_TIMESTAMPING: ::c_int = 37;
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
} else {
pub const SO_RCVTIMEO: ::c_int = 66;
pub const SO_SNDTIMEO: ::c_int = 67;
pub const SO_TIMESTAMP: ::c_int = 63;
pub const SO_TIMESTAMPNS: ::c_int = 64;
pub const SO_TIMESTAMPING: ::c_int = 65;
pub const SCM_TIMESTAMPING: ::c_int = 65;
}
}

// pub const SO_RCVTIMEO_OLD: ::c_int = 20;
// pub const SO_SNDTIMEO_OLD: ::c_int = 21;
pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22;
Expand All @@ -49,17 +66,14 @@ pub const SO_ATTACH_FILTER: ::c_int = 26;
pub const SO_DETACH_FILTER: ::c_int = 27;
pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER;
pub const SO_PEERNAME: ::c_int = 28;
pub const SO_TIMESTAMP: ::c_int = 29;
// pub const SO_TIMESTAMP_OLD: ::c_int = 29;
pub const SO_ACCEPTCONN: ::c_int = 30;
pub const SO_PEERSEC: ::c_int = 31;
pub const SO_SNDBUFFORCE: ::c_int = 32;
pub const SO_RCVBUFFORCE: ::c_int = 33;
pub const SO_PASSSEC: ::c_int = 34;
pub const SO_TIMESTAMPNS: ::c_int = 35;
// pub const SO_TIMESTAMPNS_OLD: ::c_int = 35;
pub const SO_MARK: ::c_int = 36;
pub const SO_TIMESTAMPING: ::c_int = 37;
// pub const SO_TIMESTAMPING_OLD: ::c_int = 37;
pub const SO_PROTOCOL: ::c_int = 38;
pub const SO_DOMAIN: ::c_int = 39;
Expand Down Expand Up @@ -119,7 +133,6 @@ cfg_if! {
// Defined in unix/linux_like/mod.rs
// pub const SCM_TIMESTAMP: ::c_int = SO_TIMESTAMP;
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;

// Ioctl Constants

Expand Down Expand Up @@ -270,7 +283,7 @@ cfg_if! {
pub const RLIMIT_NICE: ::c_int = 13;
pub const RLIMIT_RTPRIO: ::c_int = 14;
pub const RLIMIT_RTTIME: ::c_int = 15;
pub const RLIM_NLIMITS: ::c_int = 15;
pub const RLIM_NLIMITS: ::c_int = 16;
pub const RLIMIT_NLIMITS: ::c_int = RLIM_NLIMITS;
}
}
Expand Down
27 changes: 21 additions & 6 deletions src/unix/linux_like/linux/arch/mips/mod.rs
Expand Up @@ -33,8 +33,15 @@ pub const SO_RCVLOWAT: ::c_int = 0x1004;
// NOTE: These definitions are now being renamed with _OLD postfix,
// but CI haven't support them yet.
// Some related consts could be found in b32.rs and b64.rs
pub const SO_SNDTIMEO: ::c_int = 0x1005;
pub const SO_RCVTIMEO: ::c_int = 0x1006;
cfg_if! {
if #[cfg(target_env = "musl")] {
pub const SO_SNDTIMEO: ::c_int = 0x43;
pub const SO_RCVTIMEO: ::c_int = 0x42;
} else {
pub const SO_SNDTIMEO: ::c_int = 0x1005;
pub const SO_RCVTIMEO: ::c_int = 0x1006;
}
}
// pub const SO_SNDTIMEO_OLD: ::c_int = 0x1005;
// pub const SO_RCVTIMEO_OLD: ::c_int = 0x1006;
pub const SO_ACCEPTCONN: ::c_int = 0x1009;
Expand Down Expand Up @@ -88,9 +95,17 @@ pub const SO_BINDTOIFINDEX: ::c_int = 62;
// NOTE: These definitions are now being renamed with _OLD postfix,
// but CI haven't support them yet.
// Some related consts could be found in b32.rs and b64.rs
pub const SO_TIMESTAMP: ::c_int = 29;
pub const SO_TIMESTAMPNS: ::c_int = 35;
pub const SO_TIMESTAMPING: ::c_int = 37;
cfg_if! {
if #[cfg(target_env = "musl")] {
pub const SO_TIMESTAMP: ::c_int = 63;
pub const SO_TIMESTAMPNS: ::c_int = 64;
pub const SO_TIMESTAMPING: ::c_int = 65;
} else {
pub const SO_TIMESTAMP: ::c_int = 29;
pub const SO_TIMESTAMPNS: ::c_int = 35;
pub const SO_TIMESTAMPING: ::c_int = 37;
}
}
// pub const SO_TIMESTAMP_OLD: ::c_int = 29;
// pub const SO_TIMESTAMPNS_OLD: ::c_int = 35;
// pub const SO_TIMESTAMPING_OLD: ::c_int = 37;
Expand Down Expand Up @@ -254,7 +269,7 @@ cfg_if! {
pub const RLIMIT_NICE: ::c_int = 13;
pub const RLIMIT_RTPRIO: ::c_int = 14;
pub const RLIMIT_RTTIME: ::c_int = 15;
pub const RLIM_NLIMITS: ::c_int = 15;
pub const RLIM_NLIMITS: ::c_int = 16;
pub const RLIMIT_NLIMITS: ::c_int = RLIM_NLIMITS;
pub const RLIM_INFINITY: ::rlim_t = !0;
}
Expand Down
21 changes: 21 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Expand Up @@ -184,6 +184,11 @@ s! {
}

pub struct input_event {
#[cfg(musl_time64_abi)]
pub input_event_sec: ::c_ulong,
#[cfg(musl_time64_abi)]
pub input_event_usec: ::c_ulong,
#[cfg(not(musl_time64_abi))]
pub time: ::timeval,
pub type_: ::__u16,
pub code: ::__u16,
Expand Down Expand Up @@ -3752,6 +3757,7 @@ cfg_if! {
pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int;
pub fn aio_error(aiocbp: *const aiocb) -> ::c_int;
pub fn aio_return(aiocbp: *mut aiocb) -> ::ssize_t;
#[cfg_attr(musl_time64_abi, link_name = "__aio_suspend_time64")]
pub fn aio_suspend(
aiocb_list: *const *const aiocb,
nitems: ::c_int,
Expand Down Expand Up @@ -3805,6 +3811,7 @@ cfg_if! {
riovcnt: ::c_ulong,
flags: ::c_ulong,
) -> isize;
#[cfg_attr(musl_time64_abi, link_name = "__futimes_time64")]
pub fn futimes(
fd: ::c_int,
times: *const ::timeval
Expand Down Expand Up @@ -3832,6 +3839,7 @@ extern "C" {
pub fn seed48(xseed: *mut ::c_ushort) -> *mut ::c_ushort;
pub fn lcong48(p: *mut ::c_ushort);

#[cfg_attr(musl_time64_abi, link_name = "__lutimes_time64")]
pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int;

pub fn setpwent();
Expand Down Expand Up @@ -3949,7 +3957,9 @@ extern "C" {
pub fn fremovexattr(filedes: ::c_int, name: *const c_char) -> ::c_int;
pub fn signalfd(fd: ::c_int, mask: *const ::sigset_t, flags: ::c_int) -> ::c_int;
pub fn timerfd_create(clockid: ::clockid_t, flags: ::c_int) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__timerfd_gettime64")]
pub fn timerfd_gettime(fd: ::c_int, curr_value: *mut itimerspec) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__timerfd_settime64")]
pub fn timerfd_settime(
fd: ::c_int,
flags: ::c_int,
Expand All @@ -3971,6 +3981,7 @@ extern "C" {
msg_len: ::size_t,
msg_prio: *mut ::c_uint,
) -> ::ssize_t;
#[cfg_attr(musl_time64_abi, link_name = "__mq_timedreceive_time64")]
pub fn mq_timedreceive(
mqd: ::mqd_t,
msg_ptr: *mut ::c_char,
Expand All @@ -3984,6 +3995,7 @@ extern "C" {
msg_len: ::size_t,
msg_prio: ::c_uint,
) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__mq_timedsend_time64")]
pub fn mq_timedsend(
mqd: ::mqd_t,
msg_ptr: *const ::c_char,
Expand All @@ -4003,6 +4015,7 @@ extern "C" {
pub fn dup3(oldfd: ::c_int, newfd: ::c_int, flags: ::c_int) -> ::c_int;
pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int;
pub fn mkostemps(template: *mut ::c_char, suffixlen: ::c_int, flags: ::c_int) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__sigtimedwait_time64")]
pub fn sigtimedwait(
set: *const sigset_t,
info: *mut siginfo_t,
Expand Down Expand Up @@ -4118,6 +4131,7 @@ extern "C" {
pub fn umount(target: *const ::c_char) -> ::c_int;
pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int;
pub fn tee(fd_in: ::c_int, fd_out: ::c_int, len: ::size_t, flags: ::c_uint) -> ::ssize_t;
#[cfg_attr(musl_time64_abi, link_name = "__settimeofday_time64")]
pub fn settimeofday(tv: *const ::timeval, tz: *const ::timezone) -> ::c_int;
pub fn splice(
fd_in: ::c_int,
Expand All @@ -4128,7 +4142,9 @@ extern "C" {
flags: ::c_uint,
) -> ::ssize_t;
pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__sched_rr_get_interval_time64")]
pub fn sched_rr_get_interval(pid: ::pid_t, tp: *mut ::timespec) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__sem_timedwait_time64")]
pub fn sem_timedwait(sem: *mut sem_t, abstime: *const ::timespec) -> ::c_int;
pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int;
pub fn sched_setparam(pid: ::pid_t, param: *const ::sched_param) -> ::c_int;
Expand All @@ -4150,6 +4166,7 @@ extern "C" {
pub fn personality(persona: ::c_ulong) -> ::c_int;
pub fn prctl(option: ::c_int, ...) -> ::c_int;
pub fn sched_getparam(pid: ::pid_t, param: *mut ::sched_param) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__ppoll_time64")]
pub fn ppoll(
fds: *mut ::pollfd,
nfds: nfds_t,
Expand All @@ -4165,6 +4182,7 @@ extern "C" {
protocol: ::c_int,
) -> ::c_int;
pub fn pthread_mutex_consistent(mutex: *mut pthread_mutex_t) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__pthread_mutex_timedlock_time64")]
pub fn pthread_mutex_timedlock(
lock: *mut pthread_mutex_t,
abstime: *const ::timespec,
Expand All @@ -4182,6 +4200,7 @@ extern "C" {
...
) -> ::c_int;
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__clock_nanosleep_time64")]
pub fn clock_nanosleep(
clk_id: ::clockid_t,
flags: ::c_int,
Expand Down Expand Up @@ -4444,7 +4463,9 @@ extern "C" {
) -> ::c_int;
pub fn timer_delete(timerid: ::timer_t) -> ::c_int;
pub fn timer_getoverrun(timerid: ::timer_t) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__timer_gettime64")]
pub fn timer_gettime(timerid: ::timer_t, curr_value: *mut ::itimerspec) -> ::c_int;
#[cfg_attr(musl_time64_abi, link_name = "__timer_settime64")]
pub fn timer_settime(
timerid: ::timer_t,
flags: ::c_int,
Expand Down