LLVM's Link Time Optimizer integrated into GNU ld

Hello,

I have a very early version of GNU’s ld, part of GNU binutils, with LLVM’s Link Time Optimization integrated with it. This allows the linker to link LLVM bytecode and native objects together into a single executable. It is still very early in development, and I’ll be working on doing more robust testing on it in the upcoming weeks, but it at least handles simple cases. If you are interested in trying it out, and providing feedback on how it performs, especially on some other platforms (mine is amd64-linux), I would be very interested.

If you are interested in trying this, please pick up the patches to LLVM from bugs #1055 and #1073, as they are necessary to build LLVM’s LTO suitable to link into binutils. The should be in LLVM’s CVS soon, but aren’t yet.

Then use the following monolithic patch from the binutils CVS. It is monolithic only because binutils includes the verbatim, and automatically generated configure and Makefile.in scripts. The changes are actually quite small, and should (hopefully) apply cleanly, even as the CVS moves – the files changed for this process are among the least frequently changing in binutils development.
http://code.chandlerc.net/binutils/binutils-tot.2007.01.06.patch

or

Grab a branch of this bzr repository of binutils. I will try and sync it to CVS every week or so, but it shouldn’t be an issue for most people. It will allow actually tinkering with the implementation in a nice DRCS manner.
http://code.chandlerc.net/binutils/bzr

Finally, configure and build binutils similar to the following

cd ${BINUTILS_OBJ_ROOT}
${BINUTILS_SRC_ROOT}/configure --prefix=${BINUTILS_INSTALL_PATH} --with-llvm=${LLVM_INSTALL_PATH}
make
make install

where LLVM_INSTALL_PATH is equivalent to the prefix provided LLVM when it was configured and built. If ‘llvm-config’ is in your path, then simply specifying ‘–with-llvm’ may be sufficient, but i haven’t tested that behavior.

Please, comments, suggestions, questions, and bugs are all welcome, and hopefully this will grow to be a very usable tool.
-Chandler Carruth

Hello again,

I’ve put together a new patch. This is cleaned up some from the previous one with feedback from some GCC/toolchain people to get the formatting correct. I also removed some of the debugging output that was previously included, and removed the configure and Makefile.in changes. Instead please follow the below instructions for building.

http://code.chandlerc.net/binutils/binutils.trim.2007.01.06.patch

cd ${BINUTILS_SRC_ROOT}/ld
automake -ic
autoconf
cd ${BINUTILS_OBJ_ROOT}
${BINUTILS_SRC_ROOT}/configure --prefix=${BINUTILS_INSTALL_PATH} --with-llvm=${LLVM_INSTALL_PATH}

make
make install

I hope this helps people who are interested in reviewing the patch as well as applying it, and cleans up the output for people applying the patch.

-Chandler Carruth

Excellent.

I've applied #1073 patch.