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">
8 <sect1 id="ch-system-gcc" role="wrap">
9 <?dbhtml filename="gcc.html"?>
11 <sect1info condition="script">
12 <productname>gcc</productname>
13 <productnumber>&gcc-version;</productnumber>
14 <address>&gcc-url;</address>
17 <title>GCC-&gcc-version;</title>
19 <indexterm zone="ch-system-gcc">
20 <primary sortas="a-GCC">GCC</primary>
23 <sect2 role="package">
26 <para>The GCC package contains the GNU compiler collection, which includes
27 the C and C++ compilers.</para>
30 <segtitle>&buildtime;</segtitle>
31 <segtitle>&diskspace;</segtitle>
34 <seg>&gcc-ch6-sbu;</seg>
35 <seg>&gcc-ch6-du;</seg>
41 <sect2 role="installation">
42 <title>Installation of GCC</title>
44 <para>If building on x86_64, change the default directory name for 64-bit
45 libraries to <quote>lib</quote>:</para>
47 <screen><userinput remap="pre">case $(uname -m) in
49 sed -e '/m64=/s/lib64/lib/' \
50 -i.orig gcc/config/i386/t-linux64
52 esac</userinput></screen>
54 <para>Remove the symlink created earlier as the final gcc includes will be
55 installed here:</para>
57 <screen><userinput remap="pre">rm -f /usr/lib/gcc</userinput></screen>
59 <para>The GCC documentation recommends building GCC in a dedicated build directory:</para>
61 <screen><userinput remap="pre">mkdir -v build
62 cd build</userinput></screen>
64 <para>Prepare GCC for compilation:</para>
66 <screen><userinput remap="configure">SED=sed \
67 ../configure --prefix=/usr \
68 --enable-languages=c,c++ \
71 --with-system-zlib</userinput></screen>
73 <para>Note that for other languages, there are some prerequisites that
74 are not yet available. See the
75 <ulink url="&blfs-book;general/gcc.html">BLFS Book</ulink>
76 for instructions on how to build all of GCC's supported languages.</para>
79 <title>The meaning of the new configure parameters:</title>
82 <term><envar>SED=sed</envar></term>
84 <para>Setting this environment variable prevents a hard-coded
85 path to /tools/bin/sed.</para>
90 <term><parameter>--with-system-zlib</parameter></term>
92 <para>This switch tells GCC to link to the system installed copy of
93 the Zlib library, rather than its own internal copy.</para>
98 <para>Compile the package:</para>
100 <screen><userinput remap="make">make</userinput></screen>
103 <para>In this section, the test suite for GCC is considered
104 critical. Do not skip it under any circumstance.</para>
107 <para>One set of tests in the GCC test suite is known to exhaust the stack,
108 so increase the stack size prior to running the tests:</para>
110 <screen><userinput remap="test">ulimit -s 32768</userinput></screen>
112 <para>Test the results, but do not stop at errors:</para>
114 <screen><userinput remap="test">make -k check</userinput></screen>
116 <para>To receive a summary of the test suite results, run:</para>
118 <screen><userinput remap="test">../contrib/test_summary</userinput></screen>
120 <para>For only the summaries, pipe the output through
121 <userinput>grep -A7 Summ</userinput>.</para>
123 <para>Results can be compared with those located at <ulink
124 url="&test-results;"/> and
125 <ulink url="https://gcc.gnu.org/ml/gcc-testresults/"/>.</para>
127 <para>A few unexpected failures cannot always be avoided. The GCC developers
128 are usually aware of these issues, but have not resolved them yet.
129 In particular, six tests in the libstdc++ test suite are known to fail
130 when running as the root user as we do here.
131 Unless the test results are vastly different from those at the above URL,
132 it is safe to continue.</para>
135 On some combinations of kernel configuration and AMD processors
136 there may be more than 1100 failures in the gcc.target/i386/mpx
137 tests (which are designed to test the MPX option on recent
138 Intel processors). These can safely be ignored on AMD
142 <para>Install the package:</para>
144 <screen><userinput remap="install">make install</userinput></screen>
146 <para>Create a symlink required by the <ulink
147 url="https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s09.html">FHS</ulink>
148 for "historical" reasons.</para>
150 <screen><userinput remap="install">ln -sv ../usr/bin/cpp /lib</userinput></screen>
152 <para>Many packages use the name <command>cc</command> to call the C
153 compiler. To satisfy those packages, create a symlink:</para>
155 <screen><userinput remap="install">ln -sv gcc /usr/bin/cc</userinput></screen>
157 <para>Add a compatibility symlink to enable building programs with
158 Link Time Optimization (LTO):</para>
160 <screen><userinput remap="install">install -v -dm755 /usr/lib/bfd-plugins
161 ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/&gcc-version;/liblto_plugin.so \
162 /usr/lib/bfd-plugins/</userinput></screen>
164 <para>Now that our final toolchain is in place, it is important to again ensure
165 that compiling and linking will work as expected. We do this by performing
166 the same sanity checks as we did earlier in the chapter:</para>
168 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
170 xpointer="xpointer(//*[@os='a'])"/>
172 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
174 xpointer="xpointer(//*[@os='b'])"/>
176 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
178 xpointer="xpointer(//*[@os='c'])"/>
180 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
182 xpointer="xpointer(//*[@os='d'])"/>
184 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
186 xpointer="xpointer(//*[@os='e'])"/>
188 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
190 xpointer="xpointer(//*[@os='f'])"/>
192 <screen><computeroutput>/usr/lib/gcc/x86_64-pc-linux-gnu/&gcc-version;/../../../../lib/crt1.o succeeded
193 /usr/lib/gcc/x86_64-pc-linux-gnu/&gcc-version;/../../../../lib/crti.o succeeded
194 /usr/lib/gcc/x86_64-pc-linux-gnu/&gcc-version;/../../../../lib/crtn.o succeeded</computeroutput></screen>
196 <para>Depending on your machine architecture, the above may differ slightly,
197 the difference usually being the name of the directory
198 after <filename class="directory">/usr/lib/gcc</filename>. The important
199 thing to look for here is that <command>gcc</command> has found all three
200 <filename>crt*.o</filename> files under the
201 <filename class="directory">/usr/lib</filename> directory.</para>
203 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
205 xpointer="xpointer(//*[@os='g'])"/>
207 <screen><userinput>grep -B4 '^ /usr/include' dummy.log</userinput></screen>
209 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
211 xpointer="xpointer(//*[@os='h'])"/>
213 <screen><computeroutput>#include <...> search starts here:
214 /usr/lib/gcc/x86_64-pc-linux-gnu/&gcc-version;/include
216 /usr/lib/gcc/x86_64-pc-linux-gnu/&gcc-version;/include-fixed
217 /usr/include</computeroutput></screen>
219 <para>Again, note that the directory named after your target triplet may be
220 different than the above, depending on your architecture.</para>
222 <!-- This appears to be obsolete
224 <note><para>As of version 4.3.0, GCC now unconditionally installs the
225 <filename>limits.h</filename> file into the private
226 <filename class="directory">include-fixed</filename> directory, and that
227 directory is required to be in place.</para></note>
230 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
232 xpointer="xpointer(//*[@os='i'])"/>
234 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
236 xpointer="xpointer(//*[@os='j'])"/>
238 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
240 xpointer="xpointer(//*[@os='k'])"/>
242 <screen><computeroutput>SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib64")
243 SEARCH_DIR("/usr/local/lib64")
245 SEARCH_DIR("/usr/lib64")
246 SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib")
247 SEARCH_DIR("/usr/local/lib")
249 SEARCH_DIR("/usr/lib");</computeroutput></screen>
251 <para>A 32-bit system may see a few different directories. For example, here
252 is the output from an i686 machine:</para>
254 <screen><computeroutput>SEARCH_DIR("/usr/i686-pc-linux-gnu/lib32")
255 SEARCH_DIR("/usr/local/lib32")
257 SEARCH_DIR("/usr/lib32")
258 SEARCH_DIR("/usr/i686-pc-linux-gnu/lib")
259 SEARCH_DIR("/usr/local/lib")
261 SEARCH_DIR("/usr/lib");</computeroutput></screen>
263 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
265 xpointer="xpointer(//*[@os='l'])"/>
267 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
269 xpointer="xpointer(//*[@os='m'])"/>
271 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
273 xpointer="xpointer(//*[@os='n'])"/>
275 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
277 xpointer="xpointer(//*[@os='o'])"/>
279 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
281 xpointer="xpointer(//*[@os='p'])"/>
283 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
285 xpointer="xpointer(//*[@os='q'])"/>
287 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
289 xpointer="xpointer(//*[@os='r'])"/>
291 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
293 xpointer="xpointer(//*[@os='s'])"/>
295 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
297 xpointer="xpointer(//*[@os='t'])"/>
299 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
301 xpointer="xpointer(//*[@os='u'])"/>
303 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
305 xpointer="xpointer(//*[@os='v'])"/>
307 <para>Finally, move a misplaced file:</para>
309 <screen><userinput remap="install">mkdir -pv /usr/share/gdb/auto-load/usr/lib
310 mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib</userinput></screen>
314 <sect2 id="contents-gcc" role="content">
315 <title>Contents of GCC</title>
318 <segtitle>Installed programs</segtitle>
319 <segtitle>Installed libraries</segtitle>
320 <segtitle>Installed directories</segtitle>
323 <seg>c++, cc (link to gcc), cpp, g++, gcc,
324 gcc-ar, gcc-nm, gcc-ranlib, and gcov</seg>
326 <seg>libasan.{a,so}, libatomic.{a,so}, libgcc.a, libgcc_eh.a,
327 libgcc_s.so, libgcov.a, libgomp.{a,so}, libiberty.a, libitm.{a,so},
329 libquadmath.{a,so}, libssp.{a,so},
330 libssp_nonshared.a, libstdc++.{a,so}, libsupc++.a, and libtsan.{a,so}</seg>
332 <seg>/usr/include/c++, /usr/lib/gcc, /usr/libexec/gcc, and
333 /usr/share/gcc-&gcc-version;</seg>
338 <bridgehead renderas="sect3">Short Descriptions</bridgehead>
339 <?dbfo list-presentation="list"?>
340 <?dbhtml list-presentation="table"?>
342 <varlistentry id="c">
343 <term><command>c++</command></term>
345 <para>The C++ compiler</para>
346 <indexterm zone="ch-system-gcc c">
347 <primary sortas="b-c++">c++</primary>
352 <varlistentry id="cc">
353 <term><command>cc</command></term>
355 <para>The C compiler</para>
356 <indexterm zone="ch-system-gcc cc">
357 <primary sortas="b-cc">cc</primary>
362 <varlistentry id="cpp">
363 <term><command>cpp</command></term>
365 <para>The C preprocessor; it is used by the compiler to expand the
366 #include, #define, and similar statements in the source files</para>
367 <indexterm zone="ch-system-gcc cpp">
368 <primary sortas="b-cpp">cpp</primary>
373 <varlistentry id="g">
374 <term><command>g++</command></term>
376 <para>The C++ compiler</para>
377 <indexterm zone="ch-system-gcc g">
378 <primary sortas="b-g++">g++</primary>
383 <varlistentry id="gcc">
384 <term><command>gcc</command></term>
386 <para>The C compiler</para>
387 <indexterm zone="ch-system-gcc gcc">
388 <primary sortas="b-gcc">gcc</primary>
393 <varlistentry id="gcc-ar">
394 <term><command>gcc-ar</command></term>
396 <para>A wrapper around <command>ar</command> that adds a
397 plugin to the command line. This program is only used
398 to add "link time optimization" and is not useful with the
399 default build options</para>
400 <indexterm zone="ch-system-gcc gcc-ar">
401 <primary sortas="b-gcc-ar">gc-ar</primary>
406 <varlistentry id="gcc-nm">
407 <term><command>gcc-nm</command></term>
409 <para>A wrapper around <command>nm</command> that adds a
410 plugin to the command line. This program is only used
411 to add "link time optimization" and is not useful with the
412 default build options</para>
413 <indexterm zone="ch-system-gcc gcc-nm">
414 <primary sortas="b-gcc-nm">gc-nm</primary>
419 <varlistentry id="gcc-ranlib">
420 <term><command>gcc-ranlib</command></term>
422 <para>A wrapper around <command>ranlib</command> that adds a
423 plugin to the command line. This program is only used
424 to add "link time optimization" and is not useful with the
425 default build options</para>
426 <indexterm zone="ch-system-gcc gcc-ranlib">
427 <primary sortas="b-gcc-ranlib">gc-ranlib</primary>
432 <varlistentry id="gcov">
433 <term><command>gcov</command></term>
435 <para>A coverage testing tool; it is used to analyze programs to
436 determine where optimizations will have the most effect</para>
437 <indexterm zone="ch-system-gcc gcov">
438 <primary sortas="b-gcov">gcov</primary>
443 <varlistentry id="libasan">
444 <term><command>libasan</command></term>
446 <para>The Address Sanitizer runtime library</para>
447 <indexterm zone="ch-system-gcc libasan">
448 <primary sortas="b-libasan">libasan</primary>
453 <varlistentry id="libgcc">
454 <term><filename class="libraryfile">libgcc</filename></term>
456 <para>Contains run-time support for <command>gcc</command></para>
457 <indexterm zone="ch-system-gcc libgcc">
458 <primary sortas="c-libgcc">libgcc</primary>
463 <varlistentry id="libgcov">
464 <term><filename class="libraryfile">libgcov</filename></term>
466 <para>This library is linked in to a program when GCC is instructed
467 to enable profiling</para>
468 <indexterm zone="ch-system-gcc libgcov">
469 <primary sortas="c-libgcov">libgcov</primary>
474 <varlistentry id="libgomp">
475 <term><filename class="libraryfile">libgomp</filename></term>
477 <para>GNU implementation of the OpenMP API for multi-platform
478 shared-memory parallel programming in C/C++ and Fortran</para>
479 <indexterm zone="ch-system-gcc libgomp">
480 <primary sortas="c-libgomp">libgomp</primary>
485 <varlistentry id="libiberty">
486 <term><filename class="libraryfile">libiberty</filename></term>
488 <para>Contains routines used by various GNU programs, including
489 <command>getopt</command>, <command>obstack</command>,
490 <command>strerror</command>, <command>strtol</command>, and
491 <command>strtoul</command></para>
492 <indexterm zone="ch-system-gcc libiberty">
493 <primary sortas="c-libiberty">libiberty</primary>
498 <varlistentry id="liblto_plugin">
499 <term><filename class="libraryfile">liblto_plugin</filename></term>
501 <para>GCC's Link Time Optimization (LTO) plugin allows GCC to perform
502 optimizations across compilation units</para>
503 <indexterm zone="ch-system-gcc liblto_plugin">
504 <primary sortas="c-liblto_plugin">liblto_plugin</primary>
509 <varlistentry id="libquadmath">
510 <term><filename class="libraryfile">libquadmath</filename></term>
512 <para>GCC Quad Precision Math Library API</para>
513 <indexterm zone="ch-system-gcc libquadmath">
514 <primary sortas="c-libquadmath">libquadmath</primary>
519 <varlistentry id="libssp">
520 <term><filename class="libraryfile">libssp</filename></term>
522 <para>Contains routines supporting GCC's stack-smashing protection
524 <indexterm zone="ch-system-gcc libssp">
525 <primary sortas="c-libssp">libssp</primary>
530 <varlistentry id="libstdc">
531 <term><filename class="libraryfile">libstdc++</filename></term>
533 <para>The standard C++ library</para>
534 <indexterm zone="ch-system-gcc libstdc">
535 <primary sortas="c-libstdc++">libstdc++</primary>
540 <varlistentry id="libsupc">
541 <term><filename class="libraryfile">libsupc++</filename></term>
543 <para>Provides supporting routines for the C++ programming
545 <indexterm zone="ch-system-gcc libsupc">
546 <primary sortas="c-libsupc++">libsupc++</primary>
551 <varlistentry id="libtsan">
552 <term><filename class="libraryfile">libtsan</filename></term>
554 <para>The Thread Sanitizer runtime library</para>
555 <indexterm zone="ch-system-gcc libtsan">
556 <primary sortas="c-libtsan">libtsan</primary>