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

Rebase of "Upgrade musl supported version to 1.2.3" #3791

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
"libc_const_extern_fn",
"libc_const_extern_fn_unstable",
"libc_deny_warnings",
"musl_time64_abi",
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be renamed to musl_redir_time64?

Musl uses _REDIR_TIME64 in their source, I think the name is a bit more intuitive because only 32-bit does these hacks (64-bit always has the 64-bit time interface).

];

// Extra values to allow for check-cfg.
Expand Down Expand Up @@ -67,6 +68,12 @@ fn main() {
Some(_) | None => (),
}

// Some ABIs need to redirect time related symbols to their time64
// equivalents. See #2088 and #1848 for more information.
if is_musl_time64_abi() {
set_cfg("musl_time64_abi");
Copy link
Contributor

Choose a reason for hiding this comment

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

We should set two separate configs here:

  • musl_redir_time64 (musl_time64_abi) which corresponds to musl's _REDIR_TIME64
  • linux_time_bits64 which corresponds to __USE_TIME_BITS64 in uapi

We need this to be split because musl and glibc share the kernel uapi

}

// On CI: deny all warnings
if libc_ci {
set_cfg("libc_deny_warnings");
Expand Down Expand Up @@ -213,3 +220,22 @@ fn set_cfg(cfg: &str) {
}
println!("cargo:rustc-cfg={}", cfg);
}

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,
_ => false,
},
Err(_) => false,
}
}
Comment on lines +224 to +241
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably shouldn't match literal targets here since we only care about the prefix and the suffix. Instead could we:

  • Add const TARGET_PREFIXES_32BIT: &[&str] = &[/* ... */]; that contains arm-, i586-, etc
  • Add const MUSL_SUFFIXES : &[&str] = &[/* ... */]; with -musleabi, -musl, etc
  • Add fn target_is_32bit(target: &str) -> bool that checks if it starts if target starts with any of TARGET_PREFIXES_32BIT. Then we can reuse it with the GNU change.
  • Add fn target_is_musl(target: &str) -> bool that does the same with the suffixes
  • Add fn target_is_linux(target: &str) -> bool that checks if it contains -linux-
  • Check these three functions in order to set musl_redir_time64/musl_time64_abi

2 changes: 1 addition & 1 deletion ci/install-musl.sh
Original file line number Diff line number Diff line change
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: 24 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,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);
}
_ => {}
}
Comment on lines +3304 to +3320
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this in build.rs if it's set automatically by our crate's build script?


headers! { cfg:
"ctype.h",
Expand Down Expand Up @@ -3506,6 +3523,10 @@ fn test_linux(target: &str) {

// typedefs don't need any keywords
t if t.ends_with("_t") => t.to_string(),

// 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),
// put `union` in front of all unions:
Expand Down Expand Up @@ -3862,6 +3883,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
5 changes: 5 additions & 0 deletions src/unix/linux_like/emscripten/lfs64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ pub unsafe extern "C" fn mmap64(
//
// These aliases are mostly fine though, neither function takes a LFS64-namespaced type as an
// argument, nor do their names clash with any declared types.
//
// Targets wasm32-unknown-emscripten in CI recognize them as unused imports.
// Like the same one at src/unix/linux_like/linux/musl/lfs64.rs, here they are also allowed.
#[allow(unused_imports)]
pub use open as open64;
#[allow(unused_imports)]
pub use openat as openat64;

#[inline]
Expand Down
30 changes: 20 additions & 10 deletions src/unix/linux_like/linux/arch/generic/mod.rs
Original file line number Diff line number Diff line change
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 @@ -126,7 +140,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 @@ -311,10 +324,7 @@ cfg_if! {
pub const RLIMIT_NICE: ::c_int = 13;
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")]
pub const RLIM_NLIMITS: ::c_int = 15;
#[allow(deprecated)]
#[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
pub const RLIM_NLIMITS: ::c_int = 16;
pub const RLIMIT_NLIMITS: ::c_int = RLIM_NLIMITS;
}
}
Expand Down
30 changes: 21 additions & 9 deletions src/unix/linux_like/linux/arch/mips/mod.rs
Original file line number Diff line number Diff line change
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 @@ -287,10 +302,7 @@ cfg_if! {
pub const RLIMIT_NICE: ::c_int = 13;
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")]
pub const RLIM_NLIMITS: ::c_int = 15;
#[allow(deprecated)]
#[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
pub const RLIM_NLIMITS: ::c_int = 16;
pub const RLIMIT_NLIMITS: ::c_int = RLIM_NLIMITS;
pub const RLIM_INFINITY: ::rlim_t = !0;
}
Expand Down
Loading
Loading