Building clang/LLVM with ELLCC Pre-compiled Binaries

ELLCC has periodic pre-compiled binary releases that can be download and installed on various Linux hosts. A coworker wanted to take advantage of that and use ELLCC to bootstrap clang/LLVM instead of GCC. The steps described here can be used to build clang/LLVM on systems where either no GCC exists, or where the version of GCC that’s installed isn’t new enough to handle clang/LLVM C++11 code base.

An advantage of using the pre-compiled ELLCC binaries is that they are statically linked and can be run on just about any new-ish Linux box (post about 2.16).

Here’s how I build clang/LLVM using ELLCC. First I created a directory to work in:

sh-4.3$ mkdir clang
sh-4.3$ cd clang/

Then I downloaded an ELLCC binary tarball from the download page and un-tared it:

sh-4.3$ tar xvfp ~/Downloads/ellcc-x86_64-linux-eng-0.1.21.tgz

This created the ellcc directory and the subdirectories containing the ELLCC release. Then I got the latest LLVM and clang sources:

sh-4.3$ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
sh-4.3$ cd llvm/tools/
sh-4.3$ svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
sh-4.3$ cd ../..

My coworker ran into problems because currently ELLCC only supports static linking and parts of clang/LLVM are unconditionally built as shared libraries. Also, there are a few small incompatibilities resulting from the fact that ELLCC uses musl as its standard C library. A small set of patches are needed to make the stock clang/LLVM sources compile with ELLCC. Thus is the patch file: http://ellcc.org/clang-ecc.patch. You can download and apply it like this:

sh-4.3$ cd llvm
sh-4.3$ wget http://ellcc.org/clang-ecc.patch
sh-4.3$ patch -p0 < clang-ecc.patch
sh-4.3$ cd ..

Now we're ready to build:

sh-4.3$ mkdir llvm-build
sh-4.3$ cd llvm-build/
sh-4.3$ CC=/home/rich/ellcc/bin/ecc CXX=/home/rich/ellcc/bin/ecc++ CPP="/home/rich/ellcc/bin/ecc -E" ../llvm-ecc-src/configure --enable-optimized --enable-shared=no
sh-4.3$ make -j 6

Your configure line will be a little different if you're running tcsh: You'll need to set CC, etc. as environment variables with setenv. Also, I use "make -j 6" because I happen to have a 6 core system. You'll want to adjust for your system.

After the build, the bin directory looks like this:

sh-4.3$ ls Release+Asserts/bin/
arcmt-test    lli-child-target  llvm-link            llvm-stress
bugpoint      llvm-ar           llvm-lit             llvm-symbolizer
c-arcmt-test  llvm-as           llvm-lto             llvm-tblgen
c-index-test  llvm-bcanalyzer   llvm-mc              not
clang         llvm-config       llvm-mcmarkup        obj2yaml
clang++       llvm-cov          llvm-nm              opt
clang-check   llvm-c-test       llvm-objdump         sancov
clang-format  llvm-cxxdump      llvm-pdbdump         scan-build
clang-tblgen  llvm-diff         llvm-PerfectShuffle  scan-view
count         llvm-dis          llvm-profdata        verify-uselistorder
diagtool      llvm-dsymutil     llvm-ranlib          yaml2obj
FileCheck     llvm-dwarfdump    llvm-readobj         yaml-bench
fpcmp         llvm-dwp          llvm-rtdyld
llc           llvm-extract      llvm-size
lli           llvm-lib          llvm-split

The clang created has been statically linked:

sh-4.3$ file Release+Asserts/bin/clang
Release+Asserts/bin/clang: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=2465acda3f4acf5c88e0491f984f4f4048b47015, not stripped

If you use that clang to rebuild, the result will use the normal system shared libraries.

When everything is finished building you can do a "make install" to install clang and the LLVM tools in the default location which will be under /usr/local unless you supply a --prefix option to the configure command. You now have a compiled version of clang that uses your system header files and libraries. Unlike ecc, it also can create and use shared libraries and in fact uses them by default.

Leave a Reply

Your email address will not be published.