Skip to content

Linker binaries (ld, lld, rust-lld) fail to find system-wide libraries, while using compiler binaries (gcc, clang) works fine #130062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vadorovsky opened this issue Sep 7, 2024 · 4 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@vadorovsky
Copy link
Contributor

I'm trying to build the integration-test subproject from https://github.com/aya-rs/aya on Alpine Linux, for x86_64-unknown-linux-musl target.

Using the default linker (without specifying, so it defaults to gcc) works fine:

77d2cb0e3483:~/aya# cargo build --target x86_64-unknown-linux-musl --package integration-test
[...]
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 17.70s

(full log)

Same when specifying gcc as a linker:

77d2cb0e3483:~/aya# cargo build --target x86_64-unknown-linux-musl --config "target.x86_64-unknown-linux-musl.linker = \"gcc\"" --package integration-test
[...]
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 18.06s

(full log)

Using clang works too:

77d2cb0e3483:~/aya# cargo build --target x86_64-unknown-linux-musl --config "target.x86_64-unknown-linux-musl.linker = \"clang\"" --package integration-test
[...]
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 17.93s

(full log)

However, using linker binaries directly doesn't work, regardless of which linker I'm trying to use.

GNU ld:

77d2cb0e3483:~/aya# cargo build --target x86_64-unknown-linux-musl --config "target.x86_64-unknown-linux-musl.linker = \"ld\"" --package integration-test
[...]
   Compiling memoffset v0.6.5
error: linking with `ld` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/bin:/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/bin:/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/bin:/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "ld" "--version-script=/tmp/rustccmphOr/list" "--no-undefined-version" "/tmp/rustccmphOr/symbols.o" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.indoc.42d2e69cb3cf60e2-cgu.0.rcgu.o" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.indoc.42d2e69cb3cf60e2-cgu.1.rcgu.o" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.indoc.42d2e69cb3cf60e2-cgu.2.rcgu.o" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.indoc.42d2e69cb3cf60e2-cgu.3.rcgu.o" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.0b2ljoonqdxfdg051zdpul0wc.rcgu.rmeta" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.1hsylygegiy7qnlli60pr13rf.rcgu.o" "--as-needed" "-L" "/root/aya/target/debug/deps" "-L" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Bstatic" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libproc_macro-d2aa9b2c4004c068.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-1b60b176e45a0318.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-57b45c66d2e62c49.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libobject-0123438d987de009.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libmemchr-05f3c42b49d78619.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libaddr2line-45c700404e36c3de.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libgimli-cf5f9b37b545ed6e.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-44abbf672f21a10b.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd_detect-9b6d712a985955e4.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-e4ec61de4b8ef447.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-c72777eb88217fe3.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libminiz_oxide-b0a8429443e0fed6.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libadler-820055e0e9cc55a4.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-2ceb129e8b1d5c77.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-8cd2ce184499d012.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-ada011f709b467ef.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-67a0423d44ab989a.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-15fc71c4e52ac90f.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-273f69939f389095.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-c8f82c72237d07e8.rlib" "-Bdynamic" "-lgcc_s" "-lc" "--eh-frame-hdr" "-z" "noexecstack" "-L" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-o" "/root/aya/target/debug/deps/libindoc-4e3fe2b7cb1d37d2.so" "--gc-sections" "-shared" "-soname=libindoc-4e3fe2b7cb1d37d2.so" "-z" "relro" "-z" "now"
  = note: ld: cannot find -lgcc: No such file or directory

(full log)

lld:

77d2cb0e3483:~/aya# cargo build --target x86_64-unknown-linux-musl --config "target.x86_64-unknown-linux-musl.linker = \"lld\"" --package integration-test
[...]
error: could not compile `indoc` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: linking with `lld` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/bin:/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/bin:/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/bin:/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "lld" "-flavor" "gnu" "--version-script=/tmp/rustc2C6Ud8/list" "--no-undefined-version" "/tmp/rustc2C6Ud8/symbols.o" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.rustversion.4145b995296d1182-cgu.0.rcgu.o" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.rustversion.4145b995296d1182-cgu.1.rcgu.o" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.rustversion.4145b995296d1182-cgu.2.rcgu.o" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.rustversion.4145b995296d1182-cgu.3.rcgu.o" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.rustversion.4145b995296d1182-cgu.4.rcgu.o" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.rustversion.4145b995296d1182-cgu.5.rcgu.o" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.rustversion.4145b995296d1182-cgu.6.rcgu.o" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.rustversion.4145b995296d1182-cgu.7.rcgu.o" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.rustversion.4145b995296d1182-cgu.8.rcgu.o" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.f01o1e0hk9d1mcr47j33gnmo6.rcgu.rmeta" "/root/aya/target/debug/deps/rustversion-a51ee28261058709.8219qqgkv2oj66wv6vzyrwhri.rcgu.o" "--as-needed" "-L" "/root/aya/target/debug/deps" "-L" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Bstatic" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libproc_macro-d2aa9b2c4004c068.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-1b60b176e45a0318.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-57b45c66d2e62c49.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libobject-0123438d987de009.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libmemchr-05f3c42b49d78619.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libaddr2line-45c700404e36c3de.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libgimli-cf5f9b37b545ed6e.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-44abbf672f21a10b.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd_detect-9b6d712a985955e4.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-e4ec61de4b8ef447.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-c72777eb88217fe3.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libminiz_oxide-b0a8429443e0fed6.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libadler-820055e0e9cc55a4.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-2ceb129e8b1d5c77.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-8cd2ce184499d012.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-ada011f709b467ef.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-67a0423d44ab989a.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-15fc71c4e52ac90f.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-273f69939f389095.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-c8f82c72237d07e8.rlib" "-Bdynamic" "-lgcc_s" "-lc" "--eh-frame-hdr" "-z" "noexecstack" "-L" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-o" "/root/aya/target/debug/deps/librustversion-a51ee28261058709.so" "--gc-sections" "-shared" "-soname=librustversion-a51ee28261058709.so" "-z" "relro" "-z" "now"
  = note: lld: error: unable to find library -lgcc_s
          lld: error: unable to find library -lc

(full log)

rust-lld:

77d2cb0e3483:~/aya# cargo build --target x86_64-unknown-linux-musl --config "target.x86_64-unknown-linux-musl.linker = \"rust-lld\"" --package integration-test
[...]
   Compiling bytes v1.7.1
error: linking with `rust-lld` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/bin:/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/bin:/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/bin:/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "rust-lld" "-flavor" "gnu" "--version-script=/tmp/rustcGf3OGU/list" "--no-undefined-version" "/tmp/rustcGf3OGU/symbols.o" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.indoc.42d2e69cb3cf60e2-cgu.0.rcgu.o" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.indoc.42d2e69cb3cf60e2-cgu.1.rcgu.o" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.indoc.42d2e69cb3cf60e2-cgu.2.rcgu.o" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.indoc.42d2e69cb3cf60e2-cgu.3.rcgu.o" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.0b2ljoonqdxfdg051zdpul0wc.rcgu.rmeta" "/root/aya/target/debug/deps/indoc-4e3fe2b7cb1d37d2.1hsylygegiy7qnlli60pr13rf.rcgu.o" "--as-needed" "-L" "/root/aya/target/debug/deps" "-L" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Bstatic" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libproc_macro-d2aa9b2c4004c068.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-1b60b176e45a0318.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-57b45c66d2e62c49.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libobject-0123438d987de009.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libmemchr-05f3c42b49d78619.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libaddr2line-45c700404e36c3de.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libgimli-cf5f9b37b545ed6e.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-44abbf672f21a10b.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd_detect-9b6d712a985955e4.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-e4ec61de4b8ef447.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-c72777eb88217fe3.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libminiz_oxide-b0a8429443e0fed6.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libadler-820055e0e9cc55a4.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-2ceb129e8b1d5c77.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-8cd2ce184499d012.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-ada011f709b467ef.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-67a0423d44ab989a.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-15fc71c4e52ac90f.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-273f69939f389095.rlib" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-c8f82c72237d07e8.rlib" "-Bdynamic" "-lgcc_s" "-lc" "--eh-frame-hdr" "-z" "noexecstack" "-L" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-o" "/root/aya/target/debug/deps/libindoc-4e3fe2b7cb1d37d2.so" "--gc-sections" "-shared" "-soname=libindoc-4e3fe2b7cb1d37d2.so" "-z" "relro" "-z" "now"
  = note: rust-lld: error: unable to find library -lgcc_s
          rust-lld: error: unable to find library -lc

(full log)

My preference would be to be able to use rust-lld, which is currently broken.

I will try to dig in and fix it myself, but I would be thankful for any information where I could look. For now my plan is to check what -L arguments are being passed for each build and see whether they are constructed differently when using linker binaries.

@vadorovsky vadorovsky added the C-bug Category: This is a bug. label Sep 7, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 7, 2024
@Noratrieb
Copy link
Member

i think this is expected, you're supposed to use the C compiler driver as the linker, as it knows where to find these libraries. use -Clink-arg=-fuse-ld=lld to then make the C compiler invoke lld as the actual linker.

@Noratrieb Noratrieb added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 7, 2024
@vadorovsky
Copy link
Contributor Author

Nightly on x86_64-unknown-linux-gnu recently switched to rust-lld as the default linker, so I think that "you're supposed to use the C compiler as the linker" isn't true and rust-lld is already being more and more adopted?

I was hoping to be able to use rust-lld, because it makes linking faster and makes cross-compilation easier, without necessity to install LLVM toolchain on the system.

@bjorn3
Copy link
Member

bjorn3 commented Sep 7, 2024

On nightly x86_64 Linux we tell the C compiler to invoke rust-lld instead of the system linker. The C compiler still handles passing the right linker args for things like finding system libraries.

@vadorovsky
Copy link
Contributor Author

Gotcha, thanks for clarification. I also found your another explanation here

vadorovsky added a commit to vadorovsky/aya that referenced this issue Sep 7, 2024
rust-lld on Linux  is unaware of system libraries and seems like there is
no way to point it to them. That often triggers issues like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

More explanation:

https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/2
rust-lang/rust#130062 (comment)

Fixes aya-rs#907
vadorovsky added a commit to vadorovsky/aya that referenced this issue Sep 7, 2024
rust-lld on Linux  is unaware of system libraries and seems like there is
no way to point it to them. That often triggers issues like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

More explanation:

https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/2
rust-lang/rust#130062 (comment)

Fixes aya-rs#907
vadorovsky added a commit to vadorovsky/aya that referenced this issue Sep 7, 2024
rust-lld on Linux  is unaware of system libraries and seems like there is
no way to point it to them. That often triggers issues like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

More explanation:

https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/2
rust-lang/rust#130062 (comment)

Fixes aya-rs#907
vadorovsky added a commit to vadorovsky/aya that referenced this issue Oct 8, 2024
rust-lld on Linux  is unaware of system libraries and seems like there is
no way to point it to them. That often triggers issues like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

More explanation:

https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/2
rust-lang/rust#130062 (comment)

Fixes aya-rs#907
vadorovsky added a commit to vadorovsky/aya that referenced this issue Oct 9, 2024
The recommendation (coming from rust-lang/rust#130062) is using C
compiler driver as a linker, which is able to find system-wide
libraries. Using linker binaries directly in `-C linker` (e.g.
`-C linker=rust-lld`) often results in errors like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

Fixes aya-rs#907
vadorovsky added a commit to vadorovsky/aya that referenced this issue Oct 9, 2024
The recommendation (coming from rust-lang/rust#130062) for Linux hosts
is using C compiler driver as a linker, which is able to find
system-wide libraries. Using linker binaries directly in `-C linker`
(e.g. `-C linker=rust-lld`) often results in errors like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

However, `-C linker=rust-lld` still works the best on macOS, where
Rust toolchains come with unwinder and runtime and there is usually no
need to link system libraries. Keep setting it only for macOS.

Fixes aya-rs#907
vadorovsky added a commit to vadorovsky/aya that referenced this issue Oct 9, 2024
The recommendation (coming from rust-lang/rust#130062) for Linux hosts
is using C compiler driver as a linker, which is able to find
system-wide libraries. Using linker binaries directly in `-C linker`
(e.g. `-C linker=rust-lld`) often results in errors like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

Not touching the linker settings is usually the best approach for Linux
systems. Native builds pick up the default C toolchain. Cross builds
default to GCC cross wrapper, but that's easy to supress with clang
and lld using RUSTFLAGS.

However, `-C linker=rust-lld` still works the best on macOS, where
Rust toolchains come with unwinder and runtime and there is usually no
need to link system libraries. Keep setting it only for macOS.

Fixes aya-rs#907
vadorovsky added a commit to vadorovsky/aya that referenced this issue Oct 9, 2024
The recommendation (coming from rust-lang/rust#130062) for Linux hosts
is using C compiler driver as a linker, which is able to find
system-wide libraries. Using linker binaries directly in `-C linker`
(e.g. `-C linker=rust-lld`) often results in errors like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

Not touching the linker settings is usually the best approach for Linux
systems. Native builds pick up the default C toolchain. Cross builds
default to GCC cross wrapper, but that's easy to supress with clang
and lld using RUSTFLAGS.

However, `-C linker=rust-lld` still works the best on macOS, where
Rust toolchains come with unwinder and runtime and there is usually no
need to link system libraries. Keep setting it only for macOS.

Fixes aya-rs#907
tamird pushed a commit to vadorovsky/aya that referenced this issue Nov 21, 2024
The recommendation (coming from rust-lang/rust#130062) for Linux hosts
is using C compiler driver as a linker, which is able to find
system-wide libraries. Using linker binaries directly in `-C linker`
(e.g. `-C linker=rust-lld`) often results in errors like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

Not touching the linker settings is usually the best approach for Linux
systems. Native builds pick up the default C toolchain. Cross builds
default to GCC cross wrapper, but that's easy to supress with clang
and lld using RUSTFLAGS.

However, `-C linker=rust-lld` still works the best on macOS, where
Rust toolchains come with unwinder and runtime and there is usually no
need to link system libraries. Keep setting it only for macOS.

Fixes aya-rs#907
vadorovsky added a commit to vadorovsky/aya that referenced this issue Nov 26, 2024
The recommendation (coming from rust-lang/rust#130062) for Linux hosts
is using C compiler driver as a linker, which is able to find
system-wide libraries. Using linker binaries directly in `-C linker`
(e.g. `-C linker=rust-lld`) often results in errors like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

Not touching the linker settings is usually the best approach for Linux
systems. Native builds pick up the default C toolchain. Cross builds
default to GCC cross wrapper, but that's easy to supress with clang and
lld using RUSTFLAGS.

However, `-C linker=rust-lld` still works the best on macOS, where Rust
toolchains come with libc and runtime library and there is no need to
link any system libraries. Keep setting it only for macOS.

Fixes aya-rs#907
dave-tucker pushed a commit to dave-tucker/aya that referenced this issue Feb 6, 2025
The recommendation (coming from rust-lang/rust#130062) for Linux hosts
is using C compiler driver as a linker, which is able to find
system-wide libraries. Using linker binaries directly in `-C linker`
(e.g. `-C linker=rust-lld`) often results in errors like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

Not touching the linker settings is usually the best approach for Linux
systems. Native builds pick up the default C toolchain. Cross builds
default to GCC cross wrapper, but that's easy to supress with clang and
lld using RUSTFLAGS.

However, `-C linker=rust-lld` still works the best on macOS, where Rust
toolchains come with libc and runtime library and there is no need to
link any system libraries. Keep setting it only for macOS.

Fixes aya-rs#907
dave-tucker pushed a commit to dave-tucker/aya that referenced this issue Feb 6, 2025
The recommendation (coming from rust-lang/rust#130062) for Linux hosts
is using C compiler driver as a linker, which is able to find
system-wide libraries. Using linker binaries directly in `-C linker`
(e.g. `-C linker=rust-lld`) often results in errors like:

```
cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc...
cargo:warning=  |
cargo:warning=  = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un
cargo:warning=  = note: rust-lld: error: unable to find library -lgcc_s
cargo:warning=          rust-lld: error: unable to find library -lc
cargo:warning=
cargo:warning=
cargo:warning=
cargo:warning=error: aborting due to 1 previous error
```

Not touching the linker settings is usually the best approach for Linux
systems. Native builds pick up the default C toolchain. Cross builds
default to GCC cross wrapper, but that's easy to supress with clang and
lld using RUSTFLAGS.

However, `-C linker=rust-lld` still works the best on macOS, where Rust
toolchains come with libc and runtime library and there is no need to
link any system libraries. Keep setting it only for macOS.

Fixes aya-rs#907
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants