aboutsummaryrefslogtreecommitdiff
path: root/en_US.ISO8859-1/articles/custom-gcc/article.sgml
blob: 1df19d7ebd0984a19f0742f57ad1c568eb0bc63f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<!DOCTYPE article PUBLIC "-//FreeBSD//DTD DocBook XML V4.2-Based Extension//EN"
	"../../../share/sgml/freebsd42.dtd" [
<!ENTITY % entities PUBLIC "-//FreeBSD//ENTITIES DocBook FreeBSD Entity Set//EN" "../../share/sgml/entities.ent">
%entities;
]>

<article lang='en'>
  <articleinfo>
    <title>Using newer version of <application>GCC</application> and
      <application>binutils</application> with the &os; Ports
      Collection</title>

    <author>
      <firstname>Martin</firstname>
      <surname>Matuska</surname>
      <affiliation>
	<address><email>mm@FreeBSD.org</email></address>
      </affiliation>
    </author>

    <legalnotice 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>
  </articleinfo>

  <sect1 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 id="prerequisites">
    <title>Prerequisites</title>

    <sect2 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 && make install</userinput></screen>
    </sect2>

    <sect2 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.
	<filename role="package">lang/gcc43</filename> or
	<filename role="package">lang/gcc45</filename>).</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/<replaceable>gcc44</replaceable> && make install</userinput></screen>
    </sect2>
  </sect1>

  <sect1 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 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/*) && 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 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 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/*) && 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 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/*) && 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
	<filename role="package">net/openldap</filename>* ports.  It is
	also possible to specify more ports on a single line:</para>

      <programlisting>.if empty(.CURDIR:M/usr/ports/net/openldap*) && empty(.CURDIR:M/usr/ports/xxx/yyy) && ...</programlisting>
    </sect2>
  </sect1>

  <sect1 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 <ulink
	url="http://people.freebsd.org/~mm/benchmarks/perlbench/"></ulink>
      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>