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-fin-sbu;</seg>
35 <seg>&gcc-fin-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>The GCC documentation recommends building GCC in a dedicated build directory:</para>
56 <screen><userinput remap="pre">mkdir -v build
57 cd build</userinput></screen>
59 <para>Prepare GCC for compilation:</para>
61 <screen><userinput remap="configure">../configure --prefix=/usr \
63 --enable-languages=c,c++ \
66 --with-system-zlib</userinput></screen>
68 <para>Note that for other programming languages there are some prerequisites that
69 are not yet available. See the
70 <ulink url="&blfs-book;general/gcc.html">BLFS Book GCC page</ulink>
71 for instructions on how to build all of GCC's supported languages.</para>
74 <title>The meaning of the new configure parameters:</title>
77 <term><parameter>LD=ld</parameter></term>
79 <para>This parameter makes the configure script use the ld installed
80 by the binutils built earlier in this chapter, rather than
81 the cross-built version which would otherwise be used.</para>
86 <term><parameter>--with-system-zlib</parameter></term>
88 <para>This switch tells GCC to link to the system installed copy of
89 the zlib library, rather than its own internal copy.</para>
94 <para>Compile the package:</para>
96 <screen><userinput remap="make">make</userinput></screen>
99 <para>In this section, the test suite for GCC is considered
100 critical. Do not skip it under any circumstance.</para>
103 <para>One set of tests in the GCC test suite is known to exhaust the default
104 stack, so increase the stack size prior to running the tests:</para>
106 <screen><userinput remap="test">ulimit -s 32768</userinput></screen>
108 <para>Test the results as a non-privileged user, but do not stop at errors:</para>
110 <screen><userinput remap="test">chown -Rv tester .
111 su tester -c "PATH=$PATH make -k check"</userinput></screen>
113 <para>To receive a summary of the test suite results, run:</para>
115 <screen><userinput remap="test">../contrib/test_summary</userinput></screen>
117 <para>For only the summaries, pipe the output through
118 <userinput>grep -A7 Summ</userinput>.</para>
120 <para>Results can be compared with those located at <ulink
121 url="&test-results;"/> and
122 <ulink url="https://gcc.gnu.org/ml/gcc-testresults/"/>.</para>
124 <para>Six tests related to get_time are known to fail. These are
125 apparently related to the en_HK locale.</para>
127 <para>Additionally the following tests related to the following files
128 are known to fail with glibc-2.32: asan_test.C, co-ret-17-void-ret-coro.C,
129 pr95519-05-gro.C, pr80166.c.</para>
131 <!-- don't fail anymore after the move of iana-etc and /etc/hosts
132 <para>Two tests named lookup.cc and reverse.cc in experimental/net
133 are known to fail in LFS chroot environment because they require
134 /etc/hosts and iana-etc.</para>
136 <para>A few unexpected failures cannot always be avoided. The GCC developers
137 are usually aware of these issues, but have not resolved them yet.
138 Unless the test results are vastly different from those at the above URL,
139 it is safe to continue.</para>
142 On some combinations of kernel configuration and AMD processors
143 there may be more than 1100 failures in the gcc.target/i386/mpx
144 tests (which are designed to test the MPX option on recent
145 Intel processors). These can safely be ignored on AMD
146 processors. These tests will also fail on Intel processors if MPX support
147 is not enabled in the kernel even though it is present on the CPU.
150 <para>Install the package and remove an unneeded directory:</para>
152 <screen><userinput remap="install">make install
153 rm -rf /usr/lib/gcc/$(gcc -dumpmachine)/&gcc-version;/include-fixed/bits/</userinput></screen>
155 <para>The GCC build directory is owned by <systemitem class="username">
156 tester</systemitem> now and the ownership of the installed header
157 directory (and its content) will be incorrect. Change the ownership to
158 <systemitem class="username">root</systemitem> user and group:</para>
160 <screen><userinput remap="install">chown -v -R root:root \
161 /usr/lib/gcc/*linux-gnu/&gcc-version;/include{,-fixed}</userinput></screen>
163 <para>Create a symlink required by the <ulink
164 url="https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s09.html">FHS</ulink>
165 for "historical" reasons.</para>
167 <screen><userinput remap="install">ln -sv ../usr/bin/cpp /lib</userinput></screen>
168 <!-- already done earlier
169 <para>Many packages use the name <command>cc</command> to call the C
170 compiler. To satisfy those packages, create a symlink:</para>
172 <screen><userinput remap="install">ln -sv gcc /usr/bin/cc</userinput></screen>
174 <para>Add a compatibility symlink to enable building programs with
175 Link Time Optimization (LTO):</para>
177 <screen><userinput remap="install">install -v -dm755 /usr/lib/bfd-plugins
178 ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/&gcc-version;/liblto_plugin.so \
179 /usr/lib/bfd-plugins/</userinput></screen>
181 <para>Now that our final toolchain is in place, it is important to again ensure
182 that compiling and linking will work as expected. We do this by performing
183 some sanity checks:</para>
185 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
187 xpointer="xpointer(//*[@os='a'])"/>
189 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
191 xpointer="xpointer(//*[@os='b'])"/>
193 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
195 xpointer="xpointer(//*[@os='c'])"/>
197 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
199 xpointer="xpointer(//*[@os='d'])"/>
201 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
203 xpointer="xpointer(//*[@os='e'])"/>
205 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
207 xpointer="xpointer(//*[@os='f'])"/>
209 <screen><computeroutput>/usr/lib/gcc/x86_64-pc-linux-gnu/&gcc-version;/../../../../lib/crt1.o succeeded
210 /usr/lib/gcc/x86_64-pc-linux-gnu/&gcc-version;/../../../../lib/crti.o succeeded
211 /usr/lib/gcc/x86_64-pc-linux-gnu/&gcc-version;/../../../../lib/crtn.o succeeded</computeroutput></screen>
213 <para>Depending on your machine architecture, the above may differ slightly.
214 The difference will be the name of the directory
215 after <filename class="directory">/usr/lib/gcc</filename>. The important
216 thing to look for here is that <command>gcc</command> has found all three
217 <filename>crt*.o</filename> files under the
218 <filename class="directory">/usr/lib</filename> directory.</para>
220 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
222 xpointer="xpointer(//*[@os='g'])"/>
224 <screen><userinput>grep -B4 '^ /usr/include' dummy.log</userinput></screen>
226 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
228 xpointer="xpointer(//*[@os='h'])"/>
230 <screen><computeroutput>#include <...> search starts here:
231 /usr/lib/gcc/x86_64-pc-linux-gnu/&gcc-version;/include
233 /usr/lib/gcc/x86_64-pc-linux-gnu/&gcc-version;/include-fixed
234 /usr/include</computeroutput></screen>
236 <para>Again, the directory named after your target triplet may be
237 different than the above, depending on your system architecture.</para>
239 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
241 xpointer="xpointer(//*[@os='i'])"/>
243 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
245 xpointer="xpointer(//*[@os='j'])"/>
247 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
249 xpointer="xpointer(//*[@os='k'])"/>
251 <screen><computeroutput>SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib64")
252 SEARCH_DIR("/usr/local/lib64")
254 SEARCH_DIR("/usr/lib64")
255 SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib")
256 SEARCH_DIR("/usr/local/lib")
258 SEARCH_DIR("/usr/lib");</computeroutput></screen>
260 <para>A 32-bit system may see a few different directories. For example, here
261 is the output from an i686 machine:</para>
263 <screen><computeroutput>SEARCH_DIR("/usr/i686-pc-linux-gnu/lib32")
264 SEARCH_DIR("/usr/local/lib32")
266 SEARCH_DIR("/usr/lib32")
267 SEARCH_DIR("/usr/i686-pc-linux-gnu/lib")
268 SEARCH_DIR("/usr/local/lib")
270 SEARCH_DIR("/usr/lib");</computeroutput></screen>
272 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
274 xpointer="xpointer(//*[@os='l'])"/>
276 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
278 xpointer="xpointer(//*[@os='m'])"/>
280 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
282 xpointer="xpointer(//*[@os='n'])"/>
284 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
286 xpointer="xpointer(//*[@os='o'])"/>
288 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
290 xpointer="xpointer(//*[@os='p'])"/>
292 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
294 xpointer="xpointer(//*[@os='q'])"/>
296 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
298 xpointer="xpointer(//*[@os='r'])"/>
300 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
302 xpointer="xpointer(//*[@os='s'])"/>
304 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
306 xpointer="xpointer(//*[@os='t'])"/>
308 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
310 xpointer="xpointer(//*[@os='u'])"/>
312 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
314 xpointer="xpointer(//*[@os='v'])"/>
316 <para>Finally, move a misplaced file:</para>
318 <screen><userinput remap="install">mkdir -pv /usr/share/gdb/auto-load/usr/lib
319 mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib</userinput></screen>
323 <sect2 id="contents-gcc" role="content">
324 <title>Contents of GCC</title>
327 <segtitle>Installed programs</segtitle>
328 <segtitle>Installed libraries</segtitle>
329 <segtitle>Installed directories</segtitle>
332 <seg>c++, cc (link to gcc), cpp, g++, gcc,
333 gcc-ar, gcc-nm, gcc-ranlib, gcov, gcov-dump, and gcov-tool</seg>
335 <seg>libasan.{a,so}, libatomic.{a,so}, libcc1.so, libgcc.a, libgcc_eh.a,
336 libgcc_s.so, libgcov.a, libgomp.{a,so}, libitm.{a,so},
337 liblsan.{a,so}, liblto_plugin.so,
338 libquadmath.{a,so}, libssp.{a,so}, libssp_nonshared.a,
339 libstdc++.{a,so}, libstdc++fs.a, libsupc++.a, libtsan.{a,so},
340 and libubsan.{a,so}</seg>
342 <seg>/usr/include/c++, /usr/lib/gcc, /usr/libexec/gcc, and
343 /usr/share/gcc-&gcc-version;</seg>
348 <bridgehead renderas="sect3">Short Descriptions</bridgehead>
349 <?dbfo list-presentation="list"?>
350 <?dbhtml list-presentation="table"?>
352 <varlistentry id="c">
353 <term><command>c++</command></term>
355 <para>The C++ compiler</para>
356 <indexterm zone="ch-system-gcc c">
357 <primary sortas="b-c++">c++</primary>
362 <varlistentry id="cc">
363 <term><command>cc</command></term>
365 <para>The C compiler</para>
366 <indexterm zone="ch-system-gcc cc">
367 <primary sortas="b-cc">cc</primary>
372 <varlistentry id="cpp">
373 <term><command>cpp</command></term>
375 <para>The C preprocessor; it is used by the compiler to expand the
376 #include, #define, and similar statements in the source files</para>
377 <indexterm zone="ch-system-gcc cpp">
378 <primary sortas="b-cpp">cpp</primary>
383 <varlistentry id="g">
384 <term><command>g++</command></term>
386 <para>The C++ compiler</para>
387 <indexterm zone="ch-system-gcc g">
388 <primary sortas="b-g++">g++</primary>
393 <varlistentry id="gcc">
394 <term><command>gcc</command></term>
396 <para>The C compiler</para>
397 <indexterm zone="ch-system-gcc gcc">
398 <primary sortas="b-gcc">gcc</primary>
403 <varlistentry id="gcc-ar">
404 <term><command>gcc-ar</command></term>
406 <para>A wrapper around <command>ar</command> that adds a
407 plugin to the command line. This program is only used
408 to add "link time optimization" and is not useful with the
409 default build options</para>
410 <indexterm zone="ch-system-gcc gcc-ar">
411 <primary sortas="b-gcc-ar">gc-ar</primary>
416 <varlistentry id="gcc-nm">
417 <term><command>gcc-nm</command></term>
419 <para>A wrapper around <command>nm</command> that adds a
420 plugin to the command line. This program is only used
421 to add "link time optimization" and is not useful with the
422 default build options</para>
423 <indexterm zone="ch-system-gcc gcc-nm">
424 <primary sortas="b-gcc-nm">gc-nm</primary>
429 <varlistentry id="gcc-ranlib">
430 <term><command>gcc-ranlib</command></term>
432 <para>A wrapper around <command>ranlib</command> that adds a
433 plugin to the command line. This program is only used
434 to add "link time optimization" and is not useful with the
435 default build options</para>
436 <indexterm zone="ch-system-gcc gcc-ranlib">
437 <primary sortas="b-gcc-ranlib">gc-ranlib</primary>
442 <varlistentry id="gcov">
443 <term><command>gcov</command></term>
445 <para>A coverage testing tool; it is used to analyze programs to
446 determine where optimizations will have the most effect</para>
447 <indexterm zone="ch-system-gcc gcov">
448 <primary sortas="b-gcov">gcov</primary>
453 <varlistentry id="gcov-dump">
454 <term><command>gcov-dump</command></term>
456 <para>Offline gcda and gcno profile dump tool</para>
457 <indexterm zone="ch-system-gcc gcov-dump">
458 <primary sortas="b-gcov-dump">gcov-dump</primary>
463 <varlistentry id="gcov-tool">
464 <term><command>gcov-tool</command></term>
466 <para>Offline gcda profile processing tool</para>
467 <indexterm zone="ch-system-gcc gcov-tool">
468 <primary sortas="b-gcov-tool">gcov-tool</primary>
473 <varlistentry id="libasan">
474 <term><filename class="libraryfile">libasan</filename></term>
476 <para>The Address Sanitizer runtime library</para>
477 <indexterm zone="ch-system-gcc libasan">
478 <primary sortas="b-libasan">libasan</primary>
483 <varlistentry id="libatomic">
484 <term><filename class="libraryfile">libatomic</filename></term>
486 <para>GCC atomic built-in runtime library</para>
487 <indexterm zone="ch-system-gcc libatomic">
488 <primary sortas="b-libatomic">libatomic</primary>
493 <varlistentry id="libcc1">
494 <term><filename class="libraryfile">libcc1</filename></term>
496 <para>The C preprocessing library</para>
497 <indexterm zone="ch-system-gcc libcc1">
498 <primary sortas="b-libcc1">libcc1</primary>
503 <varlistentry id="libgcc">
504 <term><filename class="libraryfile">libgcc</filename></term>
506 <para>Contains run-time support for <command>gcc</command></para>
507 <indexterm zone="ch-system-gcc libgcc">
508 <primary sortas="c-libgcc">libgcc</primary>
513 <varlistentry id="libgcov">
514 <term><filename class="libraryfile">libgcov</filename></term>
516 <para>This library is linked in to a program when GCC is instructed
517 to enable profiling</para>
518 <indexterm zone="ch-system-gcc libgcov">
519 <primary sortas="c-libgcov">libgcov</primary>
524 <varlistentry id="libgomp">
525 <term><filename class="libraryfile">libgomp</filename></term>
527 <para>GNU implementation of the OpenMP API for multi-platform
528 shared-memory parallel programming in C/C++ and Fortran</para>
529 <indexterm zone="ch-system-gcc libgomp">
530 <primary sortas="c-libgomp">libgomp</primary>
535 <varlistentry id="liblsan">
536 <term><filename class="libraryfile">liblsan</filename></term>
538 <para>The Leak Sanitizer runtime library</para>
539 <indexterm zone="ch-system-gcc liblsan">
540 <primary sortas="c-liblsan">liblsan</primary>
545 <varlistentry id="liblto_plugin">
546 <term><filename class="libraryfile">liblto_plugin</filename></term>
548 <para>GCC's Link Time Optimization (LTO) plugin allows GCC to perform
549 optimizations across compilation units</para>
550 <indexterm zone="ch-system-gcc liblto_plugin">
551 <primary sortas="c-liblto_plugin">liblto_plugin</primary>
556 <varlistentry id="libquadmath">
557 <term><filename class="libraryfile">libquadmath</filename></term>
559 <para>GCC Quad Precision Math Library API</para>
560 <indexterm zone="ch-system-gcc libquadmath">
561 <primary sortas="c-libquadmath">libquadmath</primary>
566 <varlistentry id="libssp">
567 <term><filename class="libraryfile">libssp</filename></term>
569 <para>Contains routines supporting GCC's stack-smashing protection
571 <indexterm zone="ch-system-gcc libssp">
572 <primary sortas="c-libssp">libssp</primary>
577 <varlistentry id="libstdc">
578 <term><filename class="libraryfile">libstdc++</filename></term>
580 <para>The standard C++ library</para>
581 <indexterm zone="ch-system-gcc libstdc">
582 <primary sortas="c-libstdc++">libstdc++</primary>
587 <varlistentry id="libstdcfs">
588 <term><filename class="libraryfile">libstdc++fs</filename></term>
590 <para>ISO/IEC TS 18822:2015 Filesystem library</para>
591 <indexterm zone="ch-system-gcc libstdcfs">
592 <primary sortas="c-libstdc++fs">libstdc++fs</primary>
597 <varlistentry id="libsupc">
598 <term><filename class="libraryfile">libsupc++</filename></term>
600 <para>Provides supporting routines for the C++ programming
602 <indexterm zone="ch-system-gcc libsupc">
603 <primary sortas="c-libsupc++">libsupc++</primary>
608 <varlistentry id="libtsan">
609 <term><filename class="libraryfile">libtsan</filename></term>
611 <para>The Thread Sanitizer runtime library</para>
612 <indexterm zone="ch-system-gcc libtsan">
613 <primary sortas="c-libtsan">libtsan</primary>
618 <varlistentry id="libubsan">
619 <term><filename class="libraryfile">libubsan</filename></term>
621 <para>The Undefined Behavior Sanitizer runtime library</para>
622 <indexterm zone="ch-system-gcc libubsan">
623 <primary sortas="c-libubsan">libubsan</primary>