@@ -440,6 +440,35 @@ impl LinkerFeaturesCli {
440
440
_ => None ,
441
441
}
442
442
}
443
+
444
+ /// Checks usage of unstable variants for linker features for the given `target_tuple`.
445
+ /// Returns `Ok` if no unstable variants are used.
446
+ pub ( crate ) fn check_unstable_variants ( & self , target_tuple : & TargetTuple ) -> Result < ( ) , String > {
447
+ let mentioned_features = self . enabled . union ( self . disabled ) ;
448
+ let has_lld = mentioned_features. is_lld_enabled ( ) ;
449
+
450
+ // Check that -Clinker-features=[-+]lld is not used anywhere else than on x64
451
+ // without -Zunstable-options.
452
+ if has_lld && target_tuple. tuple ( ) != "x86_64-unknown-linux-gnu" {
453
+ return Err ( format ! (
454
+ "`-C linker-features` with lld are unstable for the `{target_tuple}` target, \
455
+ the `-Z unstable-options` flag must also be passed to use it on this target",
456
+ ) ) ;
457
+ }
458
+
459
+ for feature in LinkerFeatures :: all ( ) {
460
+ // Check that no other features were enabled without -Zunstable-options
461
+ // Note that this should currently be unreachable, because the `-Clinker-features` parser
462
+ // currently only accepts lld.
463
+ if feature != LinkerFeatures :: LLD && mentioned_features. contains ( feature) {
464
+ return Err ( "`-C linker-features` is stable only for the lld feature, \
465
+ the`-Z unstable-options` flag must also be passed to use it with other features"
466
+ . to_string ( ) ) ;
467
+ }
468
+ }
469
+
470
+ Ok ( ( ) )
471
+ }
443
472
}
444
473
445
474
/// Used with `-Z assert-incr-state`.
@@ -2601,9 +2630,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2601
2630
}
2602
2631
}
2603
2632
2604
- if !nightly_options:: is_unstable_enabled ( matches)
2605
- && cg. force_frame_pointers == FramePointer :: NonLeaf
2606
- {
2633
+ let unstable_options_enabled = nightly_options:: is_unstable_enabled ( matches) ;
2634
+ if !unstable_options_enabled && cg. force_frame_pointers == FramePointer :: NonLeaf {
2607
2635
early_dcx. early_fatal (
2608
2636
"`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
2609
2637
and a nightly compiler",
@@ -2613,7 +2641,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2613
2641
// For testing purposes, until we have more feedback about these options: ensure `-Z
2614
2642
// unstable-options` is required when using the unstable `-C link-self-contained` and `-C
2615
2643
// linker-flavor` options.
2616
- if !nightly_options :: is_unstable_enabled ( matches ) {
2644
+ if !unstable_options_enabled {
2617
2645
let uses_unstable_self_contained_option =
2618
2646
cg. link_self_contained . are_unstable_variants_set ( ) ;
2619
2647
if uses_unstable_self_contained_option {
@@ -2661,6 +2689,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2661
2689
let debuginfo = select_debuginfo ( matches, & cg) ;
2662
2690
let debuginfo_compression = unstable_opts. debuginfo_compression ;
2663
2691
2692
+ if !unstable_options_enabled {
2693
+ if let Err ( error) = cg. linker_features . check_unstable_variants ( & target_triple) {
2694
+ early_dcx. early_fatal ( error) ;
2695
+ }
2696
+ }
2697
+
2664
2698
let crate_name = matches. opt_str ( "crate-name" ) ;
2665
2699
let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
2666
2700
// Parse any `-l` flags, which link to native libraries.
0 commit comments