Skip to content

Commit ad90ea8

Browse files
authored
Rollup merge of #135927 - azhogin:azhogin/retpoline, r=davidtwco
retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features `-Zretpoline` and `-Zretpoline-external-thunk` flags are target modifiers (tracked to be equal in linked crates). * Enables target features for `-Zretpoline-external-thunk`: `+retpoline-external-thunk`, `+retpoline-indirect-branches`, `+retpoline-indirect-calls`. * Enables target features for `-Zretpoline`: `+retpoline-indirect-branches`, `+retpoline-indirect-calls`. It corresponds to clang -mretpoline & -mretpoline-external-thunk flags. Also this PR forbids to specify those target features manually (warning). Issue: rust-lang/rust#116852
2 parents 98e21c8 + f485c26 commit ad90ea8

File tree

3 files changed

+10
-39
lines changed

3 files changed

+10
-39
lines changed

messages.ftl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ codegen_gcc_unknown_ctarget_feature_prefix =
22
unknown feature specified for `-Ctarget-feature`: `{$feature}`
33
.note = features must begin with a `+` to enable or `-` to disable it
44
5-
codegen_gcc_forbidden_ctarget_feature =
6-
target feature `{$feature}` cannot be toggled with `-Ctarget-feature`: {$reason}
7-
85
codegen_gcc_unwinding_inline_asm =
96
GCC backend does not support unwinding from inline asm
107
@@ -26,10 +23,6 @@ codegen_gcc_unknown_ctarget_feature =
2623
.possible_feature = you might have meant: `{$rust_feature}`
2724
.consider_filing_feature_request = consider filing a feature request
2825
29-
codegen_gcc_unstable_ctarget_feature =
30-
unstable feature specified for `-Ctarget-feature`: `{$feature}`
31-
.note = this feature is not stably supported; its behavior can change in the future
32-
3326
codegen_gcc_missing_features =
3427
add the missing features in a `target_feature` attribute
3528

src/errors.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,6 @@ pub(crate) struct UnknownCTargetFeature<'a> {
1717
pub rust_feature: PossibleFeature<'a>,
1818
}
1919

20-
#[derive(Diagnostic)]
21-
#[diag(codegen_gcc_unstable_ctarget_feature)]
22-
#[note]
23-
pub(crate) struct UnstableCTargetFeature<'a> {
24-
pub feature: &'a str,
25-
}
26-
27-
#[derive(Diagnostic)]
28-
#[diag(codegen_gcc_forbidden_ctarget_feature)]
29-
pub(crate) struct ForbiddenCTargetFeature<'a> {
30-
pub feature: &'a str,
31-
pub enabled: &'a str,
32-
pub reason: &'a str,
33-
}
34-
3520
#[derive(Subdiagnostic)]
3621
pub(crate) enum PossibleFeature<'a> {
3722
#[help(codegen_gcc_possible_feature)]

src/gcc_util.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ use rustc_codegen_ssa::errors::TargetFeatureDisableOrEnable;
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::unord::UnordSet;
77
use rustc_session::Session;
8+
use rustc_session::features::{StabilityExt, retpoline_features_by_flags};
89
use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES;
910
use smallvec::{SmallVec, smallvec};
1011

11-
use crate::errors::{
12-
ForbiddenCTargetFeature, PossibleFeature, UnknownCTargetFeature, UnknownCTargetFeaturePrefix,
13-
UnstableCTargetFeature,
14-
};
12+
use crate::errors::{PossibleFeature, UnknownCTargetFeature, UnknownCTargetFeaturePrefix};
13+
14+
fn gcc_features_by_flags(sess: &Session) -> Vec<&str> {
15+
let mut features: Vec<&str> = Vec::new();
16+
retpoline_features_by_flags(sess, &mut features);
17+
features
18+
}
1519

1620
/// The list of GCC features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
1721
/// `--target` and similar).
@@ -45,7 +49,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
4549

4650
// Compute implied features
4751
let mut all_rust_features = vec![];
48-
for feature in sess.opts.cg.target_feature.split(',') {
52+
for feature in sess.opts.cg.target_feature.split(',').chain(gcc_features_by_flags(sess)) {
4953
if let Some(feature) = feature.strip_prefix('+') {
5054
all_rust_features.extend(
5155
UnordSet::from(sess.target.implied_target_features(feature))
@@ -94,18 +98,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
9498
sess.dcx().emit_warn(unknown_feature);
9599
}
96100
Some(&(_, stability, _)) => {
97-
if let Err(reason) = stability.toggle_allowed() {
98-
sess.dcx().emit_warn(ForbiddenCTargetFeature {
99-
feature,
100-
enabled: if enable { "enabled" } else { "disabled" },
101-
reason,
102-
});
103-
} else if stability.requires_nightly().is_some() {
104-
// An unstable feature. Warn about using it. (It makes little sense
105-
// to hard-error here since we just warn about fully unknown
106-
// features above).
107-
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
108-
}
101+
stability.verify_feature_enabled_by_flag(sess, enable, feature);
109102
}
110103
}
111104

0 commit comments

Comments
 (0)