Skip to content

sess: -Zbranch-protection is a target modifier#152909

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
davidtwco:branch-protection-target-modifier
Mar 20, 2026
Merged

sess: -Zbranch-protection is a target modifier#152909
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
davidtwco:branch-protection-target-modifier

Conversation

@davidtwco
Copy link
Member

-Zbranch-protection only makes sense if the entire crate graph has the option set, otherwise the security properties that branch protection provides won't be effective - hence a target modifier. This flag is unstable so I don't think this warrants an MCP.

@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 Feb 20, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2026

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

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

@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member

bjorn3 commented Feb 20, 2026

I don't see a reason why we shouldn't compile the standard library with branch protection enabled to give users the ability to enable branch protection for their own executable without recompiling the standard library. There is no ABI constraint that prevents mixing. In fact hardware cfi extensions tend to use reuse instructions that were nops when cfi is disabled. An option would be to deny depending on libraries compiled without branch protection from a crate with it enabled, but not the other way around. Just like we do for mixing panic=abort and panic=unwind.

`-Zbranch-protection` only makes sense if the entire crate graph has
the option set, otherwise the security properties that branch protection
provides won't be effective. This flag is unstable so I don't think this
warrants an MCP.
@davidtwco
Copy link
Member Author

I don't see a reason why we shouldn't compile the standard library with branch protection enabled to give users the ability to enable branch protection for their own executable without recompiling the standard library. There is no ABI constraint that prevents mixing. In fact hardware cfi extensions tend to use reuse instructions that were nops when cfi is disabled. An option would be to deny depending on libraries compiled without branch protection from a crate with it enabled, but not the other way around. Just like we do for mixing panic=abort and panic=unwind.

I'm not convinced, I think think this flag is better as a target modifier because you don't get the security properties of branch protection unless the entire crate graph has it, so turning it on for some crates gives a false sense of security. I think it's better to have consistency with how target modifiers behave and have only the "flags that must match across crate graph" and "flags that can be different across crate graph" behaviours that users learn than expand the additional third category that panic="abort"/panic="unwind" fit into.

As a target modifier, it's hard to compile the standard library with branch protection unless we also change the default to enable branch protection, which is another discussion.

@davidtwco davidtwco force-pushed the branch-protection-target-modifier branch from e76f989 to cca2865 Compare March 10, 2026 12:55
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Mar 10, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 10, 2026

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.

@jackh726
Copy link
Member

My 2 cents, I think it makes sense to have this be something to some crates in a tree can set without other crates setting it, and in this sense, setting this as a target modifier doesn't quite make sense. That being said, I also buy the reasoning that you most often likely want to enable it for the whole crate graph.

Unfortunately, we don't have something like with lints, where we can say "enable this for my crate only" vs "enable this for the entire crate graph" (and you would want the "obvious"/"easy" option to be enable for the entire crate graph). This is probably something we should think about more generally.

I'm going to r+ this, as it is unstable. But @davidtwco can you update the tracking issue to reflect this unresolved question?

@bors r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 19, 2026

📌 Commit cca2865 has been approved by jackh726

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 Mar 19, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 19, 2026
…-modifier, r=jackh726

sess: `-Zbranch-protection` is a target modifier

`-Zbranch-protection` only makes sense if the entire crate graph has the option set, otherwise the security properties that branch protection provides won't be effective - hence a target modifier. This flag is unstable so I don't think this warrants an MCP.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 19, 2026
…-modifier, r=jackh726

sess: `-Zbranch-protection` is a target modifier

`-Zbranch-protection` only makes sense if the entire crate graph has the option set, otherwise the security properties that branch protection provides won't be effective - hence a target modifier. This flag is unstable so I don't think this warrants an MCP.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 19, 2026
…-modifier, r=jackh726

sess: `-Zbranch-protection` is a target modifier

`-Zbranch-protection` only makes sense if the entire crate graph has the option set, otherwise the security properties that branch protection provides won't be effective - hence a target modifier. This flag is unstable so I don't think this warrants an MCP.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 19, 2026
…-modifier, r=jackh726

sess: `-Zbranch-protection` is a target modifier

`-Zbranch-protection` only makes sense if the entire crate graph has the option set, otherwise the security properties that branch protection provides won't be effective - hence a target modifier. This flag is unstable so I don't think this warrants an MCP.
rust-bors bot pushed a commit that referenced this pull request Mar 20, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #152909 (sess: `-Zbranch-protection` is a target modifier)
 - #153556 (`impl` restriction lowering)
 - #154048 (Don't emit rustdoc `missing_doc_code_examples` lint on impl items)
 - #153992 (bootstrap: Optionally print a backtrace if a command fails)
 - #154019 (two smaller feature cleanups)
 - #154059 (tests: Activate `must_not_suspend` test for `MutexGuard` dropped before `await`)
 - #154075 (Rewrite `query_ensure_result`.)
 - #154082 (Updates derive_where and removes workaround)
 - #154084 (Preserve braces around `self` in use tree pretty printing)
 - #154086 (Insert space after float literal ending with `.` in pretty printer)
 - #154087 (Fix whitespace after fragment specifiers in macro pretty printing)
 - #154109 (tests: Add regression test for async closures involving HRTBs)
rust-bors bot pushed a commit that referenced this pull request Mar 20, 2026
Rollup of 15 pull requests

Successful merges:

 - #152909 (sess: `-Zbranch-protection` is a target modifier)
 - #153556 (`impl` restriction lowering)
 - #154048 (Don't emit rustdoc `missing_doc_code_examples` lint on impl items)
 - #150935 (Introduce #[diagnostic::on_move(message)])
 - #152973 (remove -Csoft-float)
 - #153862 (Rename `cycle_check` to `find_cycle`)
 - #153992 (bootstrap: Optionally print a backtrace if a command fails)
 - #154019 (two smaller feature cleanups)
 - #154059 (tests: Activate `must_not_suspend` test for `MutexGuard` dropped before `await`)
 - #154075 (Rewrite `query_ensure_result`.)
 - #154082 (Updates derive_where and removes workaround)
 - #154084 (Preserve braces around `self` in use tree pretty printing)
 - #154086 (Insert space after float literal ending with `.` in pretty printer)
 - #154087 (Fix whitespace after fragment specifiers in macro pretty printing)
 - #154109 (tests: Add regression test for async closures involving HRTBs)
@rust-bors rust-bors bot merged commit 845fd53 into rust-lang:main Mar 20, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants