Building LLVM with LLVM with no dependence on GCC

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?

Best wishes,
Fabiano

aptget.txt (465 Bytes)

configure1.txt (28.8 KB)

libgccdevmissing.txt (1.76 KB)

libstdc++devmissing.txt (1.48 KB)

configure2.txt (29.5 KB)

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,

Thus wrote David Demelier via llvm-dev:

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

Thank you so much for your help, but when I try to build LLVM with LLVM like so:
=== snip ===
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;libunwind" \
  -DLIBCXX_CXX_ABI=libcxxabi \
  -DLIBCXX_USE_COMPILER_RT=On \
  -DLIBCXXABI_USE_LLVM_UNWINDER=On \
  -DLIBCXXABI_USE_COMPILER_RT=On \
  -DLIBCXX_HAS_GCC_S_LIB=Off \
  -DLIBUNWIND_USE_COMPILER_RT=On \
  -DCLANG_DEFAULT_CXX_STDLIB=libc++ \
  -DCLANG_DEFAULT_RTLIB=compiler-rt \
  -DCLANG_DEFAULT_LINKER=lld \
  ../llvm-project/llvm # configure3.txt
=== snap ===

I'm getting this error:
=== snip ===
[ 40%] Building CXX object projects/libcxx/src/CMakeFiles/cxx_shared.dir/exception.cpp.o
/home/fips/llvm-project/libcxx/src/exception.cpp:14:22: fatal error: cxxabi.h: No such file or directory
compilation terminated.
projects/libcxx/src/CMakeFiles/cxx_shared.dir/build.make:254: recipe for target 'projects/libcxx/src/CMakeFiles/cxx_shared.dir/exception.cpp.o' failed
make[2]: *** [projects/libcxx/src/CMakeFiles/cxx_shared.dir/exception.cpp.o] Error 1
CMakeFiles/Makefile2:11064: recipe for target 'projects/libcxx/src/CMakeFiles/cxx_shared.dir/all' failed
make[1]: *** [projects/libcxx/src/CMakeFiles/cxx_shared.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
=== snap ===

Do you perhaps still have your exact commands used? :wink:

Greetings,
Fabiano

configure3.txt (35 KB)

Hello? Anyone here with step-by-step instructions for getting a GCC-free
(and possibly glibc-free) LLVM on Ubuntu?

Greetings,
Fabiano

You can install clang and lld, both LLVM, using Ubuntu get.

From there you can download and build LLVM and install the latest version.
Be sure to use -DCMAKE_BUILD_TYPE=Release.

The LLVM libc project is at

Siva Chandra at Google is heading up the LLVM libc project.

Neil Nelson