[1fa2099] | 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 |
|
---|
| 8 | <sect1 id="ch-tools-gcc-pass2" role="wrap">
|
---|
| 9 | <?dbhtml filename="gcc-pass2.html"?>
|
---|
| 10 |
|
---|
| 11 | <sect1info condition="script">
|
---|
[60970f9] | 12 | <productname>gcc-pass2</productname>
|
---|
[1fa2099] | 13 | <productnumber>&gcc-version;</productnumber>
|
---|
| 14 | <address>&gcc-url;</address>
|
---|
| 15 | </sect1info>
|
---|
| 16 |
|
---|
| 17 | <title>GCC-&gcc-version; - Pass 2</title>
|
---|
| 18 |
|
---|
| 19 | <indexterm zone="ch-tools-gcc-pass2">
|
---|
| 20 | <primary sortas="a-GCC">GCC</primary>
|
---|
| 21 | <secondary>tools, pass 2</secondary>
|
---|
| 22 | </indexterm>
|
---|
| 23 |
|
---|
| 24 | <sect2 role="package">
|
---|
| 25 | <title/>
|
---|
| 26 |
|
---|
| 27 | <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
|
---|
| 28 | href="../chapter06/gcc.xml"
|
---|
| 29 | xpointer="xpointer(/sect1/sect2[1]/para[1])"/>
|
---|
| 30 |
|
---|
| 31 | <segmentedlist>
|
---|
| 32 | <segtitle>&buildtime;</segtitle>
|
---|
| 33 | <segtitle>&diskspace;</segtitle>
|
---|
| 34 |
|
---|
| 35 | <seglistitem>
|
---|
| 36 | <seg>&gcc-ch5p2-sbu;</seg>
|
---|
| 37 | <seg>&gcc-ch5p2-du;</seg>
|
---|
| 38 | </seglistitem>
|
---|
| 39 | </segmentedlist>
|
---|
| 40 |
|
---|
| 41 | </sect2>
|
---|
| 42 |
|
---|
| 43 | <sect2 role="installation">
|
---|
| 44 | <title>Installation of GCC</title>
|
---|
| 45 |
|
---|
[997d961] | 46 | <para arch="default">As in the first build of GCC, the GMP, MPFR, and MPC packages are
|
---|
| 47 | required. Unpack the tarballs and move them into the required directory
|
---|
| 48 | names:</para>
|
---|
| 49 | <para arch="ml_32,ml_x32,ml_all">As in the first build of GCC, the GMP, MPFR, MPC and ISL packages are
|
---|
| 50 | required. Unpack the tarballs and move them into the required directory
|
---|
| 51 | names:</para>
|
---|
[1fa2099] | 52 |
|
---|
[997d961] | 53 | <screen arch="default"><userinput remap="pre">tar -xf ../mpfr-&mpfr-version;.tar.xz
|
---|
| 54 | mv -v mpfr-&mpfr-version; mpfr
|
---|
| 55 | tar -xf ../gmp-&gmp-version;.tar.xz
|
---|
| 56 | mv -v gmp-&gmp-version; gmp
|
---|
| 57 | tar -xf ../mpc-&mpc-version;.tar.gz
|
---|
| 58 | mv -v mpc-&mpc-version; mpc</userinput></screen>
|
---|
| 59 | <screen arch="ml_32,ml_x32,ml_all"><userinput remap="pre">tar -xf ../mpfr-&mpfr-version;.tar.xz
|
---|
| 60 | mv -v mpfr-&mpfr-version; mpfr
|
---|
| 61 | tar -xf ../gmp-&gmp-version;.tar.xz
|
---|
| 62 | mv -v gmp-&gmp-version; gmp
|
---|
| 63 | tar -xf ../mpc-&mpc-version;.tar.gz
|
---|
| 64 | mv -v mpc-&mpc-version; mpc
|
---|
| 65 | tar -xf ../isl-&isl-version;.tar.xz
|
---|
| 66 | mv -v isl-&isl-version; isl</userinput></screen>
|
---|
[1fa2099] | 67 |
|
---|
| 68 | <para>Once again, change the location of GCC's default dynamic linker to
|
---|
| 69 | use the one installed in <filename
|
---|
| 70 | class="directory">/tools</filename>.</para>
|
---|
| 71 |
|
---|
| 72 | <screen><userinput remap="pre">for file in gcc/config/{linux,i386/linux{,64}}.h
|
---|
| 73 | do
|
---|
| 74 | cp -uv $file{,.orig}
|
---|
[8eb3fe4] | 75 | sed -e 's@/lib\(64\)\?\(32\)\?\(x32\)\?/ld@/tools&@g' \
|
---|
[1fa2099] | 76 | -e 's@/usr@/tools@g' $file.orig > $file
|
---|
| 77 | touch $file.orig
|
---|
[a3df607] | 78 | done
|
---|
| 79 | sed -e "/^#define[[:blank:]]*STANDARD_STARTFILE_PREFIX_1/ s;\".*\";\"/tools/lib/\";" \
|
---|
| 80 | -e "/^#define[[:blank:]]*STANDARD_STARTFILE_PREFIX_2/ s;\".*\";\"\";" \
|
---|
| 81 | -i gcc/gcc.c</userinput></screen>
|
---|
[1fa2099] | 82 |
|
---|
[8eb3fe4] | 83 | <para arch="default">If building on x86_64, change the default directory
|
---|
| 84 | name for 64-bit libraries to <quote>lib</quote>:</para>
|
---|
[1fa2099] | 85 |
|
---|
[8eb3fe4] | 86 | <screen arch="default"><userinput remap="pre">case $(uname -m) in
|
---|
[1fa2099] | 87 | x86_64)
|
---|
| 88 | sed -e '/m64=/s/lib64/lib/' \
|
---|
| 89 | -i.orig gcc/config/i386/t-linux64
|
---|
| 90 | ;;
|
---|
| 91 | esac</userinput></screen>
|
---|
[7b4634c] | 92 | <screen arch="ml_32,ml_x32,ml_all"><userinput remap="pre">sed -e '/m64=/s/lib64/lib/' \
|
---|
| 93 | -e '/m32=/s/m32=.*/m32=..\/lib32$(call if_multiarch,:i386-linux-gnu)/' \
|
---|
| 94 | -i.orig gcc/config/i386/t-linux64</userinput></screen>
|
---|
[1fa2099] | 95 |
|
---|
[997d961] | 96 | <para>Our first build of GCC has installed a couple of internal system
|
---|
| 97 | headers. Normally one of them, <filename>limits.h</filename>, will in turn
|
---|
| 98 | include the corresponding system <filename>limits.h</filename> header, in
|
---|
| 99 | this case, <filename>/tools/include/limits.h</filename>. However, at the
|
---|
| 100 | time of the first build of gcc <filename>/tools/include/limits.h</filename>
|
---|
| 101 | did not exist, so the internal header that GCC installed is a partial,
|
---|
| 102 | self-contained file and does not include the extended features of the
|
---|
| 103 | system header. This was adequate for building the temporary libc, but this
|
---|
| 104 | build of GCC now requires the full internal header. Create a full version
|
---|
| 105 | of the internal header using a command that is identical to what the GCC
|
---|
| 106 | build system does in normal circumstances:</para>
|
---|
[ede49cd] | 107 |
|
---|
[997d961] | 108 | <screen><userinput remap="pre">cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
|
---|
| 109 | `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h</userinput></screen>
|
---|
| 110 | <!--
|
---|
| 111 | <para>For x86 machines, the limited number of registers is a bottleneck
|
---|
| 112 | for the system. Free one up by not using a frame pointer that is not
|
---|
| 113 | needed:</para>
|
---|
[ede49cd] | 114 |
|
---|
[997d961] | 115 | <screen><userinput remap="pre">case `uname -m` in
|
---|
| 116 | i?86) sed -i 's/^T_CFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in ;;
|
---|
| 117 | esac</userinput></screen>
|
---|
| 118 | -->
|
---|
[1fa2099] | 119 | <para>Create a separate build directory again:</para>
|
---|
| 120 |
|
---|
| 121 | <screen><userinput remap="pre">mkdir -v build
|
---|
| 122 | cd build</userinput></screen>
|
---|
| 123 |
|
---|
| 124 | <para>Before starting to build GCC, remember to unset any environment
|
---|
| 125 | variables that override the default optimization flags.</para>
|
---|
| 126 |
|
---|
| 127 | <para>Now prepare GCC for compilation:</para>
|
---|
| 128 |
|
---|
[01ffc23] | 129 | <screen><userinput arch="default" remap="configure">mloptions="--disable-multilib"</userinput>
|
---|
| 130 | <userinput arch="ml_32,ml_x32,ml_all" remap="configure">mloptions="--with-system-zlib --enable-multilib --with-multilib-list=m64"</userinput>
|
---|
| 131 | <userinput arch="ml_32,ml_all" remap="configure">mloptions="$mloptions,m32"</userinput>
|
---|
| 132 | <userinput arch="ml_x32,ml_all" remap="configure">mloptions="$mloptions,mx32"</userinput>
|
---|
[ee1a413] | 133 | <userinput remap="configure">CC=$LFS_TGT-gcc \
|
---|
[8eb3fe4] | 134 | CXX=$LFS_TGT-g++ \
|
---|
| 135 | AR=$LFS_TGT-ar \
|
---|
| 136 | RANLIB=$LFS_TGT-ranlib \
|
---|
| 137 | ../configure \
|
---|
| 138 | --prefix=/tools \
|
---|
| 139 | --with-local-prefix=/tools \
|
---|
| 140 | --with-native-system-header-dir=/tools/include \
|
---|
| 141 | --enable-languages=c,c++ \
|
---|
| 142 | --disable-libstdcxx-pch \
|
---|
| 143 | --disable-bootstrap \
|
---|
[01ffc23] | 144 | --disable-libgomp \
|
---|
| 145 | $mloptions</userinput></screen>
|
---|
[8eb3fe4] | 146 |
|
---|
[1fa2099] | 147 | <variablelist>
|
---|
| 148 | <title>The meaning of the new configure options:</title>
|
---|
| 149 |
|
---|
| 150 | <varlistentry>
|
---|
| 151 | <term><parameter>--enable-languages=c,c++</parameter></term>
|
---|
| 152 | <listitem>
|
---|
| 153 | <para>This option ensures that both the C and C++ compilers are
|
---|
| 154 | built.</para>
|
---|
| 155 | </listitem>
|
---|
| 156 | </varlistentry>
|
---|
| 157 |
|
---|
| 158 | <varlistentry>
|
---|
| 159 | <term><parameter>--disable-libstdcxx-pch</parameter></term>
|
---|
| 160 | <listitem>
|
---|
| 161 | <para>Do not build the pre-compiled header (PCH) for
|
---|
| 162 | <filename class="libraryfile">libstdc++</filename>. It takes up a
|
---|
| 163 | lot of space, and we have no use for it.</para>
|
---|
| 164 | </listitem>
|
---|
| 165 | </varlistentry>
|
---|
| 166 |
|
---|
| 167 | <varlistentry>
|
---|
| 168 | <term><parameter>--disable-bootstrap</parameter></term>
|
---|
| 169 | <listitem>
|
---|
| 170 | <para>For native builds of GCC, the default is to do a "bootstrap"
|
---|
| 171 | build. This does not just compile GCC, but compiles it several times.
|
---|
| 172 | It uses the programs compiled in a first round to compile itself a
|
---|
| 173 | second time, and then again a third time. The second and third
|
---|
| 174 | iterations are compared to make sure it can reproduce itself
|
---|
| 175 | flawlessly. This also implies that it was compiled correctly.
|
---|
| 176 | However, the LFS build method should provide a solid compiler
|
---|
| 177 | without the need to bootstrap each time.</para>
|
---|
| 178 | </listitem>
|
---|
| 179 | </varlistentry>
|
---|
| 180 |
|
---|
| 181 | </variablelist>
|
---|
| 182 |
|
---|
| 183 | <para>Compile the package:</para>
|
---|
| 184 |
|
---|
| 185 | <screen><userinput remap="make">make</userinput></screen>
|
---|
| 186 |
|
---|
| 187 | <para>Install the package:</para>
|
---|
| 188 |
|
---|
| 189 | <screen><userinput remap="install">make install</userinput></screen>
|
---|
| 190 |
|
---|
| 191 | <para>As a finishing touch, create a symlink. Many programs and scripts
|
---|
| 192 | run <command>cc</command> instead of <command>gcc</command>, which is
|
---|
| 193 | used to keep programs generic and therefore usable on all kinds of UNIX
|
---|
| 194 | systems where the GNU C compiler is not always installed. Running
|
---|
| 195 | <command>cc</command> leaves the system administrator free to decide
|
---|
| 196 | which C compiler to install:</para>
|
---|
| 197 |
|
---|
| 198 | <screen><userinput remap="install">ln -sv gcc /tools/bin/cc</userinput></screen>
|
---|
| 199 |
|
---|
| 200 | <caution>
|
---|
| 201 | <para>At this point, it is imperative to stop and ensure that the basic
|
---|
| 202 | functions (compiling and linking) of the new toolchain are working as
|
---|
| 203 | expected. To perform a sanity check, run the following commands:</para>
|
---|
| 204 |
|
---|
| 205 | <screen><userinput>echo 'int main(){}' > dummy.c
|
---|
| 206 | cc dummy.c
|
---|
| 207 | readelf -l a.out | grep ': /tools'</userinput></screen>
|
---|
| 208 |
|
---|
| 209 | <para>If everything is working correctly, there should be no errors,
|
---|
| 210 | and the output of the last command will be of the form:</para>
|
---|
| 211 |
|
---|
| 212 | <screen><computeroutput>[Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2]</computeroutput></screen>
|
---|
| 213 |
|
---|
[8eb3fe4] | 214 |
|
---|
[ee1a413] | 215 | <para arch="ml_32,ml_all">Repeat the test for 32-bit:</para>
|
---|
[8eb3fe4] | 216 |
|
---|
[ee1a413] | 217 | <screen arch="ml_32,ml_all"><userinput>cc -m32 dummy.c
|
---|
[8eb3fe4] | 218 | readelf -l a.out | grep ': /tools'</userinput></screen>
|
---|
| 219 |
|
---|
[ee1a413] | 220 | <para arch="ml_32,ml_all">In this case, the output shoud be:</para>
|
---|
[8eb3fe4] | 221 |
|
---|
[ee1a413] | 222 | <screen arch="ml_32,ml_all"><computeroutput>[Requesting program interpreter: /tools/lib/ld-linux.so.2]</computeroutput></screen>
|
---|
[8eb3fe4] | 223 |
|
---|
[ee1a413] | 224 | <para arch="ml_x32,ml_all">Repeat the test for x32-bit:</para>
|
---|
[8eb3fe4] | 225 |
|
---|
[ee1a413] | 226 | <screen arch="ml_x32,ml_all"><userinput>cc -mx32 dummy.c
|
---|
[8eb3fe4] | 227 | readelf -l a.out | grep ': /tools'</userinput></screen>
|
---|
| 228 |
|
---|
[ee1a413] | 229 | <para arch="ml_x32,ml_all">In this case, the output shoud be:</para>
|
---|
[8eb3fe4] | 230 |
|
---|
[3c72497] | 231 | <screen arch="ml_x32,ml_all"><computeroutput>[Requesting program interpreter: /tools/libx32/ld-linux-x32.so.2]</computeroutput></screen>
|
---|
[8eb3fe4] | 232 |
|
---|
| 233 | <para arch="default">Note that the dynamic linker will be
|
---|
| 234 | /tools/lib/ld-linux.so.2 for 32-bit machines.</para>
|
---|
[1fa2099] | 235 |
|
---|
| 236 | <para>If the output is not shown as above or there was no output at all,
|
---|
| 237 | then something is wrong. Investigate and retrace the steps to find out
|
---|
| 238 | where the problem is and correct it. This issue must be resolved before
|
---|
| 239 | continuing on. First, perform the sanity check again, using
|
---|
| 240 | <command>gcc</command> instead of <command>cc</command>. If this works,
|
---|
| 241 | then the <filename class="symlink">/tools/bin/cc</filename> symlink is
|
---|
| 242 | missing. Install the symlink as per above.
|
---|
| 243 | Next, ensure that the <envar>PATH</envar> is correct. This
|
---|
| 244 | can be checked by running <command>echo $PATH</command> and verifying that
|
---|
| 245 | <filename class="directory">/tools/bin</filename> is at the head of the
|
---|
| 246 | list. If the <envar>PATH</envar> is wrong it could mean that you are not
|
---|
| 247 | logged in as user <systemitem class="username">lfs</systemitem> or that
|
---|
[ede49cd] | 248 | something went wrong back in <xref linkend="ch-preps-settingenviron"
|
---|
[1fa2099] | 249 | role="."/></para>
|
---|
| 250 |
|
---|
| 251 | <para>Once all is well, clean up the test files:</para>
|
---|
| 252 |
|
---|
| 253 | <screen><userinput>rm -v dummy.c a.out</userinput></screen>
|
---|
| 254 |
|
---|
| 255 | </caution>
|
---|
| 256 |
|
---|
| 257 | </sect2>
|
---|
| 258 |
|
---|
| 259 | <sect2 role="content">
|
---|
| 260 | <title/>
|
---|
| 261 |
|
---|
| 262 | <para>Details on this package are located in
|
---|
| 263 | <xref linkend="contents-gcc" role="."/></para>
|
---|
| 264 |
|
---|
| 265 | </sect2>
|
---|
| 266 |
|
---|
| 267 | </sect1>
|
---|