default-linker-linux-override doesn't work when cross-compiling
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Summary
Command used
I added the following UI test:
//@ compile-flags: --print=link-args
//@ build-pass
//@ check-stdout
//@ only-aarch64-unknown-linux-gnu
//@ error-pattern:rust-lld
fn main() {}
and ran the following command:
./x test --set target.aarch64-unknown-linux-gnu.default-linker-linux-override='"self-contained-lld-cc"' tests/ui/aarch64-lld.rs --target aarch64-unknown-linux-gnu
Expected behaviour
The compiler uses LLD and the test passes.
Actual behaviour
The compiler doesn't use lld.
Bootstrap configuration (bootstrap.toml)
profile = "compiler"
[target.aarch64-unknown-linux-gnu]
default-linker-linux-override = "self-contained-lld-cc"
[rust]
lld = true
Operating system
macOS Tahoe 26.3.1
HEAD
27dbdb57a2f
Additional context
I tracked this down to bootstrap only considering the host when setting CFG_DEFAULT_LINKER_SELF_CONTAINED_LLD_CC, not the target. This means that it's impossible to e.g. build an aarch64 rustc that uses LLD by default from an x86 host.
I'm not sure how to fix this. I think we'd probably need to add something like CFG_DEFAULT_LINKER_SELF_CONTAINED_LLD_CC=aarch64-unknown-linux-gnu, and then pass that unconditionally when building rustc_target? But then we have to do complicated parsing in the specs, and I don't know a way to do that at compile time :/
Build Log
Testing stage1 with compiletest suite=ui mode=ui (aarch64-unknown-linux-gnu)
running 1 tests
[ui] tests/ui/aarch64-lld.rs ... F
failures:
---- [ui] tests/ui/aarch64-lld.rs stdout ----
Saved the actual stdout to `/home/ci/upstream/build/x86_64-unknown-linux-gnu/test/ui/aarch64-lld/aarch64-lld.stdout`
normalized stdout:
LC_ALL="C" PATH="$BUILD_DIR/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin:$BUILD_DIR/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:$BUILD_DIR/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin:$BUILD_DIR/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/home/ci/persistent/dotfiles/bin:/home/ci/.local/bin:/home/ci/.local/lib/cargo/bin:/home/ci/.local/lib/go/bin:/home/ci/.venv/bin:/home/ci/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "aarch64-linux-gnu-gcc" "$TEST_BUILD_DIR/rustcyh1Pp9/symbols.o" "$TEST_BUILD_DIR/aarch64-lld.aarch64_lld.31f9f67adb3ca5c1-cgu.0.rcgu.o" "-Wl,--as-needed" "-Wl,-Bdynamic" "$BUILD_DIR/x86_64-unknown-linux-gnu/stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd-18c52d86096f6e42.so" "-Wl,-Bstatic" "$BUILD_DIR/x86_64-unknown-linux-gnu/stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcompiler_builtins-b7605cee281f95bb.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "$TEST_BUILD_DIR/rustcyh1Pp9/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "$BUILD_DIR/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-L" "$BUILD_DIR/x86_64-unknown-linux-gnu/stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "$TEST_BUILD_DIR/aarch64-lld" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,--strip-debug" "-nodefaultlibs" "-Wl,-rpath,$ORIGIN/../../../stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib,--enable-new-dtags,-z,origin"
The actual stdout differed from the expected stdout
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args aarch64-lld.rs`
error: 1 errors occurred comparing output.
status: exit status: 0
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/home/ci/upstream/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "/home/ci/upstream/tests/ui/aarch64-lld.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/home/ci/.local/lib/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/home/ci/upstream/vendor" "--sysroot" "/home/ci/upstream/build/x86_64-unknown-linux-gnu/stage1" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/home/ci/upstream/build/x86_64-unknown-linux-gnu/test/ui/aarch64-lld" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/home/ci/upstream/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=aarch64-linux-gnu-gcc" "--print=link-args"
--- stdout -------------------------------
LC_ALL="C" PATH="/home/ci/upstream/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/ci/upstream/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/home/ci/upstream/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/ci/upstream/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/home/ci/persistent/dotfiles/bin:/home/ci/.local/bin:/home/ci/.local/lib/cargo/bin:/home/ci/.local/lib/go/bin:/home/ci/.venv/bin:/home/ci/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "aarch64-linux-gnu-gcc" "/home/ci/upstream/build/x86_64-unknown-linux-gnu/test/ui/aarch64-lld/rustcyh1Pp9/symbols.o" "/home/ci/upstream/build/x86_64-unknown-linux-gnu/test/ui/aarch64-lld/aarch64-lld.aarch64_lld.31f9f67adb3ca5c1-cgu.0.rcgu.o" "-Wl,--as-needed" "-Wl,-Bdynamic" "/home/ci/upstream/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd-18c52d86096f6e42.so" "-Wl,-Bstatic" "/home/ci/upstream/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcompiler_builtins-b7605cee281f95bb.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/home/ci/upstream/build/x86_64-unknown-linux-gnu/test/ui/aarch64-lld/rustcyh1Pp9/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/ci/upstream/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/home/ci/upstream/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "/home/ci/upstream/build/x86_64-unknown-linux-gnu/test/ui/aarch64-lld/aarch64-lld" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,--strip-debug" "-nodefaultlibs" "-Wl,-rpath,$ORIGIN/../../../stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib,--enable-new-dtags,-z,origin"
------------------------------------------
stderr: none
---- [ui] tests/ui/aarch64-lld.rs stdout end ----
failures:
[ui] tests/ui/aarch64-lld.rs
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 21033 filtered out; finished in 85.80ms
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=aarch64-unknown-linux-gnu
Build completed unsuccessfully in 0:00:03
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/ui/aarch64-lld.rs and reproduce it using the shown ./x test command with the cross-compiling bootstrap.toml configuration. Trace how CFG_DEFAULT_LINKER_SELF_CONTAINED_LLD_CC is set for the target rather than only the host. Done means the test's link arguments use rust-lld when default-linker-linux-override is configured for aarch64-unknown-linux-gnu.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100