@@ -402,7 +402,7 @@ impl LinkSelfContained {
402
402
}
403
403
}
404
404
405
- /// The different values that `-Z linker-features` can take on the CLI: a list of individually
405
+ /// The different values that `-C linker-features` can take on the CLI: a list of individually
406
406
/// enabled or disabled features used during linking.
407
407
///
408
408
/// There is no need to enable or disable them in bulk. Each feature is fine-grained, and can be
@@ -442,6 +442,39 @@ impl LinkerFeaturesCli {
442
442
_ => None ,
443
443
}
444
444
}
445
+
446
+ /// When *not* using `-Z unstable-options` on the CLI, ensure only stable linker features are
447
+ /// used, for the given `TargetTuple`. Returns `Ok` if no unstable variants are used.
448
+ /// The caller should ensure that e.g. `nightly_options::is_unstable_enabled()`
449
+ /// returns false.
450
+ pub ( crate ) fn check_unstable_variants ( & self , target_tuple : & TargetTuple ) -> Result < ( ) , String > {
451
+ // `-C linker-features=-lld` is only stable on x64 linux.
452
+ let has_minus_lld = self . disabled . is_lld_enabled ( ) ;
453
+ if has_minus_lld && target_tuple. tuple ( ) != "x86_64-unknown-linux-gnu" {
454
+ return Err ( format ! (
455
+ "`-C linker-features=-lld` is unstable on the `{target_tuple}` \
456
+ target. The `-Z unstable-options` flag must also be passed to use it on this target",
457
+ ) ) ;
458
+ }
459
+
460
+ // Any `+lld` or non-lld feature used is unstable, and that's an error.
461
+ let unstable_enabled = self . enabled ;
462
+ let unstable_disabled = self . disabled - LinkerFeatures :: LLD ;
463
+ if !unstable_enabled. union ( unstable_disabled) . is_empty ( ) {
464
+ let unstable_features: Vec < _ > = unstable_enabled
465
+ . iter ( )
466
+ . map ( |f| format ! ( "+{}" , f. as_str( ) . unwrap( ) ) )
467
+ . chain ( unstable_disabled. iter ( ) . map ( |f| format ! ( "-{}" , f. as_str( ) . unwrap( ) ) ) )
468
+ . collect ( ) ;
469
+ return Err ( format ! (
470
+ "`-C linker-features={}` is unstable, and also requires the \
471
+ `-Z unstable-options` flag to be used",
472
+ unstable_features. join( "," ) ,
473
+ ) ) ;
474
+ }
475
+
476
+ Ok ( ( ) )
477
+ }
445
478
}
446
479
447
480
/// Used with `-Z assert-incr-state`.
@@ -2638,9 +2671,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2638
2671
}
2639
2672
}
2640
2673
2641
- if !nightly_options:: is_unstable_enabled ( matches)
2642
- && cg. force_frame_pointers == FramePointer :: NonLeaf
2643
- {
2674
+ let unstable_options_enabled = nightly_options:: is_unstable_enabled ( matches) ;
2675
+ if !unstable_options_enabled && cg. force_frame_pointers == FramePointer :: NonLeaf {
2644
2676
early_dcx. early_fatal (
2645
2677
"`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
2646
2678
and a nightly compiler",
@@ -2650,7 +2682,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2650
2682
// For testing purposes, until we have more feedback about these options: ensure `-Z
2651
2683
// unstable-options` is required when using the unstable `-C link-self-contained` and `-C
2652
2684
// linker-flavor` options.
2653
- if !nightly_options :: is_unstable_enabled ( matches ) {
2685
+ if !unstable_options_enabled {
2654
2686
let uses_unstable_self_contained_option =
2655
2687
cg. link_self_contained . are_unstable_variants_set ( ) ;
2656
2688
if uses_unstable_self_contained_option {
@@ -2706,6 +2738,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2706
2738
let debuginfo = select_debuginfo ( matches, & cg) ;
2707
2739
let debuginfo_compression = unstable_opts. debuginfo_compression ;
2708
2740
2741
+ if !unstable_options_enabled {
2742
+ if let Err ( error) = cg. linker_features . check_unstable_variants ( & target_triple) {
2743
+ early_dcx. early_fatal ( error) ;
2744
+ }
2745
+ }
2746
+
2709
2747
let crate_name = matches. opt_str ( "crate-name" ) ;
2710
2748
let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
2711
2749
// Parse any `-l` flags, which link to native libraries.
0 commit comments