[llvm-dev] Building LLVM with LLVM with no dependence on GCC
David Demelier via llvm-dev
llvm-dev at lists.llvm.org
Tue Sep 17 08:23:50 PDT 2019
Le 17/09/2019 à 16:27, Fabiano Sidler via llvm-dev a écrit :
> Hi folks!
>
> I'm trying to get rid of any dependency on libgcc*, but without success so
> far. The following commands were executed on a freshliy installed and updated
> Ubuntu 16.04 LTS:
> === snip ===
> sudo apt-get install build-essential libffi-dev cmake # see aptget.txt for packages installed
> sudo mv /usr/local /usr/local.orig
> git clone https://github.com/llvm/llvm-project.git
> cd llvm-project; git checkout llvmorg-9.0.0-rc5; cd -
> mkdir build; cd build
> cmake \
> -DLLVM_ENABLE_FFI=ON \
> -DCMAKE_BUILD_TYPE=Release \
> -DLLVM_ENABLE_RTTI=ON \
> -DLLVM_TARGETS_TO_BUILD="host" \
> -DBUILD_SHARED_LIBS=ON \
> -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;compiler-rt;lld" \
> ../llvm-project/llvm # configure1.txt
> cmake --build .
> cmake -DCMAKE_INSTALL_PREFIX=/tmp/llvm/usr/local -P cmake_install.cmake
> sudo mv /tmp/llvm/usr/local /usr
> sudo rm /usr/bin/ld
> sudo ln -s /usr/local/bin/ld.lld /usr/bin/ld
> sudo apt-get remove build-essential g++ g++-5 gcc gcc-5 libgcc-5-dev libstdc++-5-dev
> cd ..; rm -r build; mkdir build; cd -
> cmake \
> -DLLVM_ENABLE_FFI=ON \
> -DCMAKE_BUILD_TYPE=Release \
> -DLLVM_ENABLE_RTTI=ON \
> -DLLVM_TARGETS_TO_BUILD="host" \
> -DBUILD_SHARED_LIBS=ON \
> -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;compiler-rt;lld" \
> ../llvm-project/llvm # fails, pleas see libgccdevmissing.txt
> sudo apt-get install libgcc-5-dev
> cd ..; rm -r build; mkdir build; cd -
> cmake \
> -DLLVM_ENABLE_FFI=ON \
> -DCMAKE_BUILD_TYPE=Release \
> -DLLVM_ENABLE_RTTI=ON \
> -DLLVM_TARGETS_TO_BUILD="host" \
> -DBUILD_SHARED_LIBS=ON \
> -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;compiler-rt;lld" \
> ../llvm-project/llvm # fails, please see libstdc++devmissing.txt
> sudo apt-get install libstdc++-5-dev
> cd ..; rm -r build; mkdir build; cd -
> cmake \
> -DLLVM_ENABLE_FFI=ON \
> -DCMAKE_BUILD_TYPE=Release \
> -DLLVM_ENABLE_RTTI=ON \
> -DLLVM_TARGETS_TO_BUILD="host" \
> -DBUILD_SHARED_LIBS=ON \
> -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;compiler-rt;lld" \
> ../llvm-project/llvm # configure2.txt
> cmake --build .
> rm -r /tmp/llvm
> cmake -DCMAKE_INSTALL_PREFIX=/tmp/llvm/usr/local -P cmake_install.cmake
> cd ..
> tar cJf llvm9.txz -C /tmp/llvm/usr/local .
> === snap ===
>
> When I unpack that now on another fresh system, I'm still getting the following:
> === snip ===
> ld: error: cannot open crtbegin.o: No such file or directory
> ld: error: unable to find library -lgcc
> ld: error: unable to find library -lgcc_s
> ld: error: unable to find library -lc
> ld: error: unable to find library -lgcc
> ld: error: unable to find library -lgcc_s
> ld: error: cannot open crtend.o: No such file or directory
> clang-9: error: linker command failed with exit code 1 (use -v to see invocation)
> === snap ===
>
> Any hint on how to make this work?
It's a bit time consuming because you first need to build clang and
llvm, then rebuild clang with clang so that it is configured to use
libc++, libc++abi, libunwind by default and then rebuild it again.
Finally, you need to build llvm, libc++, libc++abi, libunwind so that
they are no longer linked to libgcc.
I don't have the procedure in head again but I've posted this several
months ago for my pure LLVM based Linux distribution.
Also you will need to add more options to the components. See for example:
LIBCXX_CXX_ABI=libcxxabi
LIBCXX_USE_COMPILER_RT=On
LIBCXXABI_USE_LLVM_UNWINDER=On
LIBCXXABI_USE_COMPILER_RT=On
LIBCXX_HAS_GCC_S_LIB=Off
LIBUNWIND_USE_COMPILER_RT=On
And as mentioned above
CLANG_DEFAULT_CXX_STDLIB=libc++
CLANG_DEFAULT_RTLIB=compiler-rt
CLANG_DEFAULT_LINKER=lld
HTH,
--
David
More information about the llvm-dev
mailing list