profile
viewpoint

Ask questionsBuilding LLVM with Clang fails

In config.toml, under [target.x86_64-unknown-linux-gnu], one can set cc and cxx to configure the C/C++ compiler used for building LLVM.

When using clang/clang++, regardless of whether use-libcxx is set under [llvm], the LLVM_LIBSTDCXX_MIN compile test fails due to a #include error.

The error happens because passing --target=x86_64-unknown-linux-gnu to clang/clang++ changes the default header search paths. See https://github.com/rust-lang/rust/issues/63417#issuecomment-520510331

My system uses LLVM 8.0.0 Release. (clang version 8.0.0 (tags/RELEASE_800/final) | Target: x86_64-solus-linux)

Original Issue Text:

I am currently trying to build rust on a Solus 4 machine.

The error happens in stage 0 when building LLVM, where it complains about an incompatible version of libstdc++, even if use-libcxx = true is set under [llvm].

Dependencies (g++ clang++ python make cmake curl git):

g++ (Solus) 8.3.1 20190320
clang version 8.0.0 (tags/RELEASE_800/final)
Python 2.7.16
GNU Make 4.2.1
cmake version 3.15.1
curl 7.65.3 (x86_64-solus-linux-gnu) libcurl/7.65.3 OpenSSL/1.0.2r zlib/1.2.11 libssh2/1.7.0_DEV nghttp2/1.36.0
git version 2.22.0

x.py build --stage 0 output:

Updating only changed submodules
Submodules updated in 0.02 seconds
    Finished dev [unoptimized] target(s) in 0.09s
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.11s
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 test artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.08s
Copying stage0 test from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 compiler artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.10s
Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building LLVM for x86_64-unknown-linux-gnu
running: "cmake" "/home/luna/shared/projects/rust/src/llvm-project/llvm" "-DLLVM_ENABLE_ASSERTIONS=ON" "-DLLVM_TARGETS_TO_BUILD=AArch64;ARM;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=" "-DLLVM_INCLUDE_EXAMPLES=OFF" "-DLLVM_INCLUDE_TESTS=OFF" "-DLLVM_INCLUDE_DOCS=OFF" "-DLLVM_INCLUDE_BENCHMARKS=OFF" "-DLLVM_ENABLE_ZLIB=OFF" "-DWITH_POLLY=OFF" "-DLLVM_ENABLE_TERMINFO=OFF" "-DLLVM_ENABLE_LIBEDIT=OFF" "-DLLVM_ENABLE_Z3_SOLVER=OFF" "-DLLVM_PARALLEL_COMPILE_JOBS=4" "-DLLVM_TARGET_ARCH=x86_64" "-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-gnu" "-DLLVM_OCAML_INSTALL_PATH=usr/lib/ocaml" "-DLLVM_LINK_LLVM_DYLIB=ON" "-DLLVM_ENABLE_LIBXML2=OFF" "-DLLVM_VERSION_SUFFIX=-rust-1.38.0-dev-f2b0c6766" "-DPYTHON_EXECUTABLE=/usr/bin/python2.7" "-DCMAKE_INSTALL_MESSAGE=LAZY" "-DCMAKE_C_COMPILER=clang" "-DCMAKE_CXX_COMPILER=clang++" "-DCMAKE_C_FLAGS=-ffunction-sections -fdata-sections -fPIC --target=x86_64-unknown-linux-gnu" "-DCMAKE_CXX_FLAGS=-ffunction-sections -fdata-sections -fPIC --target=x86_64-unknown-linux-gnu" "-DCMAKE_INSTALL_PREFIX=/home/luna/shared/projects/rust/build/x86_64-unknown-linux-gnu/llvm" "-DCMAKE_BUILD_TYPE=Release"
-- Could NOT find Z3: Found unsuitable version "0.0.0", but required is at least "4.7.1" (found Z3_LIBRARIES-NOTFOUND)
CMake Error at cmake/modules/CheckCompilerVersion.cmake:83 (message):
  libstdc++ version must be at least 4.8.
Call Stack (most recent call first):
  cmake/config-ix.cmake:13 (include)
  CMakeLists.txt:618 (include)


-- Configuring incomplete, errors occurred!
See also "/home/luna/shared/projects/rust/build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeOutput.log".
See also "/home/luna/shared/projects/rust/build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeError.log".
thread 'main' panicked at '
command did not execute successfully, got: exit code: 1

build script failed, must exit now', /home/luna/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.38/src/lib.rs:813:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
	finished in 0.027
failed to run: /home/luna/shared/projects/rust/build/bootstrap/debug/bootstrap build --stage 0
Build completed unsuccessfully in 0:00:01

config.toml and build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeOutput.log: https://gist.github.com/LunarLambda/9b6674731bb1d8f123bca143d546d94e

I would like to avoid having to setup an Ubuntu/Debian system or having to compile GCC 4.8 manually just to build Rust. Any help is appreciated

rust-lang/rust

Answer questions LunarLambda

The test that fails in particular is LLVM_LIBSTDCXX_MIN

The particular test says: Test for libstdc++ version of at least 4.8 by checking for _ZNKSt17bad_function_call4whatEv.

The bizarre thing is that

I ran nm -D /usr/lib64/libstdc++.so | grep _ZNKSt17bad_function_call4whatEv

And it matches!
00000000000c8510 T _ZNKSt17bad_function_call4whatEv

And that test is behind a elseif(NOT LLVM_ENABLE_LIBCXX) gate

And my config.toml has

[llvm]
use-libcxx = true

So this flag in particular seems to not get passed correctly.

And looking around the same file, this test is only ever run to begin with if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang").

So I guess I'll make a fresh checkout and set everything to compile with gcc/g++ instead?

useful!

Related questions

Spurious NaNs produced by trig functions with valid inputs on Windows GNU toolchains hot 2
using 'cargo install xsv' on windows 10 triggers rustc internal error hot 1
chain() make collect very slow hot 1
if/while Some(n) = &mut foo sugar will leak a temporary mutable borrow to current scope in particular situation hot 1
build an empty project failed (undefined reference to `__onexitbegin') hot 1
Invalid collision with TryFrom implementation? hot 1
Crater runs for Rust 1.38.0 hot 1
Spurious NaNs produced by trig functions with valid inputs on Windows GNU toolchains hot 1
under latest MinGW, cannot link with C code using stdout hot 1
Archive all nightlies hot 1
Internal compiler error: can't buffer lints after HIR lowering hot 1
Tracking issue for `Option::contains` and `Result::contains` hot 1
async fn + rustfmt don't "just work" inside of RLS hot 1
Include images in rustdoc output hot 1
Some closures are not inlined in release mode hot 1
Github User Rank List