[LLVMdev] building dragonegg (LLVM 2.7) on Snow Leopard (Mac OS X 10.6.3)
kenneth.hoste at elis.ugent.be
Tue Jun 1 04:36:52 PDT 2010
With some help from Duncan through IRC, I just succeeded in building the dragonegg GCC plugin on Snow Leopard.
I first installed LLVM 2.7, and I'm using the dragonegg-2.7 release available on the LLVM website 
in combination with the 4.5.0 release of GCC.
Below is an outline of the steps required to get it to work, which is hopefully of use to others.
*) Build GCC-4.5.0
Next to applying the patch in the gcc-pathces directory of dragonegg and the one available at , which enables
plugin support (kind of) on Snow Leopard, I needed to make another change to the GCC codebase.
In gcc-4.5.0/configure, I needed to comment out the as_fn_error line (line 6020) which causes configure to
complain because Snow Leopard is not an ELF target. I just replaced it with an echo producing a warning that
configure is simply ignoring the fact that the target is not an ELF target.
This is OK, because dragonegg will cause GCC never to use the ELF stuff when performing LTO.
Although I'm not 100% sure it's required, I also installed libelf-0.8.13, to avoid further problems with GCC
complaining about the lack of ELF support.
Of course, I needed to make sure the GMP, MPFR and MPC libraries were recent enough.
I then configured GCC as follows (in gcc-4.5.0_obj):
../gcc-4.5.0_src/configure --with-libelf=/path/to/libelf-0.8.13 --prefix=/path/to/gcc-4.5.0 --enable-languages=c,c++,fortran --enable-checking --with-gmp=/path/to/gmp-4.3.2 --with-mpfr=/path/to/mpfr-2.4.2 --with-mpc=/path/to/mpc-0.8.2 --enable-plugin --enable-lto --disable-bootstrap
"make" and "make install" completed the building process.
*) Building dragonegg
Getting dragonegg to build required adding a fair amount of include directories to CPPFLAGS in order to get it to work.
One important note is that the order matters here, i.e. don't specify the gcc-4.5.0_obj/intl before the gcc-4.5.0_obj/gcc directory,
because otherwise the config.h in the former directory will be preferred above the config.h in the latter dir, causing problems
with SIZEOF_LONG being undefined.
The exact command line used to build dragonegg:
CC=/path/to/gcc-4.5.0/bin/gcc CXX=/path/to/gcc-4.5.0/bin/g++ CPPFLAGS="-I/path/to/gcc-4.5.0_src/gcc/config -I/path/to/gmp-4.3.2/include -I/path/to/mpfr-2.4.2/include -I/path/to/mpc-0.8.2/include -I/path/to/gcc-4.5.0_obj/gcc -I/path/to/gcc-4.5.0_obj/intl" GCC=/path/to/gcc-4.5.0/bin/gcc make
*) Testing dragonegg
A quick test of dragonegg by compiling a hello world C program to bytecode revealed that it works:
/path/togcc-4.5.0/bin/gcc -fplugin=./dragonegg.so test.c -S -o - -flto
More information about the llvm-dev