gcc.xml 19 KB

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