1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
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 | <!ENTITY gcc-download-http "&gnu-http;/gcc/gcc-&gcc-version;/gcc-&gcc-version;.tar.xz">
|
---|
8 | <!ENTITY gcc-download-ftp " ">
|
---|
9 | <!-- Update this also on the grub-uefi page -->
|
---|
10 | <!ENTITY gcc-md5sum "2268420ba02dc01821960e274711bde0">
|
---|
11 | <!ENTITY gcc-size "88 MB">
|
---|
12 | <!ENTITY gcc-buildsize "11 GB (3.4 GB installed with all listed languages; add 1.6 GB for tests)">
|
---|
13 | <!ENTITY gcc-time "14 SBU (add 34 SBU for tests; both with parallelism=8)">
|
---|
14 | ]>
|
---|
15 |
|
---|
16 | <sect1 id="gcc" xreflabel="GCC-&gcc-version;">
|
---|
17 | <?dbhtml filename="gcc.html" ?>
|
---|
18 |
|
---|
19 |
|
---|
20 | <title>GCC-&gcc-version;</title>
|
---|
21 |
|
---|
22 | <indexterm zone="gcc">
|
---|
23 | <primary sortas="a-gcc-5-0">GCC-&gcc-version;</primary>
|
---|
24 | </indexterm>
|
---|
25 |
|
---|
26 | <sect2 role="package">
|
---|
27 | <title>Introduction to GCC</title>
|
---|
28 |
|
---|
29 | <para>
|
---|
30 | The <application>GCC</application> package contains the GNU Compiler
|
---|
31 | Collection. This page describes the installation of compilers for the
|
---|
32 | following languages: C, C++, Fortran, Objective C, Objective C++, Go, and Modula2.
|
---|
33 | Since C and C++ are installed in LFS, this page is either for upgrading
|
---|
34 | C and C++, or for installing additional compilers.
|
---|
35 | </para>
|
---|
36 |
|
---|
37 | <note>
|
---|
38 | <para>
|
---|
39 | Additional languages, among which D and Ada, are available in the
|
---|
40 | collection. D and Ada have a binary bootstrap requirement for the first
|
---|
41 | installation, so their installation is not described here. To install
|
---|
42 | them, you can proceed along the same lines as below after installing
|
---|
43 | the corresponding compiler from a binary package, adding
|
---|
44 | <option>ada</option> or <option>d</option> to the
|
---|
45 | <parameter>--enable-languages</parameter> line.
|
---|
46 | </para>
|
---|
47 | </note>
|
---|
48 |
|
---|
49 | &lfs121_checked;
|
---|
50 |
|
---|
51 | <caution>
|
---|
52 | <para>
|
---|
53 | If you are upgrading <application>GCC</application> from any other
|
---|
54 | version prior to &gcc-version;, then you must be careful compiling 3rd
|
---|
55 | party kernel modules. You should ensure that the kernel and all its
|
---|
56 | native modules are also compiled using the same version of
|
---|
57 | <application>GCC</application> that you use to build the 3rd party module.
|
---|
58 | This issue does not affect native kernel (and kernel modules) updates,
|
---|
59 | as the instructions below are a complete reinstallation of
|
---|
60 | <application>GCC</application>. If you have existing 3rd party modules
|
---|
61 | installed, ensure they are recompiled using the updated version of
|
---|
62 | <application>GCC</application>.
|
---|
63 | </para>
|
---|
64 | </caution>
|
---|
65 |
|
---|
66 | <bridgehead renderas="sect3">Package Information</bridgehead>
|
---|
67 | <itemizedlist spacing="compact">
|
---|
68 | <listitem>
|
---|
69 | <para>
|
---|
70 | Download (HTTP): <ulink url="&gcc-download-http;"/>
|
---|
71 | </para>
|
---|
72 | </listitem>
|
---|
73 | <listitem>
|
---|
74 | <para>
|
---|
75 | Download (FTP): <ulink url="&gcc-download-ftp;"/>
|
---|
76 | </para>
|
---|
77 | </listitem>
|
---|
78 | <listitem>
|
---|
79 | <para>
|
---|
80 | Download MD5 sum: &gcc-md5sum;
|
---|
81 | </para>
|
---|
82 | </listitem>
|
---|
83 | <listitem>
|
---|
84 | <para>
|
---|
85 | Download size: &gcc-size;
|
---|
86 | </para>
|
---|
87 | </listitem>
|
---|
88 | <listitem>
|
---|
89 | <para>
|
---|
90 | Estimated disk space required: &gcc-buildsize;
|
---|
91 | </para>
|
---|
92 | </listitem>
|
---|
93 | <listitem>
|
---|
94 | <para>
|
---|
95 | Estimated build time: &gcc-time;
|
---|
96 | </para>
|
---|
97 | </listitem>
|
---|
98 | </itemizedlist>
|
---|
99 | <!--
|
---|
100 | <bridgehead renderas="sect3">Additional Downloads</bridgehead>
|
---|
101 | <itemizedlist spacing="compact">
|
---|
102 | <listitem>
|
---|
103 | <para>
|
---|
104 | Optional patch when adding Go to the desired language list:
|
---|
105 | <ulink url="&patch-root;/gcc-&gcc-version;-fix_go_version-1.patch"/>
|
---|
106 | </para>
|
---|
107 | </listitem>
|
---|
108 | </itemizedlist>
|
---|
109 | -->
|
---|
110 | <bridgehead renderas="sect3">GCC Dependencies</bridgehead>
|
---|
111 |
|
---|
112 | <bridgehead renderas="sect4">Optional</bridgehead>
|
---|
113 | <para role="optional">
|
---|
114 | <xref linkend="gdb"/>,
|
---|
115 | <xref linkend="graphviz"/> (some tests use it if installed; note that
|
---|
116 | if it's installed but not built with
|
---|
117 | <xref role='nodep' linkend='libpng'/> these tests will fail),
|
---|
118 | <xref linkend="valgrind"/> (for tests), and
|
---|
119 | <ulink url="https://repo.or.cz/isl.git">ISL</ulink> (to enable graphite optimization)
|
---|
120 | </para>
|
---|
121 |
|
---|
122 | </sect2>
|
---|
123 |
|
---|
124 | <sect2 role="installation">
|
---|
125 | <title>Installation of GCC</title>
|
---|
126 |
|
---|
127 | <important>
|
---|
128 | <para>
|
---|
129 | Even if you specify only languages other than C and C++ to the
|
---|
130 | <command>./configure</command> command below, the
|
---|
131 | installation process will overwrite your existing
|
---|
132 | <application>GCC</application> C and C++ compilers and libraries.
|
---|
133 | Running the full suite of tests is recommended.
|
---|
134 | </para>
|
---|
135 |
|
---|
136 | <para>
|
---|
137 | Do not continue with the <command>make install</command> command
|
---|
138 | until you are confident the build was successful. You can compare your
|
---|
139 | test results with those found at <ulink
|
---|
140 | url="https://gcc.gnu.org/ml/gcc-testresults/"/>. You may also want to
|
---|
141 | refer to the information found in the <application>GCC</application>
|
---|
142 | section of Chapter 8 in the LFS book (<ulink
|
---|
143 | url="&lfs-root;/chapter08/gcc.html"/>).
|
---|
144 | </para>
|
---|
145 | </important>
|
---|
146 |
|
---|
147 | <para>
|
---|
148 | The instructions below are intentionally performing a
|
---|
149 | <quote>bootstrap</quote> process. Bootstrapping is needed for robustness
|
---|
150 | and is highly recommended when upgrading the compilers version. To disable
|
---|
151 | bootstrap anyway, add <parameter>--disable-bootstrap</parameter> to the
|
---|
152 | <command>./configure</command> options below.
|
---|
153 | </para>
|
---|
154 |
|
---|
155 | <para>
|
---|
156 | Install <application>GCC</application> by running the following commands:
|
---|
157 | </para>
|
---|
158 |
|
---|
159 | <screen><userinput>case $(uname -m) in
|
---|
160 | x86_64)
|
---|
161 | sed -i.orig '/m64=/s/lib64/lib/' gcc/config/i386/t-linux64
|
---|
162 | ;;
|
---|
163 | esac
|
---|
164 |
|
---|
165 | mkdir build &&
|
---|
166 | cd build &&
|
---|
167 |
|
---|
168 | ../configure \
|
---|
169 | --prefix=/usr \
|
---|
170 | --disable-multilib \
|
---|
171 | --with-system-zlib \
|
---|
172 | --enable-default-pie \
|
---|
173 | --enable-default-ssp \
|
---|
174 | --enable-host-pie \
|
---|
175 | --disable-fixincludes \
|
---|
176 | --enable-languages=c,c++,fortran,go,objc,obj-c++,m2 &&
|
---|
177 | make</userinput></screen>
|
---|
178 |
|
---|
179 | <para>If running tests, as in LFS, remove/fix several known test failures:</para>
|
---|
180 |
|
---|
181 | <screen><userinput>sed -e '/cpython/d' -i ../gcc/testsuite/gcc.dg/plugin/plugin.exp
|
---|
182 | sed -e 's/no-pic /&-no-pie /' -i ../gcc/testsuite/gcc.target/i386/pr113689-1.c
|
---|
183 | sed -e 's/300000/(1|300000)/' -i ../libgomp/testsuite/libgomp.c-c++-common/pr109062.c
|
---|
184 | sed -e 's/{ target nonpic } //' \
|
---|
185 | -e '/GOTPCREL/d' -i ../gcc/testsuite/gcc.target/i386/fentryname3.c</userinput></screen>
|
---|
186 |
|
---|
187 | <para>
|
---|
188 | If you have installed additional packages such as
|
---|
189 | <application>valgrind</application> and <application>gdb</application>,
|
---|
190 | the <application>gcc</application> part of the test suite will run more
|
---|
191 | tests than in LFS. Some of those will report FAIL and others XPASS
|
---|
192 | (pass when expected to FAIL). As of gcc-14.1.0, about 74 FAILs occur
|
---|
193 | in the <quote>guality</quote> suite, as well as miscellaneous failures
|
---|
194 | throughout the rest of the test suite.
|
---|
195 | If all the compilers above are built, there will be a little over 110
|
---|
196 | unexpected failures out of over 617,000 tests. To run the tests, issue:
|
---|
197 | </para>
|
---|
198 |
|
---|
199 |
|
---|
200 | <screen><userinput>ulimit -s 32768 &&
|
---|
201 | make -k check</userinput></screen>
|
---|
202 | <!-- The command above may error out, so using && may prevent the summary
|
---|
203 | to be run. -->
|
---|
204 |
|
---|
205 | <para>
|
---|
206 | The tests are very long, and the results may be hard to find in the
|
---|
207 | logs, specially if you use parallel jobs with make. You can get a summary
|
---|
208 | of the tests with:
|
---|
209 | </para>
|
---|
210 |
|
---|
211 | <screen><userinput>../contrib/test_summary</userinput></screen>
|
---|
212 |
|
---|
213 | <para>
|
---|
214 | Now, as the <systemitem class="username">root</systemitem> user:
|
---|
215 | </para>
|
---|
216 |
|
---|
217 | <screen role="root"><userinput>make install &&
|
---|
218 |
|
---|
219 | mkdir -pv /usr/share/gdb/auto-load/usr/lib &&
|
---|
220 | mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib &&
|
---|
221 |
|
---|
222 | chown -v -R root:root \
|
---|
223 | /usr/lib/gcc/*linux-gnu/&gcc-version;/include{,-fixed} &&
|
---|
224 |
|
---|
225 | ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/&gcc-version;/liblto_plugin.so \
|
---|
226 | /usr/lib/bfd-plugins/</userinput></screen>
|
---|
227 |
|
---|
228 | </sect2>
|
---|
229 |
|
---|
230 | <sect2 role="commands">
|
---|
231 | <title>Command Explanations</title>
|
---|
232 |
|
---|
233 | <para>
|
---|
234 | <command>mkdir build; cd build</command>: The
|
---|
235 | <application>GCC</application> documentation recommends
|
---|
236 | building the package in a dedicated build directory.
|
---|
237 | </para>
|
---|
238 |
|
---|
239 | <para>
|
---|
240 | <parameter>--disable-multilib</parameter>: This parameter ensures
|
---|
241 | that files are created for the specific architecture of your computer.
|
---|
242 | </para>
|
---|
243 |
|
---|
244 | <para>
|
---|
245 | <parameter>--with-system-zlib</parameter>: Uses the system
|
---|
246 | <application>zlib</application> instead of the bundled one.
|
---|
247 | <application>zlib</application> is used for compressing
|
---|
248 | and decompressing <application>GCC</application>'s intermediate
|
---|
249 | language in LTO (Link Time Optimization) object files.
|
---|
250 | </para>
|
---|
251 |
|
---|
252 | <para>
|
---|
253 | <parameter>--enable-default-pie</parameter>: Makes the
|
---|
254 | <option>-fpie</option> option the default when compiling programs.
|
---|
255 | Together with the <xref linkend="gASLR"/> feature enabled in the kernel,
|
---|
256 | this defeats some kind of attacks based on known memory layouts.
|
---|
257 | </para>
|
---|
258 |
|
---|
259 | <para>
|
---|
260 | <parameter>--enable-default-ssp</parameter>: Makes the
|
---|
261 | <option>-fstack-protector-strong</option> option the default when
|
---|
262 | compiling programs. <xref linkend="gSSP"/> is a technique preventing
|
---|
263 | alteration of the program flow by corrupting the parameter stack.
|
---|
264 | </para>
|
---|
265 |
|
---|
266 | <para>
|
---|
267 | <parameter>--enable-host-pie</parameter>: Makes the compiler
|
---|
268 | executables PIE (Position Independent Executable). This can be used to
|
---|
269 | enhance protection against ROP (Return Oriented Programming) attacks,
|
---|
270 | and can be viewed as part of a wider trend to harden binaries.
|
---|
271 | </para>
|
---|
272 |
|
---|
273 | <para>
|
---|
274 | <parameter>--enable-languages=c,c++,fortran,go,objc,obj-c++,m2</parameter>:
|
---|
275 | This command identifies which languages to build. You may modify
|
---|
276 | this command to remove undesired languages. GCC also supports Ada
|
---|
277 | and D, but building GCC with Ada (or D) support needs an existing
|
---|
278 | Ada (or D) compiler. So they are not enabled here.
|
---|
279 | </para>
|
---|
280 |
|
---|
281 | <para>
|
---|
282 | <command>ulimit -s 32768</command>: This command prevents several
|
---|
283 | tests from running out of stack space.
|
---|
284 | </para>
|
---|
285 |
|
---|
286 | <para>
|
---|
287 | <command>make -k check</command>: This command runs the test suite
|
---|
288 | without stopping if any errors are encountered.
|
---|
289 | </para>
|
---|
290 |
|
---|
291 | <para>
|
---|
292 | <command>../contrib/test_summary</command>: This command will produce
|
---|
293 | a summary of the test suite results. You can append <command>| grep
|
---|
294 | -A7 Summ</command> to the command to produce an even more condensed
|
---|
295 | version of the summary. You may also wish to redirect the output
|
---|
296 | to a file for review and comparison later on.
|
---|
297 | </para>
|
---|
298 |
|
---|
299 | <para>
|
---|
300 | <command>mv -v /usr/lib/*gdb.py ...</command>: The installation
|
---|
301 | stage puts some files used by <application>gdb</application> under the
|
---|
302 | <filename class="directory">/usr/lib</filename> directory. This generates
|
---|
303 | spurious error messages when performing <command>ldconfig</command>. This
|
---|
304 | command moves the files to another location.
|
---|
305 | </para>
|
---|
306 |
|
---|
307 | <para>
|
---|
308 | <command>chown -v -R root:root /usr/lib/gcc/*linux-gnu/...</command>:
|
---|
309 | If the package is built by a user other than root, the ownership of the
|
---|
310 | installed <filename class="directory">include</filename> directory (and
|
---|
311 | its content) will be incorrect. This command changes the ownership to the
|
---|
312 | <systemitem class="username">root</systemitem> user and group.
|
---|
313 | </para>
|
---|
314 |
|
---|
315 | <para>
|
---|
316 | <option>--enable-host-shared --enable-languages=jit</option>:
|
---|
317 | Build <systemitem class="library">libgccjit</systemitem>, a library
|
---|
318 | for embedding GCC inside programs and libraries for generating machine
|
---|
319 | code. Despite <quote>JIT</quote> (just-in-time) in the name, the
|
---|
320 | library can be used for AOT (ahead-of-time) compilation as well.
|
---|
321 | <option>--enable-host-shared</option> is needed for building
|
---|
322 | <systemitem class="library">libgccjit</systemitem>, but it
|
---|
323 | significantly slows down GCC. So
|
---|
324 | <systemitem class="library">libgccjit</systemitem> should be built and
|
---|
325 | installed separately, not as a part of the <quote>main</quote> GCC
|
---|
326 | installation. If you need this library, configure GCC with
|
---|
327 | these two options and install the library by running
|
---|
328 | <!-- from Arch, not tested -->
|
---|
329 | <command>make -C gcc jit.install-common jit.install-info</command>
|
---|
330 | as the &root; user. This library is not used by any BLFS package,
|
---|
331 | nor tested by the BLFS developers.
|
---|
332 | </para>
|
---|
333 |
|
---|
334 | </sect2>
|
---|
335 |
|
---|
336 | <sect2 role="content">
|
---|
337 | <title>Contents</title>
|
---|
338 |
|
---|
339 | <para>
|
---|
340 | Some program and library names and descriptions are not listed here,
|
---|
341 | but can be found at
|
---|
342 | <ulink url="&lfs-root;/chapter08/gcc.html#contents-gcc">LFS section
|
---|
343 | for GCC</ulink> as they were
|
---|
344 | initially installed during the building of LFS.
|
---|
345 | </para>
|
---|
346 |
|
---|
347 | <segmentedlist>
|
---|
348 | <segtitle>Installed Programs</segtitle>
|
---|
349 | <segtitle>Installed Libraries</segtitle>
|
---|
350 | <segtitle>Installed Directories</segtitle>
|
---|
351 |
|
---|
352 | <seglistitem>
|
---|
353 | <seg>
|
---|
354 | gccgo, gfortran, gm2, go, and gofmt, hard-linked to architecture
|
---|
355 | specific names
|
---|
356 | </seg>
|
---|
357 | <seg>
|
---|
358 | libgfortran.{so,a}, libgm2.{so,a}
|
---|
359 | libgo.{so,a}, libgobegin.a, libgolibbegin.a,
|
---|
360 | libobjc.{so,a}, and numerous other run-time libraries and executables
|
---|
361 | </seg>
|
---|
362 | <seg>
|
---|
363 | /usr/lib/go
|
---|
364 | </seg>
|
---|
365 | </seglistitem>
|
---|
366 | </segmentedlist>
|
---|
367 |
|
---|
368 | <variablelist>
|
---|
369 | <bridgehead renderas="sect3">Short Descriptions</bridgehead>
|
---|
370 | <?dbfo list-presentation="list"?>
|
---|
371 | <?dbhtml list-presentation="table"?>
|
---|
372 |
|
---|
373 | <varlistentry id="gccgo">
|
---|
374 | <term><command>gccgo</command></term>
|
---|
375 | <listitem>
|
---|
376 | <para>
|
---|
377 | is a GCC-based compiler for the <application>Go</application>
|
---|
378 | language
|
---|
379 | </para>
|
---|
380 | <indexterm zone="gcc gccgo">
|
---|
381 | <primary sortas="b-gccgo">gccgo</primary>
|
---|
382 | </indexterm>
|
---|
383 | </listitem>
|
---|
384 | </varlistentry>
|
---|
385 |
|
---|
386 | <varlistentry id="gm2">
|
---|
387 | <term><command>gm2</command></term>
|
---|
388 | <listitem>
|
---|
389 | <para>
|
---|
390 | is a GCC-based compiler for the
|
---|
391 | <application>Modula-2</application> language
|
---|
392 | </para>
|
---|
393 | <indexterm zone="gcc gm2">
|
---|
394 | <primary sortas="b-gm2">gm2</primary>
|
---|
395 | </indexterm>
|
---|
396 | </listitem>
|
---|
397 | </varlistentry>
|
---|
398 |
|
---|
399 | <varlistentry id="go">
|
---|
400 | <term><command>go</command></term>
|
---|
401 | <listitem>
|
---|
402 | <para>
|
---|
403 | is a tool for managing <application>Go</application> source code
|
---|
404 | </para>
|
---|
405 | <indexterm zone="gcc go">
|
---|
406 | <primary sortas="b-go">go</primary>
|
---|
407 | </indexterm>
|
---|
408 | </listitem>
|
---|
409 | </varlistentry>
|
---|
410 |
|
---|
411 | <varlistentry id="gofmt">
|
---|
412 | <term><command>gofmt</command></term>
|
---|
413 | <listitem>
|
---|
414 | <para>
|
---|
415 | is a tool for formatting <application>Go</application> source code
|
---|
416 | </para>
|
---|
417 | <indexterm zone="gcc gofmt">
|
---|
418 | <primary sortas="b-gofmt">gofmt</primary>
|
---|
419 | </indexterm>
|
---|
420 | </listitem>
|
---|
421 | </varlistentry>
|
---|
422 | <!--
|
---|
423 | <varlistentry id="gdc">
|
---|
424 | <term><command>gdc</command></term>
|
---|
425 | <listitem>
|
---|
426 | <para>
|
---|
427 | is a GCC-based compiler for the <application>D</application>
|
---|
428 | language
|
---|
429 | </para>
|
---|
430 | <indexterm zone="gcc gdc">
|
---|
431 | <primary sortas="b-gdc">gdc</primary>
|
---|
432 | </indexterm>
|
---|
433 | </listitem>
|
---|
434 | </varlistentry>
|
---|
435 | -->
|
---|
436 | <varlistentry id="gfortran">
|
---|
437 | <term><command>gfortran</command></term>
|
---|
438 | <listitem>
|
---|
439 | <para>
|
---|
440 | is a GCC-based compiler for the <application>Fortran</application>
|
---|
441 | language
|
---|
442 | </para>
|
---|
443 | <indexterm zone="gcc gfortran">
|
---|
444 | <primary sortas="b-gfortran">gfortran</primary>
|
---|
445 | </indexterm>
|
---|
446 | </listitem>
|
---|
447 | </varlistentry>
|
---|
448 |
|
---|
449 | </variablelist>
|
---|
450 |
|
---|
451 | </sect2>
|
---|
452 |
|
---|
453 | </sect1>
|
---|