doc/en_US.ISO8859-1/articles/custom-gcc/article.xml
2013-11-13 07:52:45 +00:00

225 lines
8.4 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE article PUBLIC "-//FreeBSD//DTD DocBook XML V5.0-Based Extension//EN"
"http://www.FreeBSD.org/XML/share/xml/freebsd50.dtd">
<article xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<info><title>Using newer version of <application>GCC</application> and
<application>binutils</application> with the &os; Ports
Collection</title>
<author><personname><firstname>Martin</firstname><surname>Matuska</surname></personname><affiliation>
<address><email>mm@FreeBSD.org</email></address>
</affiliation></author>
<legalnotice xml:id="trademarks" role="trademarks">
&tm-attrib.freebsd;
&tm-attrib.general;
</legalnotice>
<copyright>
<year>2009</year>
<holder>The &os; Documentation Project</holder>
</copyright>
<pubdate>$FreeBSD$</pubdate>
<releaseinfo>$FreeBSD$</releaseinfo>
<abstract>
<para>This article describes how to use newer versions of the
<application>GCC</application> compilers and
<application>binutils</application> from the &os; ports tree.
Custom <application>GCC</application> configurations are also
discussed.</para>
</abstract>
</info>
<sect1 xml:id="intro">
<title>Introduction</title>
<para>The default system compiler as of &os; 8.0 is
<application>GCC</application> version 4.2.1. In addition, the
base system of &os; includes <application>binutils</application>
version 2.15. These versions are several years old and lack,
among other things, support for recent <acronym>CPU</acronym>
instructions like <acronym>SSSE3</acronym>,
<acronym>SSE4.1</acronym>, <acronym>SSE4.2</acronym>, etc.
Due to licensing issues, new versions of these applications will
not be integrated into the base system. Luckily, it is possible
to use a newer version of the <application>GCC</application>
compiler (e.g. version 4.4) with the help of the &os; ports
tree.</para>
</sect1>
<sect1 xml:id="prerequisites">
<title>Prerequisites</title>
<sect2 xml:id="installing-binutils">
<title>Installing binutils from ports</title>
<para>To make use of all of the new features in the latest
<application>GCC</application> versions, the latest version of
<application>binutils</application> needs to be installed.
Installation of the newer version of
<application>binutils</application> is optional; but without it,
there will be no support for new <acronym>CPU</acronym>
instructions.</para>
<para>To install the latest available version of
<application>binutils</application> using the &os; ports tree,
issue the following command:</para>
<screen>&prompt.root; <userinput>cd /usr/ports/devel/binutils &amp;&amp; make install</userinput></screen>
</sect2>
<sect2 xml:id="installing-gcc">
<title>Installing GCC from ports</title>
<para>The &os; ports tree offers several new versions of
<application>GCC</application>. The following example is for
the stable version 4.4. However, it is possible to install
previous or later development versions (e.g.
<package>lang/gcc43</package> or
<package>lang/gcc45</package>).</para>
<para>To install one of the mentioned
<application>GCC</application> ports, run the following
command:</para>
<screen>&prompt.root; <userinput>cd /usr/ports/lang/gcc44 &amp;&amp; make install</userinput></screen>
</sect2>
</sect1>
<sect1 xml:id="configuring-ports-gcc">
<title>Configuring ports for custom version of
<application>GCC</application></title>
<para>Additional system configuration is required in order to use
custom version of <application>GCC</application> installed from
the &os; ports tree.</para>
<sect2 xml:id="adjusting-make.conf">
<title>Adjusting <filename>make.conf</filename></title>
<para>Add the following lines to the
<filename>/etc/make.conf</filename> file (or modify
appropriately):</para>
<programlisting>.if !empty(.CURDIR:M/usr/ports/*) &amp;&amp; exists(/usr/local/bin/gcc44)
CC=gcc44
CXX=g++44
CPP=cpp44
.endif</programlisting>
<para>Alternatively, it is possible to specify the
<envar>${CC}</envar> and <envar>${CPP}</envar> variables
manually.</para>
<note>
<para>The examples above are for <application>GCC</application>
version 4.4. To use <command>gcc43</command>, replace
<literal>"gcc44"</literal> with <literal>"gcc43"</literal> and
<literal>"4.4"</literal> with <literal>"4.3"</literal> and so
on.</para>
</note>
</sect2>
<sect2 xml:id="adjusting-libmap.conf">
<title>Adjusting <filename>libmap.conf</filename></title>
<para>Many of the ports' binaries and libraries link to libgcc_s
or libstdc++. The base system already includes these libraries,
but from an earlier version of <application>GCC</application>
(version 4.2.1). To supply rtld (and ldd) with correct versions,
add the following lines to the
<filename>/etc/libmap.conf</filename> file (or modify
appropriately):</para>
<programlisting>libgcc_s.so.1 gcc44/libgcc_s.so.1
libgomp.so.1 gcc44/libgomp.so.1
libobjc.so.3 gcc44/libobjc.so.2
libssp.so.0 gcc44/libssp.so.0
libstdc++.so.6 gcc44/libstdc++.so.6</programlisting>
<note>
<para>The examples above are for <application>GCC</application>
version 4.4. To use <command>gcc43</command>, replace
<literal>"gcc44"</literal> with <literal>"gcc43"</literal>
and so on. Note also that all of these libraries are fully
backwards compatible with base system libraries.</para>
</note>
<warning>
<para>Some C++ programs may refuse to work if these libraries
are not mapped correctly. If it is not feasible to map them
all, it is recommended to map at least libstdc++.so.</para>
</warning>
</sect2>
<sect2 xml:id="custom-cflags">
<title>Custom <literal>CFLAGS</literal> for the ports tree</title>
<para>To add custom <literal>CFLAGS</literal> for the ports tree
which are unsupported by the base system, adjust the
<filename>/etc/make.conf</filename> according to the following
example:</para>
<programlisting>.if !empty(.CURDIR:M/usr/ports/*) &amp;&amp; exists(/usr/local/bin/gcc44)
CC=gcc44
CXX=g++44
CPP=cpp44
CFLAGS+=-mssse3
.endif</programlisting>
<para>It is possible to completely replace
<literal>CFLAGS</literal> and/or define custom
<literal>CPUTYPE</literal> as well. We recommend setting
<literal>CPUTYPE</literal> because many ports decide their
optimizations flags based on this variable.</para>
</sect2>
<sect2 xml:id="excluding-unbuildable-ports">
<title>Excluding ports that do not build with new version of
<application>GCC</application></title>
<para>To exclude ports that have problems with custom version of
<application>GCC</application>, adjust the
<filename>/etc/make.conf</filename> according to the following
example:</para>
<programlisting>.if !empty(.CURDIR:M/usr/ports/*) &amp;&amp; exists(/usr/local/bin/gcc44)
.if empty(.CURDIR:M/usr/ports/net/openldap*)
CC=gcc44
CXX=g++44
CPP=cpp44
.endif
.endif</programlisting>
<para>The example above excludes the forced use of
<command>gcc</command> 4.4 for the
<package>net/openldap</package>* ports. It is
also possible to specify more ports on a single line:</para>
<programlisting>.if empty(.CURDIR:M/usr/ports/net/openldap*) &amp;&amp; empty(.CURDIR:M/usr/ports/xxx/yyy) &amp;&amp; ...</programlisting>
</sect2>
</sect1>
<sect1 xml:id="performance-imparct">
<title>Impact on the binary performance</title>
<para>Using <application>GCC</application> version 4.4 with
<acronym>SSSE3</acronym> instruction set enabled (if supported by
the <acronym>CPU</acronym>) may yield up to 10% average increase
in binary performance. In certain tests, the results show
more than a 20% performance boost (e.g. in multimedia
processing).</para>
<para>The table located at <uri xlink:href="http://people.freebsd.org/~mm/benchmarks/perlbench/">http://people.freebsd.org/~mm/benchmarks/perlbench/</uri>
shows a comparison of <application>GCC</application> versions
currently available in base &os; system,
<application>GCC</application> version 4.3 and
<application>GCC</application> version 4.4 with various
combinations of <literal>CFLAGS</literal> using the perlbench
benchmark suite.</para>
</sect1>
</article>