Linking with clang-XX fails · Issue #106454 · rust-lang/rust (original) (raw)

I tried this code:

main.rs:

#![no_std] #![no_main] use core::panic::PanicInfo;

fn main() { loop {} }

#[panic_handler] pub fn lib_panic(_: &PanicInfo) -> ! { loop {} }

compilation without specifying a linker works (uses rust-lld):

cargo +nightly rustc --target=aarch64-unknown-none -- -Clink-arg=-nostdlib Finished dev [unoptimized + debuginfo] target(s) in 0.08s

compilation while specifying clang as a linker-driver works:

CARGO_TARGET_AARCH64_UNKNOWN_NONE_LINKER=/usr/bin/clang cargo +nightly rustc --target=aarch64-unknown-none -- -Clink-arg=--target=aarch64-linux-gnu -Clink-arg=-fuse-ld=lld -Clink-arg=-nostdlib Finished dev [unoptimized + debuginfo] target(s) in 0.12s

linking with clang-13 (or any other clang-xx version) fails:

$ CARGO_TARGET_AARCH64_UNKNOWN_NONE_LINKER=/usr/bin/clang-13 cargo +nightly rustc --target=aarch64-unknown-none -- -Clink-arg=--target=aarch64-linux-gnu -Clink-arg=-fuse-ld=lld -Clink-arg=-nostdlib

error: linking with /usr/bin/clang-13 failed: exit status: 1 | = note: LC_ALL="C" PATH="/home/jschwender/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/jschwender/.local/bin:/home/jschwender/.vscode-server/bin/e8a3071ea4344d9d48ef8a4df2c097372b0c5161/bin/remote-cli:/home/jschwender/.local/bin:/home/jschwender/.local/bin:/home/jschwender/.local/bin:/home/jschwender/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/jschwender/.dotnet/tools" VSLANG="1033" "/usr/bin/clang-13" "-flavor" "gnu" "/tmp/rustc2MlvQb/symbols.o" "/home/jschwender/xxx/test_linker/target/aarch64-unknown-none/debug/deps/test_linker-d064d105ad8c7d65.364uq591xu04qgaj.rcgu.o" "--as-needed" "-L" "/home/jschwender/xxx/test_linker/target/aarch64-unknown-none/debug/deps" "-L" "/home/jschwender/xxx/test_linker/target/debug/deps" "-L" "/home/jschwender/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-none/lib" "-Bstatic" "/home/jschwender/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-none/lib/librustc_std_workspace_core-f455852cb746dc8f.rlib" "/home/jschwender/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-none/lib/libcore-ca53c4fff67da7f4.rlib" "/home/jschwender/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-none/lib/libcompiler_builtins-bf82cb7204be09eb.rlib" "-Bdynamic" "--eh-frame-hdr" "-znoexecstack" "-L" "/home/jschwender/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-none/lib" "-o" "/home/jschwender/xxx/test_linker/target/aarch64-unknown-none/debug/deps/test_linker-d064d105ad8c7d65" "--gc-sections" "--target=aarch64-linux-gnu" "-fuse-ld=lld" "-nostdlib" = note: clang: error: unsupported option '--as-needed' clang: error: unsupported option '--eh-frame-hdr' clang: error: unsupported option '--gc-sections' clang: error: unknown argument: '-flavor' clang: error: unknown argument: '-znoexecstack' clang: error: no such file or directory: 'gnu'

warning: test_linker (bin "test_linker") generated 1 warning error: could not compile test_linker due to previous error; 1 warning emitted

I expected to see this happen: If linking with clang works, linking with clang-13 or clang-14 etc. should also work.

Instead, this happened: Linking failed with clang-13. It looks like the detection of the linker failed and -Wl, was not added in some flags rust added.

Meta

Rust 1.65 and latest nigthly

rustc --version --verbose:

rustc 1.68.0-nightly (c7572670a 2023-01-03)
binary: rustc
commit-hash: c7572670a1302f5c7e245d069200e22da9df0316
commit-date: 2023-01-03
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6