coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

Build with LLVM toolchain fails trying to link -lstdc++

Open marv opened this issue 3 years ago • 2 comments

I'm trying to build coreutils 0.0.15 on a x86_64-pc-linux-musl host using the full LLVM toolchain and see the following build error:

     Running `rustc --crate-name libstdbuf --edition=2021 src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type cdylib --crate-type rlib --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C metadata=4ec7dfb44b6efeaf --out-dir /var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps -L dependency=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps --extern cpp=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libcpp-39d70af48c051706.rlib --extern libc=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/liblibc-ff170cb258c59480.rlib --extern uucore=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libuucore-d83760c1bbb309c1.rlib --cfg unsound_local_offset -L native=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/build/uu_stdbuf_libstdbuf-cb993f1c8ffe36ef/out -l static=rust_cpp_generated -l stdc++`
error: linking with `x86_64-pc-linux-musl-cc` failed: exit status: 1
  |
  = note: "x86_64-pc-linux-musl-cc" "-Wl,--version-script=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/temp/rustcxLfyqB/list" "-m64" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libstdbuf.libstdbuf.558e0097-cgu.0.rcgu.o" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libstdbuf.libstdbuf.558e0097-cgu.1.rcgu.o" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libstdbuf.libstdbuf.558e0097-cgu.2.rcgu.o" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libstdbuf.libstdbuf.558e0097-cgu.3.rcgu.o" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libstdbuf.libstdbuf.558e0097-cgu.4.rcgu.o" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libstdbuf.libstdbuf.558e0097-cgu.5.rcgu.o" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libstdbuf.3obrx1xdcffhymfk.rcgu.o" "-Wl,--as-needed" "-L" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps" "-L" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/build/uu_stdbuf_libstdbuf-cb993f1c8ffe36ef/out" "-L" "/usr/x86_64-pc-linux-musl/lib64/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,-Bstatic" "-lrust_cpp_generated" "-Wl,-Bdynamic" "-lstdc++" "-Wl,-Bstatic" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libuucore-d83760c1bbb309c1.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libwild-126bf31ea27038b4.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libonce_cell-311301e94de6bd52.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libglob-0eef6b960cbe5145.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libos_display-106b2773ac9a4087.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libunicode_width-e2d244b077adc045.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libclap-91e013f4c888f960.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libatty-b628773fc4c936a6.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/liblibc-ff170cb258c59480.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libstrsim-2166d5cdec101589.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libtermcolor-e10e2a0dd5dc25a1.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libtextwrap-69437f980857a2ef.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libclap_lex-61b0a090cfde7a5b.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libos_str_bytes-bf6cb4c582798695.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libindexmap-1cc619eee18db4e3.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libhashbrown-34f6e61c5169be09.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libbitflags-d5d642aef161b071.rlib" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libcpp-39d70af48c051706.rlib" "-Wl,--start-group" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-1bb28b9666eb41f6.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-89123c7d14d48815.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libobject-a8558f0af4165fab.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libmemchr-73aea80a2cd1b05e.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libaddr2line-22b3ceb550cf3a57.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libgimli-c6ed4c1d40548be7.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-858f48cdb549f28b.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd_detect-1d6a5a2909327eca.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-073bd1ff0b8f28b4.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libminiz_oxide-b32a3e1e823e2f19.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libadler-904a968573847fb7.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-e336981fe875b20e.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-020c5a55201c2c4a.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-f6aaf92b27a2ab64.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-728e00740adfb891.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-43b733ac896d52c6.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-e5a171a5ca28c6ab.rlib" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-b92770760398b71c.rlib" "-Wl,--end-group" "/usr/x86_64-pc-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-1e1ccfe4116c6a1b.rlib" "-Wl,-Bdynamic" "-lunwind" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/x86_64-pc-linux-musl/lib64/rustlib/x86_64-unknown-linux-musl/lib" "-o" "/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/liblibstdbuf.so" "-Wl,--gc-sections" "-shared" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: ld.lld: error: unable to find library -lstdc++
          clang-15: error: linker command failed with exit code 1 (use -v to see invocation)


error: could not compile `uu_stdbuf_libstdbuf` due to previous error

Caused by:
  process didn't exit successfully: `rustc --crate-name libstdbuf --edition=2021 src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type cdylib --crate-type rlib --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C metadata=4ec7dfb44b6efeaf --out-dir /var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps -L dependency=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps --extern cpp=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libcpp-39d70af48c051706.rlib --extern libc=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/liblibc-ff170cb258c59480.rlib --extern uucore=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/deps/libuucore-d83760c1bbb309c1.rlib --cfg unsound_local_offset -L native=/var/tmp/paludis/build/sys-apps-uutils-0.0.15/work/coreutils-0.0.15/target/release/build/uu_stdbuf_libstdbuf-cb993f1c8ffe36ef/out -l static=rust_cpp_generated -l stdc++` (exit status: 1)
warning: build failed, waiting for other jobs to finish...

The system doesn't have libstdc++ and should use libc++. The rust compiler was built with use-libcxx if that matters somehow

Any pointers where the stdc++ comes from would be very appreciated

marv avatar Sep 24 '22 15:09 marv

Okay, something I found curious. I can only find the x86_64-unknown-linux-musl triple and not x86_64-pc-linux-musl (see docs). Am I overlooking something or is it a typo?

Now on to the actual investigation :). So we have some C code in stdbuf, which is the code that gets injected into the process to change the buffer. We use the cpp crate, which in turn uses the cc crate which has this method of determining the C++ standard library:

/// Returns the C++ standard library:
/// 1. If [cpp_link_stdlib](cc::Build::cpp_link_stdlib) is set, uses its value.
/// 2. Else if the `CXXSTDLIB` environment variable is set, uses its value.
/// 3. Else the default is `libc++` for OS X and BSDs, `libc++_shared` for Android,
/// `None` for MSVC and `libstdc++` for anything else.

https://github.com/rust-lang/cc-rs/blob/53272c5953cf0d8d6bfe7252935f9ff6fca56ce2/src/lib.rs#L2512-L2545

So it could be a solution to set the CXXSTDLIB env var? If that works, we could probably also open an issue at cc to tell them to use libc++ for musl.

tertsdiepraam avatar Sep 24 '22 16:09 tertsdiepraam

the solution is to set CXXSTDLIB=c++ some musl distros use libstdc++ so you can't really change the default.

Ella-0 avatar Jul 24 '24 01:07 Ella-0