build.html 20 KB

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