File tree 2 files changed +26
-18
lines changed
2 files changed +26
-18
lines changed Original file line number Diff line number Diff line change
1
+ fn main ( ) {
2
+ // retpolines are not yet recognized by rust as a regular target feature.
3
+ // We can't detect them with `cfg(target_feature = "retpoline")`, but we can detect them in
4
+ // rustflags, since they shouldn't be the default for any target.
5
+ let rustflags = std:: env:: var ( "CARGO_ENCODED_RUSTFLAGS" ) . unwrap ( ) ;
6
+ let retpolines_enabled = rustflags. split ( '\x1f' ) . any ( |flag| {
7
+ let features = flag
8
+ . strip_prefix ( "target-feature=" )
9
+ . or ( flag. strip_prefix ( "-Ctarget-feature=" ) ) ;
10
+ if let Some ( features) = features {
11
+ features
12
+ . split ( ',' )
13
+ . any ( |feature| feature. starts_with ( "+retpoline" ) )
14
+ } else {
15
+ false
16
+ }
17
+ } ) ;
18
+
19
+ if retpolines_enabled {
20
+ println ! ( "cargo::rustc-cfg=retpoline" )
21
+ }
22
+ println ! ( "cargo::rustc-check-cfg=cfg(retpoline)" ) ;
23
+ println ! ( "cargo::rerun-if-changed=build.rs" ) ;
24
+ }
Original file line number Diff line number Diff line change @@ -381,27 +381,11 @@ impl Dispatcher {
381
381
if !crate :: util:: fn_params ( & self . func . sig ) . is_empty ( )
382
382
|| self . func . sig . asyncness . is_some ( )
383
383
|| util:: impl_trait_present ( & self . func . sig )
384
+ || cfg ! ( retpoline)
384
385
{
385
386
self . direct_dispatcher_fn ( ) ?
386
387
} else {
387
- let indirect = self . indirect_dispatcher_fn ( ) ?;
388
- let direct = self . direct_dispatcher_fn ( ) ?;
389
- parse_quote ! {
390
- {
391
- #[ cfg( not( any(
392
- target_feature = "retpoline" ,
393
- target_feature = "retpoline-indirect-branches" ,
394
- target_feature = "retpoline-indirect-calls" ,
395
- ) ) ) ]
396
- #indirect
397
- #[ cfg( any(
398
- target_feature = "retpoline" ,
399
- target_feature = "retpoline-indirect-branches" ,
400
- target_feature = "retpoline-indirect-calls" ,
401
- ) ) ]
402
- #direct
403
- }
404
- }
388
+ self . indirect_dispatcher_fn ( ) ?
405
389
}
406
390
} else {
407
391
self . static_dispatcher_fn ( )
You can’t perform that action at this time.
0 commit comments