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

Fails to build when linking with lld #21

Closed
Kmeakin opened this issue Apr 21, 2022 · 3 comments
Closed

Fails to build when linking with lld #21

Kmeakin opened this issue Apr 21, 2022 · 3 comments

Comments

@Kmeakin
Copy link

Kmeakin commented Apr 21, 2022

The unwind-sys crate fails to build when using lld as the linker:

RUSTFLAGS='-Clink-args=-fuse-ld=lld' cargo t --all-features produces a linker error:

          ld.lld: error: /usr/lib/x86_64-linux-gnu/libunwind-ptrace.so: undefined reference to lzma_stream_buffer_decode [--no-allow-shlib-undefined]
          ld.lld: error: /usr/lib/x86_64-linux-gnu/libunwind-ptrace.so: undefined reference to lzma_index_uncompressed_size [--no-allow-shlib-undefined]
          ld.lld: error: /usr/lib/x86_64-linux-gnu/libunwind-ptrace.so: undefined reference to lzma_index_end [--no-allow-shlib-undefined]
          ld.lld: error: /usr/lib/x86_64-linux-gnu/libunwind-ptrace.so: undefined reference to lzma_index_buffer_decode [--no-allow-shlib-undefined]
          ld.lld: error: /usr/lib/x86_64-linux-gnu/libunwind-ptrace.so: undefined reference to lzma_stream_footer_decode [--no-allow-shlib-undefined]
          ld.lld: error: /usr/lib/x86_64-linux-gnu/libunwind-ptrace.so: undefined reference to lzma_index_size [--no-allow-shlib-undefined]
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `unwind-sys` due to previous error

Your crate seems to rely on some GNU ld behaviour that the lld team are unwilling to replicate (llvm/llvm-project#54700).

I suggest this can be fixed by adding a cargo:rustc-link-lib=lzma directive to your build.rs build script.

@sfackler
Copy link
Owner

sfackler commented Apr 21, 2022

The build script relies on pkg-config for its linker configuration. You should file this issue on the libunwind project (or the packager that created your libunwind binaries): https://github.com/sfackler/rstack/blob/master/unwind-sys/build.rs#L11

@Kmeakin
Copy link
Author

Kmeakin commented Apr 21, 2022

libunwind.pc includes -llzma in its Libs.private, which is only added to the linker args if pkg-config is called with the --static flag.

The solution is to replace
let library = pkg_config::probe_library(lib).unwrap();
with
let library = pkg_config::Config::new().statik(true).probe(lib).unwrap();
in build.rs.

@sfackler
Copy link
Owner

sfackler commented Apr 21, 2022

But you're not statically linking to libunwind - the linker error references libunwind-ptrace.so which is a dynamic library. libunwind-ptrace.so should internally declare its dependency on liblzma. It appears that that may not be the case which would be either a bug in the libunwind project or a bug in whatever built your libunwind binaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants