gcc.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-system-gcc" role="wrap">
  8. <?dbhtml filename="gcc.html"?>
  9. <sect1info condition="script">
  10. <productname>gcc</productname>
  11. <productnumber>&gcc-version;</productnumber>
  12. <address>&gcc-url;</address>
  13. </sect1info>
  14. <title>GCC-&gcc-version;</title>
  15. <indexterm zone="ch-system-gcc">
  16. <primary sortas="a-GCC">GCC</primary>
  17. </indexterm>
  18. <sect2 role="package">
  19. <title/>
  20. <para>The GCC package contains the GNU compiler collection, which includes
  21. the C and C++ compilers.</para>
  22. <segmentedlist>
  23. <segtitle>&buildtime;</segtitle>
  24. <segtitle>&diskspace;</segtitle>
  25. <seglistitem>
  26. <seg>&gcc-ch6-sbu;</seg>
  27. <seg>&gcc-ch6-du;</seg>
  28. </seglistitem>
  29. </segmentedlist>
  30. </sect2>
  31. <sect2 role="installation">
  32. <title>Installation of GCC</title>
  33. <!--
  34. <para>First apply some fixes from the upstream repository:</para>
  35. <screen><userinput remap="pre">patch -Np1 -i ../&gcc-upstream-patch;</userinput></screen>
  36. -->
  37. <para>The GCC documentation recommends building GCC outside of the source
  38. directory in a dedicated build directory:</para>
  39. <screen><userinput remap="pre">mkdir -v ../gcc-build
  40. cd ../gcc-build</userinput></screen>
  41. <para>Prepare GCC for compilation:</para>
  42. <screen><userinput remap="configure">SED=sed \
  43. ../gcc-&gcc-version;/configure \
  44. --prefix=/usr \
  45. --enable-languages=c,c++ \
  46. --disable-multilib \
  47. --disable-bootstrap \
  48. --with-system-zlib</userinput></screen>
  49. <para>Note that for other languages, there are some prerequisites that
  50. are not yet available. See the
  51. <ulink url="&blfs-book;general/gcc.html">BLFS Book</ulink>
  52. for instructions on how to build all of GCC's supported languages.</para>
  53. <variablelist>
  54. <title>The meaning of the new configure option:</title>
  55. <varlistentry>
  56. <term><envar>SED=sed</envar></term>
  57. <listitem>
  58. <para>Setting this environment variable prevents a hard-coded
  59. path to /tools/bin/sed.</para>
  60. </listitem>
  61. </varlistentry>
  62. <varlistentry>
  63. <term><parameter>--with-system-zlib</parameter></term>
  64. <listitem>
  65. <para>This switch tells GCC to link to the system installed copy of
  66. the Zlib library, rather than its own internal copy.</para>
  67. </listitem>
  68. </varlistentry>
  69. </variablelist>
  70. <para>Compile the package:</para>
  71. <screen><userinput remap="make">make</userinput></screen>
  72. <important>
  73. <para>In this section, the test suite for GCC is considered
  74. critical. Do not skip it under any circumstance.</para>
  75. </important>
  76. <para>One set of tests in the GCC test suite is known to exhaust the stack,
  77. so increase the stack size prior to running the tests:</para>
  78. <screen><userinput remap="test">ulimit -s 32768</userinput></screen>
  79. <para>Test the results, but do not stop at errors:</para>
  80. <screen><userinput remap="test">make -k check</userinput></screen>
  81. <para>To receive a summary of the test suite results, run:</para>
  82. <screen><userinput remap="test">../gcc-&gcc-version;/contrib/test_summary</userinput></screen>
  83. <para>For only the summaries, pipe the output through
  84. <userinput>grep -A7 Summ</userinput>.</para>
  85. <para>Results can be compared with those located at <ulink
  86. url="&test-results;"/> and <ulink url="http://gcc.gnu.org/ml/gcc-testresults/"/>.</para>
  87. <para>A few unexpected failures cannot always be avoided. The GCC developers
  88. are usually aware of these issues, but have not resolved them yet.
  89. In particular, one test in the libgomp test suite is known to fail.
  90. Unless the test results are vastly different from those at the above URL,
  91. it is safe to continue.</para>
  92. <para>Install the package:</para>
  93. <screen><userinput remap="install">make install</userinput></screen>
  94. <para>Some packages expect the C preprocessor to be installed in the
  95. <filename class="directory">/lib</filename> directory.
  96. To support those packages, create this symlink:</para>
  97. <screen><userinput remap="install">ln -sv ../usr/bin/cpp /lib</userinput></screen>
  98. <para>Many packages use the name <command>cc</command> to call the C
  99. compiler. To satisfy those packages, create a symlink:</para>
  100. <screen><userinput remap="install">ln -sv gcc /usr/bin/cc</userinput></screen>
  101. <para>Add a compatibility symlink to enable building programs with
  102. Link Time Optimization (LTO):</para>
  103. <screen><userinput remap="install">install -v -dm755 /usr/lib/bfd-plugins
  104. ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/&gcc-version;/liblto_plugin.so \
  105. /usr/lib/bfd-plugins/</userinput></screen>
  106. <para>Now that our final toolchain is in place, it is important to again ensure
  107. that compiling and linking will work as expected. We do this by performing
  108. the same sanity checks as we did earlier in the chapter:</para>
  109. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  110. href="adjusting.xml"
  111. xpointer="xpointer(//*[@os='a'])"/>
  112. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  113. href="adjusting.xml"
  114. xpointer="xpointer(//*[@os='b'])"/>
  115. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  116. href="adjusting.xml"
  117. xpointer="xpointer(//*[@os='c'])"/>
  118. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  119. href="adjusting.xml"
  120. xpointer="xpointer(//*[@os='d'])"/>
  121. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  122. href="adjusting.xml"
  123. xpointer="xpointer(//*[@os='e'])"/>
  124. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  125. href="adjusting.xml"
  126. xpointer="xpointer(//*[@os='f'])"/>
  127. <screen><computeroutput>/usr/lib/gcc/i686-pc-linux-gnu/&gcc-version;/../../../crt1.o succeeded
  128. /usr/lib/gcc/i686-pc-linux-gnu/&gcc-version;/../../../crti.o succeeded
  129. /usr/lib/gcc/i686-pc-linux-gnu/&gcc-version;/../../../crtn.o succeeded</computeroutput></screen>
  130. <para>Depending on your machine architecture, the above may differ slightly,
  131. the difference usually being the name of the directory
  132. after <filename class="directory">/usr/lib/gcc</filename>. If your machine is
  133. a 64-bit system, you may also see a directory named <filename class="directory">lib64</filename>
  134. towards the end of the string. The important thing to
  135. look for here is that <command>gcc</command> has found all three
  136. <filename>crt*.o</filename> files under the
  137. <filename class="directory">/usr/lib</filename> directory.</para>
  138. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  139. href="adjusting.xml"
  140. xpointer="xpointer(//*[@os='g'])"/>
  141. <screen><userinput>grep -B4 '^ /usr/include' dummy.log</userinput></screen>
  142. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  143. href="adjusting.xml"
  144. xpointer="xpointer(//*[@os='h'])"/>
  145. <screen><computeroutput>#include &lt;...&gt; search starts here:
  146. /usr/lib/gcc/i686-pc-linux-gnu/&gcc-version;/include
  147. /usr/local/include
  148. /usr/lib/gcc/i686-pc-linux-gnu/&gcc-version;/include-fixed
  149. /usr/include</computeroutput></screen>
  150. <para>Again, note that the directory named after your target triplet may be
  151. different than the above, depending on your architecture.</para>
  152. <note><para>As of version 4.3.0, GCC now unconditionally installs the
  153. <filename>limits.h</filename> file into the private
  154. <filename class="directory">include-fixed</filename> directory, and that
  155. directory is required to be in place.</para></note>
  156. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  157. href="adjusting.xml"
  158. xpointer="xpointer(//*[@os='i'])"/>
  159. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  160. href="adjusting.xml"
  161. xpointer="xpointer(//*[@os='j'])"/>
  162. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  163. href="adjusting.xml"
  164. xpointer="xpointer(//*[@os='k'])"/>
  165. <screen><computeroutput>SEARCH_DIR("/usr/i686-pc-linux-gnu/lib32")
  166. SEARCH_DIR("/usr/local/lib32")
  167. SEARCH_DIR("/lib32")
  168. SEARCH_DIR("/usr/lib32")
  169. SEARCH_DIR("/usr/i686-pc-linux-gnu/lib")
  170. SEARCH_DIR("/usr/local/lib")
  171. SEARCH_DIR("/lib")
  172. SEARCH_DIR("/usr/lib");</computeroutput></screen>
  173. <para>A 64-bit system may see a few different directories. For example, here
  174. is the output from an x86_64 machine:</para>
  175. <screen><computeroutput>SEARCH_DIR("/usr/x86_64-unknown-linux-gnu/lib64")
  176. SEARCH_DIR("/usr/local/lib64")
  177. SEARCH_DIR("/lib64")
  178. SEARCH_DIR("/usr/lib64")
  179. SEARCH_DIR("/usr/x86_64-unknown-linux-gnu/lib")
  180. SEARCH_DIR("/usr/local/lib")
  181. SEARCH_DIR("/lib")
  182. SEARCH_DIR("/usr/lib");</computeroutput></screen>
  183. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  184. href="adjusting.xml"
  185. xpointer="xpointer(//*[@os='l'])"/>
  186. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  187. href="adjusting.xml"
  188. xpointer="xpointer(//*[@os='m'])"/>
  189. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  190. href="adjusting.xml"
  191. xpointer="xpointer(//*[@os='n'])"/>
  192. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  193. href="adjusting.xml"
  194. xpointer="xpointer(//*[@os='o'])"/>
  195. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  196. href="adjusting.xml"
  197. xpointer="xpointer(//*[@os='p'])"/>
  198. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  199. href="adjusting.xml"
  200. xpointer="xpointer(//*[@os='q'])"/>
  201. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  202. href="adjusting.xml"
  203. xpointer="xpointer(//*[@os='r'])"/>
  204. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  205. href="adjusting.xml"
  206. xpointer="xpointer(//*[@os='s'])"/>
  207. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  208. href="adjusting.xml"
  209. xpointer="xpointer(//*[@os='t'])"/>
  210. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  211. href="adjusting.xml"
  212. xpointer="xpointer(//*[@os='u'])"/>
  213. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  214. href="adjusting.xml"
  215. xpointer="xpointer(//*[@os='v'])"/>
  216. <para>Finally, move a misplaced file:</para>
  217. <screen><userinput remap="install">mkdir -pv /usr/share/gdb/auto-load/usr/lib
  218. mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib</userinput></screen>
  219. </sect2>
  220. <sect2 id="contents-gcc" role="content">
  221. <title>Contents of GCC</title>
  222. <segmentedlist>
  223. <segtitle>Installed programs</segtitle>
  224. <segtitle>Installed libraries</segtitle>
  225. <segtitle>Installed directories</segtitle>
  226. <seglistitem>
  227. <seg>c++, cc (link to gcc), cpp, g++, gcc,
  228. gcc-ar, gcc-nm, gcc-ranlib, and gcov</seg>
  229. <seg>libasan.{a,so}, libatomic.{a,so}, libgcc.a, libgcc_eh.a,
  230. libgcc_s.so, libgcov.a, libgomp.{a,so}, libiberty.a, libitm.{a,so},
  231. liblto_plugin.so,
  232. libquadmath.{a,so}, libssp.{a,so},
  233. libssp_nonshared.a, libstdc++.{a,so}, libsupc++.a, and libtsan.{a,so}</seg>
  234. <seg>/usr/include/c++, /usr/lib/gcc, /usr/libexec/gcc, and
  235. /usr/share/gcc-&gcc-version;</seg>
  236. </seglistitem>
  237. </segmentedlist>
  238. <variablelist>
  239. <bridgehead renderas="sect3">Short Descriptions</bridgehead>
  240. <?dbfo list-presentation="list"?>
  241. <?dbhtml list-presentation="table"?>
  242. <varlistentry id="c">
  243. <term><command>c++</command></term>
  244. <listitem>
  245. <para>The C++ compiler</para>
  246. <indexterm zone="ch-system-gcc c">
  247. <primary sortas="b-c++">c++</primary>
  248. </indexterm>
  249. </listitem>
  250. </varlistentry>
  251. <varlistentry id="cc">
  252. <term><command>cc</command></term>
  253. <listitem>
  254. <para>The C compiler</para>
  255. <indexterm zone="ch-system-gcc cc">
  256. <primary sortas="b-cc">cc</primary>
  257. </indexterm>
  258. </listitem>
  259. </varlistentry>
  260. <varlistentry id="cpp">
  261. <term><command>cpp</command></term>
  262. <listitem>
  263. <para>The C preprocessor; it is used by the compiler to expand the
  264. #include, #define, and similar statements in the source files</para>
  265. <indexterm zone="ch-system-gcc cpp">
  266. <primary sortas="b-cpp">cpp</primary>
  267. </indexterm>
  268. </listitem>
  269. </varlistentry>
  270. <varlistentry id="g">
  271. <term><command>g++</command></term>
  272. <listitem>
  273. <para>The C++ compiler</para>
  274. <indexterm zone="ch-system-gcc g">
  275. <primary sortas="b-g++">g++</primary>
  276. </indexterm>
  277. </listitem>
  278. </varlistentry>
  279. <varlistentry id="gcc">
  280. <term><command>gcc</command></term>
  281. <listitem>
  282. <para>The C compiler</para>
  283. <indexterm zone="ch-system-gcc gcc">
  284. <primary sortas="b-gcc">gcc</primary>
  285. </indexterm>
  286. </listitem>
  287. </varlistentry>
  288. <varlistentry id="gcc-ar">
  289. <term><command>gcc-ar</command></term>
  290. <listitem>
  291. <para>A wrapper around <command>ar</command> that adds a
  292. plugin to the command line. This program is only used
  293. to add "link time optization" and is not useful with the
  294. default build options</para>
  295. <indexterm zone="ch-system-gcc gcc-ar">
  296. <primary sortas="b-gcc-ar">gc-ar</primary>
  297. </indexterm>
  298. </listitem>
  299. </varlistentry>
  300. <varlistentry id="gcc-nm">
  301. <term><command>gcc-nm</command></term>
  302. <listitem>
  303. <para>A wrapper around <command>nm</command> that adds a
  304. plugin to the command line. This program is only used
  305. to add "link time optization" and is not useful with the
  306. default build options</para>
  307. <indexterm zone="ch-system-gcc gcc-nm">
  308. <primary sortas="b-gcc-nm">gc-nm</primary>
  309. </indexterm>
  310. </listitem>
  311. </varlistentry>
  312. <varlistentry id="gcc-ranlib">
  313. <term><command>gcc-ranlib</command></term>
  314. <listitem>
  315. <para>A wrapper around <command>ranlib</command> that adds a
  316. plugin to the command line. This program is only used
  317. to add "link time optization" and is not useful with the
  318. default build options</para>
  319. <indexterm zone="ch-system-gcc gcc-ranlib">
  320. <primary sortas="b-gcc-ranlib">gc-ranlib</primary>
  321. </indexterm>
  322. </listitem>
  323. </varlistentry>
  324. <varlistentry id="gcov">
  325. <term><command>gcov</command></term>
  326. <listitem>
  327. <para>A coverage testing tool; it is used to analyze programs to
  328. determine where optimizations will have the most effect</para>
  329. <indexterm zone="ch-system-gcc gcov">
  330. <primary sortas="b-gcov">gcov</primary>
  331. </indexterm>
  332. </listitem>
  333. </varlistentry>
  334. <varlistentry id="libasan">
  335. <term><command>libasan</command></term>
  336. <listitem>
  337. <para>The Address Sanitizer runtime library</para>
  338. <indexterm zone="ch-system-gcc libasan">
  339. <primary sortas="b-libasan">libasan</primary>
  340. </indexterm>
  341. </listitem>
  342. </varlistentry>
  343. <varlistentry id="libgcc">
  344. <term><filename class="libraryfile">libgcc</filename></term>
  345. <listitem>
  346. <para>Contains run-time support for <command>gcc</command></para>
  347. <indexterm zone="ch-system-gcc libgcc">
  348. <primary sortas="c-libgcc">libgcc</primary>
  349. </indexterm>
  350. </listitem>
  351. </varlistentry>
  352. <varlistentry id="libgcov">
  353. <term><filename class="libraryfile">libgcov</filename></term>
  354. <listitem>
  355. <para>This library is linked in to a program when GCC is instructed
  356. to enable profiling</para>
  357. <indexterm zone="ch-system-gcc libgcov">
  358. <primary sortas="c-libgcov">libgcov</primary>
  359. </indexterm>
  360. </listitem>
  361. </varlistentry>
  362. <varlistentry id="libgomp">
  363. <term><filename class="libraryfile">libgomp</filename></term>
  364. <listitem>
  365. <para>GNU implementation of the OpenMP API for multi-platform
  366. shared-memory parallel programming in C/C++ and Fortran</para>
  367. <indexterm zone="ch-system-gcc libgomp">
  368. <primary sortas="c-libgomp">libgomp</primary>
  369. </indexterm>
  370. </listitem>
  371. </varlistentry>
  372. <varlistentry id="libiberty">
  373. <term><filename class="libraryfile">libiberty</filename></term>
  374. <listitem>
  375. <para>Contains routines used by various GNU programs, including
  376. <command>getopt</command>, <command>obstack</command>,
  377. <command>strerror</command>, <command>strtol</command>, and
  378. <command>strtoul</command></para>
  379. <indexterm zone="ch-system-gcc libiberty">
  380. <primary sortas="c-libiberty">libiberty</primary>
  381. </indexterm>
  382. </listitem>
  383. </varlistentry>
  384. <varlistentry id="liblto_plugin">
  385. <term><filename class="libraryfile">liblto_plugin</filename></term>
  386. <listitem>
  387. <para>GCC's Link Time Optimization (LTO) plugin allows GCC to perform
  388. optimizations across compilation units</para>
  389. <indexterm zone="ch-system-gcc liblto_plugin">
  390. <primary sortas="c-liblto_plugin">liblto_plugin</primary>
  391. </indexterm>
  392. </listitem>
  393. </varlistentry>
  394. <varlistentry id="libquadmath">
  395. <term><filename class="libraryfile">libquadmath</filename></term>
  396. <listitem>
  397. <para>GCC Quad Precision Math Library API</para>
  398. <indexterm zone="ch-system-gcc libquadmath">
  399. <primary sortas="c-libquadmath">libquadmath</primary>
  400. </indexterm>
  401. </listitem>
  402. </varlistentry>
  403. <varlistentry id="libssp">
  404. <term><filename class="libraryfile">libssp</filename></term>
  405. <listitem>
  406. <para>Contains routines supporting GCC's stack-smashing protection
  407. functionality</para>
  408. <indexterm zone="ch-system-gcc libssp">
  409. <primary sortas="c-libssp">libssp</primary>
  410. </indexterm>
  411. </listitem>
  412. </varlistentry>
  413. <varlistentry id="libstdc">
  414. <term><filename class="libraryfile">libstdc++</filename></term>
  415. <listitem>
  416. <para>The standard C++ library</para>
  417. <indexterm zone="ch-system-gcc libstdc">
  418. <primary sortas="c-libstdc++">libstdc++</primary>
  419. </indexterm>
  420. </listitem>
  421. </varlistentry>
  422. <varlistentry id="libsupc">
  423. <term><filename class="libraryfile">libsupc++</filename></term>
  424. <listitem>
  425. <para>Provides supporting routines for the C++ programming
  426. language</para>
  427. <indexterm zone="ch-system-gcc libsupc">
  428. <primary sortas="c-libsupc++">libsupc++</primary>
  429. </indexterm>
  430. </listitem>
  431. </varlistentry>
  432. <varlistentry id="libtsan">
  433. <term><filename class="libraryfile">libtsan</filename></term>
  434. <listitem>
  435. <para>The Thread Sanitizer runtime library</para>
  436. <indexterm zone="ch-system-gcc libtsan">
  437. <primary sortas="c-libtsan">libtsan</primary>
  438. </indexterm>
  439. </listitem>
  440. </varlistentry>
  441. </variablelist>
  442. </sect2>
  443. </sect1>