Repository navigation
Problem linking libunwind when compiling clippy #85751
Description
We are building the Rust compiler from nightly, from which we define a Bazel toolchain.
In addition to rustc, the toolchain includes other tools, such as clippy and rustfmt, which we build as well.
We require the binaries to be statically linked, so they are self-contained and do not depend on shared libraries.
In particular, we need to statically link the version of libunwind that gets built when compiling llvm.
So in config.toml we have
[rust]
llvm-libunwind = "in-tree"
[llvm]
static-libstdcpp = true
cflags = "-D_GLIBCXX_USE_CXX11_ABI=0 -stdlib=libc++ --rtlib=compiler-rt -unwindlib=libunwind -static-libstdc++ -static-libgcc -DUCHAR_TYPE=uint16_t -g0"
ldflags = "-L<staging_dir>/llvm/lib -lunwind -Bstatic -static-libstdc++ -static-libgcc -g0"
ninja = true
Then, after compiling llvm, we hackishly force static linking by removing the .so: rm llvm/lib/libunwind.so*. This works around #29527
This works for rustc and rustfmt, but not clippy. It seems that clippy is not being told to use the in-tree version of libunwind, and so we get a linker error:
(using <BD> for brevity to indicate the common build directory path)
Building stage1 tool clippy-driver (x86_64-unknown-linux-gnu)
Compiling ucd-trie v0.1.3
Compiling pulldown-cmark v0.8.0
Compiling rustc-semver v1.1.0
Compiling if_chain v1.0.0
Compiling rustc_tools_util v0.2.0 (/tmp/build-rustc-staging.g27EHWwDms/rustc-src/src/tools/clippy/rustc_tools_util)
Compiling quine-mc_cluskey v0.2.4
Compiling unicase v2.6.0
Compiling itertools v0.9.0
Compiling pest v2.1.3
Compiling clippy v0.1.54 (/tmp/build-rustc-staging.g27EHWwDms/rustc-src/src/tools/clippy)
Compiling clippy_utils v0.1.54 (/tmp/build-rustc-staging.g27EHWwDms/rustc-src/src/tools/clippy/clippy_utils)
Compiling semver-parser v0.10.2
Compiling semver v0.11.0
Compiling cargo_metadata v0.12.0
Compiling clippy_lints v0.1.54 (/tmp/build-rustc-staging.g27EHWwDms/rustc-src/src/tools/clippy/clippy_lints)
error: linking with `/usr/bin/clang++` failed: exit status: 1
|
= note: "/usr/bin/clang++" "-m64" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-Wl,--as-needed" "-L" "<BD>/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.0.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.1.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.10.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.11.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.12.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.13.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.14.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.15.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.2.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.3.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.4.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.5.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.6.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.7.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.8.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.9.rcgu.o" "-o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps" "-L" "<BD>/stage1-tools/release/deps" "-L" "<BD>/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_lints-2c94a74107bddb69.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libtoml-dd7456c55c44c90a.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libregex_syntax-4e074f16cdab16e6.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libcargo_metadata-572da3e0be85a7d1.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libserde_json-4b2f39e93e914c91.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libryu-fe03cf9014177fe1.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libitoa-254a369192b0e41b.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libpulldown_cmark-a3cb3d622d5299ec.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libmemchr-5fc53eaed5b93baf.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libunicase-08b754bdb3e79b40.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libbitflags-fa4146283c7dcf7f.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/liburl-e334d4999ae40e26.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libidna-4ccd292e8ff413b7.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libunicode_normalization-977261e1ba455667.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libtinyvec-5931f1f70217b006.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libunicode_bidi-306ecb356465bbde.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libform_urlencoded-c5adc592c24847fe.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libpercent_encoding-c42753e7ff933803.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libmatches-1ba42f8e6736589f.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libitertools-91c2c298f57ac430.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libeither-285099727ca0d3a5.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libquine_mc_cluskey-6ff02b0b5df613fb.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libsemver-cc320f53f6085e6e.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libsemver_parser-71420aeaef3a7d9b.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libpest-41b2d2072c136e80.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libucd_trie-848f9c70f929d69f.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libserde-bba5b8307b4c2e1f.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_utils-8af687cb6957b8f8.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/librustc_semver-f95ec72f9354327c.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libif_chain-14b305b09fe6df2e.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/librustc_tools_util-ddfcfb1da96998e3.rlib" "-L" "<BD>/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lrustc_driver-d0d9704efb4ebe56" "-Wl,--start-group" "-L" "<BD>/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lstd-bc7a0745f1fbbd95" "-Wl,--end-group" "-Wl,-Bstatic" "<BD>/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d845064f5e2f3da0.rlib" "-Wl,-Bdynamic" "-lrt" "-ldl" "-lpthread" "-lm" "-lunwind" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,-rpath,$ORIGIN/../lib"
= note: /usr/bin/ld: cannot find -lunwind
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: aborting due to previous error
error: could not compile `clippy`
To learn more, run the command again with --verbose.
command did not execute successfully: "/tmp/build-rustc-staging.g27EHWwDms/rustc-beta-toolchain/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "12" "--release" "--frozen" "--manifest-path" "/tmp/build-rustc-staging.g27EHWwDms/rustc-src/src/tools/clippy/Cargo.toml" "--message-format" "json-render-diagnostics"
expected success, got: exit code: 101
Building stage1 tool cargo-clippy (x86_64-unknown-linux-gnu)
Compiling clippy v0.1.54 (/tmp/build-rustc-staging.g27EHWwDms/rustc-src/src/tools/clippy)
error: linking with `/usr/bin/clang++` failed: exit status: 1
|
= note: "/usr/bin/clang++" "-m64" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-Wl,--as-needed" "-L" "<BD>/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.0.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.1.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.10.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.11.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.12.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.13.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.14.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.15.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.2.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.3.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.4.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.5.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.6.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.7.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.8.rcgu.o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5.clippy_driver.b4xue1do-cgu.9.rcgu.o" "-o" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/clippy_driver-2fc6d04ae4266cd5" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps" "-L" "<BD>/stage1-tools/release/deps" "-L" "<BD>/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_lints-2c94a74107bddb69.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libtoml-dd7456c55c44c90a.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libregex_syntax-4e074f16cdab16e6.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libcargo_metadata-572da3e0be85a7d1.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libserde_json-4b2f39e93e914c91.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libryu-fe03cf9014177fe1.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libitoa-254a369192b0e41b.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libpulldown_cmark-a3cb3d622d5299ec.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libmemchr-5fc53eaed5b93baf.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libunicase-08b754bdb3e79b40.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libbitflags-fa4146283c7dcf7f.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/liburl-e334d4999ae40e26.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libidna-4ccd292e8ff413b7.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libunicode_normalization-977261e1ba455667.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libtinyvec-5931f1f70217b006.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libunicode_bidi-306ecb356465bbde.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libform_urlencoded-c5adc592c24847fe.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libpercent_encoding-c42753e7ff933803.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libmatches-1ba42f8e6736589f.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libitertools-91c2c298f57ac430.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libeither-285099727ca0d3a5.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libquine_mc_cluskey-6ff02b0b5df613fb.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libsemver-cc320f53f6085e6e.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libsemver_parser-71420aeaef3a7d9b.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libpest-41b2d2072c136e80.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libucd_trie-848f9c70f929d69f.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libserde-bba5b8307b4c2e1f.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_utils-8af687cb6957b8f8.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/librustc_semver-f95ec72f9354327c.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libif_chain-14b305b09fe6df2e.rlib" "<BD>/stage1-tools/x86_64-unknown-linux-gnu/release/deps/librustc_tools_util-ddfcfb1da96998e3.rlib" "-L" "<BD>/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lrustc_driver-d0d9704efb4ebe56" "-Wl,--start-group" "-L" "<BD>/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lstd-bc7a0745f1fbbd95" "-Wl,--end-group" "-Wl,-Bstatic" "<BD>/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d845064f5e2f3da0.rlib" "-Wl,-Bdynamic" "-lrt" "-ldl" "-lpthread" "-lm" "-lunwind" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,-rpath,$ORIGIN/../lib"
= note: /usr/bin/ld: cannot find -lunwind
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: aborting due to previous error
error: could not compile `clippy`
To learn more, run the command again with --verbose.
command did not execute successfully: "/tmp/build-rustc-staging.g27EHWwDms/rustc-beta-toolchain/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "12" "--release" "--frozen" "--manifest-path" "/tmp/build-rustc-staging.g27EHWwDms/rustc-src/src/tools/clippy/Cargo.toml" "--message-format" "json-render-diagnostics"
expected success, got: exit code: 101
Additional information:
- We are compiling in a debian:buster docker image.
- Possibly very relevant work in progress: build llvm libunwind.a in rustbuild #85600
- We are currently using the 2021-05-18 nightly (git version 3e99439), and building it with the 2021-04-07 beta compiler (git version 2157381).
Activity
petrhosek commentedon May 27, 2021
Can you try using the following flags:
-Clink-arg=-static-libgcc -Clink-arg=-unwindlib=libunwind? That will tell Clang to link libunwind statically, that is Clang will pass-l:libunwind.ato the linker.petrochenkov commentedon May 27, 2021
cc @12101111
12101111 commentedon May 28, 2021
The linking command line is assembled in linker_with_args
This is the end part of linking command, and the are added to command line by link_local_crate_native_libs_and_dependent_crate_libs:
This part, among all
rlibfiles before this are handled by add_upstream_rust_crates.And compiler_builtins is alaways the last object file added here:
rust/compiler/rustc_codegen_ssa/src/back/link.rs
Lines 1952 to 1959 in df3d86b
This part is handled by add_upstream_native_libraries
"-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc"clearly come fromlibc:https://github.com/rust-lang/libc/blob/9c4944a6e5d71e11009461941b3999b1c7d7e51f/src/unix/mod.rs#L324
But which crate link to
"-lrt" "-ldl" "-lpthread" "-lm" "-lunwind"?Can you apply this patch:
and rebuild rustc and clippy with this:
It should output like this:
jfgoog commentedon May 28, 2021
(Note: wrote this reply before seeing 12101111's response, which I am still digesting. This is in response to petrhosek's comment)
Thanks! I'm working on following your suggestion. I thought I could do this by modifying rustflags in src/tools/clippy/.cargo/config:
But that cargo config doesn't seem to be picked up when we build clippy, because the link command, and the associated error, seems to be the same as what I posted above.
The overall build command we are using in the docker image is:
python3 x.py build library/std compiler/rustc src/tools/rustfmt src/tools/cargo src/tools/clippy, which seems to use the following "cargo build" command to build clippy:/tmp/build-rustc-staging.J6gyafxhMk/rustc-beta-toolchain/bin/cargo build --target x86_64-unknown-linux-gnu -Zbinary-dep-depinfo -j 12 --release --frozen --manifest-path /tmp/build-rustc-staging.J6gyafxhMk/rustc-src/src/tools/clippy/Cargo.toml --message-format json-render-diagnosticsjfgoog commentedon May 28, 2021
Working on following 12101111's instructions. This will be a little complicated because, if I understand correctly, I need to patch and rebuild the beta rustc, because that's what's used to build the nightly. So I need to compile the compiler to compile my compiler. :)
12101111 commentedon May 28, 2021
You don't need build beta compiler, stage1 will contain this change and that's enough
https://rustc-dev-guide.rust-lang.org/building/bootstrapping.html
jfgoog commentedon May 28, 2021
OK. I am surprised by that, because the "cargo build" command for clippy uses the version of cargo in the beta toolchain (see my earlier comment)
12101111 commentedon May 28, 2021
You should build rust toolchain using
./x.py distjfgoog commentedon May 28, 2021
output from "Building stage1 tool clippy-driver" to the linker error:
clippy-build.txt
This was built as described above. I am inquiring as to why we are not doing
./x.py dist12101111 commentedon May 28, 2021
There should be lines that contain the log from clippy crate:
INFO rustc_codegen_ssa::back::link preparing Executable to ".....clippy_driver-.....INFO rustc_codegen_ssa::back::link "clang++ ... -o clippy_driver-......But I don't find them in your log.
jfgoog commentedon May 28, 2021
I checked all the output I have from the build command. There are no instances of "preparing Executable to.*clippy".
Are you sure I don't need to apply your patch to the beta compiler? As I said, clippy seems to be getting built using "cargo build" from the beta compiler. It looks like we may be setting this explicitly in our config.toml:
I'm going to try patching and rebuilding the beta toolchain.
jfgoog commentedon May 28, 2021
Here's the output with the patch applied to the beta toolchain, but not the nightly (I hope I don't need it applied to both, but if so I can do that next)
clippy-build.txt
This does contain the following lines which may be of interest to you based on your earlier comment:
But I'm not sure this adds much new information, because the linker command and error were in my original report.
jfgoog commentedon May 28, 2021
Full output from building rustc, clippy, etc. after building llvm (a superset of the file above)
full-rustc-build.txt
jfgoog commentedon May 28, 2021
This looks suspicious:
Our llvm.cflags include
-unwindlib=libunwind. Maybe should be--unwindlib=libunwindwith a double dash?jfgoog commentedon May 28, 2021
Nope, that wasn't it.
--unwindlib=libunwinddoesn't work. Not sure why the warning inserts a space tho.12101111 commentedon May 29, 2021
"-lrt" "-ldl" "-lpthread" "-lm" "-lunwind"is from rustc_llvm's build.rs"-lrt" "-ldl" "-lpthread" "-lm"is fromrust/compiler/rustc_llvm/build.rs
Line 216 in f58631b
-lunwindis fromrust/compiler/rustc_llvm/build.rs
Lines 248 to 252 in f58631b
rust/src/bootstrap/compile.rs
Lines 677 to 680 in f58631b
Could you try to remove
-lunwindfrom llvm.ldflags?jfgoog commentedon May 29, 2021
Without
-lunwind, rustc fails to build, before we get to clippy:build.txt
I wonder if this is because we are deleting libunwind.so as a hack to force static linking?
jfgoog commentedon May 29, 2021
A theory about what's going on here:
Based on the code snippets for how
-lunwindis being passed to the linker, it seems like-lunwindis getting picked cleverly out of llvm.ldflags. But it might not be sufficient to just pick out-lunwind. We also need the path to the llvm directory, at least ifllvm-libunwind = "in-tree".We're specifying
-L<staging_dir>/llvm/libin llvm.ldflags, but it seems like cargo is not passing that when we link clippy.12101111 commentedon May 29, 2021
This is a known issue: #76020 and will be fixed by #85600. I'm cleaning this pr, but got a strange ICE.
jfgoog commentedon May 29, 2021
I was able to get it build by hacking
src/tools/clippy/build.rsand addingjfgoog commentedon May 29, 2021
@12101111 thanks for your help. Let me know if you want me to patch in anything to test.
jyn514 commentedon May 25, 2023
I am not sure the status of this issue. it looks like you did get clippy working?
Regardless, "deleting libunwind.so in the sysroot and then building rustc" is not a use case we're going to support, so I'm going to close this.