gcc.xml 20 KB

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