diff --git a/.github/workflows/full_ci.yml b/.github/workflows/full_ci.yml index 27037fea55248..3d60b36c61a55 100644 --- a/.github/workflows/full_ci.yml +++ b/.github/workflows/full_ci.yml @@ -165,6 +165,7 @@ jobs: - i686-linux-android - i686-unknown-linux-musl - loongarch64-unknown-linux-gnu + - loongarch64-unknown-linux-musl - powerpc-unknown-linux-gnu - powerpc64-unknown-linux-gnu - powerpc64le-unknown-linux-gnu diff --git a/ci/docker/loongarch64-unknown-linux-musl/Dockerfile b/ci/docker/loongarch64-unknown-linux-musl/Dockerfile new file mode 100644 index 0000000000000..c1219c034c81f --- /dev/null +++ b/ci/docker/loongarch64-unknown-linux-musl/Dockerfile @@ -0,0 +1,14 @@ +FROM ubuntu:24.04 + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates curl gcc git libc6-dev make qemu-user xz-utils + +COPY install-musl-cross.sh / +RUN sh /install-musl-cross.sh loongarch64-unknown-linux-musl + +ENV CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_MUSL_LINKER=loongarch64-unknown-linux-musl-gcc \ + CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_MUSL_RUNNER="qemu-loongarch64" \ + CC_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-gcc \ + CFLAGS_loongarch64_unknown_linux_musl="-mabi=lp64d -fPIC" \ + QEMU_LD_PREFIX=/loongarch64-unknown-linux-musl/loongarch64-unknown-linux-musl/sysroot \ + PATH=$PATH:/loongarch64-unknown-linux-musl/bin:/rust/bin diff --git a/ci/install-musl-cross.sh b/ci/install-musl-cross.sh new file mode 100644 index 0000000000000..38381dc9bd6bf --- /dev/null +++ b/ci/install-musl-cross.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# +# Install musl cross toolchain + +set -ex + +MUSL_CROSS_VER=20241103 +MUSL_CROSS_URL=https://github.com/musl-cross/musl-cross/releases/download/$MUSL_CROSS_VER/$1.tar.xz + +curl -L --retry 5 "$MUSL_CROSS_URL" | tar -xJf - -C / diff --git a/libc-test/build.rs b/libc-test/build.rs index 230c9d87a9321..9d97705a1444a 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -4489,14 +4489,14 @@ fn test_linux(target: &str) { (struct_ == "iw_encode_ext" && field == "key") || // the `tcpi_snd_rcv_wscale` map two bitfield fields stored in a u8 (struct_ == "tcp_info" && field == "tcpi_snd_rcv_wscale") || - // the `tcpi_delivery_rate_app_limited` field is a bitfield on musl - (musl && struct_ == "tcp_info" && field == "tcpi_delivery_rate_app_limited") || - // the `tcpi_fast_open_client_fail` field is a bitfield on musl - (musl && struct_ == "tcp_info" && field == "tcpi_fast_open_client_fail") || + // the `tcpi_delivery_fastopen_bitfields` map two bitfield fields stored in a u8 + (musl && struct_ == "tcp_info" && field == "tcpi_delivery_fastopen_bitfields") || // either fsid_t or int[2] type (struct_ == "fanotify_event_info_fid" && field == "fsid") || // `handle` is a VLA - (struct_ == "fanotify_event_info_fid" && field == "handle") + (struct_ == "fanotify_event_info_fid" && field == "handle") || + // invalid application of 'sizeof' to incomplete type 'long unsigned int[]' + (musl && struct_ == "mcontext_t" && field == "__extcontext" && loongarch64) }); cfg.skip_roundtrip(move |s| match s { diff --git a/libc-test/semver/linux-gnu-loongarch64.txt b/libc-test/semver/linux-gnu-loongarch64.txt index dd1781a03504e..ec6595b79b76f 100644 --- a/libc-test/semver/linux-gnu-loongarch64.txt +++ b/libc-test/semver/linux-gnu-loongarch64.txt @@ -1,6 +1,21 @@ +KEYCTL_CAPABILITIES +KEYCTL_CAPS0_BIG_KEY +KEYCTL_CAPS0_CAPABILITIES +KEYCTL_CAPS0_DIFFIE_HELLMAN +KEYCTL_CAPS0_INVALIDATE +KEYCTL_CAPS0_MOVE +KEYCTL_CAPS0_PERSISTENT_KEYRINGS +KEYCTL_CAPS0_PUBLIC_KEY +KEYCTL_CAPS0_RESTRICT_KEYRING +KEYCTL_CAPS1_NS_KEYRING_NAME +KEYCTL_CAPS1_NS_KEY_TAG +KEYCTL_MOVE +MADV_SOFT_OFFLINE PTRACE_GETFPREGS PTRACE_GETFPXREGS PTRACE_GETREGS PTRACE_SETFPREGS PTRACE_SETFPXREGS PTRACE_SETREGS +PTRACE_SYSEMU +PTRACE_SYSEMU_SINGLESTEP diff --git a/libc-test/semver/linux-loongarch64.txt b/libc-test/semver/linux-loongarch64.txt index 2e2b66b83bf42..ebcd4bf93356f 100644 --- a/libc-test/semver/linux-loongarch64.txt +++ b/libc-test/semver/linux-loongarch64.txt @@ -40,26 +40,11 @@ BPF_XOR CIBAUD FICLONE FICLONERANGE -KEYCTL_CAPABILITIES -KEYCTL_CAPS0_BIG_KEY -KEYCTL_CAPS0_CAPABILITIES -KEYCTL_CAPS0_DIFFIE_HELLMAN -KEYCTL_CAPS0_INVALIDATE -KEYCTL_CAPS0_MOVE -KEYCTL_CAPS0_PERSISTENT_KEYRINGS -KEYCTL_CAPS0_PUBLIC_KEY -KEYCTL_CAPS0_RESTRICT_KEYRING -KEYCTL_CAPS1_NS_KEYRING_NAME -KEYCTL_CAPS1_NS_KEY_TAG -KEYCTL_MOVE -MADV_SOFT_OFFLINE MAP_SYNC NFT_MSG_DELOBJ NFT_MSG_GETOBJ NFT_MSG_GETOBJ_RESET NFT_MSG_NEWOBJ -PTRACE_SYSEMU -PTRACE_SYSEMU_SINGLESTEP SCM_TIMESTAMPNS SCM_WIFI_STATUS SIGSTKFLT diff --git a/src/unix/linux_like/linux/arch/generic/mod.rs b/src/unix/linux_like/linux/arch/generic/mod.rs index 63511e61f83e0..0d2514b60aa41 100644 --- a/src/unix/linux_like/linux/arch/generic/mod.rs +++ b/src/unix/linux_like/linux/arch/generic/mod.rs @@ -353,7 +353,10 @@ cfg_if! { pub const RLIMIT_RTPRIO: ::c_int = 14; pub const RLIMIT_RTTIME: ::c_int = 15; #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] + #[cfg(not(target_arch = "loongarch64"))] pub const RLIM_NLIMITS: ::c_int = 15; + #[cfg(target_arch = "loongarch64")] + pub const RLIM_NLIMITS: ::c_int = 16; #[allow(deprecated)] #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] pub const RLIMIT_NLIMITS: ::c_int = RLIM_NLIMITS; diff --git a/src/unix/linux_like/linux/musl/b64/loongarch64/mod.rs b/src/unix/linux_like/linux/musl/b64/loongarch64/mod.rs index de2477022950b..40bdb0aa42e3c 100644 --- a/src/unix/linux_like/linux/musl/b64/loongarch64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/loongarch64/mod.rs @@ -11,10 +11,6 @@ pub type __u64 = ::c_ulonglong; pub type __s64 = ::c_longlong; s! { - pub struct pthread_attr_t { - __size: [::c_ulong; 7], - } - pub struct stat { pub st_dev: ::dev_t, pub st_ino: ::ino_t, @@ -59,21 +55,6 @@ s! { __unused: [::c_int; 2], } - pub struct statfs { - pub f_type: ::c_long, - pub f_bsize: ::c_long, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_long, - pub f_frsize: ::c_long, - pub f_flags: ::c_long, - pub f_spare: [::c_long; 4], - } - pub struct statfs64 { pub f_type: ::c_long, pub f_bsize: ::c_long, @@ -96,7 +77,7 @@ s! { pub cuid: ::uid_t, pub cgid: ::gid_t, pub mode: ::c_uint, - pub __seq: ::c_ushort, + pub __seq: ::c_int, __pad2: ::c_ushort, __unused1: ::c_ulong, __unused2: ::c_ulong, @@ -126,10 +107,10 @@ s! { #[repr(align(16))] pub struct mcontext_t { - pub __pc: ::c_ulonglong, - pub __gregs: [::c_ulonglong; 32], + pub __pc: ::c_ulong, + pub __gregs: [::c_ulong; 32], pub __flags: ::c_uint, - pub __extcontext: [::c_ulonglong; 0], + pub __extcontext: [::c_ulong; 0], } #[repr(align(8))] @@ -467,7 +448,7 @@ pub const SYS_futex_requeue: ::c_long = 456; pub const O_APPEND: ::c_int = 1024; pub const O_DIRECT: ::c_int = 0x4000; pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_LARGEFILE: ::c_int = 0; +pub const O_LARGEFILE: ::c_int = 0o0100000; pub const O_NOFOLLOW: ::c_int = 0x20000; pub const O_CREAT: ::c_int = 64; pub const O_EXCL: ::c_int = 128; @@ -476,7 +457,7 @@ pub const O_NONBLOCK: ::c_int = 2048; pub const O_SYNC: ::c_int = 1052672; pub const O_RSYNC: ::c_int = 1052672; pub const O_DSYNC: ::c_int = 4096; -pub const O_ASYNC: ::c_int = 4096; +pub const O_ASYNC: ::c_int = 0o20000; pub const SIGSTKSZ: ::size_t = 16384; pub const MINSIGSTKSZ: ::size_t = 4096; @@ -660,6 +641,7 @@ pub const ECHOPRT: ::tcflag_t = 0x00000400; pub const ECHOCTL: ::tcflag_t = 0x00000200; pub const ISIG: ::tcflag_t = 0x00000001; pub const ICANON: ::tcflag_t = 0x00000002; +pub const XCASE: ::tcflag_t = 0x00000004; pub const PENDIN: ::tcflag_t = 0x00004000; pub const NOFLSH: ::tcflag_t = 0x00000080; pub const CIBAUD: ::tcflag_t = 0o02003600000; diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 2135fb588122f..3c13e3a3d131a 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -355,14 +355,16 @@ s! { pub tcpi_backoff: u8, pub tcpi_options: u8, /* - * FIXME(musl): when musl headers are more up to date + * FIXME(musl): enable on all targets once musl headers are more up to date + */ /// This contains the bitfields `tcpi_snd_wscale` and `tcpi_rcv_wscale`. /// Each is 4 bits. + #[cfg(target_arch = "loongarch64")] pub tcpi_snd_rcv_wscale: u8, /// This contains the bitfields `tcpi_delivery_rate_app_limited` (1 bit) and /// `tcpi_fastopen_client_fail` (2 bits). + #[cfg(target_arch = "loongarch64")] pub tcpi_delivery_fastopen_bitfields: u8, - */ pub tcpi_rto: u32, pub tcpi_ato: u32, pub tcpi_snd_mss: u32, @@ -407,9 +409,11 @@ s! { pub tcpi_bytes_retrans: u64, pub tcpi_dsack_dups: u32, pub tcpi_reord_seen: u32, - // FIXME(musl): to uncomment once CI musl is updated - //pub tcpi_rcv_ooopack: u32, - //pub tcpi_snd_wnd: u32, + // FIXME(musl): enable on all targets once CI musl is updated + #[cfg(target_arch = "loongarch64")] + pub tcpi_rcv_ooopack: u32, + #[cfg(target_arch = "loongarch64")] + pub tcpi_snd_wnd: u32, } } @@ -449,8 +453,17 @@ s_no_extra_traits! { pub ut_exit: __exit_status, #[cfg(target_env = "musl")] + #[cfg(not(target_arch = "loongarch64"))] pub ut_session: ::c_long, + #[cfg(target_env = "musl")] + #[cfg(target_arch = "loongarch64")] + pub ut_session: ::c_int, + + #[cfg(target_env = "musl")] + #[cfg(target_arch = "loongarch64")] + __ut_pad2: ::c_int, + #[cfg(target_env = "ohos")] #[cfg(target_endian = "little")] pub ut_session: ::c_int, @@ -712,7 +725,10 @@ pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4; +#[cfg(not(target_arch = "loongarch64"))] pub const CPU_SETSIZE: ::c_int = 128; +#[cfg(target_arch = "loongarch64")] +pub const CPU_SETSIZE: ::c_int = 1024; pub const PTRACE_TRACEME: ::c_int = 0; pub const PTRACE_PEEKTEXT: ::c_int = 1;