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