Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

470 Zeilen
20KB

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