Skip to content
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

linux_like: Unify statx definitions #3978

Merged
merged 1 commit into from
Nov 24, 2024
Merged

Conversation

neuschaefer
Copy link
Contributor

@neuschaefer neuschaefer commented Oct 16, 2024

Description

The statx system call and corresponding constants are defined by the Linux kernel and don't depend on the libc or architecture. The only difference is whether a libc exports the statx syscall wrapper or not.

We can thus unify the statx definitions for all Linux "like" platforms: GNU (glibc), Android (bionic), and (in a later commit) musl.

The statx struct is in a separate file because the style check doesn't allow multiple s! macros in one file, and #[cfg()] doesn't work in s!.

Plain u64 (or uint64_t in C) can't be used for the statx fields because bionic defines them as __u64, and provides incompatible definitions of uint64_t and __u64.

Sources

none

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI (failed due to unrelated error, linux/errqueue.h)

@rustbot
Copy link
Collaborator

rustbot commented Oct 16, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

Comment on lines 1892 to 1893
mod linux_statx;
pub use self::linux_statx::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me, but could you inline the definitions here rather than creating an API-specific module?

Copy link
Contributor Author

@neuschaefer neuschaefer Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but I wasn't able to use s! and apply cfg! conditions. Maybe there's some trick that I missed, but otherwise, I'd leave it for a later refactoring, if at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, what exactly is the error? This should work okay, see e.g.

cfg_if! {
if #[cfg(not(target_arch = "sparc64"))] {
s!{

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgross35 not sure what I previously did wrong, but it seems to work now. I'll update the PR, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the problems are back, the style check isn't happy:

src/unix/linux_like/mod.rs:1892: constant found after extern function when it belongs before
src/unix/linux_like/mod.rs:1933: struct found after constant when it belongs before
src/unix/linux_like/mod.rs:1933: multiple s! macros in one module

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wound up disabling that multiple s! check because it's kind of false-positive-y, so this should be good with a rebase after #4107 lands (~1 hour)

Sorry for all the conflicts, been doing a lot of branch cleanup work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgross35 thanks a lot!

Copy link
Contributor Author

@neuschaefer neuschaefer Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, the other two ordering errors still occur. Perhaps I could move the constants/structs to the other constants/structs. Should I try that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required that things are ordered typedefs->types->functions->consts, it looks like your cfg_if block is reversed.

It it still complains after you correct the ordering, I think you might just need to split into three invocations of cfg_if! and sort it with the rest of the file.

@tgross35
Copy link
Contributor

tgross35 commented Nov 6, 2024

Also cc @maurer regarding android changes

@tgross35 tgross35 added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Nov 6, 2024
@tgross35
Copy link
Contributor

tgross35 commented Nov 6, 2024

@rustbot author for the above.

Just comment @rustbot review once changed

@neuschaefer
Copy link
Contributor Author

Thanks for reviewing!

@rustbot review

@maurer
Copy link

maurer commented Nov 13, 2024

Unifying this should be fine, as our statx definition in Android is directly derived from kernel headers.

There are also at least four new members on this struct, but they ate the padding so what's written here is still right.

@neuschaefer
Copy link
Contributor Author

While I'm at it, I am also rebasing onto main.

@tgross35 tgross35 removed the O-wasm label Nov 14, 2024
@bors
Copy link
Contributor

bors commented Nov 18, 2024

☔ The latest upstream changes (presumably #4094) made this pull request unmergeable. Please resolve the merge conflicts.

The statx system call and corresponding constants are defined by the
Linux kernel and don't depend on the libc or architecture. The only
difference is whether a libc exports the statx syscall wrapper or not.

We can thus unify the statx definitions for all Linux "like" platforms:
GNU (glibc), Android (bionic), and (in a later commit) musl.

Plain u64 (or uint64_t in C) can't be used for the statx fields because
bionic defines them as __u64, and provides incompatible definitions of
uint64_t and __u64.
@neuschaefer
Copy link
Contributor Author

@rustbot review

@tgross35 tgross35 added this pull request to the merge queue Nov 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 23, 2024
@neuschaefer
Copy link
Contributor Author

Hmm,

    "test_tier2": {
      "result": "cancelled",
      "outputs": {}
    },

apparently that's what lead to this PR getting kicked out of the merge queue

@tgross35 tgross35 added this pull request to the merge queue Nov 24, 2024
@tgross35
Copy link
Contributor

Probably a timeout, sometimes the android jobs get stuck. You can see the relevant run under “view details” where GH says it removed from the queue.

Added it back.

Merged via the queue into rust-lang:main with commit 57b620b Nov 24, 2024
45 checks passed
@neuschaefer neuschaefer deleted the statx-unify branch November 24, 2024 01:46
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 25, 2024
The statx system call and corresponding constants are defined by the
Linux kernel and don't depend on the libc or architecture. The only
difference is whether a libc exports the statx syscall wrapper or not.

We can thus unify the statx definitions for all Linux "like" platforms:
GNU (glibc), Android (bionic), and (in a later commit) musl.

Plain u64 (or uint64_t in C) can't be used for the statx fields because
bionic defines them as __u64, and provides incompatible definitions of
uint64_t and __u64.

(backport <rust-lang#3978>)
(cherry picked from commit e46bbe4)
This was referenced Nov 25, 2024
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 25, 2024
The statx system call and corresponding constants are defined by the
Linux kernel and don't depend on the libc or architecture. The only
difference is whether a libc exports the statx syscall wrapper or not.

We can thus unify the statx definitions for all Linux "like" platforms:
GNU (glibc), Android (bionic), and (in a later commit) musl.

Plain u64 (or uint64_t in C) can't be used for the statx fields because
bionic defines them as __u64, and provides incompatible definitions of
uint64_t and __u64.

(backport <rust-lang#3978>)
(cherry picked from commit e46bbe4)
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 25, 2024
The statx system call and corresponding constants are defined by the
Linux kernel and don't depend on the libc or architecture. The only
difference is whether a libc exports the statx syscall wrapper or not.

We can thus unify the statx definitions for all Linux "like" platforms:
GNU (glibc), Android (bionic), and (in a later commit) musl.

Plain u64 (or uint64_t in C) can't be used for the statx fields because
bionic defines them as __u64, and provides incompatible definitions of
uint64_t and __u64.

(backport <rust-lang#3978>)
(cherry picked from commit e46bbe4)
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 25, 2024
The statx system call and corresponding constants are defined by the
Linux kernel and don't depend on the libc or architecture. The only
difference is whether a libc exports the statx syscall wrapper or not.

We can thus unify the statx definitions for all Linux "like" platforms:
GNU (glibc), Android (bionic), and (in a later commit) musl.

Plain u64 (or uint64_t in C) can't be used for the statx fields because
bionic defines them as __u64, and provides incompatible definitions of
uint64_t and __u64.

(backport <rust-lang#3978>)
(cherry picked from commit e46bbe4)
@tgross35 tgross35 added stable-applied This PR has been cherry-picked to libc's stable release branch and removed stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants