@@ -439,6 +439,35 @@ impl LinkerFeaturesCli {
439439 _ => None ,
440440 }
441441 }
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+ }
442471}
443472
444473/// Used with `-Z assert-incr-state`.
@@ -2587,9 +2616,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
25872616 }
25882617 }
25892618
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 {
25932621 early_dcx. early_fatal (
25942622 "`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
25952623 and a nightly compiler",
@@ -2599,7 +2627,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
25992627 // For testing purposes, until we have more feedback about these options: ensure `-Z
26002628 // unstable-options` is required when using the unstable `-C link-self-contained` and `-C
26012629 // linker-flavor` options.
2602- if !nightly_options :: is_unstable_enabled ( matches ) {
2630+ if !unstable_options_enabled {
26032631 let uses_unstable_self_contained_option =
26042632 cg. link_self_contained . are_unstable_variants_set ( ) ;
26052633 if uses_unstable_self_contained_option {
@@ -2647,6 +2675,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26472675 let debuginfo = select_debuginfo ( matches, & cg) ;
26482676 let debuginfo_compression = unstable_opts. debuginfo_compression ;
26492677
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+
26502684 let crate_name = matches. opt_str ( "crate-name" ) ;
26512685 let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
26522686 // Parse any `-l` flags, which link to native libraries.
0 commit comments