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

Target modifiers (special marked options) are recorded in metainfo #133138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

azhogin
Copy link
Contributor

@azhogin azhogin commented Nov 17, 2024

Target modifiers (special marked options) are recorded in metainfo and compared to be equal in different linked crates.

PR for this RFC: rust-lang/rfcs#3716

Option may be marked as TARGET_MODIFIER, example: regparm: Option<u32> = (None, parse_opt_number, [TRACKED TARGET_MODIFIER].
If an TARGET_MODIFIER-marked option has non-default value, it will be recorded in crate metainfo as a Vec<TargetModifier>:

pub struct TargetModifier {
    pub opt: OptionsTargetModifiers,
    pub value_name: String,
}

OptionsTargetModifiers is a macro-generated enum.

Option value code (for comparison) is generated using Debug trait.

Error example:

error: mixing `-Zregparm` will cause an ABI mismatch in crate `incompatible_regparm`
  --> $DIR/incompatible_regparm.rs:10:1
   |
LL | #![crate_type = "lib"]
   | ^
   |
   = help: the `-Zregparm` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
   = note: `-Zregparm=1` in this crate is incompatible with `-Zregparm=2` in dependency `wrong_regparm`
   = help: set `-Zregparm=2` in this crate or `-Zregparm=1` in `wrong_regparm`
   = help: if you are sure this will not cause problems, use `-Cunsafe-allow-abi-mismatch=regparm` to silence this error

error: aborting due to 1 previous error

-Cunsafe-allow-abi-mismatch=regparm,reg-struct-return to disable list of flags.

@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2024

r? @davidtwco

rustbot has assigned @davidtwco.
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

@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 Nov 17, 2024
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from d99ff62 to bd52a23 Compare November 18, 2024 19:21
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from bd52a23 to 500600b Compare November 18, 2024 22:37
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch 2 times, most recently from db91299 to 43e5956 Compare November 20, 2024 22:32
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 43e5956 to 6793451 Compare November 21, 2024 10:31
compiler/rustc_metadata/src/creader.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_metadata/src/creader.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/messages.ftl Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
tests/ui/target_modifiers/incompatible_regparm.rs Outdated Show resolved Hide resolved
@rustbot rustbot 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 Nov 21, 2024
@azhogin azhogin force-pushed the azhogin/target-modifiers branch 2 times, most recently from 95f9595 to 9cd86c3 Compare November 26, 2024 22:28
@azhogin
Copy link
Contributor Author

azhogin commented Nov 28, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 28, 2024
@azhogin azhogin marked this pull request as ready for review November 28, 2024 10:54
@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 9cd86c3 to 97a8240 Compare November 28, 2024 11:57
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 97a8240 to 8603b2b Compare November 28, 2024 13:12
compiler/rustc_lint/messages.ftl Outdated Show resolved Hide resolved
compiler/rustc_lint/messages.ftl Outdated Show resolved Hide resolved
@bors

This comment was marked as resolved.

@jieyouxu jieyouxu 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 Jan 13, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Jan 13, 2025

I think the enum key is a lot better, I'll pass this on to someone else just to get another opinion on it.

@davidtwco btw, could you slightly elaborate on what you mean by this? As in, do you want feedback from another reviewer for an aspect of this change in particular, or this PR as a whole (like a second pair of eyes on it)?

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from a084519 to 682d57f Compare January 15, 2025 16:18
@rust-log-analyzer

This comment has been minimized.

@davidtwco
Copy link
Member

I think the enum key is a lot better, I'll pass this on to someone else just to get another opinion on it.

@davidtwco btw, could you slightly elaborate on what you mean by this? As in, do you want feedback from another reviewer for an aspect of this change in particular, or this PR as a whole (like a second pair of eyes on it)?

The latter, just to make sure someone else agrees it's going in the right direction

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 682d57f to 07d1c0a Compare January 15, 2025 19:47
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 07d1c0a to 5d168f2 Compare January 16, 2025 07:29
@rust-log-analyzer

This comment has been minimized.

}

/// A recorded -Zopt_name=opt_value (or -Copt_name=opt_value)
/// for ABI-changing or vulnerability-affecting options.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// for ABI-changing or vulnerability-affecting options.
/// which alter the ABI or effectiveness of exploit mitigations.

I don't think "vulnerability-affecting" is a good term for this. The usual term is "exploit mitigation".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -296,6 +300,83 @@ impl CStore {
}
}

pub fn report_incompatible_target_modifiers(&self, tcx: TyCtxt<'_>, krate: &Crate) {
Copy link
Member

@saethlin saethlin Jan 19, 2025

Choose a reason for hiding this comment

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

I expected this function to just be something like

if !tcx.target_modifiers(LOCAL_CRATE) != tcx.target_modifiers(krate) {
    tcx.emit_err(...
}

but instead, it's way more complicated. Why? What is it doing? It sort of looks like it's trying to come up with a good diagnostic, but I can't even tell if it does the equality check right. So if this is all just in the name of a good diagnostic, can you clearly separate the equality check from the diagnostic reporting? The failure case and this function as a whole is cold, there's no need to avoid looping over flags many times or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is for good diagnostic.
I have added such a code for clarity:

if mods != *data.target_modifiers() {
    Self::report_target_modifiers_extended(tcx, krate, &mods, data);
}

Also, unsafe_allow_abi_mismatch need to be taken into account to skip allowed mismatches.
-Cunsafe-allow-abi-mismatch=regparm,reg-struct-return.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 5d168f2 to 18e4b9f Compare January 22, 2025 06:42
@azhogin
Copy link
Contributor Author

azhogin commented Jan 22, 2025

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 22, 2025
@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 18e4b9f to 8e2f3d7 Compare January 22, 2025 11:13
@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 8e2f3d7 to 2a544ab Compare January 22, 2025 18:53
@saethlin
Copy link
Member

Thanks! Sorry this PR spent a long time in review. We're still polishing the whole goals process, which should hopefully speed up review for goal-related PRs like this one.

@bors r=davidtwco,saethlin

@bors
Copy link
Contributor

bors commented Jan 23, 2025

📌 Commit 2a544ab has been approved by davidtwco,saethlin

It is now in the queue for this repository.

@bors bors 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 Jan 23, 2025
@jieyouxu jieyouxu assigned davidtwco and saethlin and unassigned jieyouxu Jan 23, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Jan 23, 2025
…r=davidtwco,saethlin

Target modifiers (special marked options) are recorded in metainfo

Target modifiers (special marked options) are recorded in metainfo and compared to be equal in different linked crates.

PR for this RFC: rust-lang/rfcs#3716

Option may be marked as `TARGET_MODIFIER`, example: `regparm: Option<u32> = (None, parse_opt_number, [TRACKED TARGET_MODIFIER]`.
If an TARGET_MODIFIER-marked option has non-default value, it will be recorded in crate metainfo as a `Vec<TargetModifier>`:
```
pub struct TargetModifier {
    pub opt: OptionsTargetModifiers,
    pub value_name: String,
}
```

OptionsTargetModifiers is a macro-generated enum.

Option value code (for comparison) is generated using `Debug` trait.

Error example:
```
error: mixing `-Zregparm` will cause an ABI mismatch in crate `incompatible_regparm`
  --> $DIR/incompatible_regparm.rs:10:1
   |
LL | #![crate_type = "lib"]
   | ^
   |
   = help: the `-Zregparm` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
   = note: `-Zregparm=1` in this crate is incompatible with `-Zregparm=2` in dependency `wrong_regparm`
   = help: set `-Zregparm=2` in this crate or `-Zregparm=1` in `wrong_regparm`
   = help: if you are sure this will not cause problems, use `-Cunsafe-allow-abi-mismatch=regparm` to silence this error

error: aborting due to 1 previous error
```

`-Cunsafe-allow-abi-mismatch=regparm,reg-struct-return` to disable list of flags.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 23, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang#133138 (Target modifiers (special marked options) are recorded in metainfo)
 - rust-lang#133154 (Reword resolve errors caused by likely missing crate in dep tree)
 - rust-lang#135366 (Enable `unreachable_pub` lint in `test` and `proc_macro` crates)
 - rust-lang#135638 (Make it possible to build GCC on CI)
 - rust-lang#135648 (support wasm inline assembly in `naked_asm!`)
 - rust-lang#135827 (CI: free disk with in-tree script instead of GitHub Action)
 - rust-lang#135855 (Only assert the `Parser` size on specific arches)
 - rust-lang#135878 (ci: use 8 core arm runner for dist-aarch64-linux)
 - rust-lang#135905 (Enable kernel sanitizers for aarch64-unknown-none-softfloat)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-metadata Area: Crate metadata 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.

10 participants