aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.8/INSTALL/build.html
blob: aaae4c4d2eeeff6473cf775f1504a331d6e898be (plain)
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<html lang="en">
<head>
<title>Installing GCC: Building</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Installing GCC: Building">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="top" href="#Top">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988-2013 Free Software Foundation, Inc.

   Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, the Front-Cover texts being (a) (see below), and
with the Back-Cover Texts being (b) (see below).  A copy of the
license is included in the section entitled "GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

     A GNU Manual

(b) The FSF's Back-Cover Text is:

     You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development.-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<h1 class="settitle">Installing GCC: Building</h1>
<a name="index-Installing-GCC_003a-Building-1"></a>
Now that GCC is configured, you are ready to build the compiler and
runtime libraries.

   <p>Some commands executed when making the compiler may fail (return a
nonzero status) and be ignored by <samp><span class="command">make</span></samp>.  These failures, which
are often due to files that were not found, are expected, and can safely
be ignored.

   <p>It is normal to have compiler warnings when compiling certain files. 
Unless you are a GCC developer, you can generally ignore these warnings
unless they cause compilation to fail.  Developers should attempt to fix
any warnings encountered, however they can temporarily continue past
warnings-as-errors by specifying the configure flag
<samp><span class="option">--disable-werror</span></samp>.

   <p>On certain old systems, defining certain environment variables such as
<samp><span class="env">CC</span></samp> can interfere with the functioning of <samp><span class="command">make</span></samp>.

   <p>If you encounter seemingly strange errors when trying to build the
compiler in a directory other than the source directory, it could be
because you have previously configured the compiler in the source
directory.  Make sure you have done all the necessary preparations.

   <p>If you build GCC on a BSD system using a directory stored in an old System
V file system, problems may occur in running <samp><span class="command">fixincludes</span></samp> if the
System V file system doesn't support symbolic links.  These problems
result in a failure to fix the declaration of <code>size_t</code> in
<samp><span class="file">sys/types.h</span></samp>.  If you find that <code>size_t</code> is a signed type and
that type mismatches occur, this could be the cause.

   <p>The solution is not to use such a directory for building GCC.

   <p>Similarly, when building from SVN or snapshots, or if you modify
<samp><span class="file">*.l</span></samp> files, you need the Flex lexical analyzer generator
installed.  If you do not modify <samp><span class="file">*.l</span></samp> files, releases contain
the Flex-generated files and you do not need Flex installed to build
them.  There is still one Flex-based lexical analyzer (part of the
build machinery, not of GCC itself) that is used even if you only
build the C front end.

   <p>When building from SVN or snapshots, or if you modify Texinfo
documentation, you need version 4.7 or later of Texinfo installed if you
want Info documentation to be regenerated.  Releases contain Info
documentation pre-built for the unmodified documentation in the release.

<h3 class="section"><a name="TOC0"></a>Building a native compiler</h3>

<p>For a native build, the default configuration is to perform
a 3-stage bootstrap of the compiler when &lsquo;<samp><span class="samp">make</span></samp>&rsquo; is invoked. 
This will build the entire GCC system and ensure that it compiles
itself correctly.  It can be disabled with the <samp><span class="option">--disable-bootstrap</span></samp>
parameter to &lsquo;<samp><span class="samp">configure</span></samp>&rsquo;, but bootstrapping is suggested because
the compiler will be tested more completely and could also have
better performance.

   <p>The bootstrapping process will complete the following steps:

     <ul>
<li>Build tools necessary to build the compiler.

     <li>Perform a 3-stage bootstrap of the compiler.  This includes building
three times the target tools for use by the compiler such as binutils
(bfd, binutils, gas, gprof, ld, and opcodes) if they have been
individually linked or moved into the top level GCC source tree before
configuring.

     <li>Perform a comparison test of the stage2 and stage3 compilers.

     <li>Build runtime libraries using the stage3 compiler from the previous step.

   </ul>

   <p>If you are short on disk space you might consider &lsquo;<samp><span class="samp">make
bootstrap-lean</span></samp>&rsquo; instead.  The sequence of compilation is the
same described above, but object files from the stage1 and
stage2 of the 3-stage bootstrap of the compiler are deleted as
soon as they are no longer needed.

   <p>If you wish to use non-default GCC flags when compiling the stage2
and stage3 compilers, set <code>BOOT_CFLAGS</code> on the command line when
doing &lsquo;<samp><span class="samp">make</span></samp>&rsquo;.  For example, if you want to save additional space
during the bootstrap and in the final installation as well, you can
build the compiler binaries without debugging information as in the
following example.  This will save roughly 40% of disk space both for
the bootstrap and the final installation.  (Libraries will still contain
debugging information.)

<pre class="smallexample">     make BOOT_CFLAGS='-O' bootstrap
</pre>
   <p>You can place non-default optimization flags into <code>BOOT_CFLAGS</code>; they
are less well tested here than the default of &lsquo;<samp><span class="samp">-g -O2</span></samp>&rsquo;, but should
still work.  In a few cases, you may find that you need to specify special
flags such as <samp><span class="option">-msoft-float</span></samp> here to complete the bootstrap; or,
if the native compiler miscompiles the stage1 compiler, you may need
to work around this, by choosing <code>BOOT_CFLAGS</code> to avoid the parts
of the stage1 compiler that were miscompiled, or by using &lsquo;<samp><span class="samp">make
bootstrap4</span></samp>&rsquo; to increase the number of stages of bootstrap.

   <p><code>BOOT_CFLAGS</code> does not apply to bootstrapped target libraries. 
Since these are always compiled with the compiler currently being
bootstrapped, you can use <code>CFLAGS_FOR_TARGET</code> to modify their
compilation flags, as for non-bootstrapped target libraries. 
Again, if the native compiler miscompiles the stage1 compiler, you may
need to work around this by avoiding non-working parts of the stage1
compiler.  Use <code>STAGE1_TFLAGS</code> to this end.

   <p>If you used the flag <samp><span class="option">--enable-languages=...</span></samp> to restrict
the compilers to be built, only those you've actually enabled will be
built.  This will of course only build those runtime libraries, for
which the particular compiler has been built.  Please note,
that re-defining <samp><span class="env">LANGUAGES</span></samp> when calling &lsquo;<samp><span class="samp">make</span></samp>&rsquo;
<strong>does not</strong> work anymore!

   <p>If the comparison of stage2 and stage3 fails, this normally indicates
that the stage2 compiler has compiled GCC incorrectly, and is therefore
a potentially serious bug which you should investigate and report.  (On
a few systems, meaningful comparison of object files is impossible; they
always appear &ldquo;different&rdquo;.  If you encounter this problem, you will
need to disable comparison in the <samp><span class="file">Makefile</span></samp>.)

   <p>If you do not want to bootstrap your compiler, you can configure with
<samp><span class="option">--disable-bootstrap</span></samp>.  In particular cases, you may want to
bootstrap your compiler even if the target system is not the same as
the one you are building on: for example, you could build a
<code>powerpc-unknown-linux-gnu</code> toolchain on a
<code>powerpc64-unknown-linux-gnu</code> host.  In this case, pass
<samp><span class="option">--enable-bootstrap</span></samp> to the configure script.

   <p><code>BUILD_CONFIG</code> can be used to bring in additional customization
to the build.  It can be set to a whitespace-separated list of names. 
For each such <code>NAME</code>, top-level <samp><span class="file">config/</span><code>NAME</code><span class="file">.mk</span></samp> will
be included by the top-level <samp><span class="file">Makefile</span></samp>, bringing in any settings
it contains.  The default <code>BUILD_CONFIG</code> can be set using the
configure option <samp><span class="option">--with-build-config=</span><code>NAME</code><span class="option">...</span></samp>.  Some
examples of supported build configurations are:

     <dl>
<dt>&lsquo;<samp><span class="samp">bootstrap-O1</span></samp>&rsquo;<dd>Removes any <samp><span class="option">-O</span></samp>-started option from <code>BOOT_CFLAGS</code>, and adds
<samp><span class="option">-O1</span></samp> to it.  &lsquo;<samp><span class="samp">BUILD_CONFIG=bootstrap-O1</span></samp>&rsquo; is equivalent to
&lsquo;<samp><span class="samp">BOOT_CFLAGS='-g -O1'</span></samp>&rsquo;.

     <br><dt>&lsquo;<samp><span class="samp">bootstrap-O3</span></samp>&rsquo;<dd>Analogous to <code>bootstrap-O1</code>.

     <br><dt>&lsquo;<samp><span class="samp">bootstrap-lto</span></samp>&rsquo;<dd>Enables Link-Time Optimization for host tools during bootstrapping. 
&lsquo;<samp><span class="samp">BUILD_CONFIG=bootstrap-lto</span></samp>&rsquo; is equivalent to adding
<samp><span class="option">-flto</span></samp> to &lsquo;<samp><span class="samp">BOOT_CFLAGS</span></samp>&rsquo;.

     <br><dt>&lsquo;<samp><span class="samp">bootstrap-debug</span></samp>&rsquo;<dd>Verifies that the compiler generates the same executable code, whether
or not it is asked to emit debug information.  To this end, this
option builds stage2 host programs without debug information, and uses
<samp><span class="file">contrib/compare-debug</span></samp> to compare them with the stripped stage3
object files.  If <code>BOOT_CFLAGS</code> is overridden so as to not enable
debug information, stage2 will have it, and stage3 won't.  This option
is enabled by default when GCC bootstrapping is enabled, if
<code>strip</code> can turn object files compiled with and without debug
info into identical object files.  In addition to better test
coverage, this option makes default bootstraps faster and leaner.

     <br><dt>&lsquo;<samp><span class="samp">bootstrap-debug-big</span></samp>&rsquo;<dd>Rather than comparing stripped object files, as in
<code>bootstrap-debug</code>, this option saves internal compiler dumps
during stage2 and stage3 and compares them as well, which helps catch
additional potential problems, but at a great cost in terms of disk
space.  It can be specified in addition to &lsquo;<samp><span class="samp">bootstrap-debug</span></samp>&rsquo;.

     <br><dt>&lsquo;<samp><span class="samp">bootstrap-debug-lean</span></samp>&rsquo;<dd>This option saves disk space compared with <code>bootstrap-debug-big</code>,
but at the expense of some recompilation.  Instead of saving the dumps
of stage2 and stage3 until the final compare, it uses
<samp><span class="option">-fcompare-debug</span></samp> to generate, compare and remove the dumps
during stage3, repeating the compilation that already took place in
stage2, whose dumps were not saved.

     <br><dt>&lsquo;<samp><span class="samp">bootstrap-debug-lib</span></samp>&rsquo;<dd>This option tests executable code invariance over debug information
generation on target libraries, just like <code>bootstrap-debug-lean</code>
tests it on host programs.  It builds stage3 libraries with
<samp><span class="option">-fcompare-debug</span></samp>, and it can be used along with any of the
<code>bootstrap-debug</code> options above.

     <p>There aren't <code>-lean</code> or <code>-big</code> counterparts to this option
because most libraries are only build in stage3, so bootstrap compares
would not get significant coverage.  Moreover, the few libraries built
in stage2 are used in stage3 host programs, so we wouldn't want to
compile stage2 libraries with different options for comparison purposes.

     <br><dt>&lsquo;<samp><span class="samp">bootstrap-debug-ckovw</span></samp>&rsquo;<dd>Arranges for error messages to be issued if the compiler built on any
stage is run without the option <samp><span class="option">-fcompare-debug</span></samp>.  This is
useful to verify the full <samp><span class="option">-fcompare-debug</span></samp> testing coverage.  It
must be used along with <code>bootstrap-debug-lean</code> and
<code>bootstrap-debug-lib</code>.

     <br><dt>&lsquo;<samp><span class="samp">bootstrap-time</span></samp>&rsquo;<dd>Arranges for the run time of each program started by the GCC driver,
built in any stage, to be logged to <samp><span class="file">time.log</span></samp>, in the top level of
the build tree.

   </dl>

<h3 class="section"><a name="TOC1"></a>Building a cross compiler</h3>

<p>When building a cross compiler, it is not generally possible to do a
3-stage bootstrap of the compiler.  This makes for an interesting problem
as parts of GCC can only be built with GCC.

   <p>To build a cross compiler, we recommend first building and installing a
native compiler.  You can then use the native GCC compiler to build the
cross compiler.  The installed native compiler needs to be GCC version
2.95 or later.

   <p>If the cross compiler is to be built with support for the Java
programming language and the ability to compile .java source files is
desired, the installed native compiler used to build the cross
compiler needs to be the same GCC version as the cross compiler.  In
addition the cross compiler needs to be configured with
<samp><span class="option">--with-ecj-jar=...</span></samp>.

   <p>Assuming you have already installed a native copy of GCC and configured
your cross compiler, issue the command <samp><span class="command">make</span></samp>, which performs the
following steps:

     <ul>
<li>Build host tools necessary to build the compiler.

     <li>Build target tools for use by the compiler such as binutils (bfd,
binutils, gas, gprof, ld, and opcodes)
if they have been individually linked or moved into the top level GCC source
tree before configuring.

     <li>Build the compiler (single stage only).

     <li>Build runtime libraries using the compiler from the previous step. 
</ul>

   <p>Note that if an error occurs in any step the make process will exit.

   <p>If you are not building GNU binutils in the same source tree as GCC,
you will need a cross-assembler and cross-linker installed before
configuring GCC.  Put them in the directory
<samp><var>prefix</var><span class="file">/</span><var>target</var><span class="file">/bin</span></samp>.  Here is a table of the tools
you should put in this directory:

     <dl>
<dt><samp><span class="file">as</span></samp><dd>This should be the cross-assembler.

     <br><dt><samp><span class="file">ld</span></samp><dd>This should be the cross-linker.

     <br><dt><samp><span class="file">ar</span></samp><dd>This should be the cross-archiver: a program which can manipulate
archive files (linker libraries) in the target machine's format.

     <br><dt><samp><span class="file">ranlib</span></samp><dd>This should be a program to construct a symbol table in an archive file. 
</dl>

   <p>The installation of GCC will find these programs in that directory,
and copy or link them to the proper place to for the cross-compiler to
find them when run later.

   <p>The easiest way to provide these files is to build the Binutils package. 
Configure it with the same <samp><span class="option">--host</span></samp> and <samp><span class="option">--target</span></samp>
options that you use for configuring GCC, then build and install
them.  They install their executables automatically into the proper
directory.  Alas, they do not support all the targets that GCC
supports.

   <p>If you are not building a C library in the same source tree as GCC,
you should also provide the target libraries and headers before
configuring GCC, specifying the directories with
<samp><span class="option">--with-sysroot</span></samp> or <samp><span class="option">--with-headers</span></samp> and
<samp><span class="option">--with-libs</span></samp>.  Many targets also require &ldquo;start files&rdquo; such
as <samp><span class="file">crt0.o</span></samp> and
<samp><span class="file">crtn.o</span></samp> which are linked into each executable.  There may be several
alternatives for <samp><span class="file">crt0.o</span></samp>, for use with profiling or other
compilation options.  Check your target's definition of
<code>STARTFILE_SPEC</code> to find out what start files it uses.

<h3 class="section"><a name="TOC2"></a>Building in parallel</h3>

<p>GNU Make 3.80 and above, which is necessary to build GCC, support
building in parallel.  To activate this, you can use &lsquo;<samp><span class="samp">make -j 2</span></samp>&rsquo;
instead of &lsquo;<samp><span class="samp">make</span></samp>&rsquo;.  You can also specify a bigger number, and
in most cases using a value greater than the number of processors in
your machine will result in fewer and shorter I/O latency hits, thus
improving overall throughput; this is especially true for slow drives
and network filesystems.

<h3 class="section"><a name="TOC3"></a>Building the Ada compiler</h3>

<p>In order to build GNAT, the Ada compiler, you need a working GNAT
compiler (GCC version 4.0 or later). 
This includes GNAT tools such as <samp><span class="command">gnatmake</span></samp> and
<samp><span class="command">gnatlink</span></samp>, since the Ada front end is written in Ada and
uses some GNAT-specific extensions.

   <p>In order to build a cross compiler, it is suggested to install
the new compiler as native first, and then use it to build the cross
compiler.

   <p><samp><span class="command">configure</span></samp> does not test whether the GNAT installation works
and has a sufficiently recent version; if too old a GNAT version is
installed, the build will fail unless <samp><span class="option">--enable-languages</span></samp> is
used to disable building the Ada front end.

   <p><samp><span class="env">ADA_INCLUDE_PATH</span></samp> and <samp><span class="env">ADA_OBJECT_PATH</span></samp> environment variables
must not be set when building the Ada compiler, the Ada tools, or the
Ada runtime libraries. You can check that your build environment is clean
by verifying that &lsquo;<samp><span class="samp">gnatls -v</span></samp>&rsquo; lists only one explicit path in each
section.

<h3 class="section"><a name="TOC4"></a>Building with profile feedback</h3>

<p>It is possible to use profile feedback to optimize the compiler itself.  This
should result in a faster compiler binary.  Experiments done on x86 using gcc
3.3 showed approximately 7 percent speedup on compiling C programs.  To
bootstrap the compiler with profile feedback, use <code>make profiledbootstrap</code>.

   <p>When &lsquo;<samp><span class="samp">make profiledbootstrap</span></samp>&rsquo; is run, it will first build a <code>stage1</code>
compiler.  This compiler is used to build a <code>stageprofile</code> compiler
instrumented to collect execution counts of instruction and branch
probabilities.  Then runtime libraries are compiled with profile collected. 
Finally a <code>stagefeedback</code> compiler is built using the information collected.

   <p>Unlike standard bootstrap, several additional restrictions apply.  The
compiler used to build <code>stage1</code> needs to support a 64-bit integral type. 
It is recommended to only use GCC for this.  Also parallel make is currently
not supported since collisions in profile collecting may occur.

   <p><hr />
<p><a href="./index.html">Return to the GCC Installation page</a>

<!-- ***Testing***************************************************************** -->
<!-- ***Final install*********************************************************** -->
<!-- ***Binaries**************************************************************** -->
<!-- ***Specific**************************************************************** -->
<!-- ***Old documentation****************************************************** -->
<!-- ***GFDL******************************************************************** -->
<!-- *************************************************************************** -->
<!-- Part 6 The End of the Document -->
</body></html>