Skip to content

apple: change BPF_ALIGNMENT to usize - #5348

Merged
tgross35 merged 1 commit into
rust-lang:mainfrom
sbogomolov:apple-bpf-alignment-usize
Aug 4, 2026
Merged

apple: change BPF_ALIGNMENT to usize#5348
tgross35 merged 1 commit into
rust-lang:mainfrom
sbogomolov:apple-bpf-alignment-usize

Conversation

@sbogomolov

@sbogomolov sbogomolov commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description

The header defines BPF_ALIGNMENT as sizeof(int32_t), which is usize, not c_int.

Breaking change for anyone matching on the current type, so no stable-nomination.

Sources

Apple BPF_ALIGNMENT (net/bpf.h):

Checklist

  • Relevant tests in libc-test/semver have been updated (no new symbols)
  • No placeholder or unstable values like *LAST or *MAX are included
  • Tested locally (cd libc-test && cargo test --target mytarget)

@xtqqczze

This comment was marked as outdated.

@xtqqczze

xtqqczze commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

I think stable nomination is appropriate here since this is a fix for an incorrect type definition rather than an intentional API change.

Comment thread src/new/apple/xnu/net/bpf.rs Outdated
@sbogomolov

sbogomolov commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

I think stable nomination is appropriate here since this is a fix for an incorrect type definition rather than an intentional API change.

@rustbot label +stable-nominated

@rustbot rustbot added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Aug 1, 2026
@sbogomolov
sbogomolov force-pushed the apple-bpf-alignment-usize branch from 5d73fad to 8895eea Compare August 1, 2026 20:20
@sbogomolov
sbogomolov requested a review from xtqqczze August 1, 2026 20:20

@xtqqczze xtqqczze left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@xtqqczze

This comment was marked as outdated.

@sbogomolov
sbogomolov force-pushed the apple-bpf-alignment-usize branch from 8895eea to dbf1960 Compare August 2, 2026 19:40
@rustbot

rustbot commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I don't love backporting here - I'd call the fact that they use sizeof in the source more of an implementation detail than confirmation that the type should be size_t. But this will harmonize with FreeBSD and I doubt there are many users not already casting to usize to do something with alignment, so let's do it.

Cc @xingxue-ibm, AIX may want to change BPF_ALIGNMENT to size_t as well.

View changes since this review

@tgross35
tgross35 added this pull request to the merge queue Aug 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 4, 2026
@tgross35
tgross35 added this pull request to the merge queue Aug 4, 2026
Merged via the queue into rust-lang:main with commit 1925488 Aug 4, 2026
57 checks passed
@sbogomolov
sbogomolov deleted the apple-bpf-alignment-usize branch August 4, 2026 07:19
@xtqqczze

xtqqczze commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

I'd call the fact that they use sizeof in the source more of an implementation detail than confirmation that the type should be size_t.

bindgen actually generates this as a u32:

$ bindgen $(xcrun --show-sdk-path)/usr/include/net/bpf.h --clang-macro-fallback | grep BPF_ALIGNMENT
pub const BPF_ALIGNMENT: u32 = 4;

@sbogomolov

Copy link
Copy Markdown
Contributor Author

bindgen actually generates this as a u32:

$ bindgen $(xcrun --show-sdk-path)/usr/include/net/bpf.h --clang-macro-fallback | grep BPF_ALIGNMENT
pub const BPF_ALIGNMENT: u32 = 4;

As far as I understand, u32 here is a value heuristic, not type information. For integer macro constants bindgen evaluates the value (which is 4) and then picks a Rust type by magnitude using its default rule, which is the smallest of u32/u64 that fits. In C the expression sizeof(...) will have type size_t.

@xingxue-ibm

Copy link
Copy Markdown
Contributor

Cc @xingxue-ibm, AIX may want to change BPF_ALIGNMENT to size_t as well.

Thanks, @tgross35! Posted PR #5373 for AIX.

tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Aug 31, 2026
(backport <rust-lang#5348>)
(cherry picked from commit 1925488)
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Aug 31, 2026
(backport <rust-lang#5348>)
(cherry picked from commit 1925488)
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Aug 31, 2026
(backport <rust-lang#5348>)
(cherry picked from commit 1925488)
@tgross35 tgross35 mentioned this pull request Aug 31, 2026
@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 Aug 31, 2026
tgross35 pushed a commit to dybucc/libc that referenced this pull request Aug 31, 2026
(backport <rust-lang#5348>)
(cherry picked from commit 1925488)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-macos stable-applied This PR has been cherry-picked to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants