Skip to content

Commit 1e8c55c

Browse files
committed
Auto merge of #2935 - bossmc:alias-lfs64-symbols-on-musl, r=Amanieu
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)
2 parents a23c8ca + 75ac488 commit 1e8c55c

File tree

7 files changed

+398
-127
lines changed

7 files changed

+398
-127
lines changed

libc-test/build.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -3333,8 +3333,8 @@ fn test_linux(target: &str) {
33333333
"Ioctl" if gnu => "unsigned long".to_string(),
33343334
"Ioctl" => "int".to_string(),
33353335

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

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

3402-
_ => false,
3402+
t => {
3403+
if musl {
3404+
// LFS64 types have been removed in musl 1.2.4+
3405+
t.ends_with("64") || t.ends_with("64_t")
3406+
} else {
3407+
false
3408+
}
3409+
}
34033410
}
34043411
});
34053412

@@ -3411,6 +3418,10 @@ fn test_linux(target: &str) {
34113418
if musl && ty.starts_with("uinput_") {
34123419
return true;
34133420
}
3421+
// LFS64 types have been removed in musl 1.2.4+
3422+
if musl && (ty.ends_with("64") || ty.ends_with("64_t")) {
3423+
return true;
3424+
}
34143425
// FIXME: sparc64 CI has old headers
34153426
if sparc64 && (ty == "uinput_ff_erase" || ty == "uinput_abs_setup") {
34163427
return true;
@@ -3528,6 +3539,10 @@ fn test_linux(target: &str) {
35283539
{
35293540
return true;
35303541
}
3542+
// LFS64 types have been removed in musl 1.2.4+
3543+
if name.starts_with("RLIM64") {
3544+
return true;
3545+
}
35313546
}
35323547
match name {
35333548
// These constants are not available if gnu headers have been included

src/unix/linux_like/linux/mod.rs

+47-32
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ impl ::Clone for fpos64_t {
6161
}
6262

6363
s! {
64-
pub struct rlimit64 {
65-
pub rlim_cur: rlim64_t,
66-
pub rlim_max: rlim64_t,
67-
}
68-
6964
pub struct glob_t {
7065
pub gl_pathc: ::size_t,
7166
pub gl_pathv: *mut *mut c_char,
@@ -685,6 +680,11 @@ s! {
685680
pub struct sctp_authinfo {
686681
pub auth_keynumber: ::__u16,
687682
}
683+
684+
pub struct rlimit64 {
685+
pub rlim_cur: rlim64_t,
686+
pub rlim_max: rlim64_t,
687+
}
688688
}
689689

690690
s_no_extra_traits! {
@@ -703,14 +703,6 @@ s_no_extra_traits! {
703703
pub d_name: [::c_char; 256],
704704
}
705705

706-
pub struct dirent64 {
707-
pub d_ino: ::ino64_t,
708-
pub d_off: ::off64_t,
709-
pub d_reclen: ::c_ushort,
710-
pub d_type: ::c_uchar,
711-
pub d_name: [::c_char; 256],
712-
}
713-
714706
pub struct sockaddr_alg {
715707
pub salg_family: ::sa_family_t,
716708
pub salg_type: [::c_uchar; 14],
@@ -804,6 +796,14 @@ s_no_extra_traits! {
804796
pub tx_type: ::c_int,
805797
pub rx_filter: ::c_int,
806798
}
799+
800+
pub struct dirent64 {
801+
pub d_ino: ::ino64_t,
802+
pub d_off: ::off64_t,
803+
pub d_reclen: ::c_ushort,
804+
pub d_type: ::c_uchar,
805+
pub d_name: [::c_char; 256],
806+
}
807807
}
808808

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

4302-
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
4303-
pub fn freopen64(
4304-
filename: *const c_char,
4305-
mode: *const c_char,
4306-
file: *mut ::FILE,
4307-
) -> *mut ::FILE;
4308-
pub fn tmpfile64() -> *mut ::FILE;
4309-
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
4310-
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
4311-
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
4312-
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
43134302
pub fn fallocate(fd: ::c_int, mode: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
4314-
pub fn fallocate64(fd: ::c_int, mode: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
43154303
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
4316-
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
43174304
pub fn readahead(fd: ::c_int, offset: ::off64_t, count: ::size_t) -> ::ssize_t;
43184305
pub fn getxattr(
43194306
path: *const c_char,
@@ -4614,12 +4601,6 @@ extern "C" {
46144601
offset: *mut off_t,
46154602
count: ::size_t,
46164603
) -> ::ssize_t;
4617-
pub fn sendfile64(
4618-
out_fd: ::c_int,
4619-
in_fd: ::c_int,
4620-
offset: *mut off64_t,
4621-
count: ::size_t,
4622-
) -> ::ssize_t;
46234604
pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int;
46244605
pub fn getgrgid_r(
46254606
gid: ::gid_t,
@@ -4871,6 +4852,40 @@ extern "C" {
48714852
) -> ::ssize_t;
48724853
}
48734854

4855+
// LFS64 extensions
4856+
//
4857+
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones
4858+
cfg_if! {
4859+
if #[cfg(not(target_env = "musl"))] {
4860+
extern "C" {
4861+
pub fn fallocate64(
4862+
fd: ::c_int,
4863+
mode: ::c_int,
4864+
offset: ::off64_t,
4865+
len: ::off64_t
4866+
) -> ::c_int;
4867+
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
4868+
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
4869+
pub fn freopen64(
4870+
filename: *const c_char,
4871+
mode: *const c_char,
4872+
file: *mut ::FILE,
4873+
) -> *mut ::FILE;
4874+
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
4875+
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
4876+
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
4877+
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
4878+
pub fn sendfile64(
4879+
out_fd: ::c_int,
4880+
in_fd: ::c_int,
4881+
offset: *mut off64_t,
4882+
count: ::size_t,
4883+
) -> ::ssize_t;
4884+
pub fn tmpfile64() -> *mut ::FILE;
4885+
}
4886+
}
4887+
}
4888+
48744889
cfg_if! {
48754890
if #[cfg(target_env = "uclibc")] {
48764891
mod uclibc;

src/unix/linux_like/linux/musl/b32/riscv32/mod.rs

-16
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,6 @@ s! {
184184
__pad1: ::c_ulong,
185185
__pad2: ::c_ulong,
186186
}
187-
188-
pub struct flock {
189-
pub l_type: ::c_short,
190-
pub l_whence: ::c_short,
191-
pub l_start: ::off_t,
192-
pub l_len: ::off_t,
193-
pub l_pid: ::pid_t,
194-
}
195-
196-
pub struct flock64 {
197-
pub l_type: ::c_short,
198-
pub l_whence: ::c_short,
199-
pub l_start: ::off64_t,
200-
pub l_len: ::off64_t,
201-
pub l_pid: ::pid_t,
202-
}
203187
}
204188

205189
//pub const RLIM_INFINITY: ::rlim_t = !0;

src/unix/linux_like/linux/musl/b64/riscv64/mod.rs

-16
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,6 @@ s! {
173173
__unused5: ::c_ulong,
174174
__unused6: ::c_ulong,
175175
}
176-
177-
pub struct flock {
178-
pub l_type: ::c_short,
179-
pub l_whence: ::c_short,
180-
pub l_start: ::off_t,
181-
pub l_len: ::off_t,
182-
pub l_pid: ::pid_t,
183-
}
184-
185-
pub struct flock64 {
186-
pub l_type: ::c_short,
187-
pub l_whence: ::c_short,
188-
pub l_start: ::off64_t,
189-
pub l_len: ::off64_t,
190-
pub l_pid: ::pid_t,
191-
}
192176
}
193177

194178
pub const SYS_read: ::c_long = 63;

0 commit comments

Comments
 (0)