@@ -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`.
@@ -2587,9 +2616,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2587
2616
}
2588
2617
}
2589
2618
2590
- if !nightly_options:: is_unstable_enabled ( matches)
2591
- && cg. force_frame_pointers == FramePointer :: NonLeaf
2592
- {
2619
+ let unstable_options_enabled = nightly_options:: is_unstable_enabled ( matches) ;
2620
+ if !unstable_options_enabled && cg. force_frame_pointers == FramePointer :: NonLeaf {
2593
2621
early_dcx. early_fatal (
2594
2622
"`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
2595
2623
and a nightly compiler",
@@ -2599,7 +2627,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2599
2627
// For testing purposes, until we have more feedback about these options: ensure `-Z
2600
2628
// unstable-options` is required when using the unstable `-C link-self-contained` and `-C
2601
2629
// linker-flavor` options.
2602
- if !nightly_options :: is_unstable_enabled ( matches ) {
2630
+ if !unstable_options_enabled {
2603
2631
let uses_unstable_self_contained_option =
2604
2632
cg. link_self_contained . are_unstable_variants_set ( ) ;
2605
2633
if uses_unstable_self_contained_option {
@@ -2647,6 +2675,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2647
2675
let debuginfo = select_debuginfo ( matches, & cg) ;
2648
2676
let debuginfo_compression = unstable_opts. debuginfo_compression ;
2649
2677
2678
+ if !unstable_options_enabled {
2679
+ if let Err ( error) = cg. linker_features . check_unstable_variants ( & target_triple) {
2680
+ early_dcx. early_fatal ( error) ;
2681
+ }
2682
+ }
2683
+
2650
2684
let crate_name = matches. opt_str ( "crate-name" ) ;
2651
2685
let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
2652
2686
// Parse any `-l` flags, which link to native libraries.
0 commit comments