⬆️ ⬇️

Using alternative compilers in Gentoo using the Intel Compiler Suite example

In this article I want to tell you how to use Gentoo and other portage-based distributions to build packages using a compiler other than gcc.

The choice of alternative compilers is extensive: Intel Compiler Suite, Sun Studio Express Compilers, TenDRA C / C ++ Compiler, Tiny C Compiler and other lightweight compilers.

I will consider the transition to the most popular (AFAIK) alternative compiler - icc.

You may ask: why is it even necessary? The fact is that icc optimizes code for execution on Intel processors better than gcc.

Compare yourself:

test programbunzip2 linux-2.6.32.tar.bz2bzip2 linux-2.6.32.taroggenc -q5 testfile.wavlame -V4 testfile.wav
average lead time (gcc)22.11891.452108.55498.438
average lead time (icc)20.37368.28488.58184.626
speed increase8.5%33.9%22.5%16.3%


Agree, very good results.

Configuration of the computer on which the test was made: Intel Core 2 Duo T7250 @ 2.00 GHz; linux 2.6.31-gentoo-r7 x86; gcc-4.4.2; icc-11.1.056; All tests were performed in tmpfs - section, so as not to sin on the speed of i / o.



Installation



If you are ready, proceed with the installation.

# emerge icc

icc requires a license for its work, we will use the free non-commercial option, which can be obtained here . When you get the .lic file, put it in / opt / intel / licenses.



Configure portage



Immediately I warn you that some applications are not going to icc, and some are going to, but do not work, although the icc developers strive to make it as compatible as possible with gcc. Therefore, it cannot be said that the compiler change will be complete - something can only be collected by gcc, and we will not abandon it. We have two options: compile all icc, and separate applications - gcc, or vice versa, leave the main compiler gcc, and icc build only some programs. It’s up to you to decide which one to choose - if you can’t afford to poke around for a long time in the system, or just don’t want any extra problems, then you are more likely to accept the second option; if you have enough free time and / or desire to try something new, then your first option.



The first option: the main compiler - icc, additional - gcc


')

We assume that the flags for icc in make.conf are defined as ICCCFLAGS and ICCCXXFLAGS (as CFLAGS and CXXFLAGS for gcc); the list of packages that gcc needs to build is in /etc/portage/package.gcc; Special flags for individual packages are in /etc/portage/package.gcc-cflags and /etc/portage/package.icc-cflags.

The current compiler is defined in the OCC and OCXX environment variables — so we change them.

To do this, create a script / etc / portage / bashrc with the following content:



export GCC=${OCC} #

export GCXX=${OCXX}

export OCC="icc" #

export OCXX="icpc"

export GCCCFLAGS=${CFLAGS} #

export GCCCXXFLAGS=${CXXFLAGS}

export CFLAGS=${ICCCFLAGS} #

export CXXFLAGS=${ICCCXXFLAGS}



[ -r ${ROOT}/etc/portage/package.gcc ] || return 0

while read -a target; do

if [ "${target}" = "${CATEGORY}/${PN}" ]; then # /etc/portage/package.gcc,

export OCC="${GCC}" #

export OCXX="${GCXX}"

export CFLAGS="${GCCCFLAGS}" #

export CXXFLAGS="${GCCCXXFLAGS}"

if [ -r ${ROOT}/etc/portage/package.gcc-cflags ]; then # /etc/portage/package.gcc-cflags,

while read target flags; do

if [ "${target}" = "${CATEGORY}/${PN}" ]; then

export CFLAGS="$CFLAGS $flags" #

export CXXFLAGS="$CXXFLAGS $flags"

break

fi

done < ${ROOT}/etc/portage/package.gcc-cflags

fi

return 0

fi

done < ${ROOT}/etc/portage/package.gcc



if [ -r ${ROOT}/etc/portage/package.icc-cflags ]; then # icc

while read target flags; do

if [ "${target}" = "${CATEGORY}/${PN}" ]; then

export CFLAGS="$CFLAGS $flags"

export CXXFLAGS="$CXXFLAGS $flags"

break

fi

done < ${ROOT}/etc/portage/package.icc-cflags

fi



export CC_FOR_BUILD="${OCC}" # workaround



unset GCC

unset GCXX

unset GCCCFLAGS

unset GCCCXXFLAGS





The second option: the main compiler - gcc, additional - icc


Similar to the previous case, only here is a list of packages collected by icc in /etc/portage/package.icc



[ -r ${ROOT}/etc/portage/package.icc ] || return 0

while read -a target; do

if [ "${target}" = "${CATEGORY}/${PN}" ]; then # /etc/portage/package.icc,

export OCC="icc" #

export OCXX="icpc"

export CFLAGS="${ICCCFLAGS}" #

export CXXFLAGS="${ICCCXXFLAGS}"

if [ -r ${ROOT}/etc/portage/package.icc-cflags ]; then # /etc/portage/package.icc-cflags,

while read target flags; do

if [ "${target}" = "${CATEGORY}/${PN}" ]; then

export CFLAGS="$CFLAGS $flags" #

export CXXFLAGS="$CXXFLAGS $flags"

break

fi

done < ${ROOT}/etc/portage/package.icc-cflags

fi

export CC_FOR_BUILD="${OCC}" # workaround

return 0

fi

done < ${ROOT}/etc/portage/package.icc



if [ -r ${ROOT}/etc/portage/package.gcc-cflags ]; then # gcc

while read target flags; do

if [ "${target}" = "${CATEGORY}/${PN}" ]; then

export CFLAGS="$CFLAGS $flags"

export CXXFLAGS="$CXXFLAGS $flags"

break

fi

done < ${ROOT}/etc/portage/package.gcc-cflags

fi

fi





Everything! Your system is ready to build packages with the new compiler.



Advantages and disadvantages





A plus


One, but fat. Noticeable acceleration of processor-intensive processes - (de) audio / video encoding, (de) encryption, etc.



Minuses


1. Incomplete compatibility with gcc. Some programs are not going to icc, some are going, but not working. For example, programs that use the LZMA algorithm (xz-utils, p7zip) are assembled, but they do not unpack the archives — they are broken. I am sure that this is not the only example.

2. icc links the executables with their own libraries, and if for any reason you decide to remove it, you will have to recompile all the packages it has assembled.

3. icc is closed. For some, this is not a minus, but agree that the opening of its source would not harm anyone (except Intel, of course).



Conclusion



I want to say that switching to other compilers is no different in essence - in the script you just need to change the icc to the selected compiler.



I hope that this article will be useful to you.



PS Thanks gribozavr for an invite!

Source: https://habr.com/ru/post/83324/



All Articles