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