intel compiler hint

Robert Connolly robert at linuxfromscratch.org
Mon May 22 12:50:48 PDT 2006


I fixed something else.

robert

On May 22, 2006 03:00 pm, Robert Connolly wrote:
> Hi. I added notes for the -ipo (interprocedural optimizations) option.
> Please update this attached hint.
>
> robert
-------------- next part --------------
AUTHOR:	Robert Connolly <robert at linuxfromscratch dot org> (ashes)
	Daniel Baumann <daniel.baumann at panthera-systems.net>

DATE: 2006-05-22

LICENSE: GNU General Public License

SYNOPSIS: How to build LFS with the Intel C/C++ compiler and code profiling.

PRIMARY URI:
http://www.linuxfromscratch.org/hints/downloads/files/intel-c-compiler.txt

DESCRIPTION:
How to install the Intel C/C++ Compiler for your LFS-system.

PREREQUISITES:
An Intel CPU (Intel-clones/AMD may or may not work).
Glibc (icc is linked to /lib/ld-linux.so.2).

HINT:
The Intel C/C++ compiler collection (ICC) is a full featured compiler and
debugger suite, which is close to compatable with the GNU C/C++ compiler
collection (GCC). ICC is made only for Intel chips, and takes advantage of
Intel technology, such as Hyper-Threading, moreso than GCC does. Software
compiled with ICC is expected to perform better than if it were compiled with
GCC. Because GCC is much more tested than ICC, ICC may produce less stable
programs than GCC would with some packages. Not all packages will build with
ICC, such as X11; maybe they will in the future.

The homepage for the Intel compiler is here:
http://www.intel.com/software/products/compilers/clin/

You should also see:
http://gentoo-wiki.com/HOWTO_ICC_and_Portage

This compiler is not opensource.

This hint will give instructions to build supported software with ICC, so that
as much as possible is using it. ICC will only be installed in chapter 6 since
we will still need GCC for some packages. You can choose to install ICC without
using it to build the LFS system, or build just some packages, it's upto you.
The main reason for using ICC is for performance, so intructions are also
provided to enable profiling; this means compiling packages twice, but they
should run a bit faster. The difference between runtimes of a program compiled
with GCC, compared to ICC with profiling, varies between 2% and 40%.

For even more performance, also see the prelink.txt hint, the optimization.txt
hint (for GCC), the reiser4-on-2.6.txt hint, and (for GCC):

http://www.rocklinux.net/people/clifford/ccbench/
http://blaze.topside.org/~ashes/gcc4/ccbench-20051119.tar.bz2 (for gcc4)

Intel's compiler is only free of charge for non-commercial use. If that is what
you want then go here:

http://www.intel.com/software/products/compilers/clin/noncom.htm

And follow the instructions so that you will be emailed a license file. The
email will also give you a download location for the compressed tarball.

After that you should have two files (the numbers may be different):

l_cc_p_9.0.021.tar.gz
and
noncommercial_cpp_l_N4R8-B2RV9P4B.lic

# INSTALLATION (Tested on LFS-SVN-20051127):

# At the end of chaper 5 we will need to install Cpio, and rpm2cpio.

# Get: ftp://ftp.gnu.org/pub/gnu/cpio/cpio-2.6.tar.gz
# And: http://www.linuxfromscratch.org/patches/downloads/cpio/\
#	cpio-2.6-security_fixes-1.patch

# And install Cpio to /tools:

sed -i -e "s/invalid_arg/argmatch_invalid/" src/mt.c &&
patch -Np1 -i ../cpio-2.6-security_fixes-1.patch &&
./configure CPIO_MT_PROG=mt --prefix=/tools \
	--libexecdir=/tmp --with-rmt=/tools/libexec/rmt &&
echo "#define HAVE_SETLOCALE 1" >> config.h &&
echo "#define HAVE_LSTAT 1" >> config.h &&
make &&
make install

# If you want to install Cpio to an existing system, follow the instructions in:
# http://www.linuxfromscratch.org/blfs/view/svn/general/cpio.html

# Then get: http://www.rpm.org/tools/scripts/rpm2cpio.sh

# And install rpm2cpio to /tools with:

install rpm2cpio.sh /tools/bin/rpm2cpio

# Or change it for /usr.

# Build chapter 6's Glibc, Binutils, and GCC normally. Install ICC after GCC is
# installed in chapter 6 (before Coreutils).

# ICC has a few headers that replace libc headers, so ICC should not be
# installed to /usr. Installing to /opt (or /usr/local) is suggested. Some
# shared libraries are moved to /lib, so that nothing is linked to /opt/lib,
# since any program linked to /opt/lib should live in /opt/bin too.

# Unpack the Intel CC tarball. Then install the ICC compiler:

rpm2cpio intel-icc9-9.0-???.i386.rpm | cpio -id &&
rm -f opt/intel/cc/9.0/bin/uninstall.sh &&
chown -R 0:0 opt/ &&
mv opt/intel/cc/9.0/bin/* /opt/bin &&
mv opt/intel/cc/9.0/doc /opt/doc/icc &&
mv opt/intel/cc/9.0/include/* /opt/include &&
mv opt/intel/cc/9.0/lib/* /opt/lib &&
mv opt/intel/cc/9.0/licenses /opt/doc/icc &&
mv opt/intel/cc/9.0/man/man1/* /opt/man/man1 &&
rm -rf opt/

# Install the ICC headers:

rpm2cpio intel-isubh9-9.0-???.i386.rpm | cpio -id &&
tar -zxf opt/intel/cc/9.0/substitute_headers/libio.tar.gz -C \
	opt/intel/cc/9.0/substitute_headers/ &&
chown -R 0:0 opt/ &&
find opt/intel/cc/9.0/substitute_headers/libio -type d \
	-exec chmod 755 {} \; &&
find opt/intel/cc/9.0/substitute_headers/libio -type f \
	-exec chmod 644 {} \; &&
mv opt/intel/cc/9.0/substitute_headers/libio/* /opt/include &&
rm -rf opt/

# Install the debugger:

rpm2cpio intel-iidb9-9.0-???.i386.rpm | cpio -id &&
rm -f opt/intel/idb/9.0//uninstall.sh &&
chown -R 0:0 opt/ &&
mv opt/intel/idb/9.0//bin/* /opt/bin &&
mv opt/intel/idb/9.0//doc /opt/doc/idb &&
mv opt/intel/idb/9.0//man/man1/* /opt/man/man1 &&
rm -rf opt/

# Install the license file:

install -m644 *_cpp_l_*.lic /opt/doc/icc/licenses

# Rebuild the linker cache file:

ldconfig

# Configure the compiler (you may need to correct your version number of the
# first one):

sed -e 's/<installpackageid>/l_cc_p_9\.0\.021/' \
	-i /opt/doc/icc/csupport

sed -e 's/<INSTALLDIR>\/licenses/\/opt\/doc\/icc\/licenses/g' \
	-e 's/<INSTALLDIR>\/bin/\/opt\/bin/g' \
	-e 's/<INSTALLDIR>\/lib/\/opt\/lib/g' -i /opt/bin/icc

sed -e 's/<INSTALLDIR>\/licenses/\/opt\/doc\/icc\/licenses/g' \
	-e 's/<INSTALLDIR>\/bin/\/opt\/bin/g' \
	-e 's/<INSTALLDIR>\/lib/\/opt\/lib/g' \
	-e 's/<INSTALLDIR>\/man/\/opt\/man/g' -i /opt/bin/iccvars.csh

sed -e 's/<INSTALLDIR>\/licenses/\/opt\/doc\/icc\/licenses/g' \
	-e 's/<INSTALLDIR>\/bin/\/opt\/bin/g' \
	-e 's/<INSTALLDIR>\/lib/\/opt\/lib/g' \
	-e 's/<INSTALLDIR>\/man/\/opt\/man/g' -i /opt/bin/iccvars.sh

sed -e 's/<INSTALLDIR>\/licenses/\/opt\/doc\/icc\/licenses/g' \
	-e 's/<INSTALLDIR>\/bin/\/opt\/bin/g' \
	-e 's/<INSTALLDIR>\/lib/\/opt\/lib/g' -i /opt/bin/icpc

source /opt/bin/iccvars.sh

# If you get "bash: man: command not found", don't worry about it right now.

# Configure the debugger (make sure the version of the first one is correct):

sed -e 's/<INSTALLTIMECOMBOPACKAGEID>/l_cc_p_9\.0\.026/' \
	-i /opt/doc/idb/idbsupport

sed -e 's/<INSTALLDIR>\/licenses/\/opt\/doc\/icc\/licenses/g' \
	-e 's/<INSTALLDIR>\/bin/\/opt\/bin/g' \
	-e 's/<INSTALLDIR>\/man/\/opt\/man/g' -i /opt/bin/idbvars.csh

sed -e 's/<INSTALLDIR>\/licenses/\/opt\/doc\/icc\/licenses/g' \
	-e 's/<INSTALLDIR>\/bin/\/opt\/bin/g' \
	-e 's/<INSTALLDIR>\/man/\/opt\/man/g' -i /opt/bin/idbvars.sh

source /opt/bin/idbvars.sh

# For reasons unknown to me, ICC links to libgcc_s.so. On an LFS system
# libgcc_s.so is in /usr/lib. Incase you have /usr on a seperate partition we
# need to move libgcc_s.so to /lib:

cp /usr/lib/libgcc_s.so.1 /lib/libgcc_s.so.1 &&
ln -s libgcc_s.so.1 /lib/libgcc_s.so &&
rm -f /usr/lib/libgcc_s.so*

# If you plan to use ICC to compile most of the LFS system, the runtime
# library should be moved to /lib:

mv /opt/lib/libimf.so /lib &&
ln -s ../../lib/libimf.so /opt/lib/libimf.so

# Now we can use the Intel compiler. You should read:
# http://gentoo-wiki.com/HOWTO_ICC_and_Portage#CFLAGS

# And figure out your CFLAGS, if you are using CFLAGS. You can't use
# -fomit-frame-pointer or -pipe, and a few others. For the sake of this hint,
# and copy pasting, lets set special ICC CFLAGS now. On my Prescott I use this:

export ICC_CFLAGS="-ip -xP -O3"
export ICC_CXXFLAGS="$ICC_CFLAGS"

# Interprocedural optimizations (IPO) is a fantastic feature which optimizes
# executables at link time. This allows the compiler to make better judgements.
# A similiar option was added to GCC-4.1, -fwhole-program --combine. Using this
# option is a bit touchy though. The -ipo flag can only be used on executables,
# and not static libraries. Almost every package has static libraries which are
# linked into the programs during the build. The HLFS book happens to use the
# -fpie option which has the same requirements. To use the ICC -ipo option, check
# the HLFS book for the sed commands which add -fpie to Makefile.in's. Replace the
# "-pie -fpie" with "-ipo". The sed command for each package is different.
# Unfortunetly these commands are not available for most of the BLFS packages.

# Run this to break GCC compatability (some packages need this):

echo "-no-gcc" >> /opt/bin/icc.cfg

# Libraries compiled with ICC should get -gcc added to CFLAGS, so that
# programs compiled with GCC can use the libraries compiled with ICC.

# INSTALLING PACKAGES (Chapter 6):

# Use the GCC4 patches from LFS.

# For every package built with ICC make sure to run the testsuite because this
# is still expirmental. If one or more tests fail, retry with GCC. If the
# results are better with GCC, then use GCC.

# Don't worry about:
# "icc: warning: PGOPTI instrumentation disables IP optimizations"
# This warning is given when using -ip (-fomit-frame-pointer) while generating
# code profiles. -ip will work with the second build.

# To keep this hint shorter, I won't give complete instructions for every
# package, but I'll give notes where needed.

# To use ICC profiling we need to add "-prof_gen" and "-prof_dir=$(pwd)" to
# CFLAGS/CXXFLAGS for the first build. Then run 'make check' in order to run the
# programs and generate profiling data. If you are able to run the programs better
# than how 'make check' does, then I suggest you do that. Then 'make clean', and
# make again with "-prof_use". You can run 'make check' again if you like, and
# finally 'make install'.

# In general, use this:

env CFLAGS="$ICC_CFLAGS -prof_gen -prof_dir=$(pwd)" \
	CXXFLAGS="$ICC_CXXFLAGS -prof_gen -prof_dir=$(pwd)" LC_ALL="C" \
        LANG="en" LANGUAGE="en" CC="icc" CXX="icpc" ./configure...

# Then 'make && make check && make clean', and final build with:

env CFLAGS="$ICC_CFLAGS -prof_use -prof_dir=$(pwd)" \
	CXXFLAGS="$ICC_CXXFLAGS -prof_use -prof_dir=$(pwd)" LC_ALL="C" \
	LANG="en" LANGUAGE="en" CC="icc" CXX="icpc" ./configure...

# Then 'make && make install'.

# DB can not be compiled with ICC.

# Coreutils can compile with ICC profiling.

# Zlib can compile with ICC, but X11 will not be able to link to it, so I do not
# suggest it.

# Mktemp can compile with ICC profiling.

# Iana-Etc has no C/C++ code.

# Findutils can be compiled with ICC profiling.

# Gawk can compile with ICC profiling.

# Ncurses can compile with ICC profiling. We add the -gcc flag because Ncurses
# is a library. Ncurses also has C++ code, so CXX flags are also added.

# Readline can compile with ICC profiling, and because it is a library -gcc
# needs to be added to CFLAGS.

# Vim can compile with ICC profiling.

# M4 can compile with ICC profiling.

# Bison can compile with ICC profiling.

# Less can compile with ICC profiling.

# Groff can compile with ICC profiling.

# Sed can compile with ICC profiling.

# Flex can compile with ICC profiling.

# Gettext can compile with ICC profiling, but because it's a library add -gcc.

# Inetutils can compile with ICC profiling.

# For Iproute2 do (Iproute2 needs -gcc):

sed -e 's/gcc/icc/g' -i Makefile &&
sed -e "s|^CCOPTS .*$|& $ICC_CFLAGS -gcc -prof_gen -prof_dir=/tmp|" \
	-i Makefile

# Then 'make' and 'make clean', and:

sed -e 's/prof_gen/prof_use/g' -i Makefile

# And 'make' and 'make install'.

# Warning! Building Perl with profiling has frozen my desktop, beware.
# Perl can compile with ICC profiling. After 'make distclean' you will have to
# run ./configure again, substituting -prof_gen with -prof_use.

# Texinfo can compile with ICC profiling.

# Autoconf and Automake are scripts, and do not need to be compiled with ICC.

# Bash compiles with ICC but will crash at runtime. Do not compile Bash with
# ICC.

# File can compile with ICC profiling.

# Libtool can compile with ICC profiling.

# For Bzip2 do this after applying the patches (add -gcc to the library):

sed -e 's|gcc|icc|g' -i Makefile* &&
sed -e "s|^CFLAGS.*$|& $ICC_CFLAGS -prof_gen -prof_dir=/tmp|g" -i Makefile &&
sed -e "s|^CFLAGS.*$|& $ICC_CFLAGS -prof_gen -prof_dir=/tmp -gcc|g" \
	-i Makefile-libbz2_so

# After 'make clean':

make &&
make -f Makefile-libbz2_so clean &&
sed -e 's/prof_gen/prof_use/g' -i Makefile* &&
make -f Makefile-libbz2_so &&
make clean

# Then run 'make' and 'make install'.

# Diffutils can compile with ICC profiling.

# - For Kbd, after running ./configure, make like this:

make CC="icc" CFLAGS="$ICC_CFLAGS -prof_gen -prof_dir=$(pwd)" &&
make clean &&
make CC="icc" CFLAGS="$ICC_CFLAGS -prof_use -prof_dir=$(pwd)"

# E2fsprogs can compile with ICC profiling. We have to re-run ./configure
# like with Perl, substituting -prof_gen with -prof_use on the second pass.

# Grep can compile with ICC profiling.

# Grub does not compile with ICC.

# Gzip can compile with ICC profiling.

# Hotplug has no C code.

# Man doesn't do profiling, but can compile with ICC:

make CC="icc" CFLAGS="$ICC_CFLAGS"

# Make can compile with ICC profiling.

# - For Module-init-tools you will need to use a patch to disable the static
# linking of insmod:
# http://www.linuxfromscratch.org/patches/downloads/module-init-tools/\
#	module-init-tools-3.2.1-nostatic-1.patch

# Module-init-tools can compile with ICC profiling.

# Patch can compile with ICC profiling.

# Procps does not compile with ICC.

# Psmisc can compile with ICC profiling.

# Shadow can compile with ICC profiling.

# Sysklogd doesn't do profiling, but can compile with ICC:

make CC="icc" CFLAGS="-DSYSV $ICC_CFLAGS"

# Sysvinit doesn't do profiling, but can compile with ICC:

make -C src CC="icc" CFLAGS="$ICC_CFLAGS -D_GNU_SOURCE"

# Tar can compile with ICC profiling.

# Udev does not compile with ICC.

# Util-linux needs GCC for mkfs.minix.

# There is a project to compile the Linux kernel with ICC:

# http://www.pyrillion.org/linuxkernelpatch.html

# But I couldn't get it to work, and the advantages are minimal (about 2%).

# After LFS is installed do this:

echo "source /opt/bin/idbvars.sh" >> /etc/profile
echo "source /opt/bin/iccvars.sh" >> /etc/profile
echo 'export ICC_CFLAGS="-ip -xP -O3"' >> /etc/profile
echo 'export ICC_CXXFLAGS="$ICC_CFLAGS"' >> /etc/profile
source /etc/profile

# Your system should now be running like lightning :-)

# Beyond LFS packages which compile with ICC:

# OpenSSL

# For OpenSSL can compile with ICC profiling. After ./config, and before make:

sed -e 's|gcc|icc|g' \
	-e 's/-fomit-frame-pointer//g' \
	-e 's/-mcpu=pentium//g' \
	-e 's/-O3//g' \
	-e "s|^CFLAG.*$|& $ICC_CFLAGS -gcc -prof_gen -prof_dir=/tmp|" \
	-i Makefile

# 'make...' ane 'make clean', then:

sed -e 's/prof_gen/prof_use/' -i Makefile

# And run 'make' again, and install OpenSSL.

# OpenSSH can compile with ICC profiling.

# LibPNG can compile with ICC, but X11 won't be able to link to it. If you
# still want to compile LibPNG with ICC (for console Lynx):

make prefix=/usr ZLIBINC= ZLIBLIB= CC=icc CFLAGS="$ICC_CFLAGS -gcc" \
    ZLIBLIB= -f scripts/makefile.linux

# Freetype doesn't compile with profiling, but can compile with ICC.

# Expat doesn't compile with profiling, but can compile with ICC. Add -gcc
# to CFLAGS.

# Fontconfig can compile with ICC profiling.

# X11 does not compile with ICC (yet).

# Jpeg-6b can compile with ICC profiling. Add -gcc to CFLAGS and because this
# is a library.

# LCMS can compile with ICC profiling. Add -gcc to CFLAGS because of the
# library.

# LibMNG can compile with ICC.

make CC=icc CFLAGS="$ICC_CFLAGS -gcc"

# QT supports ICC. Before ./configure:

sed -e "s|^QMAKE_CFLAGS_RELEASE.*$|& $ICC_CFLAGS|" \
	-i mkspecs/linux-icc/qmake.conf

# Then add "-platform linux-icc -thread" to the ./configure command.

# Pkgconfig can compile with ICC profiling.

# Glib2 can compile with ICC profiling. Add -gcc to CFLAGS/CXXFLAGS.

# Libogg can compile with ICC profiling. Add -gcc to CFLAGS/CXXFLAGS.

# Libvorbis does not compile with ICC.

# Alsa-lib doesn't compile with profiling, but does compile with ICC.

# Alsa-utils can compile with ICC profiling.

# Audiofile can compile with ICC profiling. Add -gcc to CFLAGS/CXXFLAGS.

# Libmad can compile with ICC profiling. Add -gcc to CFLAGS/CXXFLAGS.

# Arts supports ICC, but the newest version of ICC does not build the latest
# stable release of Arts. So, for now, it doesn't work. I emailed KDE about it,
# after trying to build an Arts snapshot.

# Libart_lgpl does not compile with ICC.

# Wget can compile with ICC profiling.

# Libxml2 can compile with ICC profiling. Add -gcc to CFLAGS/CXXFLAGS.

# Libxslt can compile with ICC profiling. Add -gcc to CFLAGS/CXXFLAGS.

# KDE does not compile with ICC.

# Zip compiles with ICC:

sed -e 's|gcc|icc|g' -i unix/Makefile

# And use "generic_icc" as the make target.

# Unzip compiles with ICC. Run this after applying the patches:

sed -e 's|gcc|icc|g' -i unix/Makefile

# Cpio can compile with ICC profiling.

# Tcsh can compile with ICC profiling.

# GnuPG can compile with ICC profiling.

# LibIDL can compile with ICC profiling.

# Others:

# Glib
# Gtk
# Pango
# Atk
# Gtk2
# Libogg
# Libxml
# Libxst
# Audiofile
# Libmad
# Which
# GnuPG
# Cdparanoia
# Libungif
# Giflib
# Imlib2
# Aalib
# SDL
# Libdvdcs
# Libdvdread
# Xvidcore
# Lzo

# Lame
# If Lame is compiled with ICC it will cause problems with other packages, like
# FFmpeg, which try to link to libmp3lame. This package should be compiled with
# GCC.

# Xine-lib
# Popt
# Libao
# Flac123
# Wget
# Cvs
# Ncftp
# Subversion
# Ntp
# Lynx
# Bind-utils
# Vorbis-tools
# Mpg123

# For Mpg123 do:

sed -e 's at gcc@/opt/bin/icc at g' -i Makefile

# LibIDL

# Vorbisgain
# Libaal
# Reiser4progs
# Cdrtools

# For Cdrtools do:

sed -e "s/-O/$ICC_CFLAGS/" -i RULES/i586-linux-cc.rul

# And add "CC=/opt/bin/icc" to the make command.

# Irssi

# And more...

ACKNOWLEDGMENTS:
	* Thanks to Daniel Baumann for the original hint.
	* Thanks to Gentoo for their wiki page:
		http://gentoo-wiki.com/HOWTO_ICC_and_Portage

CHANGELOG:
[2005-06-25]
	* Adopted hint.
[2005-06-26]
	* Added more supported packages.
[2005-07-04]
	* It can reboot now.
[2005-12-08]
	* New Intel CC version.
	* New Cpio security patch.
	* Point Cpio to the correct location of rmt in /tools.
	* Use icpc for CXX.
	* Several more packages compile now.
	* Added instructions to profile code.
	* Added -gcc for Iproute2.
[2006-05-19]
	* Run 'make check' after building with prof_gen, to generate profiling data.
[2006-05-22]
	* Added notes for the -ipo option.


More information about the hints mailing list