Compiling with gcc's -O3 optimization level

Hi ROOT,

So, just relaying what I had found about installing using the higher-than-default optimization level for installing ROOT. I am using gcc version 4.5.2 (on Ubuntu 11.04, 64-bit machine, in case that matters), and wanted to install the patched version of ROOT 5.28. (Revision 39271, so it gets identified as 5.28/00d.)

There’s a posting about bugs that surfaced using -O2 on gcc 4.4; see eg. http://root.cern.ch/root/roottalk/roottalk09/0779.html and links therein. The overview: ROOT was fixed so that, specifically for gcc 4.4, the IO library instantiates particular template instances that it knows it will use later; otherwise, gcc 4.4 at -O2 would throw template information away, only to realize in subsequent libraries that it needed the template specializations and didn’t have the information it needed to create them anymore. (According to http://www.parashift.com/c+±faq-lite/templates.html#faq-35.12, this is not a bug in gcc; but that’s not really my concern here.)

Turns out that gcc 4.5 creates the same problem in ROOT, if you compile with -O3. So, to compile ROOT with -O3, you also have to force ROOT to do the same instantiations it would have done for gcc 4.4.

My solution was to run the following lines of code:

svn co http://root.cern.ch/svn/root/branches/v5-28-00-patches source_files
cd source_files
sed -i 's:-O2:-O3:' config/*
sed -i 's:($(GCC_VERS),gcc-4.4):(,):' io/io/Module.mk
# Then configure/make/make install as normal.

Not deep and probably not the most elegant approach, but just figured I’d post my results in case someone else ever wanted to do the same thing.

Thanks,
Clayton

PS. No, I haven’t done a speed comparison to see whether performance is significantly improved. Surely this is strongly dependent on compiler version, anyway. Just something I felt like doing.