@@ -445,6 +445,35 @@ impl LinkerFeaturesCli {
445
445
_ => None ,
446
446
}
447
447
}
448
+
449
+ /// Checks usage of unstable variants for linker features for the given `target_tuple`.
450
+ /// Returns `Ok` if no unstable variants are used.
451
+ pub ( crate ) fn check_unstable_variants ( & self , target_tuple : & TargetTuple ) -> Result < ( ) , String > {
452
+ let mentioned_features = self . enabled . union ( self . disabled ) ;
453
+ let has_lld = mentioned_features. is_lld_enabled ( ) ;
454
+
455
+ // Check that -Clinker-features=[-+]lld is not used anywhere else than on x64
456
+ // without -Zunstable-options.
457
+ if has_lld && target_tuple. tuple ( ) != "x86_64-unknown-linux-gnu" {
458
+ return Err ( format ! (
459
+ "`-C linker-features` with lld are unstable for the `{target_tuple}` target, \
460
+ the `-Z unstable-options` flag must also be passed to use it on this target",
461
+ ) ) ;
462
+ }
463
+
464
+ for feature in LinkerFeatures :: all ( ) {
465
+ // Check that no other features were enabled without -Zunstable-options
466
+ // Note that this should currently be unreachable, because the `-Clinker-features` parser
467
+ // currently only accepts lld.
468
+ if feature != LinkerFeatures :: LLD && mentioned_features. contains ( feature) {
469
+ return Err ( "`-C linker-features` is stable only for the lld feature, \
470
+ the`-Z unstable-options` flag must also be passed to use it with other features"
471
+ . to_string ( ) ) ;
472
+ }
473
+ }
474
+
475
+ Ok ( ( ) )
476
+ }
448
477
}
449
478
450
479
/// Used with `-Z assert-incr-state`.
@@ -2606,9 +2635,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2606
2635
}
2607
2636
}
2608
2637
2609
- if !nightly_options:: is_unstable_enabled ( matches)
2610
- && cg. force_frame_pointers == FramePointer :: NonLeaf
2611
- {
2638
+ let unstable_options_enabled = nightly_options:: is_unstable_enabled ( matches) ;
2639
+ if !unstable_options_enabled && cg. force_frame_pointers == FramePointer :: NonLeaf {
2612
2640
early_dcx. early_fatal (
2613
2641
"`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
2614
2642
and a nightly compiler",
@@ -2618,7 +2646,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2618
2646
// For testing purposes, until we have more feedback about these options: ensure `-Z
2619
2647
// unstable-options` is required when using the unstable `-C link-self-contained` and `-C
2620
2648
// linker-flavor` options.
2621
- if !nightly_options :: is_unstable_enabled ( matches ) {
2649
+ if !unstable_options_enabled {
2622
2650
let uses_unstable_self_contained_option =
2623
2651
cg. link_self_contained . are_unstable_variants_set ( ) ;
2624
2652
if uses_unstable_self_contained_option {
@@ -2666,6 +2694,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2666
2694
let debuginfo = select_debuginfo ( matches, & cg) ;
2667
2695
let debuginfo_compression = unstable_opts. debuginfo_compression ;
2668
2696
2697
+ if !unstable_options_enabled {
2698
+ if let Err ( error) = cg. linker_features . check_unstable_variants ( & target_triple) {
2699
+ early_dcx. early_fatal ( error) ;
2700
+ }
2701
+ }
2702
+
2669
2703
let crate_name = matches. opt_str ( "crate-name" ) ;
2670
2704
let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
2671
2705
// Parse any `-l` flags, which link to native libraries.
0 commit comments