gcc.xml 19 KB

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