Alias all LFS64 symbols to their non-LFS64 counterparts on musl - #2935
Conversation
|
r? @Amanieu (rust-highfive has picked a reviewer for you, use r? to override) |
|
This is a breaking change, we have to deprecate them on musl first otherwise user code depending on them would be broken. |
|
Unless I've missed something, this isn't a breaking change (at a crate API level at least) - all the types and functions that used to exist still do and still have the same name/arguments/structure/alignment etc. The only difference is that when rust code calls I've done a bit more work on this (ensuring that the complex types are rust-level aliases to each other on |
| // Musl's standard entrypoints are already LFS64 compatible, historically the library aliased | ||
| // these together in header files (as `#define`s) _and_ in the library with weak symbol aliases. | ||
| // | ||
| // Since <version> these aliases were removed from the library (both in the API and the ABI) so we | ||
| // alias them here to keep the crate API stable. | ||
| #[allow(dead_code)] | ||
| fn check_type_aliases( | ||
| dirent: ::dirent, | ||
| ino: ::ino_t, | ||
| flock: ::flock, | ||
| off: ::off_t, | ||
| pos: ::fpos_t, | ||
| rlimit: ::rlimit, | ||
| stat: ::stat, | ||
| statfs: ::statfs, | ||
| statvfs: ::statvfs, | ||
| ) { | ||
| let _dirent: ::dirent64 = dirent; | ||
| let _ino: ::ino64_t = ino; | ||
| let _flock: ::flock64 = flock; | ||
| let _off: ::off64_t = off; | ||
| let _pos: ::fpos64_t = pos; | ||
| let _rlimit: ::rlimit64 = rlimit; | ||
| let _stat: ::stat64 = stat; | ||
| let _statfs: ::statfs64 = statfs; | ||
| let _statvfs: ::statvfs64 = statvfs; | ||
| } |
There was a problem hiding this comment.
This could be moved to test, I guess?
There was a problem hiding this comment.
Could be, though this is merely a compile-time check that the interchangeable types are aliases (rather than identically defined separate types) it's not a test in the classical sense.
An alternative might be to #[cfg(test)] this function?
|
Ah, I see! Thanks for clarifying. Could you fix the style failure and squash commits?
No, we don't support musl 1.2.0 or higher as it contains the time64 change. We've tried to update and the discussion is ongoing: #2088 |
There's a proposed patch available today to remove the symbols from the musl library on the Maybe this PR should be deferred until @wesleywiser's 1.2 support lands - since these symbols won't be disappearing in the |
|
☔ The latest upstream changes (presumably #3095) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I tested this against ToT musl that includes the LFS64 symbol removal (https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4), and it required the attached addition to the second patch: |
328ec95 to
f2ec9e0
Compare
|
Thanks @colincross I'd not noticed the |
f2ec9e0 to
cd78c71
Compare
|
Style check is failing, but otherwise this looks good to merge. It is not a breaking change. |
|
From the discussion in #3248 this probably needs some markups. In that discussion @joshtriplett would prefer the libc crate to expose LFS64 symbols even on Musl 1.2.4 so cross-libc-targeting crates don't need to use Currently the implementation exposes aliased types with
The use of An alternative approach would be for the musl backend to define each LFS64-affected type twice and to define shim functions of the form: Which assumes:
Thoughts? |
|
I believe there was some confusion in the discussion in #3248. @joshtriplett was talking about time64, not LFS64. You're right that changing the |
|
Ok, I've added the set of shim functions (in |
|
☀️ Test successful - checks-actions, checks-cirrus-freebsd-12, checks-cirrus-freebsd-13, checks-cirrus-freebsd-14 |
This fixes the build with musl-1.2.4, for those that are still experiencing issues these steps should resolve them: 1. Downgrade to musl-1.2.3 2. Rebuild dev-lang/rust with these patches 3. Upgrade to musl-1.2.4 again 4. Rebuild rust with USE=system-bootstrap At this point USE=system-boostrap will be required with >= musl-1.2.4 until uptream merges these patches and updates their boostrap. This was tested with musl-1.2.3, musl-1.2.4 and glibc-2.37-r3. Closes: https://bugs.gentoo.org/903607 Upstream-PR: rust-lang/rust#106246 Upstream-Issue: rust-lang/libc#2934 Upstream-PR: rust-lang/libc#2935 Upstream-PR: rust-random/getrandom#326 Upstream-Commit: rust-random/getrandom@7f73e3c Signed-off-by: orbea <orbea@riseup.net>
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.
This fixes the build with musl-1.2.4, for those that are still experiencing issues these steps should resolve them: 1. Downgrade to musl-1.2.3 2. Rebuild dev-lang/rust with these patches 3. Upgrade to musl-1.2.4 again 4. Rebuild rust with USE=system-bootstrap At this point USE=system-boostrap will be required with >= musl-1.2.4 until uptream merges these patches and updates their boostrap. This was tested with musl-1.2.3, musl-1.2.4 and glibc-2.37-r3. Closes: https://bugs.gentoo.org/903607 Upstream-PR: rust-lang/rust#106246 Upstream-Issue: rust-lang/libc#2934 Upstream-PR: rust-lang/libc#2935 Upstream-PR: rust-random/getrandom#326 Upstream-Commit: rust-random/getrandom@7f73e3c Signed-off-by: orbea <orbea@riseup.net>
This fixes the build with musl-1.2.4, for those that are still experiencing issues these steps should resolve them: 1. Downgrade to musl-1.2.3 2. Rebuild dev-lang/rust with these patches 3. Upgrade to musl-1.2.4 again 4. Rebuild rust with USE=system-bootstrap At this point USE=system-boostrap will be required with >= musl-1.2.4 until uptream merges these patches and updates their boostrap. This was tested with musl-1.2.3, musl-1.2.4 and glibc-2.37-r3. Closes: https://bugs.gentoo.org/903607 Upstream-PR: rust-lang/rust#106246 Upstream-Issue: rust-lang/libc#2934 Upstream-PR: rust-lang/libc#2935 Upstream-PR: rust-random/getrandom#326 Upstream-Commit: rust-random/getrandom@7f73e3c Signed-off-by: orbea <orbea@riseup.net>
This fixes the build with musl-1.2.4, for those that are still experiencing issues these steps should resolve them: 1. Downgrade to musl-1.2.3 2. Rebuild dev-lang/rust with these patches 3. Upgrade to musl-1.2.4 again 4. Rebuild rust with USE=system-bootstrap At this point USE=system-boostrap will be required with >= musl-1.2.4 until uptream merges these patches and updates their boostrap. This was tested with musl-1.2.3, musl-1.2.4 and glibc-2.37-r3. Closes: https://bugs.gentoo.org/903607 Upstream-PR: rust-lang/rust#106246 Upstream-Issue: rust-lang/libc#2934 Upstream-PR: rust-lang/libc#2935 Upstream-PR: rust-random/getrandom#326 Upstream-Commit: rust-random/getrandom@7f73e3c Signed-off-by: orbea <orbea@riseup.net>
This fixes the build with musl-1.2.4, for those that are still experiencing issues these steps should resolve them: 1. Downgrade to musl-1.2.3 2. Rebuild dev-lang/rust with these patches 3. Upgrade to musl-1.2.4 again 4. Rebuild rust with USE=system-bootstrap At this point USE=system-boostrap will be required with >= musl-1.2.4 until uptream merges these patches and updates their boostrap. This was tested with musl-1.2.3, musl-1.2.4 and glibc-2.37-r3. Closes: https://bugs.gentoo.org/903607 Upstream-PR: rust-lang/rust#106246 Upstream-Issue: rust-lang/libc#2934 Upstream-PR: rust-lang/libc#2935 Upstream-PR: rust-random/getrandom#326 Upstream-Commit: rust-random/getrandom@7f73e3c Signed-off-by: orbea <orbea@riseup.net>
This fixes the build with musl-1.2.4, for those that are still experiencing issues these steps should resolve them: 1. Downgrade to musl-1.2.3 2. Rebuild dev-lang/rust with these patches 3. Upgrade to musl-1.2.4 again 4. Rebuild rust with USE=system-bootstrap At this point USE=system-boostrap will be required with >= musl-1.2.4 until uptream merges these patches and updates their boostrap. This was tested with musl-1.2.3, musl-1.2.4 and glibc-2.37-r3. Closes: https://bugs.gentoo.org/903607 Upstream-PR: rust-lang/rust#106246 Upstream-Issue: rust-lang/libc#2934 Upstream-PR: rust-lang/libc#2935 Upstream-PR: rust-random/getrandom#326 Upstream-Commit: rust-random/getrandom@7f73e3c Signed-off-by: orbea <orbea@riseup.net>
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
#defineentries) and in the library (as aliasing symbols). There is a desire in musl to drop the ABI compatibility shims (the symbol aliases) - currently thelibccrate exports the LFS64 symbols byextern-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 thelibccrate 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-testseems expect to build againstmusl 1.1.24(in fact, does Rust even supportmusl 1.2? It's not obvious that it does... e.g. seelibc/src/unix/linux_like/linux/musl/mod.rs
Lines 288 to 292 in d99c37d