[llvm-dev] Building LLVM with LLVM with no dependence on GCC

1,001 views
Skip to first unread message

Fabiano Sidler via llvm-dev

unread,
Sep 17, 2019, 10:28:28 AM9/17/19
to llvm...@lists.llvm.org
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
configure1.txt
libgccdevmissing.txt
libstdc++devmissing.txt
configure2.txt

David Demelier via llvm-dev

unread,
Sep 17, 2019, 11:24:04 AM9/17/19
to llvm...@lists.llvm.org

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

_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Fabiano Sidler via llvm-dev

unread,
Sep 20, 2019, 5:49:55 PM9/20/19
to llvm...@lists.llvm.org
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? ;)

Greetings,
Fabiano
configure3.txt

Fabiano Sidler via llvm-dev

unread,
Sep 24, 2019, 1:09:09 PM9/24/19
to llvm...@lists.llvm.org
Hello? Anyone here with step-by-step instructions for getting a GCC-free
(and possibly glibc-free) LLVM on Ubuntu?

Greetings,
Fabiano

Neil Nelson via llvm-dev

unread,
Sep 24, 2019, 2:17:57 PM9/24/19
to llvm...@lists.llvm.org

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.
https://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary

The LLVM libc project is at
http://llvm.org/docs//Proposals/LLVMLibC.html

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

Neil Nelson

Reply all
Reply to author
Forward
0 new messages