@@ -431,6 +431,35 @@ impl LinkerFeaturesCli {
431
431
_ => None ,
432
432
}
433
433
}
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
+ }
434
463
}
435
464
436
465
/// Used with `-Z assert-incr-state`.
@@ -2486,9 +2515,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2486
2515
}
2487
2516
}
2488
2517
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 {
2492
2520
early_dcx. early_fatal (
2493
2521
"`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
2494
2522
and a nightly compiler",
@@ -2498,7 +2526,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2498
2526
// For testing purposes, until we have more feedback about these options: ensure `-Z
2499
2527
// unstable-options` is required when using the unstable `-C link-self-contained` and `-C
2500
2528
// linker-flavor` options.
2501
- if !nightly_options :: is_unstable_enabled ( matches ) {
2529
+ if !unstable_options_enabled {
2502
2530
let uses_unstable_self_contained_option =
2503
2531
cg. link_self_contained . are_unstable_variants_set ( ) ;
2504
2532
if uses_unstable_self_contained_option {
@@ -2546,6 +2574,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2546
2574
let debuginfo = select_debuginfo ( matches, & cg) ;
2547
2575
let debuginfo_compression = unstable_opts. debuginfo_compression ;
2548
2576
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
+
2549
2583
let crate_name = matches. opt_str ( "crate-name" ) ;
2550
2584
let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
2551
2585
// Parse any `-l` flags, which link to native libraries.
0 commit comments