build.html revision 1.6 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- Copyright (C) 1988-2015 Free Software Foundation, Inc.
4
5 Permission is granted to copy, distribute and/or modify this document
6 under the terms of the GNU Free Documentation License, Version 1.3 or
7 any later version published by the Free Software Foundation; with no
8 Invariant Sections, the Front-Cover texts being (a) (see below), and
9 with the Back-Cover Texts being (b) (see below). A copy of the
10 license is included in the section entitled "GNU
11 Free Documentation License".
12
13 (a) The FSF's Front-Cover Text is:
14
15 A GNU Manual
16
17 (b) The FSF's Back-Cover Text is:
18
19 You have freedom to copy and modify this GNU Manual, like GNU
20 software. Copies published by the Free Software Foundation raise
21 funds for GNU development. -->
22 <!-- Created by GNU Texinfo 6.1, http://www.gnu.org/software/texinfo/ -->
23 <head>
24 <title>Installing GCC</title>
25
26 <meta name="description" content="Installing GCC">
27 <meta name="keywords" content="Installing GCC">
28 <meta name="resource-type" content="document">
29 <meta name="distribution" content="global">
30 <meta name="Generator" content="makeinfo">
31 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
32 <style type="text/css">
33 <!--
34 a.summary-letter {text-decoration: none}
35 blockquote.indentedblock {margin-right: 0em}
36 blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
37 blockquote.smallquotation {font-size: smaller}
38 div.display {margin-left: 3.2em}
39 div.example {margin-left: 3.2em}
40 div.lisp {margin-left: 3.2em}
41 div.smalldisplay {margin-left: 3.2em}
42 div.smallexample {margin-left: 3.2em}
43 div.smalllisp {margin-left: 3.2em}
44 kbd {font-style: oblique}
45 pre.display {font-family: inherit}
46 pre.format {font-family: inherit}
47 pre.menu-comment {font-family: serif}
48 pre.menu-preformatted {font-family: serif}
49 pre.smalldisplay {font-family: inherit; font-size: smaller}
50 pre.smallexample {font-size: smaller}
51 pre.smallformat {font-family: inherit; font-size: smaller}
52 pre.smalllisp {font-size: smaller}
53 span.nolinebreak {white-space: nowrap}
54 span.roman {font-family: initial; font-weight: normal}
55 span.sansserif {font-family: sans-serif; font-weight: normal}
56 ul.no-bullet {list-style: none}
57 -->
58 </style>
59
60
61 </head>
62
63 <body lang="en">
64 <h1 class="settitle" align="center">Installing GCC</h1>
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 <a name="index-Installing-GCC_003a-Building"></a>
86
87 <p>Now that GCC is configured, you are ready to build the compiler and
88 runtime libraries.
89 </p>
90 <p>Some commands executed when making the compiler may fail (return a
91 nonzero status) and be ignored by <code>make</code>. These failures, which
92 are often due to files that were not found, are expected, and can safely
93 be ignored.
94 </p>
95 <p>It is normal to have compiler warnings when compiling certain files.
96 Unless you are a GCC developer, you can generally ignore these warnings
97 unless they cause compilation to fail. Developers should attempt to fix
98 any warnings encountered, however they can temporarily continue past
99 warnings-as-errors by specifying the configure flag
100 <samp>--disable-werror</samp>.
101 </p>
102 <p>On certain old systems, defining certain environment variables such as
103 <code>CC</code> can interfere with the functioning of <code>make</code>.
104 </p>
105 <p>If you encounter seemingly strange errors when trying to build the
106 compiler in a directory other than the source directory, it could be
107 because you have previously configured the compiler in the source
108 directory. Make sure you have done all the necessary preparations.
109 </p>
110 <p>If you build GCC on a BSD system using a directory stored in an old System
111 V file system, problems may occur in running <code>fixincludes</code> if the
112 System V file system doesn’t support symbolic links. These problems
113 result in a failure to fix the declaration of <code>size_t</code> in
114 <samp>sys/types.h</samp>. If you find that <code>size_t</code> is a signed type and
115 that type mismatches occur, this could be the cause.
116 </p>
117 <p>The solution is not to use such a directory for building GCC.
118 </p>
119 <p>Similarly, when building from SVN or snapshots, or if you modify
120 <samp>*.l</samp> files, you need the Flex lexical analyzer generator
121 installed. If you do not modify <samp>*.l</samp> files, releases contain
122 the Flex-generated files and you do not need Flex installed to build
123 them. There is still one Flex-based lexical analyzer (part of the
124 build machinery, not of GCC itself) that is used even if you only
125 build the C front end.
126 </p>
127 <p>When building from SVN or snapshots, or if you modify Texinfo
128 documentation, you need version 4.7 or later of Texinfo installed if you
129 want Info documentation to be regenerated. Releases contain Info
130 documentation pre-built for the unmodified documentation in the release.
131 </p>
132 <a name="Building-a-native-compiler"></a>
133 <h3 class="section">Building a native compiler</h3>
134
135 <p>For a native build, the default configuration is to perform
136 a 3-stage bootstrap of the compiler when ‘<samp>make</samp>’ is invoked.
137 This will build the entire GCC system and ensure that it compiles
138 itself correctly. It can be disabled with the <samp>--disable-bootstrap</samp>
139 parameter to ‘<samp>configure</samp>’, but bootstrapping is suggested because
140 the compiler will be tested more completely and could also have
141 better performance.
142 </p>
143 <p>The bootstrapping process will complete the following steps:
144 </p>
145 <ul>
146 <li> Build tools necessary to build the compiler.
147
148 </li><li> Perform a 3-stage bootstrap of the compiler. This includes building
149 three times the target tools for use by the compiler such as binutils
150 (bfd, binutils, gas, gprof, ld, and opcodes) if they have been
151 individually linked or moved into the top level GCC source tree before
152 configuring.
153
154 </li><li> Perform a comparison test of the stage2 and stage3 compilers.
155
156 </li><li> Build runtime libraries using the stage3 compiler from the previous step.
157
158 </li></ul>
159
160 <p>If you are short on disk space you might consider ‘<samp>make
161 bootstrap-lean</samp>’ instead. The sequence of compilation is the
162 same described above, but object files from the stage1 and
163 stage2 of the 3-stage bootstrap of the compiler are deleted as
164 soon as they are no longer needed.
165 </p>
166 <p>If you wish to use non-default GCC flags when compiling the stage2
167 and stage3 compilers, set <code>BOOT_CFLAGS</code> on the command line when
168 doing ‘<samp>make</samp>’. For example, if you want to save additional space
169 during the bootstrap and in the final installation as well, you can
170 build the compiler binaries without debugging information as in the
171 following example. This will save roughly 40% of disk space both for
172 the bootstrap and the final installation. (Libraries will still contain
173 debugging information.)
174 </p>
175 <div class="smallexample">
176 <pre class="smallexample">make BOOT_CFLAGS='-O' bootstrap
177 </pre></div>
178
179 <p>You can place non-default optimization flags into <code>BOOT_CFLAGS</code>; they
180 are less well tested here than the default of ‘<samp>-g -O2</samp>’, but should
181 still work. In a few cases, you may find that you need to specify special
182 flags such as <samp>-msoft-float</samp> here to complete the bootstrap; or,
183 if the native compiler miscompiles the stage1 compiler, you may need
184 to work around this, by choosing <code>BOOT_CFLAGS</code> to avoid the parts
185 of the stage1 compiler that were miscompiled, or by using ‘<samp>make
186 bootstrap4</samp>’ to increase the number of stages of bootstrap.
187 </p>
188 <p><code>BOOT_CFLAGS</code> does not apply to bootstrapped target libraries.
189 Since these are always compiled with the compiler currently being
190 bootstrapped, you can use <code>CFLAGS_FOR_TARGET</code> to modify their
191 compilation flags, as for non-bootstrapped target libraries.
192 Again, if the native compiler miscompiles the stage1 compiler, you may
193 need to work around this by avoiding non-working parts of the stage1
194 compiler. Use <code>STAGE1_TFLAGS</code> to this end.
195 </p>
196 <p>If you used the flag <samp>--enable-languages=…</samp> to restrict
197 the compilers to be built, only those you’ve actually enabled will be
198 built. This will of course only build those runtime libraries, for
199 which the particular compiler has been built. Please note,
200 that re-defining <code>LANGUAGES</code> when calling ‘<samp>make</samp>’
201 <strong>does not</strong> work anymore!
202 </p>
203 <p>If the comparison of stage2 and stage3 fails, this normally indicates
204 that the stage2 compiler has compiled GCC incorrectly, and is therefore
205 a potentially serious bug which you should investigate and report. (On
206 a few systems, meaningful comparison of object files is impossible; they
207 always appear “different”. If you encounter this problem, you will
208 need to disable comparison in the <samp>Makefile</samp>.)
209 </p>
210 <p>If you do not want to bootstrap your compiler, you can configure with
211 <samp>--disable-bootstrap</samp>. In particular cases, you may want to
212 bootstrap your compiler even if the target system is not the same as
213 the one you are building on: for example, you could build a
214 <code>powerpc-unknown-linux-gnu</code> toolchain on a
215 <code>powerpc64-unknown-linux-gnu</code> host. In this case, pass
216 <samp>--enable-bootstrap</samp> to the configure script.
217 </p>
218 <p><code>BUILD_CONFIG</code> can be used to bring in additional customization
219 to the build. It can be set to a whitespace-separated list of names.
220 For each such <code>NAME</code>, top-level <samp>config/<code>NAME</code>.mk</samp> will
221 be included by the top-level <samp>Makefile</samp>, bringing in any settings
222 it contains. The default <code>BUILD_CONFIG</code> can be set using the
223 configure option <samp>--with-build-config=<code>NAME</code>...</samp>. Some
224 examples of supported build configurations are:
225 </p>
226 <dl compact="compact">
227 <dt>‘<samp>bootstrap-O1</samp>’</dt>
228 <dd><p>Removes any <samp>-O</samp>-started option from <code>BOOT_CFLAGS</code>, and adds
229 <samp>-O1</samp> to it. ‘<samp>BUILD_CONFIG=bootstrap-O1</samp>’ is equivalent to
230 ‘<samp>BOOT_CFLAGS='-g -O1'</samp>’.
231 </p>
232 </dd>
233 <dt>‘<samp>bootstrap-O3</samp>’</dt>
234 <dd><p>Analogous to <code>bootstrap-O1</code>.
235 </p>
236 </dd>
237 <dt>‘<samp>bootstrap-lto</samp>’</dt>
238 <dd><p>Enables Link-Time Optimization for host tools during bootstrapping.
239 ‘<samp>BUILD_CONFIG=bootstrap-lto</samp>’ is equivalent to adding
240 <samp>-flto</samp> to ‘<samp>BOOT_CFLAGS</samp>’. This option assumes that the host
241 supports the linker plugin (e.g. GNU ld version 2.21 or later or GNU gold
242 version 2.21 or later).
243 </p>
244 </dd>
245 <dt>‘<samp>bootstrap-lto-noplugin</samp>’</dt>
246 <dd><p>This option is similar to <code>bootstrap-lto</code>, but is intended for
247 hosts that do not support the linker plugin. Without the linker plugin
248 static libraries are not compiled with link-time optimizations. Since
249 the GCC middle end and back end are in <samp>libbackend.a</samp> this means
250 that only the front end is actually LTO optimized.
251 </p>
252 </dd>
253 <dt>‘<samp>bootstrap-debug</samp>’</dt>
254 <dd><p>Verifies that the compiler generates the same executable code, whether
255 or not it is asked to emit debug information. To this end, this
256 option builds stage2 host programs without debug information, and uses
257 <samp>contrib/compare-debug</samp> to compare them with the stripped stage3
258 object files. If <code>BOOT_CFLAGS</code> is overridden so as to not enable
259 debug information, stage2 will have it, and stage3 won’t. This option
260 is enabled by default when GCC bootstrapping is enabled, if
261 <code>strip</code> can turn object files compiled with and without debug
262 info into identical object files. In addition to better test
263 coverage, this option makes default bootstraps faster and leaner.
264 </p>
265 </dd>
266 <dt>‘<samp>bootstrap-debug-big</samp>’</dt>
267 <dd><p>Rather than comparing stripped object files, as in
268 <code>bootstrap-debug</code>, this option saves internal compiler dumps
269 during stage2 and stage3 and compares them as well, which helps catch
270 additional potential problems, but at a great cost in terms of disk
271 space. It can be specified in addition to ‘<samp>bootstrap-debug</samp>’.
272 </p>
273 </dd>
274 <dt>‘<samp>bootstrap-debug-lean</samp>’</dt>
275 <dd><p>This option saves disk space compared with <code>bootstrap-debug-big</code>,
276 but at the expense of some recompilation. Instead of saving the dumps
277 of stage2 and stage3 until the final compare, it uses
278 <samp>-fcompare-debug</samp> to generate, compare and remove the dumps
279 during stage3, repeating the compilation that already took place in
280 stage2, whose dumps were not saved.
281 </p>
282 </dd>
283 <dt>‘<samp>bootstrap-debug-lib</samp>’</dt>
284 <dd><p>This option tests executable code invariance over debug information
285 generation on target libraries, just like <code>bootstrap-debug-lean</code>
286 tests it on host programs. It builds stage3 libraries with
287 <samp>-fcompare-debug</samp>, and it can be used along with any of the
288 <code>bootstrap-debug</code> options above.
289 </p>
290 <p>There aren’t <code>-lean</code> or <code>-big</code> counterparts to this option
291 because most libraries are only build in stage3, so bootstrap compares
292 would not get significant coverage. Moreover, the few libraries built
293 in stage2 are used in stage3 host programs, so we wouldn’t want to
294 compile stage2 libraries with different options for comparison purposes.
295 </p>
296 </dd>
297 <dt>‘<samp>bootstrap-debug-ckovw</samp>’</dt>
298 <dd><p>Arranges for error messages to be issued if the compiler built on any
299 stage is run without the option <samp>-fcompare-debug</samp>. This is
300 useful to verify the full <samp>-fcompare-debug</samp> testing coverage. It
301 must be used along with <code>bootstrap-debug-lean</code> and
302 <code>bootstrap-debug-lib</code>.
303 </p>
304 </dd>
305 <dt>‘<samp>bootstrap-time</samp>’</dt>
306 <dd><p>Arranges for the run time of each program started by the GCC driver,
307 built in any stage, to be logged to <samp>time.log</samp>, in the top level of
308 the build tree.
309 </p>
310 </dd>
311 </dl>
312
313 <a name="Building-a-cross-compiler"></a>
314 <h3 class="section">Building a cross compiler</h3>
315
316 <p>When building a cross compiler, it is not generally possible to do a
317 3-stage bootstrap of the compiler. This makes for an interesting problem
318 as parts of GCC can only be built with GCC.
319 </p>
320 <p>To build a cross compiler, we recommend first building and installing a
321 native compiler. You can then use the native GCC compiler to build the
322 cross compiler. The installed native compiler needs to be GCC version
323 2.95 or later.
324 </p>
325 <p>If the cross compiler is to be built with support for the Java
326 programming language and the ability to compile .java source files is
327 desired, the installed native compiler used to build the cross
328 compiler needs to be the same GCC version as the cross compiler. In
329 addition the cross compiler needs to be configured with
330 <samp>--with-ecj-jar=…</samp>.
331 </p>
332 <p>Assuming you have already installed a native copy of GCC and configured
333 your cross compiler, issue the command <code>make</code>, which performs the
334 following steps:
335 </p>
336 <ul>
337 <li> Build host tools necessary to build the compiler.
338
339 </li><li> Build target tools for use by the compiler such as binutils (bfd,
340 binutils, gas, gprof, ld, and opcodes)
341 if they have been individually linked or moved into the top level GCC source
342 tree before configuring.
343
344 </li><li> Build the compiler (single stage only).
345
346 </li><li> Build runtime libraries using the compiler from the previous step.
347 </li></ul>
348
349 <p>Note that if an error occurs in any step the make process will exit.
350 </p>
351 <p>If you are not building GNU binutils in the same source tree as GCC,
352 you will need a cross-assembler and cross-linker installed before
353 configuring GCC. Put them in the directory
354 <samp><var>prefix</var>/<var>target</var>/bin</samp>. Here is a table of the tools
355 you should put in this directory:
356 </p>
357 <dl compact="compact">
358 <dt><samp>as</samp></dt>
359 <dd><p>This should be the cross-assembler.
360 </p>
361 </dd>
362 <dt><samp>ld</samp></dt>
363 <dd><p>This should be the cross-linker.
364 </p>
365 </dd>
366 <dt><samp>ar</samp></dt>
367 <dd><p>This should be the cross-archiver: a program which can manipulate
368 archive files (linker libraries) in the target machine’s format.
369 </p>
370 </dd>
371 <dt><samp>ranlib</samp></dt>
372 <dd><p>This should be a program to construct a symbol table in an archive file.
373 </p></dd>
374 </dl>
375
376 <p>The installation of GCC will find these programs in that directory,
377 and copy or link them to the proper place to for the cross-compiler to
378 find them when run later.
379 </p>
380 <p>The easiest way to provide these files is to build the Binutils package.
381 Configure it with the same <samp>--host</samp> and <samp>--target</samp>
382 options that you use for configuring GCC, then build and install
383 them. They install their executables automatically into the proper
384 directory. Alas, they do not support all the targets that GCC
385 supports.
386 </p>
387 <p>If you are not building a C library in the same source tree as GCC,
388 you should also provide the target libraries and headers before
389 configuring GCC, specifying the directories with
390 <samp>--with-sysroot</samp> or <samp>--with-headers</samp> and
391 <samp>--with-libs</samp>. Many targets also require “start files” such
392 as <samp>crt0.o</samp> and
393 <samp>crtn.o</samp> which are linked into each executable. There may be several
394 alternatives for <samp>crt0.o</samp>, for use with profiling or other
395 compilation options. Check your target’s definition of
396 <code>STARTFILE_SPEC</code> to find out what start files it uses.
397 </p>
398 <a name="Building-in-parallel"></a>
399 <h3 class="section">Building in parallel</h3>
400
401 <p>GNU Make 3.80 and above, which is necessary to build GCC, support
402 building in parallel. To activate this, you can use ‘<samp>make -j 2</samp>’
403 instead of ‘<samp>make</samp>’. You can also specify a bigger number, and
404 in most cases using a value greater than the number of processors in
405 your machine will result in fewer and shorter I/O latency hits, thus
406 improving overall throughput; this is especially true for slow drives
407 and network filesystems.
408 </p>
409 <a name="Building-the-Ada-compiler"></a>
410 <h3 class="section">Building the Ada compiler</h3>
411
412 <p>In order to build GNAT, the Ada compiler, you need a working GNAT
413 compiler (GCC version 4.0 or later).
414 This includes GNAT tools such as <code>gnatmake</code> and
415 <code>gnatlink</code>, since the Ada front end is written in Ada and
416 uses some GNAT-specific extensions.
417 </p>
418 <p>In order to build a cross compiler, it is suggested to install
419 the new compiler as native first, and then use it to build the cross
420 compiler.
421 </p>
422 <p><code>configure</code> does not test whether the GNAT installation works
423 and has a sufficiently recent version; if too old a GNAT version is
424 installed, the build will fail unless <samp>--enable-languages</samp> is
425 used to disable building the Ada front end.
426 </p>
427 <p><code>ADA_INCLUDE_PATH</code> and <code>ADA_OBJECT_PATH</code> environment variables
428 must not be set when building the Ada compiler, the Ada tools, or the
429 Ada runtime libraries. You can check that your build environment is clean
430 by verifying that ‘<samp>gnatls -v</samp>’ lists only one explicit path in each
431 section.
432 </p>
433 <a name="Building-with-profile-feedback"></a>
434 <h3 class="section">Building with profile feedback</h3>
435
436 <p>It is possible to use profile feedback to optimize the compiler itself. This
437 should result in a faster compiler binary. Experiments done on x86 using gcc
438 3.3 showed approximately 7 percent speedup on compiling C programs. To
439 bootstrap the compiler with profile feedback, use <code>make profiledbootstrap</code>.
440 </p>
441 <p>When ‘<samp>make profiledbootstrap</samp>’ is run, it will first build a <code>stage1</code>
442 compiler. This compiler is used to build a <code>stageprofile</code> compiler
443 instrumented to collect execution counts of instruction and branch
444 probabilities. Then runtime libraries are compiled with profile collected.
445 Finally a <code>stagefeedback</code> compiler is built using the information collected.
446 </p>
447 <p>Unlike standard bootstrap, several additional restrictions apply. The
448 compiler used to build <code>stage1</code> needs to support a 64-bit integral type.
449 It is recommended to only use GCC for this.
450 </p>
451 <hr />
452 <p>
453 <p><a href="./index.html">Return to the GCC Installation page</a>
454 </p>
455
456
457
458
459
460
461
462 <hr>
463
464
465
466 </body>
467 </html>
468