Wednesday, June 27, 2012

Building mozilla with clang LTO

Ingredients:

  • 1 (one) copy of clang, preferably on the new side
  • 1 (one) source tree containing mozilla-central
  • 4 (four) GiB (that's 230, not 109) of memory
  • Linux (these instructions not tested on OS X, so it may or may not work for you)

Instructions:

For the sake of example, I have clang installed to /usr/local; substitute as appropriate for your environment. Configure mozilla-central with the following mozconfig:

# -O4 tells clang to do LTO
ac_add_options --disable-debug --enable-optimize='-O4'
# Exclude this line, and your will use over 10x the amount of memory.
ac_add_options --disable-debug-symbols
# Build with clang
export CC=/usr/local/bin/clang
export CXX=/usr/local/bin/clang++
# These flags are necessary to get elfhack to compile
export LDFLAGS='-Wl,-z,norelro -flto'
# This flag is necessary to link properly
export RANLIB='ar -s --plugin /usr/local/lib/LLVMgold.so'

You may season with other configure options as desired. Configure and let build for a few hours. Admire the build process as most individual files get compiled much quicker, but be displeased when link times explode. Enjoy!

6 comments:

Mike Ratcliffe said...

Funny that you posted this a couple of hours after I had failed to get clang working on Fedora 16 (clang 2.9).

I will try this tomorrow to see if I can get it working your way.

Joshua Cranmer said...

You should really try to use a new Clang: 3.1 or trunk. You can also run into problems due to ancient glibc headers (in one of my computers, I have what appears to be a broken libstdc++ and clang combination).

jrr said...

Is runtime performance measurably improved?

Joshua Cranmer said...

I recently tried a try run to see how clang LTO does, but the tryserver doesn't yet have working clang LTO.

trevnorris said...

The LDFLAGS option causes my configuration to fail. I'm using clang 3.2. Any ideas why?

Joshua Cranmer said...

You may be hitting bug 772112.