Skip to content

Commit

Permalink
Auto merge of #2935 - bossmc:alias-lfs64-symbols-on-musl, r=Amanieu
Browse files Browse the repository at this point in the history
Alias all LFS64 symbols to their non-LFS64 counterparts on musl

As per #2934 the LFS64 symbols on musl-libc are simply aliases to the non-LFS64 symbols.  Currently this is done both in the header files (as `#define` entries) and in the library (as aliasing symbols).  There is a desire in musl to drop the ABI compatibility shims (the symbol aliases) - currently the `libc` crate exports the LFS64 symbols by `extern`-ing the compatibility shims which will fail if musl removes them.

This changes the musl build of libc to replicate the aliasing that's in the C header files (with `pub use xxx as xxx64`) so the API from the `libc` crate is unchanged, but the crate is now compatible with the upcoming musl release.

I've also checked and all the LFS64 types (e.g. `off64_t`) are already the same as their non-LFS64 equivalents.

This is an annoying change to test, `libc-test` seems expect to build against `musl 1.1.24` (in fact, does Rust even support `musl 1.2`?  It's not obvious that it does... e.g. see https://github.com/rust-lang/libc/blob/d99c37d97c7a075ffc7f4260f2dd134d1ee3daaa/src/unix/linux_like/linux/musl/mod.rs#L288-L292)
  • Loading branch information
bors committed May 31, 2023
2 parents a23c8ca + 75ac488 commit 1e8c55c
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 127 deletions.
21 changes: 18 additions & 3 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3333,8 +3333,8 @@ fn test_linux(target: &str) {
"Ioctl" if gnu => "unsigned long".to_string(),
"Ioctl" => "int".to_string(),

// In MUSL `flock64` is a typedef to `flock`.
"flock64" if musl => format!("struct {}", ty),
// LFS64 types have been removed in musl 1.2.4+
"off64_t" if musl => "off_t".to_string(),

// typedefs don't need any keywords
t if t.ends_with("_t") => t.to_string(),
Expand Down Expand Up @@ -3399,7 +3399,14 @@ fn test_linux(target: &str) {
"priority_t" if musl => true,
"name_t" if musl => true,

_ => false,
t => {
if musl {
// LFS64 types have been removed in musl 1.2.4+
t.ends_with("64") || t.ends_with("64_t")
} else {
false
}
}
}
});

Expand All @@ -3411,6 +3418,10 @@ fn test_linux(target: &str) {
if musl && ty.starts_with("uinput_") {
return true;
}
// LFS64 types have been removed in musl 1.2.4+
if musl && (ty.ends_with("64") || ty.ends_with("64_t")) {
return true;
}
// FIXME: sparc64 CI has old headers
if sparc64 && (ty == "uinput_ff_erase" || ty == "uinput_abs_setup") {
return true;
Expand Down Expand Up @@ -3528,6 +3539,10 @@ fn test_linux(target: &str) {
{
return true;
}
// LFS64 types have been removed in musl 1.2.4+
if name.starts_with("RLIM64") {
return true;
}
}
match name {
// These constants are not available if gnu headers have been included
Expand Down
79 changes: 47 additions & 32 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ impl ::Clone for fpos64_t {
}

s! {
pub struct rlimit64 {
pub rlim_cur: rlim64_t,
pub rlim_max: rlim64_t,
}

pub struct glob_t {
pub gl_pathc: ::size_t,
pub gl_pathv: *mut *mut c_char,
Expand Down Expand Up @@ -685,6 +680,11 @@ s! {
pub struct sctp_authinfo {
pub auth_keynumber: ::__u16,
}

pub struct rlimit64 {
pub rlim_cur: rlim64_t,
pub rlim_max: rlim64_t,
}
}

s_no_extra_traits! {
Expand All @@ -703,14 +703,6 @@ s_no_extra_traits! {
pub d_name: [::c_char; 256],
}

pub struct dirent64 {
pub d_ino: ::ino64_t,
pub d_off: ::off64_t,
pub d_reclen: ::c_ushort,
pub d_type: ::c_uchar,
pub d_name: [::c_char; 256],
}

pub struct sockaddr_alg {
pub salg_family: ::sa_family_t,
pub salg_type: [::c_uchar; 14],
Expand Down Expand Up @@ -804,6 +796,14 @@ s_no_extra_traits! {
pub tx_type: ::c_int,
pub rx_filter: ::c_int,
}

pub struct dirent64 {
pub d_ino: ::ino64_t,
pub d_off: ::off64_t,
pub d_reclen: ::c_ushort,
pub d_type: ::c_uchar,
pub d_name: [::c_char; 256],
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -4299,21 +4299,8 @@ extern "C" {
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
pub fn __errno_location() -> *mut ::c_int;

pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
pub fn freopen64(
filename: *const c_char,
mode: *const c_char,
file: *mut ::FILE,
) -> *mut ::FILE;
pub fn tmpfile64() -> *mut ::FILE;
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
pub fn fallocate(fd: ::c_int, mode: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
pub fn fallocate64(fd: ::c_int, mode: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
pub fn readahead(fd: ::c_int, offset: ::off64_t, count: ::size_t) -> ::ssize_t;
pub fn getxattr(
path: *const c_char,
Expand Down Expand Up @@ -4614,12 +4601,6 @@ extern "C" {
offset: *mut off_t,
count: ::size_t,
) -> ::ssize_t;
pub fn sendfile64(
out_fd: ::c_int,
in_fd: ::c_int,
offset: *mut off64_t,
count: ::size_t,
) -> ::ssize_t;
pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int;
pub fn getgrgid_r(
gid: ::gid_t,
Expand Down Expand Up @@ -4871,6 +4852,40 @@ extern "C" {
) -> ::ssize_t;
}

// LFS64 extensions
//
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones
cfg_if! {
if #[cfg(not(target_env = "musl"))] {
extern "C" {
pub fn fallocate64(
fd: ::c_int,
mode: ::c_int,
offset: ::off64_t,
len: ::off64_t
) -> ::c_int;
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
pub fn freopen64(
filename: *const c_char,
mode: *const c_char,
file: *mut ::FILE,
) -> *mut ::FILE;
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
pub fn sendfile64(
out_fd: ::c_int,
in_fd: ::c_int,
offset: *mut off64_t,
count: ::size_t,
) -> ::ssize_t;
pub fn tmpfile64() -> *mut ::FILE;
}
}
}

cfg_if! {
if #[cfg(target_env = "uclibc")] {
mod uclibc;
Expand Down
16 changes: 0 additions & 16 deletions src/unix/linux_like/linux/musl/b32/riscv32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,6 @@ s! {
__pad1: ::c_ulong,
__pad2: ::c_ulong,
}

pub struct flock {
pub l_type: ::c_short,
pub l_whence: ::c_short,
pub l_start: ::off_t,
pub l_len: ::off_t,
pub l_pid: ::pid_t,
}

pub struct flock64 {
pub l_type: ::c_short,
pub l_whence: ::c_short,
pub l_start: ::off64_t,
pub l_len: ::off64_t,
pub l_pid: ::pid_t,
}
}

//pub const RLIM_INFINITY: ::rlim_t = !0;
Expand Down
16 changes: 0 additions & 16 deletions src/unix/linux_like/linux/musl/b64/riscv64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,6 @@ s! {
__unused5: ::c_ulong,
__unused6: ::c_ulong,
}

pub struct flock {
pub l_type: ::c_short,
pub l_whence: ::c_short,
pub l_start: ::off_t,
pub l_len: ::off_t,
pub l_pid: ::pid_t,
}

pub struct flock64 {
pub l_type: ::c_short,
pub l_whence: ::c_short,
pub l_start: ::off64_t,
pub l_len: ::off64_t,
pub l_pid: ::pid_t,
}
}

pub const SYS_read: ::c_long = 63;
Expand Down
Loading

0 comments on commit 1e8c55c

Please sign in to comment.