Fix backslash alignments and a minor text update.
[linux_from_scratch.git] / chapter05 / gcc-pass1.xml
blob7398a810f2f4a3ebc626eb56e3f507f805e78008
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 ]>
8 <sect1 id="ch-tools-gcc-pass1" role="wrap">
9   <?dbhtml filename="gcc-pass1.html"?>
11   <sect1info condition="script">
12     <productname>gcc</productname>
13     <productnumber>&gcc-version;</productnumber>
14     <address>&gcc-url;</address>
15   </sect1info>
17   <title>GCC-&gcc-version; - Pass 1</title>
19   <indexterm zone="ch-tools-gcc-pass1">
20     <primary sortas="a-GCC">GCC</primary>
21     <secondary>tools, pass 1</secondary>
22   </indexterm>
24   <sect2 role="package">
25     <title/>
27     <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
28     href="../chapter06/gcc.xml"
29     xpointer="xpointer(/sect1/sect2[1]/para[1])"/>
31     <segmentedlist>
32       <segtitle>&buildtime;</segtitle>
33       <segtitle>&diskspace;</segtitle>
35       <seglistitem>
36         <seg>&gcc-ch5p1-sbu;</seg>
37         <seg>&gcc-ch5p1-du;</seg>
38       </seglistitem>
39     </segmentedlist>
41   </sect2>
43   <sect2 role="installation">
44     <title>Installation of Cross GCC</title>
46     <para>GCC now requires the GMP, MPFR and MPC packages. As these packages may
47     not be included in your host distribution, they will be built with
48     GCC.  Unpack each package into the GCC source directory and rename the
49     resulting directories so the GCC build procedures will automatically
50     use them:</para>
52     <note><para>There are frequent misunderstandings about this chapter.  The
53     procedures are the same as every other chapter as explained earlier (<xref
54     linkend='buildinstr'/>).  First extract the gcc tarball from the sources
55     directory and then change to the directory created.  Only then should you
56     proceed with the instructions below.</para></note>
58 <screen><userinput remap="pre">tar -xf ../mpfr-&mpfr-version;.tar.xz
59 mv -v mpfr-&mpfr-version; mpfr
60 tar -xf ../gmp-&gmp-version;.tar.xz
61 mv -v gmp-&gmp-extracted-version; gmp
62 tar -xf ../mpc-&mpc-version;.tar.gz
63 mv -v mpc-&mpc-version; mpc</userinput></screen>
65     <para>The following command will change the location of GCC's default
66     dynamic linker to use the one installed in <filename
67     class="directory">/tools</filename>. It also removes <filename
68     class="directory">/usr/include</filename> from GCC's include search path.
69     Issue:</para>
71 <screen><userinput remap="pre">for file in \
72  $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
74   cp -uv $file{,.orig}
75   sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&amp;@g' \
76       -e 's@/usr@/tools@g' $file.orig &gt; $file
77   echo '
78 #undef STANDARD_STARTFILE_PREFIX_1
79 #undef STANDARD_STARTFILE_PREFIX_2
80 #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
81 #define STANDARD_STARTFILE_PREFIX_2 ""' &gt;&gt; $file
82   touch $file.orig
83 done</userinput></screen>
85     <para>In case the above seems hard to follow, let's break it down a bit.
86     First we find all the files under the <filename
87     class="directory">gcc/config</filename> directory that are named either
88     <filename>linux.h</filename>, <filename>linux64.h</filename> or
89     <filename>sysv4.h</filename>.  For each file found, we copy it to a file of
90     the same name but with an added suffix of <quote>.orig</quote>. Then the
91     first sed expression prepends <quote>/tools</quote> to every instance of
92     <quote>/lib/ld</quote>, <quote>/lib64/ld</quote> or
93     <quote>/lib32/ld</quote>, while the second one replaces hard-coded
94     instances of <quote>/usr</quote>. Next, we add our define statements which
95     alter the default startfile prefix to the end of the file. Note that the
96     trailing <quote>/</quote> in <quote>/tools/lib/</quote> is required.
97     Finally, we use <command>touch</command> to update the timestamp on the
98     copied files.  When used in conjunction with <command>cp -u</command>, this
99     prevents unexpected changes to the original files in case the commands are
100     inadvertently run twice.  </para>
102     <para>GCC doesn't detect stack protection correctly, which causes problems
103     for the build of Glibc-&glibc-version;, so fix that by issuing the following
104     command:</para>
106 <screen><userinput remap="pre">sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure</userinput></screen>
107 <!--
108     <para>Also fix a problem identified upstream:</para>
110 <screen><userinput remap="pre">sed -i 's/if \((code.*))\)/if (\1 \&amp;\&amp; \!DEBUG_INSN_P (insn))/' gcc/sched-deps.c</userinput></screen>
112     <para>The GCC documentation recommends building GCC outside of the
113     source directory in a dedicated build directory:</para>
115 <screen><userinput remap="pre">mkdir -v ../gcc-build
116 cd ../gcc-build</userinput></screen>
118     <para>Prepare GCC for compilation:</para>
120 <screen><userinput remap="configure">../gcc-&gcc-version;/configure                             \
121     --target=$LFS_TGT                              \
122     --prefix=/tools                                \
123     --with-sysroot=$LFS                            \
124     --with-newlib                                  \
125     --without-headers                              \
126     --with-local-prefix=/tools                     \
127     --with-native-system-header-dir=/tools/include \
128     --disable-nls                                  \
129     --disable-shared                               \
130     --disable-multilib                             \
131     --disable-decimal-float                        \
132     --disable-threads                              \
133     --disable-libatomic                            \
134     --disable-libgomp                              \
135     --disable-libitm                               \
136     --disable-libquadmath                          \
137     --disable-libsanitizer                         \
138     --disable-libssp                               \
139     --disable-libvtv                               \
140     --disable-libcilkrts                           \
141     --disable-libstdc++-v3                         \
142     --enable-languages=c,c++</userinput></screen>
143     <variablelist>
144       <title>The meaning of the configure options:</title>
146       <varlistentry>
147         <term><parameter>--with-newlib</parameter></term>
148         <listitem>
149           <para>Since a working C library is not yet available, this ensures
150           that the inhibit_libc constant is defined when building libgcc. This prevents
151           the compiling of any code that requires libc support.</para>
152         </listitem>
153       </varlistentry>
155       <varlistentry>
156         <term><parameter>--without-headers</parameter></term>
157         <listitem>
158           <para>When creating a complete cross-compiler, GCC requires
159           standard headers compatible with the target system. For our
160           purposes these headers will not be needed. This switch prevents
161           GCC from looking for them.</para>
162         </listitem>
163       </varlistentry>
165       <varlistentry>
166         <term><parameter>--with-local-prefix=/tools</parameter></term>
167         <listitem>
168           <para>The local prefix is the location in the system that GCC will search
169           for locally installed include files. The default is <filename>/usr/local</filename>.
170           Setting this to <filename>/tools</filename> helps keep the host location of
171           <filename>/usr/local</filename> out of this GCC's search path.</para>
172         </listitem>
173       </varlistentry>
175       <varlistentry>
176         <term><parameter>--with-native-system-header-dir=/tools/include</parameter></term>
177         <listitem>
178           <para>By default GCC searches <filename>/usr/include</filename> for system
179           headers. In conjunction with the sysroot switch, this would translate normally
180           to <filename>$LFS/usr/include</filename>. However the headers that will be installed
181           in the next two sections will go to <filename>$LFS/tools/include</filename>. This
182           switch ensures that gcc will find them correctly. In the second pass of GCC, this
183           same switch will ensure that no headers from the host system are found.</para>
184         </listitem>
185       </varlistentry>
187       <varlistentry>
188         <term><parameter>--disable-shared</parameter></term>
189         <listitem>
190           <para>This switch forces GCC to link its internal libraries
191           statically. We do this to avoid possible issues with the host
192           system.</para>
193         </listitem>
194       </varlistentry>
196       <varlistentry>
197         <term><parameter>--disable-decimal-float, --disable-threads,
198         --disable-libatomic, --disable-libgomp, --disable-libitm,
199         --disable-libquadmath, --disable-libsanitizer,
200         --disable-libssp, --disable-libvtv, --disable-libcilkrts,
201         --disable-libstdc++-v3</parameter></term>
202         <listitem>
203           <para>These switches disable support for the decimal floating point
204           extension, threading, libatomic, libgomp, libitm, 
205           libquadmath, libsanitizer, libssp, libvtv, libcilkrts
206           and the C++ standard library respectively. These features will fail
207           to compile when building a cross-compiler and are not necessary for
208           the task of cross-compiling the temporary libc.</para>
209         </listitem>
210       </varlistentry>
212       <varlistentry>
213         <term><parameter>--disable-multilib</parameter></term>
214         <listitem>
215           <para>On x86_64, LFS does not yet support a multilib configuration.
216           This switch is harmless for x86.</para>
217         </listitem>
218       </varlistentry>
220       <varlistentry>
221         <term><parameter>--enable-languages=c,c++</parameter></term>
222         <listitem>
223           <para>This option ensures that only the C and C++ compilers are built.
224           These are the only languages needed now.</para>
225         </listitem>
226       </varlistentry>
228     </variablelist>
230     <para>Compile GCC by running:</para>
232 <screen><userinput remap="make">make</userinput></screen>
234     <para>Compilation is now complete. At this point, the test suite would
235     normally be run, but, as mentioned before, the test suite framework is
236     not in place yet. The benefits of running the tests at this point
237     are minimal since the programs from this first pass will soon be
238     replaced.</para>
240     <para>Install the package:</para>
242 <screen><userinput remap="install">make install</userinput></screen>
243 <!--
244     <para>Using <parameter>- -disable-shared</parameter> means that the
245     <filename>libgcc_eh.a</filename> file isn't created and installed. The
246     Glibc package depends on this library as it uses
247     <parameter>-lgcc_eh</parameter> within its build system. This dependency
248     can be satisfied by creating a symlink to <filename>libgcc.a</filename>,
249     since that file will end up containing the objects normally contained in
250     <filename>libgcc_eh.a</filename>:</para>
252 <screen><userinput remap="install">ln -sv libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | sed 's/libgcc/&amp;_eh/'`</userinput></screen>
254   </sect2>
256   <sect2 role="content">
257     <title/>
259     <para>Details on this package are located in
260     <xref linkend="contents-gcc" role="."/></para>
262   </sect2>
264 </sect1>