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