@@ -431,6 +431,35 @@ impl LinkerFeaturesCli {
431431 _ => None ,
432432 }
433433 }
434+
435+ /// Checks usage of unstable variants for linker features for the given `target_tuple`.
436+ /// Returns `Ok` if no unstable variants are used.
437+ pub ( crate ) fn check_unstable_variants ( & self , target_tuple : & TargetTuple ) -> Result < ( ) , String > {
438+ let mentioned_features = self . enabled . union ( self . disabled ) ;
439+ let has_lld = mentioned_features. is_lld_enabled ( ) ;
440+
441+ // Check that -Clinker-features=[-+]lld is not used anywhere else than on x64
442+ // without -Zunstable-options.
443+ if has_lld && target_tuple. tuple ( ) != "x86_64-unknown-linux-gnu" {
444+ return Err ( format ! (
445+ "`-C linker-features` with lld are unstable for the `{target_tuple}` target, \
446+ the `-Z unstable-options` flag must also be passed to use it on this target",
447+ ) ) ;
448+ }
449+
450+ for feature in LinkerFeatures :: all ( ) {
451+ // Check that no other features were enabled without -Zunstable-options
452+ // Note that this should currently be unreachable, because the `-Clinker-features` parser
453+ // currently only accepts lld.
454+ if feature != LinkerFeatures :: LLD && mentioned_features. contains ( feature) {
455+ return Err ( "`-C linker-features` is stable only for the lld feature, \
456+ the`-Z unstable-options` flag must also be passed to use it with other features"
457+ . to_string ( ) ) ;
458+ }
459+ }
460+
461+ Ok ( ( ) )
462+ }
434463}
435464
436465/// Used with `-Z assert-incr-state`.
@@ -2486,9 +2515,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
24862515 }
24872516 }
24882517
2489- if !nightly_options:: is_unstable_enabled ( matches)
2490- && cg. force_frame_pointers == FramePointer :: NonLeaf
2491- {
2518+ let unstable_options_enabled = nightly_options:: is_unstable_enabled ( matches) ;
2519+ if !unstable_options_enabled && cg. force_frame_pointers == FramePointer :: NonLeaf {
24922520 early_dcx. early_fatal (
24932521 "`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
24942522 and a nightly compiler",
@@ -2498,7 +2526,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
24982526 // For testing purposes, until we have more feedback about these options: ensure `-Z
24992527 // unstable-options` is required when using the unstable `-C link-self-contained` and `-C
25002528 // linker-flavor` options.
2501- if !nightly_options :: is_unstable_enabled ( matches ) {
2529+ if !unstable_options_enabled {
25022530 let uses_unstable_self_contained_option =
25032531 cg. link_self_contained . are_unstable_variants_set ( ) ;
25042532 if uses_unstable_self_contained_option {
@@ -2546,6 +2574,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
25462574 let debuginfo = select_debuginfo ( matches, & cg) ;
25472575 let debuginfo_compression = unstable_opts. debuginfo_compression ;
25482576
2577+ if !unstable_options_enabled {
2578+ if let Err ( error) = cg. linker_features . check_unstable_variants ( & target_triple) {
2579+ early_dcx. early_fatal ( error) ;
2580+ }
2581+ }
2582+
25492583 let crate_name = matches. opt_str ( "crate-name" ) ;
25502584 let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
25512585 // Parse any `-l` flags, which link to native libraries.
0 commit comments