Skip to content

Do not mark BPF extern C returns as zeroext#158030

Open
kevin-valerio wants to merge 2 commits into
rust-lang:mainfrom
kevin-valerio:fix/bpf-extern-c-narrow-ret
Open

Do not mark BPF extern C returns as zeroext#158030
kevin-valerio wants to merge 2 commits into
rust-lang:mainfrom
kevin-valerio:fix/bpf-extern-c-narrow-ret

Conversation

@kevin-valerio

Copy link
Copy Markdown
Contributor

Fixes #158028

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 17, 2026
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dingxiangfei2009 (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
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

Comment thread compiler/rustc_target/src/callconv/bpf.rs Outdated
@rustbot

rustbot commented Jun 18, 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.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 18, 2026
@kevin-valerio kevin-valerio force-pushed the fix/bpf-extern-c-narrow-ret branch from 7f7f697 to 5aaa542 Compare June 18, 2026 17:31
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 18, 2026
@kevin-valerio kevin-valerio force-pushed the fix/bpf-extern-c-narrow-ret branch from 5aaa542 to 00da20b Compare June 18, 2026 17:49
@bjorn3

bjorn3 commented Jun 18, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 00da20b has been approved by bjorn3

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 18, 2026
…bjorn3

Do not mark BPF `extern C` returns as `zeroext`

Fixes #158028
@rust-log-analyzer

This comment has been minimized.

@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 18, 2026
@rust-bors

rust-bors Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

💔 Test for d33895b failed: CI. Failed job:

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2026
@workingjubilee

Copy link
Copy Markdown
Member

It's unclear to me that there is a bug to fix here as the issue at hand rests on the question of what is the actual convention for 16-bit return values, as implemented by C compilers in practice?

@bjorn3

bjorn3 commented Jun 21, 2026

Copy link
Copy Markdown
Member

I looked at the clang source and it seemed like it didn't do any extension of return values. But then again, the code is not that easy to understand.

@workingjubilee

Copy link
Copy Markdown
Member

@kevin-valerio When reporting issues about C interop that have bubbled up from a model, please verify it actually is a problem with gcc or clang if all the declarations are correct on both sides.

If some code that originally, in C, is declared as having a signature like uint32_t func(), and it needs masking when called after being declared in Rust as unsafe extern "C" { fn func() -> u16 }, then the problem is that the declaration is incorrect. That's why we made them unsafe to declare. It is unsound to make the wrong declaration. If they do not set r0 to a value invalid as a u16 when you declare the return is a u16, then the current behavior is equally correct as the post-patch state. The eBPF layer itself of translation to actual execution can also affect these decisions here.

I don't think this patch is particularly awful, but you seem to be submitting quite a lot of things so I'd rather we not take them on good faith alone.

@workingjubilee

Copy link
Copy Markdown
Member

Specifically, "This is definitely a problem, and a rustc developer doesn't have to speculatively read clang source code hoping to figure out what would actually be going on" makes it much easier to accept this (and also future patches where things might be more complicated and less clear that we should simply accept "playing defense" because the cost is admittedly probably low? ...but also I don't really know that it's that low because I know eBPF goes through a translation layer so things can cost more).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong expansion of extern "C" u8/u16 returns on bpfel

6 participants