Gentoo Wiki ArchivesGentoo Wiki

HOWTO_ICC_and_Portage

This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc
Wikipedia has an article on:
Intel C++ Compiler

Intel's C/C++ compiler, icc, can be used as an alternative to GNU's compiler, gcc. The main benefit of using icc instead of gcc is its ability to optimize, especially for Intel CPUs. The main downside to using icc is its incompatibility with some code written specifically with gcc in mind. For instance, sys-libs/glibc and other system critical components cannot be compiled with icc. It is not possible to completely replace gcc with icc at this time. After following this guide, your system will still compile packages with gcc by default. Only prespecified packages will be compiled with icc.

dev-lang/icc is available through Portage. It does, in fact, require a license, but a free non-commercial license is available.

Just because you don't own an Intel CPU doesn't mean this HOWTO doesn't apply to you. With a bit of reverse engineering (not on our part), and a clever Perl script, we can make icc produce lovely machine code for AMD CPUs also.

Contents


Caveats

Binaries compiled with icc won't work after icc is uninstalled

Binaries compiled with icc are dynamically linked to icc libraries. Therefore, if icc is uninstalled, binaries compiled with icc will not work. Before uninstalling icc, all binaries compiled with icc should be recompiled with gcc.

icc cannot compile all packages in Portage

icc and gcc have different levels of tolerance in what code is considered valid. Some packages have been written using gcc-specific extensions cannot be compiled with icc. Compilation of these packages using icc will result in a compile error. System critical components should not be compiled with icc. If glibc is miscompiled (e.g., in a way different from how gcc would compile it) it could render the system useless.

Critical system packages that should not be compiled with icc are

app-shells/bash
sys-apps/sed
sys-devel/binutils
sys-devel/gcc
sys-libs/glibc
sys-libs/ncurses
sys-libs/libstdc++-v3
sys-libs/zlib
sys-process/procps

Installation

Simply emerge it.

emerge icc

You also need to get a license. For the purposes of this guide, we'll get a free non-commercial license. Click 'Free non-commercial Download' on Intel's Linux Compiler page. Follow the steps on the site and place your license file in /opt/intel/licenses/.

Portage Integration

/etc/make.conf

Add your icc CFLAGS to /etc/make.conf. See discussion of icc specific CFLAGS later.

File: /etc/make.conf
ICCCFLAGS="-O2 -xT -gcc"
ICCCXXFLAGS="${ICCCFLAGS}"

/etc/portage/bashrc

/etc/portage/bashrc will tell Portage which compiler to compile a package with.

File: /etc/portage/bashrc
[ -r ${ROOT}/etc/portage/package.icc ] || return 0
while read -a target; do
  if [ "${target}" = "${CATEGORY}/${PN}" ]; then
    export OCC="icc"
    export OCXX="icpc"
    export CFLAGS=${ICCCFLAGS}
    export CXXFLAGS=${ICCCXXFLAGS}
    if [ -r ${ROOT}/etc/portage/package.icc-cflags ]; then
      while read target flags; do
        if [ "${target}" = "${CATEGORY}/${PN}" ]; then
          export CFLAGS="$flags"
          export CXXFLAGS="$CFLAGS"
          break
        fi
      done < ${ROOT}/etc/portage/package.icc-cflags
    fi

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

if [ -r ${ROOT}/etc/portage/package.gcc-cflags ]; then
  while read target flags; do
    if [ "${target}" = "${CATEGORY}/${PN}" ]; then
      export CFLAGS="$flags"
      export CXXFLAGS="$CFLAGS"
      break
    fi
  done < ${ROOT}/etc/portage/package.gcc-cflags
fi

if [ "${OCC}" != "" ]; then
  export CC_FOR_BUILD="${OCC}" #workaround gcc detection function in toolchain-funcs.eclass
fi

Here's another version of a working /etc/portage/bashrc. Use this one, if you want to use icc by default and just switch to gcc where necessary by adding those packages to /etc/portage/package.gcc.

File: /etc/portage/bashrc
export GCC=${OCC}
export GCXX=${OCXX}
export OCC="icc"
export OCXX="icpc"
export CFLAGS=${ICCCFLAGS}
export CXXFLAGS=${ICCCXXFLAGS}

[ -r ${ROOT}/etc/portage/package.gcc ] || return 0
while read -a target; do
  if [ "${target}" = "${CATEGORY}/${PN}" ]; then
    export OCC=${GCC}
    export OCXX=${GCXX}
    export CFLAGS="$flags"
    export CXXFLAGS="$CFLAGS"
    if [ -r ${ROOT}/etc/portage/package.gcc-cflags ]; then
      while read target flags; do
        if [ "${target}" = "${CATEGORY}/${PN}" ]; then
          export CFLAGS="$flags"
          export CXXFLAGS="$CFLAGS"
          break
        fi
      done < ${ROOT}/etc/portage/package.gcc-cflags
    fi

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

if [ -r ${ROOT}/etc/portage/package.icc-cflags ]; then
  while read target flags; do
    if [ "${target}" = "${CATEGORY}/${PN}" ]; then
      export CFLAGS="$flags"
      export CXXFLAGS="$CFLAGS"
      break
    fi
  done < ${ROOT}/etc/portage/package.icc-cflags
fi

if [ "${OCC}" != "" ]; then
  export CC_FOR_BUILD="${OCC}" #workaround gcc detection function in toolchain-funcs.eclass
fi

unset GCC
unset GCXX

/etc/portage/package.icc

/etc/portage/package.icc will store the names of all the packages that should be compiled with icc. If a package is not listed in this file, it will be compiled with gcc.

Here's a list of packages that work well with icc.

File: /etc/portage/package.icc
dev-lang/python
dev-db/sqlite
dev-libs/libxml2
app-arch/tar
app-arch/bzip2
app-arch/gzip
app-arch/unzip
app-arch/cpio
sys-power/powertop
media-libs/x264-svn
media-sound/lame
media-libs/faac
media-libs/giflib
media-libs/speex
media-libs/libtheora
media-libs/xvid
media-libs/libogg
media-libs/libvorbis
dev-libs/lzo
net-irc/xchat
media-libs/freetype
dev-libs/glib
x11-libs/gtk+
media-libs/libpng
dev-libs/libgpg-error
media-gfx/gimp

/etc/portage/package.icc-cflags

/etc/portage/package.icc-cflags provides per-package CFLAGS for packages compiled with icc. A few packages benefit greatly from the -O3 flag. Put them in this file.

File: /etc/portage/package.icc-cflags
dev-db/sqlite -O3 -xT -gcc
dev-lang/python -O3 -xT -gcc

/etc/portage/package.gcc-cflags

The /etc/portage/bashrc file even allows us to have per-package CFLAGS for gcc too. Add your packages and CFLAGS to /etc/portage/package.gcc-cflags in the same format as /etc/portage/package.icc-cflags. Note: There is no /etc/portage/package.gcc as packages are build with gcc by default.

Finishing up

After you've created/edited these files remember to run

env-update
source /etc/profile

icc CFLAGS

For a complete list of icc CFLAGS, check

man icc

icc supports many of the same CFLAGS as gcc, so many should look familiar. It is also very forgiving. That is, if a package passes a CFLAG to icc that it doesn't recognize, it will warn and move on.

-Ox

Same behavior as gcc. x is one of the following options

Note: "-O" is the same as "-O2"

-xX

To specify a specific processor type to optimize for, pass -xX where X is one of the following options.

K - Generate SSE code
W - Generate SSE2 code
P - Generate SSE3 code
T - Generate SSSE3 code
S - Generate SSE4 code

The -x CFLAG generates specialized code to run exclusively on processors indicated by X. To generate generic code in addition to specialized code, use -axX where X is one of the previous options.

-ip[o]

The -ip flag enables Interprocedural Optimizations such as function inlining, dead code elimination, etc. This flag is recommended, but may not work with all packages. If a package is found that does not compile with this flag, add the package and its CFLAGS minus -ip to packages.icc-cflags.

The -ipo flag enables multifile Interprocedural Optimizations. Many packages do not compile with this flag. Add a package to package.icc-cflags with CFLAGS including -ipo to test.

-gcc

The -gcc CFLAG causes icc to generate code compatible with gcc. This is highly recommended, especially for libraries.

Uncripple icc on AMD CPUs

icc generates code that detects the brand of processor on which it is executing. On Intel CPUs, the binary will execute with SSE instructions, whereas it will execute 386 level instructions on AMD CPUs regardless of availability of SSE instruction sets.

(Note: the next website and the patch doesn't exist anymore) --> To make icc produce binaries that execute SSE code on AMD CPUs, use the patches found here. Use the patches that patch the compiler. It's not clear if this is a violation of the EULA, so do it at your own risk. Otherwise, you can manually patch all icc produced executables. To patch, run the Perl script found on the said website in the lib/ directory of your icc installation. It's usually /opt/intel/cce/your_version/lib.

It does exists another utility called `patch-AuthenticAMD' that does the same, to patch binaries generated by the Intel C++ compiler to get the maximum performance on AMD CPUs. It can be found here.

Common Problems

System cannot boot due to missing icc libraries

icc is installed to /opt. If /opt happens to be on a different partition than the root partition, any system tools needed to boot the system will not function before /opt is mounted. For instance, if /bin/mount has been compiled with icc, it will be unable to execute which prevents any other partitions from mounting.

The solution is to copy the icc libraries to /lib.

C compiler cannot create executables

Your license file probably cannot be found. Try to execute

icc

It will tell you if this is the case. If it is not, double check your CFLAGS.

Could not open source file limits.h

When compiling programs whose source include limits.h, you may encounter the following error.

/usr/include/gentoo-multilib/amd64/limits.h(125): catastrophic error: could not open source file "limits.h"
 # include_next <limits.h>
                          ^ 

A fix has been found, but it has not been thoroughly tested.

File: /opt/intel/cce/10.1.017/bin/icc.cfg
-idirafter /usr/include/linux

Mixed success is experienced when compiling PHP with dev-lang/icc-10.1.017 or later without this fix.

Linking fails with QT

icc version 10.1.017 reorders arguments to the linker, breaking the compilation of Qt-4.3.3. As an example the option -Qoption,ld,--dynamic-list,src/gui/QtGui.dynlist is split so that the argument to --dynamic-list does not appear immediately after it. As a work-around, obtain a trace using strace -o log -F -f -s 4000 and re-order the arguments to ld and run the command manually.

References

Links

Retrieved from "http://www.gentoo-wiki.info/Intel_C%2B%2B_Compiler"

Last modified: Fri, 12 Sep 2008 06:04:00 +1000 Hits: 75,025

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.