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