Repository: rust
Issue: When requesting a different default linker (clang) build does not use it.
Labels: A-linkage,T-bootstrap,C-bug

When building rust from source, if you have defined the default-linker to be clang, and to use lld as the linker, the build can fail during `Building rustbuild` as the linker argument is NOT changed to the linker requested.

Specifically in this case because cc is gcc-12 which adds a flag for `--fix-cortex-a53-835769`, but the system lld14 does not recognise this flag. Had the linker used clang instead of cc in this case as requested it would have succeeded due to clang not emitting this flag. 

The expected behaviour is that when a linker is requested in config.toml, it's used during the rustbuild stage. 

```
[   31s] + ./configure --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu --target=aarch64-unknown-linux-gnu,wasm32-unknown-unknown --prefix=/usr --bindir=/usr/bin --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/share/man --infodir=/usr/share/info --libdir=/usr/lib --docdir=/usr/share/doc/packages/rust --enable-local-rust --local-rust-root=/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr --disable-rpath --llvm-root=/usr --enable-llvm-link-shared --set rust.use-lld=true --set llvm.use-linker=lld --default-linker=clang --enable-optimize --enable-ccache --disable-docs --disable-compiler-docs --enable-verbose-tests --enable-vendor --enable-extended --tools=cargo --release-channel=stable
[   31s] configure: processing command line
[   31s] configure:
[   31s] configure: build.build          := aarch64-unknown-linux-gnu
[   31s] configure: build.host           := ['aarch64-unknown-linux-gnu']
[   31s] configure: build.target         := ['aarch64-unknown-linux-gnu', 'wasm32-unknown- ...
[   31s] configure: install.prefix       := /usr
[   31s] configure: install.bindir       := /usr/bin
[   31s] configure: install.sysconfdir   := /etc
[   31s] configure: install.datadir      := /usr/share
[   31s] configure: install.localstatedir := /var
[   31s] configure: install.mandir       := /usr/share/man
[   31s] configure: install.infodir      := /usr/share/info
[   31s] configure: install.libdir       := /usr/lib
[   31s] configure: install.docdir       := /usr/share/doc/packages/rust
[   31s] configure: build.rustc          := /home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch6 ...
[   31s] configure: build.cargo          := /home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch6 ...
[   31s] configure: rust.rpath           := False
[   31s] configure: target.aarch64-unknown-linux-gnu.llvm-config := /usr/bin/llvm-config
[   31s] configure: llvm.link-shared     := True
[   31s] configure: rust.use-lld         := True
[   31s] configure: llvm.use-linker      := lld
[   31s] configure: rust.default-linker  := clang
[   31s] configure: rust.optimize        := True
[   31s] configure: llvm.ccache          := True
[   31s] configure: build.docs           := False
[   31s] configure: build.compiler-docs  := False
[   31s] configure: rust.verbose-tests   := True
[   31s] configure: build.vendor         := True
[   31s] configure: build.extended       := True
[   31s] configure: build.tools          := ['cargo']
[   31s] configure: rust.channel         := stable
[   31s] configure: build.configure-args := ['--build=aarch64-unknown-linux-gnu', '--host= ...
[   31s] warning: localstatedir will be ignored
[   31s] warning: infodir will be ignored
[   31s] configure:
[   31s] configure: writing `config.toml` in current directory
[   31s] configure:
[   31s] configure: run `python /home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/x.py --help`
[   31s] configure:
[   31s] + python3 ./x.py build
[   31s] info: using vendored source, but .cargo/config is already present.
[   31s]       Reusing the current configuration file. But you may want to configure vendoring like this:
[   31s] [source.crates-io]
[   31s] replace-with = 'vendored-sources'
[   31s] registry = 'https://example.com'
[   31s]
[   31s] [source.vendored-sources]
[   31s] directory = '/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/vendor'
[   31s]
[   31s] warning: sqlite3 not available in python, skipping build directory lock
[   31s] please file an issue on rust-lang/rust
[   31s] this is not a problem for non-concurrent x.py invocations
[   31s] Building rustbuild
[   31s]    Compiling memchr v2.4.1
[   31s]    Compiling proc-macro2 v1.0.30
[   31s]    Compiling unicode-xid v0.2.2
[   31s]    Compiling syn v1.0.80
[   31s]    Compiling serde_derive v1.0.125
[   31s]    Compiling cfg-if v1.0.0
[   31s]    Compiling lazy_static v1.4.0
[   31s]    Compiling serde v1.0.125
[   31s]    Compiling log v0.4.14
[   31s]    Compiling regex-automata v0.1.10
[   32s]    Compiling crossbeam-utils v0.8.6
[   32s]    Compiling regex-syntax v0.6.25
[   32s]    Compiling libc v0.2.116
[   32s]    Compiling ryu v1.0.5
[   32s]    Compiling fnv v1.0.7
[   32s]    Compiling serde_json v1.0.59
[   32s]    Compiling same-file v1.0.6
[   32s]    Compiling once_cell v1.7.2
[   32s]    Compiling itoa v0.4.6
[   32s]    Compiling unicode-width v0.1.8
[   32s]    Compiling cc v1.0.69
[   32s]    Compiling bootstrap v0.0.0 (/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/src/bootstrap)
[   32s]    Compiling walkdir v2.3.1
[   32s]    Compiling getopts v0.2.21
[   32s]    Compiling thread_local v1.1.4
[   32s]    Compiling cmake v0.1.44
[   32s]    Compiling aho-corasick v0.7.18
[   32s]    Compiling bstr v0.2.13
[   32s]    Compiling quote v1.0.7
[   33s]    Compiling opener v0.5.0
[   33s]    Compiling filetime v0.2.14
[   33s]    Compiling regex v1.5.4
[   33s]    Compiling globset v0.4.5
[   34s]    Compiling ignore v0.4.17
[   38s]    Compiling toml v0.5.7
[   44s]     Finished dev [unoptimized] target(s) in 13.28s
[   45s] Building stage0 std artifacts (aarch64-unknown-linux-gnu -> aarch64-unknown-linux-gnu)
[   45s]    Compiling cc v1.0.69
[   45s]    Compiling core v0.0.0 (/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/library/core)
[   45s]    Compiling libc v0.2.116
[   45s]    Compiling memchr v2.4.1
[   45s]    Compiling std v0.0.0 (/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/library/std)
[   45s] error: linking with `cc` failed: exit status: 1
[   45s]   |
[   45s]   = note: "cc" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.0.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.1.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.10.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.11.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.12.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.13.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.14.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.15.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.2.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.3.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.4.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.5.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.6.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.7.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.8.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.build_script_build.4e78f585-cgu.9.rcgu.o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae.182b0246r97ohym3.rcgu.o" "-Wl,--as-needed" "-L" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/deps" "-L" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd-7d5a620ab77655ab.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libpanic_unwind-2de0d40477269ad1.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libobject-59ae13aa5b85e878.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libmemchr-25c2a8eab25c758c.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libaddr2line-484db03cffcca5b6.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libgimli-77337fc21bd1cca4.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc_demangle-8399fd816afb0bb6.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd_detect-dbd9d453a2c2347c.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libhashbrown-f5e9f9d7692ae465.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libminiz_oxide-0ae529ce319bd2e0.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libadler-91ebd391b9f3e29e.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-79cdd974e440af93.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libunwind-fb4f5845224d8c3b.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcfg_if-12a6b9815d90b1e4.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/liblibc-b0a59add1f3108e8.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/liballoc-cc0694ace9be0e66.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc_std_workspace_core-5a84de01a2ad7b8c.rlib" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcore-d1ce211496f525c3.rlib" "-Wl,--end-group" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcompiler_builtins-9453083e1ae0beda.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/abuild/rpmbuild/BUILD/rust-1.61.0-aarch64-unknown-linux-gnu/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "/home/abuild/rpmbuild/BUILD/rustc-1.61.0-src/build/aarch64-unknown-linux-gnu/stage0-std/release/build/std-1bb9ed7376897eae/build_script_build-1bb9ed7376897eae" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs" "-fuse-ld=lld"
[   45s]   = note: ld.lld: error: unknown argument '--fix-cortex-a53-835769'
[   45s]           collect2: error: ld returned 1 exit status
```