Skip to content

Commit

Permalink
Auto merge of #3261 - bossmc:remove-duplicate-types, r=JohnTitor
Browse files Browse the repository at this point in the history
Unify definitions of `siginfo_t`, `statvfs` and `statfs` in `musl` targets

During #2935 I noticed there were multiple identical definitions of some of the `bits/***.h` types in the  musl target, as well as a few places where a type was defined twice in the module tree (leading to the "upper-most" definition being the one exported by the library, in contradiction to the expectation that the "most-specific" definition would be used.

This change moves the definitions of `struct statvfs(64)` and `struct siginfo_t` to be global for all `musl` targets (see https://git.musl-libc.org/cgit/musl/tree/include/sys/statvfs.h and https://git.musl-libc.org/cgit/musl/tree/include/signal.h which are architecture-agnostic headers) and `struct statfs(64)` to be global for all 64-bit `musl` targets (see https://git.musl-libc.org/cgit/musl/tree/arch/generic/bits/statfs.h).  This also required moving `fsblkcnt64_t` and `fsfilcnt64_t` to be musl-wide too (for use in `struct statvfs64`).

It also removes a bunch of redundant (and unreachable) definitions in the `riscv64` and `riscv32` targets (there seems to be a `riscv32` target in the crate, but not in `musl` itself or at least there's no `arch/riscv32` folder in tree).

Upshot of the above is that this change has no externally visible effect, if the more specific types were intended to be used they weren't being so removing them is a no-op.  To actually use more specific type definitions one would need to `cfg` out the general definition as well as providing the specific one.

<details>

<summary>To find most of these issues I used this process</summary>

```
$ for target in $(rustc --print target-list | grep musl)
do
  echo $target
  RUSTDOCFLAGS="--output-format json --document-private-items" cargo +nightly doc -Z build-std=core --target $target
done
$ for json in target/**/doc/libc.json
do
  echo $json
  jq '.index[] | select(.inner | keys[0] == "struct") | .name' $json | sort | uniq -d
done
```

The first command uses rustdoc to create a JSON representation of the API of the crate for each (`musl`) target and the second searches that output for two exported structs of the same name within a single target.  Where there's a duplicate, only one of the two symbols is actually usable (and due to import rules, symbols defined locally take precedence over symbols imported from submodules so the less specific symbol is the one that wins).

You can do similar tests for `enum`, `typedef`, `union`, constant` by changing the second command in the obvious way, you can also do the same for `function` though you need to additionally filter on `extern "C"` (since e.g. there's many many `clone` functions defined in the crate):

```
$ jq '.index[] | select(.inner | keys[0] == "function") | select(.inner.function.header.abi | (type == "object" and keys[0] == "C"))
| .name' $json | sort | uniq -d
```

</details>

It feels like adding the checks in that methodology to CI for each target would be a good way to catch issues where a more specific definition is masked by a less-specific one.
  • Loading branch information
bors committed Jun 4, 2023
2 parents 9469613 + ec384c7 commit 99927dc
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 465 deletions.
24 changes: 0 additions & 24 deletions src/unix/linux_like/linux/musl/b32/arm/mod.rs
Expand Up @@ -112,14 +112,6 @@ s! {
pub f_spare: [::c_ulong; 4],
}

pub struct siginfo_t {
pub si_signo: ::c_int,
pub si_errno: ::c_int,
pub si_code: ::c_int,
pub _pad: [::c_int; 29],
_align: [usize; 0],
}

pub struct statfs64 {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
Expand All @@ -135,22 +127,6 @@ s! {
pub f_spare: [::c_ulong; 4],
}

pub struct statvfs64 {
pub f_bsize: ::c_ulong,
pub f_frsize: ::c_ulong,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_favail: u64,
pub f_fsid: ::c_ulong,
__f_unused: ::c_int,
pub f_flag: ::c_ulong,
pub f_namemax: ::c_ulong,
__f_spare: [::c_int; 6],
}

pub struct mcontext_t {
pub trap_no: ::c_ulong,
pub error_code: ::c_ulong,
Expand Down
24 changes: 0 additions & 24 deletions src/unix/linux_like/linux/musl/b32/hexagon.rs
Expand Up @@ -91,14 +91,6 @@ s! {
pub f_spare: [::c_ulong; 4],
}

pub struct siginfo_t {
pub si_signo: ::c_int,
pub si_errno: ::c_int,
pub si_code: ::c_int,
pub _pad: [::c_int; 29],
_align: [usize; 0],
}

pub struct statfs64 {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
Expand All @@ -113,22 +105,6 @@ s! {
pub f_flags: ::c_ulong,
pub f_spare: [::c_ulong; 4],
}

pub struct statvfs64 {
pub f_bsize: ::c_ulong,
pub f_frsize: ::c_ulong,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_favail: u64,
pub f_fsid: ::c_ulong,
__f_unused: ::c_int,
pub f_flag: ::c_ulong,
pub f_namemax: ::c_ulong,
__f_spare: [::c_int; 6],
}
}

pub const AF_FILE: ::c_int = 1;
Expand Down
27 changes: 0 additions & 27 deletions src/unix/linux_like/linux/musl/b32/mips/mod.rs
Expand Up @@ -120,14 +120,6 @@ s! {
pub f_spare: [::c_ulong; 5],
}

pub struct siginfo_t {
pub si_signo: ::c_int,
pub si_code: ::c_int,
pub si_errno: ::c_int,
pub _pad: [::c_int; 29],
_align: [usize; 0],
}

pub struct statfs64 {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
Expand All @@ -142,25 +134,6 @@ s! {
pub f_flags: ::c_ulong,
pub f_spare: [::c_ulong; 5],
}

pub struct statvfs64 {
pub f_bsize: ::c_ulong,
pub f_frsize: ::c_ulong,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_favail: u64,
#[cfg(target_endian = "little")]
pub f_fsid: ::c_ulong,
__f_unused: ::c_int,
#[cfg(target_endian = "big")]
pub f_fsid: ::c_ulong,
pub f_flag: ::c_ulong,
pub f_namemax: ::c_ulong,
__f_spare: [::c_int; 6],
}
}

pub const SIGSTKSZ: ::size_t = 8192;
Expand Down
29 changes: 0 additions & 29 deletions src/unix/linux_like/linux/musl/b32/powerpc.rs
Expand Up @@ -112,14 +112,6 @@ s! {
pub f_spare: [::c_ulong; 4],
}

pub struct siginfo_t {
pub si_signo: ::c_int,
pub si_errno: ::c_int,
pub si_code: ::c_int,
pub _pad: [::c_int; 29],
_align: [usize; 0],
}

pub struct statfs64 {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
Expand All @@ -134,25 +126,6 @@ s! {
pub f_flags: ::c_ulong,
pub f_spare: [::c_ulong; 4],
}

pub struct statvfs64 {
pub f_bsize: ::c_ulong,
pub f_frsize: ::c_ulong,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_favail: u64,
#[cfg(target_endian = "little")]
pub f_fsid: ::c_ulong,
__f_unused: ::c_int,
#[cfg(target_endian = "big")]
pub f_fsid: ::c_ulong,
pub f_flag: ::c_ulong,
pub f_namemax: ::c_ulong,
__f_spare: [::c_int; 6],
}
}

pub const MADV_SOFT_OFFLINE: ::c_int = 101;
Expand Down Expand Up @@ -380,8 +353,6 @@ pub const SIG_UNBLOCK: ::c_int = 0x01;

pub const EXTPROC: ::tcflag_t = 0x10000000;

pub const MAP_HUGETLB: ::c_int = 0x040000;

pub const F_GETLK: ::c_int = 12;
pub const F_GETOWN: ::c_int = 9;
pub const F_SETLK: ::c_int = 13;
Expand Down
132 changes: 0 additions & 132 deletions src/unix/linux_like/linux/musl/b32/riscv32/mod.rs
Expand Up @@ -4,10 +4,6 @@ pub type c_char = u8;
pub type wchar_t = ::c_int;

s! {
pub struct pthread_attr_t {
__size: [::c_ulong; 7],
}

pub struct stat {
pub st_dev: ::dev_t,
pub st_ino: ::ino_t,
Expand Down Expand Up @@ -67,21 +63,6 @@ s! {
pub f_spare: [::c_long; 4],
}

pub struct statvfs {
pub f_bsize: ::c_ulong,
pub f_frsize: ::c_ulong,
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_favail: ::fsfilcnt_t,
pub f_fsid: ::c_ulong,
pub f_flag: ::c_ulong,
pub f_namemax: ::c_ulong,
pub __f_spare: [::c_int; 6],
}

pub struct statfs64 {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
Expand All @@ -97,50 +78,12 @@ s! {
pub f_spare: [::c_ulong; 4],
}

pub struct statvfs64 {
pub f_bsize: ::c_ulong,
pub f_frsize: ::c_ulong,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_favail: u64,
pub f_fsid: ::c_ulong,
__f_unused: ::c_int,
pub f_flag: ::c_ulong,
pub f_namemax: ::c_ulong,
__f_spare: [::c_int; 6],
}

pub struct siginfo_t {
pub si_signo: ::c_int,
pub si_errno: ::c_int,
pub si_code: ::c_int,
#[doc(hidden)]
#[deprecated(
since="0.2.54",
note="Please leave a comment on \
https://github.com/rust-lang/libc/pull/1316 if you're using \
this field"
)]
pub _pad: [::c_int; 29],
_align: [u64; 0],
}

pub struct stack_t {
pub ss_sp: *mut ::c_void,
pub ss_flags: ::c_int,
pub ss_size: ::size_t,
}

pub struct sigaction {
pub sa_sigaction: ::sighandler_t,
pub sa_mask: ::sigset_t,
pub sa_flags: ::c_int,
pub sa_restorer: ::Option<unsafe extern "C" fn()>,
}

pub struct ipc_perm {
pub __key: ::key_t,
pub uid: ::uid_t,
Expand Down Expand Up @@ -189,12 +132,6 @@ s! {
//pub const RLIM_INFINITY: ::rlim_t = !0;
pub const VEOF: usize = 4;
pub const RTLD_DEEPBIND: ::c_int = 0x8;
pub const RTLD_GLOBAL: ::c_int = 0x100;
pub const RTLD_NOLOAD: ::c_int = 0x4;
pub const TIOCGSOFTCAR: ::c_ulong = 21529;
pub const TIOCSSOFTCAR: ::c_ulong = 21530;
pub const TIOCGRS485: ::c_int = 21550;
pub const TIOCSRS485: ::c_int = 21551;
//pub const RLIMIT_RSS: ::__rlimit_resource_t = 5;
//pub const RLIMIT_AS: ::__rlimit_resource_t = 9;
//pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8;
Expand Down Expand Up @@ -321,44 +258,17 @@ pub const SIG_UNBLOCK: ::c_int = 1;
pub const POLLWRNORM: ::c_short = 256;
pub const POLLWRBAND: ::c_short = 512;
pub const O_ASYNC: ::c_int = 8192;
pub const O_NDELAY: ::c_int = 2048;
pub const EFD_NONBLOCK: ::c_int = 2048;
pub const F_GETLK: ::c_int = 5;
pub const F_GETOWN: ::c_int = 9;
pub const F_SETOWN: ::c_int = 8;
pub const SFD_NONBLOCK: ::c_int = 2048;
pub const TCSANOW: ::c_int = 0;
pub const TCSADRAIN: ::c_int = 1;
pub const TCSAFLUSH: ::c_int = 2;
pub const TIOCLINUX: ::c_ulong = 21532;
pub const TIOCGSERIAL: ::c_ulong = 21534;
pub const TIOCEXCL: ::c_ulong = 21516;
pub const TIOCNXCL: ::c_ulong = 21517;
pub const TIOCSCTTY: ::c_ulong = 21518;
pub const TIOCSTI: ::c_ulong = 21522;
pub const TIOCMGET: ::c_ulong = 21525;
pub const TIOCMBIS: ::c_ulong = 21526;
pub const TIOCMBIC: ::c_ulong = 21527;
pub const TIOCMSET: ::c_ulong = 21528;
pub const TIOCCONS: ::c_ulong = 21533;
pub const TIOCM_ST: ::c_int = 8;
pub const TIOCM_SR: ::c_int = 16;
pub const TIOCM_CTS: ::c_int = 32;
pub const TIOCM_CAR: ::c_int = 64;
pub const TIOCM_RNG: ::c_int = 128;
pub const TIOCM_DSR: ::c_int = 256;

pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const O_DIRECT: ::c_int = 16384;
pub const O_DIRECTORY: ::c_int = 65536;
pub const O_NOFOLLOW: ::c_int = 131072;
pub const MAP_HUGETLB: ::c_int = 262144;
pub const MAP_LOCKED: ::c_int = 8192;
pub const MAP_NORESERVE: ::c_int = 16384;
pub const MAP_ANON: ::c_int = 32;
pub const MAP_ANONYMOUS: ::c_int = 32;
pub const MAP_DENYWRITE: ::c_int = 2048;
pub const MAP_EXECUTABLE: ::c_int = 4096;
pub const MAP_POPULATE: ::c_int = 32768;
Expand All @@ -371,9 +281,6 @@ pub const ENOTNAM: ::c_int = 118;
pub const ENAVAIL: ::c_int = 119;
pub const EISNAM: ::c_int = 120;
pub const EREMOTEIO: ::c_int = 121;
pub const FIOCLEX: ::c_int = 21585;
pub const FIONCLEX: ::c_int = 21584;
pub const FIONBIO: ::c_int = 21537;
pub const MCL_CURRENT: ::c_int = 1;
pub const MCL_FUTURE: ::c_int = 2;
pub const SIGSTKSZ: ::size_t = 8192;
Expand Down Expand Up @@ -429,24 +336,6 @@ pub const BSDLY: ::tcflag_t = 8192;
pub const FFDLY: ::tcflag_t = 32768;
pub const VTDLY: ::tcflag_t = 16384;
pub const XTABS: ::tcflag_t = 6144;
pub const B0: ::speed_t = 0;
pub const B50: ::speed_t = 1;
pub const B75: ::speed_t = 2;
pub const B110: ::speed_t = 3;
pub const B134: ::speed_t = 4;
pub const B150: ::speed_t = 5;
pub const B200: ::speed_t = 6;
pub const B300: ::speed_t = 7;
pub const B600: ::speed_t = 8;
pub const B1200: ::speed_t = 9;
pub const B1800: ::speed_t = 10;
pub const B2400: ::speed_t = 11;
pub const B4800: ::speed_t = 12;
pub const B9600: ::speed_t = 13;
pub const B19200: ::speed_t = 14;
pub const B38400: ::speed_t = 15;
pub const EXTA: ::speed_t = 14;
pub const EXTB: ::speed_t = 15;
pub const B57600: ::speed_t = 4097;
pub const B115200: ::speed_t = 4098;
pub const B230400: ::speed_t = 4099;
Expand All @@ -469,27 +358,6 @@ pub const IEXTEN: ::tcflag_t = 32768;
pub const TOSTOP: ::tcflag_t = 256;
pub const FLUSHO: ::tcflag_t = 4096;
pub const EXTPROC: ::tcflag_t = 65536;
pub const TCGETS: ::c_int = 21505;
pub const TCSETS: ::c_int = 21506;
pub const TCSETSW: ::c_int = 21507;
pub const TCSETSF: ::c_int = 21508;
pub const TCGETA: ::c_int = 21509;
pub const TCSETA: ::c_int = 21510;
pub const TCSETAW: ::c_int = 21511;
pub const TCSETAF: ::c_int = 21512;
pub const TCSBRK: ::c_int = 21513;
pub const TCXONC: ::c_int = 21514;
pub const TCFLSH: ::c_int = 21515;
pub const TIOCINQ: ::c_int = 21531;
pub const TIOCGPGRP: ::c_int = 21519;
pub const TIOCSPGRP: ::c_int = 21520;
pub const TIOCOUTQ: ::c_int = 21521;
pub const TIOCGWINSZ: ::c_int = 21523;
pub const TIOCSWINSZ: ::c_int = 21524;
pub const FIONREAD: ::c_int = 21531;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

pub const SYS_read: ::c_long = 63;
pub const SYS_write: ::c_long = 64;
Expand Down

0 comments on commit 99927dc

Please sign in to comment.