Skip to content

Commit 99927dc

Browse files
committed
Auto merge of #3261 - bossmc:remove-duplicate-types, r=JohnTitor
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.
2 parents 9469613 + ec384c7 commit 99927dc

File tree

11 files changed

+52
-465
lines changed

11 files changed

+52
-465
lines changed

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

-24
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ s! {
112112
pub f_spare: [::c_ulong; 4],
113113
}
114114

115-
pub struct siginfo_t {
116-
pub si_signo: ::c_int,
117-
pub si_errno: ::c_int,
118-
pub si_code: ::c_int,
119-
pub _pad: [::c_int; 29],
120-
_align: [usize; 0],
121-
}
122-
123115
pub struct statfs64 {
124116
pub f_type: ::c_ulong,
125117
pub f_bsize: ::c_ulong,
@@ -135,22 +127,6 @@ s! {
135127
pub f_spare: [::c_ulong; 4],
136128
}
137129

138-
pub struct statvfs64 {
139-
pub f_bsize: ::c_ulong,
140-
pub f_frsize: ::c_ulong,
141-
pub f_blocks: u64,
142-
pub f_bfree: u64,
143-
pub f_bavail: u64,
144-
pub f_files: u64,
145-
pub f_ffree: u64,
146-
pub f_favail: u64,
147-
pub f_fsid: ::c_ulong,
148-
__f_unused: ::c_int,
149-
pub f_flag: ::c_ulong,
150-
pub f_namemax: ::c_ulong,
151-
__f_spare: [::c_int; 6],
152-
}
153-
154130
pub struct mcontext_t {
155131
pub trap_no: ::c_ulong,
156132
pub error_code: ::c_ulong,

src/unix/linux_like/linux/musl/b32/hexagon.rs

-24
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ s! {
9191
pub f_spare: [::c_ulong; 4],
9292
}
9393

94-
pub struct siginfo_t {
95-
pub si_signo: ::c_int,
96-
pub si_errno: ::c_int,
97-
pub si_code: ::c_int,
98-
pub _pad: [::c_int; 29],
99-
_align: [usize; 0],
100-
}
101-
10294
pub struct statfs64 {
10395
pub f_type: ::c_ulong,
10496
pub f_bsize: ::c_ulong,
@@ -113,22 +105,6 @@ s! {
113105
pub f_flags: ::c_ulong,
114106
pub f_spare: [::c_ulong; 4],
115107
}
116-
117-
pub struct statvfs64 {
118-
pub f_bsize: ::c_ulong,
119-
pub f_frsize: ::c_ulong,
120-
pub f_blocks: u64,
121-
pub f_bfree: u64,
122-
pub f_bavail: u64,
123-
pub f_files: u64,
124-
pub f_ffree: u64,
125-
pub f_favail: u64,
126-
pub f_fsid: ::c_ulong,
127-
__f_unused: ::c_int,
128-
pub f_flag: ::c_ulong,
129-
pub f_namemax: ::c_ulong,
130-
__f_spare: [::c_int; 6],
131-
}
132108
}
133109

134110
pub const AF_FILE: ::c_int = 1;

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

-27
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ s! {
120120
pub f_spare: [::c_ulong; 5],
121121
}
122122

123-
pub struct siginfo_t {
124-
pub si_signo: ::c_int,
125-
pub si_code: ::c_int,
126-
pub si_errno: ::c_int,
127-
pub _pad: [::c_int; 29],
128-
_align: [usize; 0],
129-
}
130-
131123
pub struct statfs64 {
132124
pub f_type: ::c_ulong,
133125
pub f_bsize: ::c_ulong,
@@ -142,25 +134,6 @@ s! {
142134
pub f_flags: ::c_ulong,
143135
pub f_spare: [::c_ulong; 5],
144136
}
145-
146-
pub struct statvfs64 {
147-
pub f_bsize: ::c_ulong,
148-
pub f_frsize: ::c_ulong,
149-
pub f_blocks: u64,
150-
pub f_bfree: u64,
151-
pub f_bavail: u64,
152-
pub f_files: u64,
153-
pub f_ffree: u64,
154-
pub f_favail: u64,
155-
#[cfg(target_endian = "little")]
156-
pub f_fsid: ::c_ulong,
157-
__f_unused: ::c_int,
158-
#[cfg(target_endian = "big")]
159-
pub f_fsid: ::c_ulong,
160-
pub f_flag: ::c_ulong,
161-
pub f_namemax: ::c_ulong,
162-
__f_spare: [::c_int; 6],
163-
}
164137
}
165138

166139
pub const SIGSTKSZ: ::size_t = 8192;

src/unix/linux_like/linux/musl/b32/powerpc.rs

-29
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ s! {
112112
pub f_spare: [::c_ulong; 4],
113113
}
114114

115-
pub struct siginfo_t {
116-
pub si_signo: ::c_int,
117-
pub si_errno: ::c_int,
118-
pub si_code: ::c_int,
119-
pub _pad: [::c_int; 29],
120-
_align: [usize; 0],
121-
}
122-
123115
pub struct statfs64 {
124116
pub f_type: ::c_ulong,
125117
pub f_bsize: ::c_ulong,
@@ -134,25 +126,6 @@ s! {
134126
pub f_flags: ::c_ulong,
135127
pub f_spare: [::c_ulong; 4],
136128
}
137-
138-
pub struct statvfs64 {
139-
pub f_bsize: ::c_ulong,
140-
pub f_frsize: ::c_ulong,
141-
pub f_blocks: u64,
142-
pub f_bfree: u64,
143-
pub f_bavail: u64,
144-
pub f_files: u64,
145-
pub f_ffree: u64,
146-
pub f_favail: u64,
147-
#[cfg(target_endian = "little")]
148-
pub f_fsid: ::c_ulong,
149-
__f_unused: ::c_int,
150-
#[cfg(target_endian = "big")]
151-
pub f_fsid: ::c_ulong,
152-
pub f_flag: ::c_ulong,
153-
pub f_namemax: ::c_ulong,
154-
__f_spare: [::c_int; 6],
155-
}
156129
}
157130

158131
pub const MADV_SOFT_OFFLINE: ::c_int = 101;
@@ -380,8 +353,6 @@ pub const SIG_UNBLOCK: ::c_int = 0x01;
380353

381354
pub const EXTPROC: ::tcflag_t = 0x10000000;
382355

383-
pub const MAP_HUGETLB: ::c_int = 0x040000;
384-
385356
pub const F_GETLK: ::c_int = 12;
386357
pub const F_GETOWN: ::c_int = 9;
387358
pub const F_SETLK: ::c_int = 13;

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

-132
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ pub type c_char = u8;
44
pub type wchar_t = ::c_int;
55

66
s! {
7-
pub struct pthread_attr_t {
8-
__size: [::c_ulong; 7],
9-
}
10-
117
pub struct stat {
128
pub st_dev: ::dev_t,
139
pub st_ino: ::ino_t,
@@ -67,21 +63,6 @@ s! {
6763
pub f_spare: [::c_long; 4],
6864
}
6965

70-
pub struct statvfs {
71-
pub f_bsize: ::c_ulong,
72-
pub f_frsize: ::c_ulong,
73-
pub f_blocks: ::fsblkcnt_t,
74-
pub f_bfree: ::fsblkcnt_t,
75-
pub f_bavail: ::fsblkcnt_t,
76-
pub f_files: ::fsfilcnt_t,
77-
pub f_ffree: ::fsfilcnt_t,
78-
pub f_favail: ::fsfilcnt_t,
79-
pub f_fsid: ::c_ulong,
80-
pub f_flag: ::c_ulong,
81-
pub f_namemax: ::c_ulong,
82-
pub __f_spare: [::c_int; 6],
83-
}
84-
8566
pub struct statfs64 {
8667
pub f_type: ::c_ulong,
8768
pub f_bsize: ::c_ulong,
@@ -97,50 +78,12 @@ s! {
9778
pub f_spare: [::c_ulong; 4],
9879
}
9980

100-
pub struct statvfs64 {
101-
pub f_bsize: ::c_ulong,
102-
pub f_frsize: ::c_ulong,
103-
pub f_blocks: u64,
104-
pub f_bfree: u64,
105-
pub f_bavail: u64,
106-
pub f_files: u64,
107-
pub f_ffree: u64,
108-
pub f_favail: u64,
109-
pub f_fsid: ::c_ulong,
110-
__f_unused: ::c_int,
111-
pub f_flag: ::c_ulong,
112-
pub f_namemax: ::c_ulong,
113-
__f_spare: [::c_int; 6],
114-
}
115-
116-
pub struct siginfo_t {
117-
pub si_signo: ::c_int,
118-
pub si_errno: ::c_int,
119-
pub si_code: ::c_int,
120-
#[doc(hidden)]
121-
#[deprecated(
122-
since="0.2.54",
123-
note="Please leave a comment on \
124-
https://github.com/rust-lang/libc/pull/1316 if you're using \
125-
this field"
126-
)]
127-
pub _pad: [::c_int; 29],
128-
_align: [u64; 0],
129-
}
130-
13181
pub struct stack_t {
13282
pub ss_sp: *mut ::c_void,
13383
pub ss_flags: ::c_int,
13484
pub ss_size: ::size_t,
13585
}
13686

137-
pub struct sigaction {
138-
pub sa_sigaction: ::sighandler_t,
139-
pub sa_mask: ::sigset_t,
140-
pub sa_flags: ::c_int,
141-
pub sa_restorer: ::Option<unsafe extern "C" fn()>,
142-
}
143-
14487
pub struct ipc_perm {
14588
pub __key: ::key_t,
14689
pub uid: ::uid_t,
@@ -189,12 +132,6 @@ s! {
189132
//pub const RLIM_INFINITY: ::rlim_t = !0;
190133
pub const VEOF: usize = 4;
191134
pub const RTLD_DEEPBIND: ::c_int = 0x8;
192-
pub const RTLD_GLOBAL: ::c_int = 0x100;
193-
pub const RTLD_NOLOAD: ::c_int = 0x4;
194-
pub const TIOCGSOFTCAR: ::c_ulong = 21529;
195-
pub const TIOCSSOFTCAR: ::c_ulong = 21530;
196-
pub const TIOCGRS485: ::c_int = 21550;
197-
pub const TIOCSRS485: ::c_int = 21551;
198135
//pub const RLIMIT_RSS: ::__rlimit_resource_t = 5;
199136
//pub const RLIMIT_AS: ::__rlimit_resource_t = 9;
200137
//pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8;
@@ -321,44 +258,17 @@ pub const SIG_UNBLOCK: ::c_int = 1;
321258
pub const POLLWRNORM: ::c_short = 256;
322259
pub const POLLWRBAND: ::c_short = 512;
323260
pub const O_ASYNC: ::c_int = 8192;
324-
pub const O_NDELAY: ::c_int = 2048;
325-
pub const EFD_NONBLOCK: ::c_int = 2048;
326261
pub const F_GETLK: ::c_int = 5;
327262
pub const F_GETOWN: ::c_int = 9;
328263
pub const F_SETOWN: ::c_int = 8;
329-
pub const SFD_NONBLOCK: ::c_int = 2048;
330-
pub const TCSANOW: ::c_int = 0;
331-
pub const TCSADRAIN: ::c_int = 1;
332-
pub const TCSAFLUSH: ::c_int = 2;
333-
pub const TIOCLINUX: ::c_ulong = 21532;
334-
pub const TIOCGSERIAL: ::c_ulong = 21534;
335-
pub const TIOCEXCL: ::c_ulong = 21516;
336-
pub const TIOCNXCL: ::c_ulong = 21517;
337-
pub const TIOCSCTTY: ::c_ulong = 21518;
338-
pub const TIOCSTI: ::c_ulong = 21522;
339-
pub const TIOCMGET: ::c_ulong = 21525;
340-
pub const TIOCMBIS: ::c_ulong = 21526;
341-
pub const TIOCMBIC: ::c_ulong = 21527;
342-
pub const TIOCMSET: ::c_ulong = 21528;
343-
pub const TIOCCONS: ::c_ulong = 21533;
344-
pub const TIOCM_ST: ::c_int = 8;
345-
pub const TIOCM_SR: ::c_int = 16;
346-
pub const TIOCM_CTS: ::c_int = 32;
347-
pub const TIOCM_CAR: ::c_int = 64;
348-
pub const TIOCM_RNG: ::c_int = 128;
349-
pub const TIOCM_DSR: ::c_int = 256;
350264

351-
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
352-
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
353-
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
354265
pub const O_DIRECT: ::c_int = 16384;
355266
pub const O_DIRECTORY: ::c_int = 65536;
356267
pub const O_NOFOLLOW: ::c_int = 131072;
357268
pub const MAP_HUGETLB: ::c_int = 262144;
358269
pub const MAP_LOCKED: ::c_int = 8192;
359270
pub const MAP_NORESERVE: ::c_int = 16384;
360271
pub const MAP_ANON: ::c_int = 32;
361-
pub const MAP_ANONYMOUS: ::c_int = 32;
362272
pub const MAP_DENYWRITE: ::c_int = 2048;
363273
pub const MAP_EXECUTABLE: ::c_int = 4096;
364274
pub const MAP_POPULATE: ::c_int = 32768;
@@ -371,9 +281,6 @@ pub const ENOTNAM: ::c_int = 118;
371281
pub const ENAVAIL: ::c_int = 119;
372282
pub const EISNAM: ::c_int = 120;
373283
pub const EREMOTEIO: ::c_int = 121;
374-
pub const FIOCLEX: ::c_int = 21585;
375-
pub const FIONCLEX: ::c_int = 21584;
376-
pub const FIONBIO: ::c_int = 21537;
377284
pub const MCL_CURRENT: ::c_int = 1;
378285
pub const MCL_FUTURE: ::c_int = 2;
379286
pub const SIGSTKSZ: ::size_t = 8192;
@@ -429,24 +336,6 @@ pub const BSDLY: ::tcflag_t = 8192;
429336
pub const FFDLY: ::tcflag_t = 32768;
430337
pub const VTDLY: ::tcflag_t = 16384;
431338
pub const XTABS: ::tcflag_t = 6144;
432-
pub const B0: ::speed_t = 0;
433-
pub const B50: ::speed_t = 1;
434-
pub const B75: ::speed_t = 2;
435-
pub const B110: ::speed_t = 3;
436-
pub const B134: ::speed_t = 4;
437-
pub const B150: ::speed_t = 5;
438-
pub const B200: ::speed_t = 6;
439-
pub const B300: ::speed_t = 7;
440-
pub const B600: ::speed_t = 8;
441-
pub const B1200: ::speed_t = 9;
442-
pub const B1800: ::speed_t = 10;
443-
pub const B2400: ::speed_t = 11;
444-
pub const B4800: ::speed_t = 12;
445-
pub const B9600: ::speed_t = 13;
446-
pub const B19200: ::speed_t = 14;
447-
pub const B38400: ::speed_t = 15;
448-
pub const EXTA: ::speed_t = 14;
449-
pub const EXTB: ::speed_t = 15;
450339
pub const B57600: ::speed_t = 4097;
451340
pub const B115200: ::speed_t = 4098;
452341
pub const B230400: ::speed_t = 4099;
@@ -469,27 +358,6 @@ pub const IEXTEN: ::tcflag_t = 32768;
469358
pub const TOSTOP: ::tcflag_t = 256;
470359
pub const FLUSHO: ::tcflag_t = 4096;
471360
pub const EXTPROC: ::tcflag_t = 65536;
472-
pub const TCGETS: ::c_int = 21505;
473-
pub const TCSETS: ::c_int = 21506;
474-
pub const TCSETSW: ::c_int = 21507;
475-
pub const TCSETSF: ::c_int = 21508;
476-
pub const TCGETA: ::c_int = 21509;
477-
pub const TCSETA: ::c_int = 21510;
478-
pub const TCSETAW: ::c_int = 21511;
479-
pub const TCSETAF: ::c_int = 21512;
480-
pub const TCSBRK: ::c_int = 21513;
481-
pub const TCXONC: ::c_int = 21514;
482-
pub const TCFLSH: ::c_int = 21515;
483-
pub const TIOCINQ: ::c_int = 21531;
484-
pub const TIOCGPGRP: ::c_int = 21519;
485-
pub const TIOCSPGRP: ::c_int = 21520;
486-
pub const TIOCOUTQ: ::c_int = 21521;
487-
pub const TIOCGWINSZ: ::c_int = 21523;
488-
pub const TIOCSWINSZ: ::c_int = 21524;
489-
pub const FIONREAD: ::c_int = 21531;
490-
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
491-
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
492-
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
493361

494362
pub const SYS_read: ::c_long = 63;
495363
pub const SYS_write: ::c_long = 64;

0 commit comments

Comments
 (0)