Skip to content
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

rust-lld doesn't support libraries with zlib-compressed debug info #130063

Closed
vadorovsky opened this issue Sep 7, 2024 · 4 comments · Fixed by #130471
Closed

rust-lld doesn't support libraries with zlib-compressed debug info #130063

vadorovsky opened this issue Sep 7, 2024 · 4 comments · Fixed by #130471
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

vadorovsky commented Sep 7, 2024

rust-lld which is shipped in rustup toolchains doesn't include zlib support. That leads to issues if it tries to link static libraries which are compressed.

In my case, I'm trying to build a crate on Alpine Linux, where /usr/lib/libc.a is compressed wit zlib.

(I also had to specify -L /lib -L /usr/lib in my RUSTFLAGS to even be able to find the library, but that's a separate issue - #130062)

77d2cb0e3483:~/aya# RUSTFLAGS="-L /lib -L /usr/lib" cargo build --target x86_64-unknown-linux-musl --config "target.x86_64-unknown-linux-musl.linker = \"rust-lld\"" --package init --profile release
   Compiling libc v0.2.158
   Compiling cfg-if v1.0.0
   Compiling bitflags v2.6.0
   Compiling anyhow v1.0.86
   Compiling nix v0.29.0
   Compiling init v0.1.0 (/root/aya/init)
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/loca/aya/target/x86_64-unknown-linux-musl/release/deps/init-e28d03be64389d41.init.1ff0b768912a0f5b-cgu.5.rcgu.o" "/root/aya/target/x86_64-unknown-linux-musl/release/deps/init-e28d03be64389d41.5v5bzgpeitn8k9cw66o41lpcv.rcgu.o" "--as-needed" "-L" "/root/aya/target/x86_64-unknown-linux-musl/release/deps" "-L" "/root/aya/target/release/deps" "-L" "/lib" "-L" "/usr/lib" "-L" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Bstatic" "/root/aya/target/x86_64-unknown-linux-musl/release/deps/libnix-58a27e1bb6f49050.rlib" "/root/aya/target/x86_64-unknown-linux-musl/release/deps/libbitflags-3c134508527922bc.rlib" "/root/aya/target/x86_64-unknown-linux-musl/release/deps/libcfg_if-8d8fae249b1ab972.rlib" "/root/aya/target/x86_64-unknown-linux-musl/release/deps/liblibc-8773206ad0630d2b.rlib" "/root/aya/target/x86_64-unknown-linux-musl/release/deps/libanyhow-892885a59fdac32f.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_abort-30b1bb7d44aa9e0e.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" "-lunwind" "/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" "-lc" "/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" "--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" "-L" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained" "-o" "/root/aya/target/x86_64-unknown-linux-musl/release/deps/init-e28d03be64389d41" "--gc-sections" "-static" "-pie" "--no-dynamic-linker" "-z" "text" "-z" "relro" "-z" "now" "-O1" "--strip-debug" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtendS.o" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o"
  = note: rust-lld: error: /usr/lib/libc.a(writev.lo):(.debug_info) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(writev.lo):(.debug_abbrev) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(writev.lo):(.debug_loclists) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(writev.lo):(.debug_aranges) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(write.lo):(.debug_info) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(write.lo):(.debug_abbrev) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(unlinkat.lo):(.debug_info) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(writev.lo):(.debug_line) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(write.lo):(.debug_loclists) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(sync.lo):(.debug_info) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(unlinkat.lo):(.debug_abbrev) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(sync.lo):(.debug_abbrev) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(writev.lo):(.debug_str) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(sync.lo):(.debug_aranges) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(writev.lo):(.debug_line_str) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(write.lo):(.debug_aranges) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(symlink.lo):(.debug_info) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(setxid.lo):(.debug_info) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(setxid.lo):(.debug_abbrev) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: /usr/lib/libc.a(setgid.lo):(.debug_info) is compressed with ELFCOMPRESS_ZLIB, but lld is not built with zlib support
          rust-lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)


error: could not compile `init` (bin "init") due to 1 previous error

I think that could be fixed by enabling LLVM_ENABLE_ZLIB CMake option by default.

@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 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
@bjorn3
Copy link
Member

bjorn3 commented Sep 7, 2024

The error seems to suggest this is about zlib compressed debuginfo, nothing related to staticlibs.

@vadorovsky vadorovsky changed the title rust-lld doesn't support zlib-compressed static libraries rust-lld doesn't support libraries with zlib-compressed debug info Sep 7, 2024
@vadorovsky
Copy link
Contributor Author

The error seems to suggest this is about zlib compressed debuginfo, nothing related to staticlibs.

Fair, sorry for misleading title and description. I think that fix would still remain the same (enabling zlib in LLVM builds).

@lqd
Copy link
Member

lqd commented Sep 9, 2024

As you discovered, -Clinker is not the expected way to use rust-lld on the linux targets: using a C/C++ compiler as the linker driver will avoid the library issues.

Support is not as principled as when we enable zstd compression statically on select targets, zlib compression is more hit-or-miss depending on the builder and local configs. But saying it's not enabled at all is also incomplete. It's maybe not yet enabled on the -musl builder though.

See for example, on the latest x86_64-unknown-linux-gnu nightly:

$ rustc -Vv
rustc 1.83.0-nightly (adf8d168a 2024-09-08)
binary: rustc
commit-hash: adf8d168af9334a8bf940824fcf4207d01e05ae5
commit-date: 2024-09-08
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

$ ldd $(rustup which rustc) | grep libz
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ffff7bfe000)

And an example showing it working, on a helloworld:

$ cargo clean -q && RUSTFLAGS="-Zdebuginfo-compression=zlib" cargo build -q && readelf -t target/debug/helloworld | grep Z
       ZLIB, 0000000000001d67, 1
       ZLIB, 00000000000f722e, 1
       ZLIB, 00000000000072b0, 1
       ZLIB, 00000000000a1660, 1
       ZLIB, 00000000001481db, 1
       ZLIB, 0000000000063e78, 1

Remember that we use rust-lld by default on this target (and thus this example would also work without using the rustc -Z flag, and using a link arg: -Clink-arg=-Wl,--compress-debug-sections=zlib).

$ readelf -p .comment target/debug/helloworld

String dump of section '.comment':
  [     1]  Linker: LLD 19.1.0 (/checkout/src/llvm-project/llvm 2b259b3c201f939f2ed8d2fb0a0e9b37dd2d1321)
  [    5f]  GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
  [    8a]  rustc version 1.83.0-nightly (adf8d168a 2024-09-08)

So rust-lld is built with zlib support here, as you can see.

@khuey
Copy link
Contributor

khuey commented Sep 17, 2024

I didn't test #130471 but it should fix this

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 18, 2024
Add zlib to musl dist image so rust-lld will support zlib compression for debug info there.

Fixes rust-lang#130063.

r? `@Kobzol`
@bors bors closed this as completed in 930db09 Sep 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 18, 2024
Rollup merge of rust-lang#130471 - khuey:zlib-musl, r=Kobzol

Add zlib to musl dist image so rust-lld will support zlib compression for debug info there.

Fixes rust-lang#130063.

r? `@Kobzol`
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
6 participants