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