@@ -439,6 +439,35 @@ impl LinkerFeaturesCli {
439
439
_ => None ,
440
440
}
441
441
}
442
+
443
+ /// Checks usage of unstable variants for linker features for the given `target_tuple`.
444
+ /// Returns `Ok` if no unstable variants are used.
445
+ pub ( crate ) fn check_unstable_variants ( & self , target_tuple : & TargetTuple ) -> Result < ( ) , String > {
446
+ let mentioned_features = self . enabled . union ( self . disabled ) ;
447
+ let has_lld = mentioned_features. is_lld_enabled ( ) ;
448
+
449
+ // Check that -Clinker-features=[-+]lld is not used anywhere else than on x64
450
+ // without -Zunstable-options.
451
+ if has_lld && target_tuple. tuple ( ) != "x86_64-unknown-linux-gnu" {
452
+ return Err ( format ! (
453
+ "`-C linker-features` with lld are unstable for the `{target_tuple}` target, \
454
+ the `-Z unstable-options` flag must also be passed to use it on this target",
455
+ ) ) ;
456
+ }
457
+
458
+ for feature in LinkerFeatures :: all ( ) {
459
+ // Check that no other features were enabled without -Zunstable-options
460
+ // Note that this should currently be unreachable, because the `-Clinker-features` parser
461
+ // currently only accepts lld.
462
+ if feature != LinkerFeatures :: LLD && mentioned_features. contains ( feature) {
463
+ return Err ( "`-C linker-features` is stable only for the lld feature, \
464
+ the`-Z unstable-options` flag must also be passed to use it with other features"
465
+ . to_string ( ) ) ;
466
+ }
467
+ }
468
+
469
+ Ok ( ( ) )
470
+ }
442
471
}
443
472
444
473
/// Used with `-Z assert-incr-state`.
@@ -2595,9 +2624,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2595
2624
}
2596
2625
}
2597
2626
2598
- if !nightly_options:: is_unstable_enabled ( matches)
2599
- && cg. force_frame_pointers == FramePointer :: NonLeaf
2600
- {
2627
+ let unstable_options_enabled = nightly_options:: is_unstable_enabled ( matches) ;
2628
+ if !unstable_options_enabled && cg. force_frame_pointers == FramePointer :: NonLeaf {
2601
2629
early_dcx. early_fatal (
2602
2630
"`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
2603
2631
and a nightly compiler",
@@ -2607,7 +2635,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2607
2635
// For testing purposes, until we have more feedback about these options: ensure `-Z
2608
2636
// unstable-options` is required when using the unstable `-C link-self-contained` and `-C
2609
2637
// linker-flavor` options.
2610
- if !nightly_options :: is_unstable_enabled ( matches ) {
2638
+ if !unstable_options_enabled {
2611
2639
let uses_unstable_self_contained_option =
2612
2640
cg. link_self_contained . are_unstable_variants_set ( ) ;
2613
2641
if uses_unstable_self_contained_option {
@@ -2655,6 +2683,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2655
2683
let debuginfo = select_debuginfo ( matches, & cg) ;
2656
2684
let debuginfo_compression = unstable_opts. debuginfo_compression ;
2657
2685
2686
+ if !unstable_options_enabled {
2687
+ if let Err ( error) = cg. linker_features . check_unstable_variants ( & target_triple) {
2688
+ early_dcx. early_fatal ( error) ;
2689
+ }
2690
+ }
2691
+
2658
2692
let crate_name = matches. opt_str ( "crate-name" ) ;
2659
2693
let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
2660
2694
// Parse any `-l` flags, which link to native libraries.
0 commit comments