gcc-pass1.xml 11 KB

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