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