@@ -34,6 +34,9 @@ pub enum Stability {
34
34
/// particular for features are actually ABI configuration flags (not all targets are as nice as
35
35
/// RISC-V and have an explicit way to set the ABI separate from target features).
36
36
Forbidden { reason : & ' static str } ,
37
+ /// This feature can not be set via `-Ctarget-feature` or `#[target_feature]`, it can only be set
38
+ /// by target modifier flag. Target modifier flags are tracked to be consistent in linked modules.
39
+ EnabledByTargetModifierFlag { reason : & ' static str , flag : & ' static str } ,
37
40
}
38
41
use Stability :: * ;
39
42
@@ -49,6 +52,7 @@ impl<CTX> HashStable<CTX> for Stability {
49
52
Stability :: Forbidden { reason } => {
50
53
reason. hash_stable ( hcx, hasher) ;
51
54
}
55
+ Stability :: EnabledByTargetModifierFlag { .. } => { }
52
56
}
53
57
}
54
58
}
@@ -74,15 +78,23 @@ impl Stability {
74
78
Stability :: Unstable ( nightly_feature) => Some ( nightly_feature) ,
75
79
Stability :: Stable { .. } => None ,
76
80
Stability :: Forbidden { .. } => panic ! ( "forbidden features should not reach this far" ) ,
81
+ Stability :: EnabledByTargetModifierFlag { .. } => None ,
77
82
}
78
83
}
79
84
80
85
/// Returns whether the feature may be toggled via `#[target_feature]` or `-Ctarget-feature`.
81
86
/// (It might still be nightly-only even if this returns `true`, so make sure to also check
82
87
/// `requires_nightly`.)
83
- pub fn toggle_allowed ( & self ) -> Result < ( ) , & ' static str > {
88
+ pub fn toggle_allowed ( & self , flag_enabled : impl Fn ( & str ) -> bool ) -> Result < ( ) , & ' static str > {
84
89
match self {
85
90
Stability :: Forbidden { reason } => Err ( reason) ,
91
+ Stability :: EnabledByTargetModifierFlag { reason, flag } => {
92
+ if !flag_enabled ( * flag) {
93
+ Err ( reason)
94
+ } else {
95
+ Ok ( ( ) )
96
+ }
97
+ }
86
98
_ => Ok ( ( ) ) ,
87
99
}
88
100
}
@@ -414,6 +426,18 @@ const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
414
426
( "prfchw" , Unstable ( sym:: prfchw_target_feature) , & [ ] ) ,
415
427
( "rdrand" , Stable , & [ ] ) ,
416
428
( "rdseed" , Stable , & [ ] ) ,
429
+ ( "retpoline-external-thunk" , Stability :: EnabledByTargetModifierFlag {
430
+ reason : "use `x86-retpoline` target modifier flag instead" ,
431
+ flag : "x86-retpoline" ,
432
+ } , & [ ] ) ,
433
+ ( "retpoline-indirect-branches" , Stability :: EnabledByTargetModifierFlag {
434
+ reason : "use `x86-retpoline` target modifier flag instead" ,
435
+ flag : "x86-retpoline" ,
436
+ } , & [ ] ) ,
437
+ ( "retpoline-indirect-calls" , Stability :: EnabledByTargetModifierFlag {
438
+ reason : "use `x86-retpoline` target modifier flag instead" ,
439
+ flag : "x86-retpoline" ,
440
+ } , & [ ] ) ,
417
441
( "rtm" , Unstable ( sym:: rtm_target_feature) , & [ ] ) ,
418
442
( "sha" , Stable , & [ "sse2" ] ) ,
419
443
( "sha512" , Unstable ( sym:: sha512_sm_x86) , & [ "avx2" ] ) ,
0 commit comments