@@ -442,6 +442,35 @@ impl LinkerFeaturesCli {
442
442
_ => None ,
443
443
}
444
444
}
445
+
446
+ /// Checks usage of unstable variants for linker features for the given `target_tuple`.
447
+ /// Returns `Ok` if no unstable variants are used.
448
+ pub ( crate ) fn check_unstable_variants ( & self , target_tuple : & TargetTuple ) -> Result < ( ) , String > {
449
+ let mentioned_features = self . enabled . union ( self . disabled ) ;
450
+ let has_lld = mentioned_features. is_lld_enabled ( ) ;
451
+
452
+ // Check that -Clinker-features=[-+]lld is not used anywhere else than on x64
453
+ // without -Zunstable-options.
454
+ if has_lld && target_tuple. tuple ( ) != "x86_64-unknown-linux-gnu" {
455
+ return Err ( format ! (
456
+ "`-C linker-features` with lld are unstable for the `{target_tuple}` target, \
457
+ the `-Z unstable-options` flag must also be passed to use it on this target",
458
+ ) ) ;
459
+ }
460
+
461
+ for feature in LinkerFeatures :: all ( ) {
462
+ // Check that no other features were enabled without -Zunstable-options
463
+ // Note that this should currently be unreachable, because the `-Clinker-features` parser
464
+ // currently only accepts lld.
465
+ if feature != LinkerFeatures :: LLD && mentioned_features. contains ( feature) {
466
+ return Err ( "`-C linker-features` is stable only for the lld feature, \
467
+ the`-Z unstable-options` flag must also be passed to use it with other features"
468
+ . to_string ( ) ) ;
469
+ }
470
+ }
471
+
472
+ Ok ( ( ) )
473
+ }
445
474
}
446
475
447
476
/// Used with `-Z assert-incr-state`.
@@ -2638,9 +2667,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2638
2667
}
2639
2668
}
2640
2669
2641
- if !nightly_options:: is_unstable_enabled ( matches)
2642
- && cg. force_frame_pointers == FramePointer :: NonLeaf
2643
- {
2670
+ let unstable_options_enabled = nightly_options:: is_unstable_enabled ( matches) ;
2671
+ if !unstable_options_enabled && cg. force_frame_pointers == FramePointer :: NonLeaf {
2644
2672
early_dcx. early_fatal (
2645
2673
"`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
2646
2674
and a nightly compiler",
@@ -2650,7 +2678,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2650
2678
// For testing purposes, until we have more feedback about these options: ensure `-Z
2651
2679
// unstable-options` is required when using the unstable `-C link-self-contained` and `-C
2652
2680
// linker-flavor` options.
2653
- if !nightly_options :: is_unstable_enabled ( matches ) {
2681
+ if !unstable_options_enabled {
2654
2682
let uses_unstable_self_contained_option =
2655
2683
cg. link_self_contained . are_unstable_variants_set ( ) ;
2656
2684
if uses_unstable_self_contained_option {
@@ -2706,6 +2734,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2706
2734
let debuginfo = select_debuginfo ( matches, & cg) ;
2707
2735
let debuginfo_compression = unstable_opts. debuginfo_compression ;
2708
2736
2737
+ if !unstable_options_enabled {
2738
+ if let Err ( error) = cg. linker_features . check_unstable_variants ( & target_triple) {
2739
+ early_dcx. early_fatal ( error) ;
2740
+ }
2741
+ }
2742
+
2709
2743
let crate_name = matches. opt_str ( "crate-name" ) ;
2710
2744
let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
2711
2745
// Parse any `-l` flags, which link to native libraries.
0 commit comments