Wednesday January 4, 2006 03:01

GCC 4 in Gentoo

Posted by as Information Insemination





Last weekend I managed to try GCC 4 on my Gentoo box. My inspiron 6000 comes with Pentium M, but with gcc version of <3.4, I can only use pentium3 optimisation flag instead of pentium-m, whic is not very nice. My Pentium M 1.86 outperforms Pentium 4 2.8 (ht) by 40% in a test program compiled with pentium3 (my laptop at that time) and the Pentium 4 desktop compiled the same program without cpu optimisation. Later when we tried it with -march pentium3 and -march pentium4 respectively, my Inspiron 6000 + gentoo was just 3%-5% slower than the Pentium 4 2.8 running SuSe :) That gives the idea that this is not just for fun but might as well give performance benefit at the end. Driven by that, I wish to see if my machine can outperform the much higher clocked Pentium 4 when compiled with gcc 4 and get the pentium-m flag to work.

Methodology:

Currently my gentoo is installed with GCC 3.3.6. With gentoo upgrading the compiler and glibc was easy. First of all, unmask the to be installed gcc and glibc version.

#echo "~sys-devel/gcc-4.0.2 -*" >> /etc/portage/package.keywords #echo "~sys-lib/glibc-2.3.6 -*" >> /etc/portage/package.keywords

Sure, we’ll need to emerge:

#emerge binutils glibc gcc

Next up, choose the gcc version that we would like to use.

To get the listing of available versions:

#gcc-config -l
[1] i686-pc-linux-gnu-3.3.6 *
[2] i686-pc-linux-gnu-3.3.6-hardened
[3] i686-pc-linux-gnu-3.3.6-hardenednopie
[4] i686-pc-linux-gnu-3.3.6-hardenednopiessp
[5] i686-pc-linux-gnu-3.3.6-hardenednossp
[6] i686-pc-linux-gnu-3.4.4
[7] i686-pc-linux-gnu-3.4.4-hardened
[8] i686-pc-linux-gnu-3.4.4-hardenednopie
[9] i686-pc-linux-gnu-3.4.4-hardenednopiessp
[10] i686-pc-linux-gnu-3.4.4-hardenednossp
[11] i686-pc-linux-gnu-4.0.2

The one marked with an asterisk is the one currently used. Now, choose the desired version:

#gcc-config i686-pc-linux-gnu-4.0.2

and then rebuild the whole system..

#emerge -e system && emerge -e world

Don’t forget to also change the cpu type in kernel configuration to pentium-m, and we’re done. Ah yes, do re-compile the kernel..

Results and Discussion:

Many programs failed to compile during the emerge -e world. gcc 4 is more strict when it comes to adhering to the letter of the C/C++ specifications, and that might be the reasons for some kde package and ati-drivers, among many others, failed to compile. As some of the failed to compile packages are essential packages, I chose not to go on with gcc 4.

I need to switch to earlier version of gcc and hope everything to work as normal again. As pentium-m flag works with gcc 3.4 and above, I fall back to gcc 3.4 instead of the original 3.3.6.

#gcc-config i686-pc-linux-gnu-3.4.4
#emerge -e system && emerge -e world

Things compiled flawlessly. I couldn’t find the original program that we used to benchmark my laptop and the other desktop previously, and so I just test if the flag and gcc really boost some speed with glxgears. It managed to get the gears to rotate at 1900+ fps on average, as previously it was only rotating at the average of 1800+ fps. 100 fps (frame per second) increase is not so bad after all.





Comment Form