@@ -2696,28 +2696,28 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, String> {
2696
2696
2697
2697
/// This takes care of the various possible enrichments to the linking that can be requested on the
2698
2698
/// CLI (and emitting errors and warnings when applicable):
2699
- /// - shortcuts to `-fuse-ld` with the `gcc` flavor
2700
- /// - the unstable `-Zgcc-ld=lld` flag to use `rust-lld`, stabilized as the following item
2699
+ /// - the unstable `-Zgcc-ld=lld` flag to use `rust-lld`
2700
+ /// - the shortcut to `-fuse-ld=lld` with the `gcc` flavor, to eventually use `rust-lld` when
2701
+ /// `-Clink-self-contained=linker` is introduced.
2701
2702
fn handle_cli_linker_flavors (
2702
2703
cmd : & mut dyn Linker ,
2703
2704
sess : & Session ,
2704
2705
flavor : LinkerFlavor ,
2705
2706
crt_objects_fallback : bool ,
2706
2707
) {
2707
2708
let unstable_gcc_lld = sess. opts . unstable_opts . gcc_ld == Some ( LdImpl :: Lld ) ;
2708
- if unstable_gcc_lld {
2709
- // Sanity check: ensure `gcc` is the currently selected flavor.
2710
- if LinkerFlavor :: Gcc != flavor {
2711
- sess. fatal ( "`-Zgcc-ld` is used even though the linker flavor is not `gcc`" ) ;
2712
- }
2709
+
2710
+ // Sanity check: ensure `gcc` is the currently selected flavor.
2711
+ if unstable_gcc_lld && LinkerFlavor :: Gcc != flavor {
2712
+ sess. fatal ( "`-Zgcc-ld` is used even though the linker flavor is not `gcc`" ) ;
2713
2713
}
2714
2714
2715
2715
let cg = & sess. opts . cg ;
2716
2716
2717
2717
// The `-C linker-flavor` CLI flag can optionally enrich linker-flavors. Check whether that's
2718
2718
// applicable, and emit errors if sanity checks fail. There's currently only one enrichment:
2719
- // adding an argument to the `cc` invocation to use the `use_ld` given linker .
2720
- let use_ld = match & cg. linker_flavor {
2719
+ // adding an argument to the `cc` invocation to use `lld` .
2720
+ match & cg. linker_flavor {
2721
2721
Some ( LinkerFlavorCli :: Gcc { use_ld } ) => {
2722
2722
// Ensure `gcc` is the currently selected flavor.
2723
2723
//
@@ -2733,79 +2733,71 @@ fn handle_cli_linker_flavors(
2733
2733
) ;
2734
2734
}
2735
2735
2736
- use_ld
2736
+ if * use_ld != LdImpl :: Lld {
2737
+ // We're not in a situation needing enrichments.
2738
+ return ;
2739
+ }
2737
2740
}
2738
2741
2739
- // Note: exhaustive match arm here, to avoid fallthroughs if new linker-flavor enrichments
2740
- // are added in the future.
2741
2742
Some ( LinkerFlavorCli :: WellKnown ( _) ) | None => {
2742
- if unstable_gcc_lld {
2743
- "lld"
2744
- } else {
2743
+ if !unstable_gcc_lld {
2745
2744
// We're not in a situation needing enrichments.
2746
2745
return ;
2747
2746
}
2748
2747
}
2749
- } ;
2748
+ }
2750
2749
2751
- // From now on in this function, we handle the `gcc` linker-flavor enrichment.
2750
+ // From now on in this function, we handle the `gcc` linker-flavor enrichment to use `lld` .
2752
2751
2753
- // Except for `lld`, the given linker executable will be passed straight to `-fuse-ld`.
2754
- if use_ld == "lld" {
2755
- // Start by checking if we're in the context of a known issue that users might hit when
2756
- // using `lld`:
2757
- //
2758
- // 1. when requesting self-contained CRT linking (or on a target that does it
2759
- // automatically), and coverage/profile generation: point at #79555 "Coverage is not
2760
- // generated when using rust-lld as linker"
2761
- let instrument_coverage = cg. instrument_coverage . is_some ( )
2762
- && cg. instrument_coverage != Some ( InstrumentCoverage :: Off ) ;
2763
- let generate_profile = cg. profile_generate . enabled ( ) ;
2764
- if crt_objects_fallback && ( instrument_coverage || generate_profile) {
2765
- sess. warn (
2766
- "Using `lld`, self-contained linking, and coverage or profile generation has known \
2767
- issues. See issue #79555 for more details, at \
2768
- https://github.com/rust-lang/rust/issues/79555",
2769
- ) ;
2770
- }
2752
+ // Start by checking if we're in the context of a known issue that users might hit when
2753
+ // using `lld`:
2754
+ //
2755
+ // 1. when requesting self-contained CRT linking (or on a target that does it
2756
+ // automatically), and coverage/profile generation: point at #79555 "Coverage is not
2757
+ // generated when using rust-lld as linker"
2758
+ let instrument_coverage =
2759
+ cg. instrument_coverage . is_some ( ) && cg. instrument_coverage != Some ( InstrumentCoverage :: Off ) ;
2760
+ let generate_profile = cg. profile_generate . enabled ( ) ;
2761
+ if crt_objects_fallback && ( instrument_coverage || generate_profile) {
2762
+ sess. warn (
2763
+ "Using `lld`, self-contained linking, and coverage or profile generation has known \
2764
+ issues. See issue #79555 for more details, at \
2765
+ https://github.com/rust-lang/rust/issues/79555",
2766
+ ) ;
2767
+ }
2771
2768
2772
- // 2. Maybe point at https://github.com/flamegraph-rs/flamegraph/pull/157 or the
2773
- // corresponding rust/LLVM issue when/if it's tracked, depending on whether we use the
2774
- // workaround argument `--no-rosegment` by default when invoking `lld`.
2775
- //
2776
- // 3. If in the future, other linker flavors and targets are eligible to a `rust-lld`
2777
- // enrichment, maybe also point at target-specific issues like:
2778
- // - MSVC + ThinLTO blocker https://github.com/rust-lang/rust/issues/81408
2779
- // - the "lld on MSVC" tracking issue https://github.com/rust-lang/rust/issues/71520
2780
- // containing a list of blocking issues
2781
-
2782
- // Now, handle `rust-lld`. If the `-Zgcc-ld=lld` flag was provided, we use `rust-lld`, the
2783
- // rustup-distributed version of `lld` (when applicable, i.e. not in distro-builds) by:
2784
- // - checking the `lld-wrapper`s exist in the sysroot
2785
- // - adding their folder as a search path, or requesting to use a wrapper directly
2786
- if unstable_gcc_lld {
2787
- // A `gcc-ld` folder (containing the `lld-wrapper`s that will run `rust-lld`) is present in
2788
- // the sysroot's target-specific tool binaries folder.
2789
- let tools_path = sess. get_tools_search_paths ( false ) ;
2790
- let gcc_ld_dir = tools_path
2791
- . into_iter ( )
2792
- . map ( |p| p. join ( "gcc-ld" ) )
2793
- . find ( |p| p. join ( if sess. host . is_like_windows { "ld.exe" } else { "ld" } ) . exists ( ) )
2794
- . unwrap_or_else ( || sess. fatal ( "rust-lld (as ld) not found" ) ) ;
2795
-
2796
- cmd. arg ( {
2797
- let mut arg = OsString :: from ( "-B" ) ;
2798
- arg. push ( gcc_ld_dir) ;
2799
- arg
2800
- } ) ;
2801
- cmd. arg ( format ! ( "-Wl,-rustc-lld-flavor={}" , sess. target. lld_flavor. as_str( ) ) ) ;
2802
- } else {
2803
- // We were asked to use `lld` but not `rust-lld`.
2804
- cmd. arg ( "-fuse-ld=lld" ) ;
2805
- }
2769
+ // 2. Maybe point at https://github.com/flamegraph-rs/flamegraph/pull/157 or the
2770
+ // corresponding rust/LLVM issue when/if it's tracked, depending on whether we use the
2771
+ // workaround argument `--no-rosegment` by default when invoking `lld`.
2772
+ //
2773
+ // 3. If in the future, other linker flavors and targets are eligible to a `rust-lld`
2774
+ // enrichment, maybe also point at target-specific issues like:
2775
+ // - MSVC + ThinLTO blocker https://github.com/rust-lang/rust/issues/81408
2776
+ // - the "lld on MSVC" tracking issue https://github.com/rust-lang/rust/issues/71520
2777
+ // containing a list of blocking issues
2778
+
2779
+ // Now, handle `rust-lld`. If the `-Zgcc-ld=lld` flag was provided, we use `rust-lld`, the
2780
+ // rustup-distributed version of `lld` (when applicable, i.e. not in distro-builds) by:
2781
+ // - checking the `lld-wrapper`s exist in the sysroot
2782
+ // - adding their folder as a search path, or requesting to use a wrapper directly
2783
+ if unstable_gcc_lld {
2784
+ // A `gcc-ld` folder (containing the `lld-wrapper`s that will run `rust-lld`) is present in
2785
+ // the sysroot's target-specific tool binaries folder.
2786
+ let tools_path = sess. get_tools_search_paths ( false ) ;
2787
+ let gcc_ld_dir = tools_path
2788
+ . into_iter ( )
2789
+ . map ( |p| p. join ( "gcc-ld" ) )
2790
+ . find ( |p| p. join ( if sess. host . is_like_windows { "ld.exe" } else { "ld" } ) . exists ( ) )
2791
+ . unwrap_or_else ( || sess. fatal ( "rust-lld (as ld) not found" ) ) ;
2792
+
2793
+ cmd. arg ( {
2794
+ let mut arg = OsString :: from ( "-B" ) ;
2795
+ arg. push ( gcc_ld_dir) ;
2796
+ arg
2797
+ } ) ;
2798
+ cmd. arg ( format ! ( "-Wl,-rustc-lld-flavor={}" , sess. target. lld_flavor. as_str( ) ) ) ;
2806
2799
} else {
2807
- // Otherwise, we were just asked to use a linker executable, and it's expected that `cc`
2808
- // will find it on the $PATH.
2809
- cmd. arg ( format ! ( "-fuse-ld={}" , use_ld) ) ;
2800
+ // Otherwise, we were asked to use `lld` but not `rust-lld`.
2801
+ cmd. arg ( "-fuse-ld=lld" ) ;
2810
2802
}
2811
2803
}
0 commit comments