-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Unify definitions of siginfo_t
, statvfs
and statfs
in musl
targets
#3261
Conversation
r? @JohnTitor (rustbot has picked a reviewer for you, use r? to override) |
Thanks! @bors r+ |
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.
💔 Test failed - checks-actions |
Turns out I was both too aggressive and not aggressive enough - every target uses the same |
This MR is in danger of going stale so I'd like to resolve the style issue. However I can't find a way to write the code that meets all the conflicting requirements/intentions:
I'm trying to avoid having 10 identical copies of this type defined simply because |
☔ The latest upstream changes (presumably #3302) made this pull request unmergeable. Please resolve the merge conflicts. |
Hey @bossmc, sorry this has been stale for so long. If you are interested in rebasing so we can merge this than that would be excellent; if not, no worries. I do need to note that I don't think this is backportable, meaning we will only get the changes once 1.0 is released (which may still be a few months off). I have to assume this isn't a problem since most of this is refactoring, but just an FYI.
Your 3+4 is totally fine here - how well things optimize in debug mode is essentially a nonissue. For cases where it is, it more common for those crates to just compile dependencies in release mode, so nothing for us to worry about here. |
Let me know if you need anything else. Just @rustbot author |
7c42066
to
d7887af
Compare
Thanks! I've made that change and rebased to (what was) @rustbot review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple small nits and this lgtm, please rebase and squash.
Regarding your top post - I am entirely in favor of using rustdoc
JSON output for testing. If you are up to it, please do consider putting something like this in the libc-test
crate.
These types are redundant as they are exported from higher-level modules. [ move some non-statfs fixups here from other commits in the series, add context to the commmit message - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit b196045)
[ squash "Re-add explicit padding in 32-bit statvfs", reword commit summary - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit d210d71)
These are redundant as they are exported from higher-level modules. [ extract this commit to only cover glibc - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit ca7eedd)
This moves similar types together (e.g. statfs and statfs64) so removing them is cleaner. Co-authored-by: Andy Caldwell <[email protected]> (backport <rust-lang#3261>) (cherry picked from commit 6c0952e)
Musl provides a single definition for `siginfo_t` [1] with the order of `si_code` and `si_errno` controlled by `__SI_SWAP_ERRNO_CODE`. This is only set on mips (both 32- and 64-bit). [1]: https://github.com/kraj/musl/blob/ffb23aef7b5339b8c3234f4c6a93c488dc873919/include/signal.h#L99-L147 [ extracted from "Remove all redundant definitions in musl backend", add context to the commit message - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit e1ff5d6)
`statvfs` already exists in `musl/mod.rs`. Use that were possible and move a common version of `statvfs64` there. [ reduce this patch to only cover statvfs*, leaving statfs as a separate change - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit adcc84d)
Only mips uses a special statfs(64) [ squash "Use `#[cfg]` blocks to special-case statfs on mips", change this patch to only cover statfs and statfs64, include part of "Remove new redundant definitions" - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit fb7785a)
These types are redundant as they are exported from higher-level modules. [ move some non-statfs fixups here from other commits in the series, add context to the commmit message - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit b196045)
[ squash "Re-add explicit padding in 32-bit statvfs", reword commit summary - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit d210d71)
These are redundant as they are exported from higher-level modules. [ extract this commit to only cover glibc - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit ca7eedd)
This moves similar types together (e.g. statfs and statfs64) so removing them is cleaner. Co-authored-by: Andy Caldwell <[email protected]> (backport <rust-lang#3261>) (cherry picked from commit 6c0952e)
Musl provides a single definition for `siginfo_t` [1] with the order of `si_code` and `si_errno` controlled by `__SI_SWAP_ERRNO_CODE`. This is only set on mips (both 32- and 64-bit). [1]: https://github.com/kraj/musl/blob/ffb23aef7b5339b8c3234f4c6a93c488dc873919/include/signal.h#L99-L147 [ extracted from "Remove all redundant definitions in musl backend", add context to the commit message - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit e1ff5d6)
`statvfs` already exists in `musl/mod.rs`. Use that were possible and move a common version of `statvfs64` there. [ reduce this patch to only cover statvfs*, leaving statfs as a separate change - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit adcc84d)
Only mips uses a special statfs(64) [ squash "Use `#[cfg]` blocks to special-case statfs on mips", change this patch to only cover statfs and statfs64, include part of "Remove new redundant definitions" - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit fb7785a)
These types are redundant as they are exported from higher-level modules. [ move some non-statfs fixups here from other commits in the series, add context to the commmit message - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit b196045)
[ squash "Re-add explicit padding in 32-bit statvfs", reword commit summary - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit d210d71)
These are redundant as they are exported from higher-level modules. [ extract this commit to only cover glibc - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit ca7eedd)
This moves similar types together (e.g. statfs and statfs64) so removing them is cleaner. Co-authored-by: Andy Caldwell <[email protected]> (backport <rust-lang#3261>) (cherry picked from commit 6c0952e)
Musl provides a single definition for `siginfo_t` [1] with the order of `si_code` and `si_errno` controlled by `__SI_SWAP_ERRNO_CODE`. This is only set on mips (both 32- and 64-bit). [1]: https://github.com/kraj/musl/blob/ffb23aef7b5339b8c3234f4c6a93c488dc873919/include/signal.h#L99-L147 [ extracted from "Remove all redundant definitions in musl backend", add context to the commit message - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit e1ff5d6)
`statvfs` already exists in `musl/mod.rs`. Use that were possible and move a common version of `statvfs64` there. [ reduce this patch to only cover statvfs*, leaving statfs as a separate change - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit adcc84d)
Only mips uses a special statfs(64) [ squash "Use `#[cfg]` blocks to special-case statfs on mips", change this patch to only cover statfs and statfs64, include part of "Remove new redundant definitions" - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit fb7785a)
These types are redundant as they are exported from higher-level modules. [ move some non-statfs fixups here from other commits in the series, add context to the commmit message - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit b196045)
[ squash "Re-add explicit padding in 32-bit statvfs", reword commit summary - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit d210d71)
These are redundant as they are exported from higher-level modules. [ extract this commit to only cover glibc - Trevor ] (backport <rust-lang#3261>) (cherry picked from commit ca7eedd)
re: squash - understood, and I like the re-sculpted commits you've done. I've had other maintainers insist on "squash and merge" for all changes, and I've never liked that policy, so sorry I jumped to a conclusion here! Nice to get these changes in and thanks for the reviews and support. |
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)
andstruct siginfo_t
to be global for allmusl
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) andstruct statfs(64)
to be global for all 64-bitmusl
targets (see https://git.musl-libc.org/cgit/musl/tree/arch/generic/bits/statfs.h). This also required movingfsblkcnt64_t
andfsfilcnt64_t
to be musl-wide too (for use instruct statvfs64
).It also removes a bunch of redundant (and unreachable) definitions in the
riscv64
andriscv32
targets (there seems to be ariscv32
target in the crate, but not inmusl
itself or at least there's noarch/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.To find most of these issues I used this process
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 forfunction
though you need to additionally filter onextern "C"
(since e.g. there's many manyclone
functions defined in the crate):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.