build.html revision 1.14
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 8Permission is granted to copy, distribute and/or modify this document 9under the terms of the GNU Free Documentation License, Version 1.3 or 10any later version published by the Free Software Foundation; with no 11Invariant Sections, the Front-Cover texts being (a) (see below), and 12with the Back-Cover Texts being (b) (see below). A copy of the 13license is included in the section entitled "GNU 14Free Documentation License". 15 16(a) The FSF's Front-Cover Text is: 17 18A GNU Manual 19 20(b) The FSF's Back-Cover Text is: 21 22You 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<!-- 36a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em} 37a.summary-letter {text-decoration: none} 38blockquote.indentedblock {margin-right: 0em} 39div.display {margin-left: 3.2em} 40div.example {margin-left: 3.2em} 41kbd {font-style: oblique} 42pre.display {font-family: inherit} 43pre.format {font-family: inherit} 44pre.menu-comment {font-family: serif} 45pre.menu-preformatted {font-family: serif} 46span.nolinebreak {white-space: nowrap} 47span.roman {font-family: initial; font-weight: normal} 48span.sansserif {font-family: sans-serif; font-weight: normal} 49span:hover a.copiable-anchor {visibility: visible} 50ul.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 82runtime libraries. 83</p> 84<p>Some commands executed when making the compiler may fail (return a 85nonzero status) and be ignored by <code>make</code>. These failures, which 86are often due to files that were not found, are expected, and can safely 87be ignored. 88</p> 89<p>It is normal to have compiler warnings when compiling certain files. 90Unless you are a GCC developer, you can generally ignore these warnings 91unless they cause compilation to fail. Developers should attempt to fix 92any warnings encountered, however they can temporarily continue past 93warnings-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 100compiler in a directory other than the source directory, it could be 101because you have previously configured the compiler in the source 102directory. 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 105V file system, problems may occur in running <code>fixincludes</code> if the 106System V file system doesn’t support symbolic links. These problems 107result 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 109that 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 115installed. If you do not modify <samp>*.l</samp> files, releases contain 116the Flex-generated files and you do not need Flex installed to build 117them. There is still one Flex-based lexical analyzer (part of the 118build machinery, not of GCC itself) that is used even if you only 119build the C front end. 120</p> 121<p>When building from the source repository or snapshots, or if you modify Texinfo 122documentation, you need version 4.7 or later of Texinfo installed if you 123want Info documentation to be regenerated. Releases contain Info 124documentation 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 130a 3-stage bootstrap of the compiler when ‘<samp>make</samp>’ is invoked. 131This will build the entire GCC system and ensure that it compiles 132itself correctly. It can be disabled with the <samp>--disable-bootstrap</samp> 133parameter to ‘<samp>configure</samp>’, but bootstrapping is suggested because 134the compiler will be tested more completely and could also have 135better 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 143three times the target tools for use by the compiler such as binutils 144(bfd, binutils, gas, gprof, ld, and opcodes) if they have been 145individually linked or moved into the top level GCC source tree before 146configuring. 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 155bootstrap-lean</samp>’ instead. The sequence of compilation is the 156same described above, but object files from the stage1 and 157stage2 of the 3-stage bootstrap of the compiler are deleted as 158soon as they are no longer needed. 159</p> 160<p>If you wish to use non-default GCC flags when compiling the stage2 161and stage3 compilers, set <code>BOOT_CFLAGS</code> on the command line when 162doing ‘<samp>make</samp>’. For example, if you want to save additional space 163during the bootstrap and in the final installation as well, you can 164build the compiler binaries without debugging information as in the 165following example. This will save roughly 40% of disk space both for 166the bootstrap and the final installation. (Libraries will still contain 167debugging 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 174are less well tested here than the default of ‘<samp>-g -O2</samp>’, but should 175still work. In a few cases, you may find that you need to specify special 176flags such as <samp>-msoft-float</samp> here to complete the bootstrap; or, 177if the native compiler miscompiles the stage1 compiler, you may need 178to work around this, by choosing <code>BOOT_CFLAGS</code> to avoid the parts 179of the stage1 compiler that were miscompiled, or by using ‘<samp>make 180bootstrap4</samp>’ to increase the number of stages of bootstrap. 181</p> 182<p><code>BOOT_CFLAGS</code> does not apply to bootstrapped target libraries. 183Since these are always compiled with the compiler currently being 184bootstrapped, you can use <code>CFLAGS_FOR_TARGET</code> to modify their 185compilation flags, as for non-bootstrapped target libraries. 186Again, if the native compiler miscompiles the stage1 compiler, you may 187need to work around this by avoiding non-working parts of the stage1 188compiler. Use <code>STAGE1_TFLAGS</code> to this end. 189</p> 190<p>If you used the flag <samp>--enable-languages=…</samp> to restrict 191the compilers to be built, only those you’ve actually enabled will be 192built. This will of course only build those runtime libraries, for 193which the particular compiler has been built. Please note, 194that 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 198that the stage2 compiler has compiled GCC incorrectly, and is therefore 199a potentially serious bug which you should investigate and report. (On 200a few systems, meaningful comparison of object files is impossible; they 201always appear “different”. If you encounter this problem, you will 202need 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 206bootstrap your compiler even if the target system is not the same as 207the 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 213to the build. It can be set to a whitespace-separated list of names. 214For each such <code>NAME</code>, top-level <samp>config/<code>NAME</code>.mk</samp> will 215be included by the top-level <samp>Makefile</samp>, bringing in any settings 216it contains. The default <code>BUILD_CONFIG</code> can be set using the 217configure option <samp>--with-build-config=<code>NAME</code>...</samp>. Some 218examples 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 236supports the linker plugin (e.g. GNU ld version 2.21 or later or GNU gold 237version 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 242hosts that do not support the linker plugin. Without the linker plugin 243static libraries are not compiled with link-time optimizations. Since 244the GCC middle end and back end are in <samp>libbackend.a</samp> this means 245that 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 250faster build by only using LTO in the final bootstrap stage. 251With ‘<samp>make profiledbootstrap</samp>’ the LTO frontend 252is 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 257or not it is asked to emit debug information. To this end, this 258option builds stage2 host programs without debug information, and uses 259<samp>contrib/compare-debug</samp> to compare them with the stripped stage3 260object files. If <code>BOOT_CFLAGS</code> is overridden so as to not enable 261debug information, stage2 will have it, and stage3 won’t. This option 262is enabled by default when GCC bootstrapping is enabled, if 263<code>strip</code> can turn object files compiled with and without debug 264info into identical object files. In addition to better test 265coverage, 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 271during stage2 and stage3 and compares them as well, which helps catch 272additional potential problems, but at a great cost in terms of disk 273space. 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>, 278but at the expense of some recompilation. Instead of saving the dumps 279of stage2 and stage3 until the final compare, it uses 280<samp>-fcompare-debug</samp> to generate, compare and remove the dumps 281during stage3, repeating the compilation that already took place in 282stage2, 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 287generation on target libraries, just like <code>bootstrap-debug-lean</code> 288tests 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 293because most libraries are only build in stage3, so bootstrap compares 294would not get significant coverage. Moreover, the few libraries built 295in stage2 are used in stage3 host programs, so we wouldn’t want to 296compile 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 301stage is run without the option <samp>-fcompare-debug</samp>. This is 302useful to verify the full <samp>-fcompare-debug</samp> testing coverage. It 303must 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 311assumes that the host supports Intel CET (e.g. GNU assembler version 3122.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, 317built in any stage, to be logged to <samp>time.log</samp>, in the top level of 318the 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 323accesses 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 3333-stage bootstrap of the compiler. This makes for an interesting problem 334as 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 337native compiler. You can then use the native GCC compiler to build the 338cross compiler. The installed native compiler needs to be GCC version 3392.95 or later. 340</p> 341<p>Assuming you have already installed a native copy of GCC and configured 342your cross compiler, issue the command <code>make</code>, which performs the 343following 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, 349binutils, gas, gprof, ld, and opcodes) 350if they have been individually linked or moved into the top level GCC source 351tree 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, 361you will need a cross-assembler and cross-linker installed before 362configuring GCC. Put them in the directory 363<samp><var>prefix</var>/<var>target</var>/bin</samp>. Here is a table of the tools 364you 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 377archive 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, 386and copy or link them to the proper place to for the cross-compiler to 387find them when run later. 388</p> 389<p>The easiest way to provide these files is to build the Binutils package. 390Configure it with the same <samp>--host</samp> and <samp>--target</samp> 391options that you use for configuring GCC, then build and install 392them. They install their executables automatically into the proper 393directory. Alas, they do not support all the targets that GCC 394supports. 395</p> 396<p>If you are not building a C library in the same source tree as GCC, 397you should also provide the target libraries and headers before 398configuring 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 401as <samp>crt0.o</samp> and 402<samp>crtn.o</samp> which are linked into each executable. There may be several 403alternatives for <samp>crt0.o</samp>, for use with profiling or other 404compilation 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 412building in parallel. To activate this, you can use ‘<samp>make -j 2</samp>’ 413instead of ‘<samp>make</samp>’. You can also specify a bigger number, and 414in most cases using a value greater than the number of processors in 415your machine will result in fewer and shorter I/O latency hits, thus 416improving overall throughput; this is especially true for slow drives 417and 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 430should result in a faster compiler binary. Experiments done on x86 using gcc 4313.3 showed approximately 7 percent speedup on compiling C programs. To 432bootstrap 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> 435compiler. This compiler is used to build a <code>stageprofile</code> compiler 436instrumented to collect execution counts of instruction and branch 437probabilities. Training run is done by building <code>stagetrain</code> 438compiler. Finally a <code>stagefeedback</code> compiler is built 439using the information collected. 440</p> 441<p>Unlike standard bootstrap, several additional restrictions apply. The 442compiler used to build <code>stage1</code> needs to support a 64-bit integral type. 443It is recommended to only use GCC for this. 444</p> 445<p>On Linux/x86_64 hosts with some restrictions (no virtualization) it is 446also possible to do autofdo build with ‘<samp>make 447autoprofiledback</samp>’. This uses Linux perf to sample branches in the 448binary and then rebuild it with feedback derived from the profile. 449Linux perf and the <code>autofdo</code> toolkit needs to be installed for 450this. 451</p> 452<p>Only the profile from the current build is used, so when an error 453occurs it is recommended to clean before restarting. Otherwise 454the 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