@@ -2596,6 +2596,17 @@ fn handle_cli_linker_flavors(
25962596 }
25972597
25982598 let cg = & sess. opts . cg ;
2599+ let unstable_self_contained_linker = cg. link_self_contained . linker . is_on ( ) ;
2600+
2601+ // Sanity check for distro-builds: they don't distribute `rust-lld`, and the `-C
2602+ // link-self-contained=linker` flag cannot be used there: the `rust.lld` flag has to be enabled
2603+ // in `config.toml` so that `#[cfg(rust_lld_enabled)] applies.
2604+ if unstable_self_contained_linker && !cfg ! ( rust_lld_enabled) {
2605+ sess. fatal (
2606+ "Using `-Clink-self-contained=linker` requires the \
2607+ compiler to be built with the `rust.lld` flag enabled",
2608+ ) ;
2609+ }
25992610
26002611 // The `-C linker-flavor` CLI flag can optionally enrich linker-flavors. Check whether that's
26012612 // applicable, and emit errors if sanity checks fail. There's currently only one enrichment:
@@ -2660,12 +2671,10 @@ fn handle_cli_linker_flavors(
26602671
26612672 // Now, handle `rust-lld`. If both the `-Clink-self-contained=linker` and
26622673 // `-Clinker-flavor=gcc:lld` flags were provided, we use `rust-lld`, the rustup-distributed
2663- // version of `lld` (when applicable, i.e. not in distro-builds) by:
2674+ // version of `lld` (when applicable` , i.e. not in distro-builds) by:
26642675 // - checking the `lld-wrapper`s exist in the sysroot
26652676 // - adding their folder as a search path, or requesting to use a wrapper directly
2666- //
2667- // FIXME: make sure rust.lld config flag is turned on before adding the sysroot magic handling
2668- if sess. opts . cg . link_self_contained . linker . is_on ( ) || unstable_gcc_lld {
2677+ if unstable_self_contained_linker || unstable_gcc_lld {
26692678 // A `gcc-ld` folder (containing the `lld-wrapper`s that will run `rust-lld`) is present in
26702679 // the sysroot's target-specific tool binaries folder.
26712680 let tools_path = sess. get_tools_search_paths ( false ) ;
0 commit comments