gcc-pass1.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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">
  8. <?dbhtml filename="gcc-pass1.html"?>
  9. <sect1info condition="script">
  10. <productname>gcc</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-extracted-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 \
  57. $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
  58. do
  59. cp -uv $file{,.orig}
  60. sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&amp;@g' \
  61. -e 's@/usr@/tools@g' $file.orig &gt; $file
  62. echo '
  63. #undef STANDARD_STARTFILE_PREFIX_1
  64. #undef STANDARD_STARTFILE_PREFIX_2
  65. #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
  66. #define STANDARD_STARTFILE_PREFIX_2 ""' &gt;&gt; $file
  67. touch $file.orig
  68. done</userinput></screen>
  69. <para>In case the above seems hard to follow, let's break it down a bit.
  70. First we find all the files under the <filename
  71. class="directory">gcc/config</filename> directory that are named either
  72. <filename>linux.h</filename>, <filename>linux64.h</filename> or
  73. <filename>sysv4.h</filename>. For each file found, we copy it to a file of
  74. the same name but with an added suffix of <quote>.orig</quote>. Then the
  75. first sed expression prepends <quote>/tools</quote> to every instance of
  76. <quote>/lib/ld</quote>, <quote>/lib64/ld</quote> or
  77. <quote>/lib32/ld</quote>, while the second one replaces hard-coded
  78. instances of <quote>/usr</quote>. Next, we add our define statements which
  79. alter the default startfile prefix to the end of the file. Note that the
  80. trailing <quote>/</quote> in <quote>/tools/lib/</quote> is required.
  81. Finally, we use <command>touch</command> to update the timestamp on the
  82. copied files. When used in conjunction with <command>cp -u</command>, this
  83. prevents unexpected changes to the original files in case the commands are
  84. inadvertently run twice. </para>
  85. <para>GCC doesn't detect stack protection correctly, which causes problems
  86. for the build of Glibc-&glibc-version;, so fix that by issuing the following
  87. command:</para>
  88. <screen><userinput remap="pre">sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure</userinput></screen>
  89. <para>The GCC documentation recommends building GCC outside of the
  90. source directory in a dedicated build directory:</para>
  91. <screen><userinput remap="pre">mkdir -v ../gcc-build
  92. cd ../gcc-build</userinput></screen>
  93. <para>Prepare GCC for compilation:</para>
  94. <screen><userinput remap="configure">../gcc-&gcc-version;/configure \
  95. --target=$LFS_TGT \
  96. --prefix=/tools \
  97. --with-sysroot=$LFS \
  98. --with-newlib \
  99. --without-headers \
  100. --with-local-prefix=/tools \
  101. --with-native-system-header-dir=/tools/include \
  102. --disable-nls \
  103. --disable-shared \
  104. --disable-multilib \
  105. --disable-decimal-float \
  106. --disable-threads \
  107. --disable-libatomic \
  108. --disable-libgomp \
  109. --disable-libitm \
  110. --disable-libmudflap \
  111. --disable-libquadmath \
  112. --disable-libsanitizer \
  113. --disable-libssp \
  114. --disable-libvtv \
  115. --disable-libcilkrts \
  116. --disable-libstdc++-v3 \
  117. --enable-languages=c,c++ \
  118. --with-mpfr-include=$(pwd)/../gcc-&gcc-version;/mpfr/src \
  119. --with-mpfr-lib=$(pwd)/mpfr/src/.libs</userinput></screen>
  120. <variablelist>
  121. <title>The meaning of the configure options:</title>
  122. <varlistentry>
  123. <term><parameter>--with-newlib</parameter></term>
  124. <listitem>
  125. <para>Since a working C library is not yet available, this ensures
  126. that the inhibit_libc constant is defined when building libgcc. This prevents
  127. the compiling of any code that requires libc support.</para>
  128. </listitem>
  129. </varlistentry>
  130. <varlistentry>
  131. <term><parameter>--without-headers</parameter></term>
  132. <listitem>
  133. <para>When creating a complete cross-compiler, GCC requires
  134. standard headers compatible with the target system. For our
  135. purposes these headers will not be needed. This switch prevents
  136. GCC from looking for them.</para>
  137. </listitem>
  138. </varlistentry>
  139. <varlistentry>
  140. <term><parameter>--with-local-prefix=/tools</parameter></term>
  141. <listitem>
  142. <para>The local prefix is the location in the system that GCC will search
  143. for locally installed include files. The default is <filename>/usr/local</filename>.
  144. Setting this to <filename>/tools</filename> helps keep the host location of
  145. <filename>/usr/local</filename> out of this GCC's search path.</para>
  146. </listitem>
  147. </varlistentry>
  148. <varlistentry>
  149. <term><parameter>--with-native-system-header-dir=/tools/include</parameter></term>
  150. <listitem>
  151. <para>By default GCC searches <filename>/usr/include</filename> for system
  152. headers. In conjunction with the sysroot switch, this would translate normally
  153. to <filename>$LFS/usr/include</filename>. However the headers that will be installed
  154. in the next two sections will go to <filename>$LFS/tools/include</filename>. This
  155. switch ensures that gcc will find them correctly. In the second pass of GCC, this
  156. same switch will ensure that no headers from the host system are found.</para>
  157. </listitem>
  158. </varlistentry>
  159. <varlistentry>
  160. <term><parameter>--disable-shared</parameter></term>
  161. <listitem>
  162. <para>This switch forces GCC to link its internal libraries
  163. statically. We do this to avoid possible issues with the host
  164. system.</para>
  165. </listitem>
  166. </varlistentry>
  167. <varlistentry>
  168. <term><parameter>--disable-decimal-float, --disable-threads,
  169. --disable-libatomic, --disable-libgomp, --disable-libitm,
  170. --disable-libmudflap, --disable-libquadmath, --disable-libsanitizer,
  171. --disable-libssp, --disable-libstdc++-v3</parameter></term>
  172. <listitem>
  173. <para>These switches disable support for the decimal floating point
  174. extension, threading, libatomic, libgomp, libitm, libmudflap,
  175. libquadmath, libsanitizer, libssp and the C++ standard library
  176. respectively. These features will fail to compile when building a
  177. cross-compiler and are not necessary for the task of cross-compiling
  178. the temporary libc.</para>
  179. </listitem>
  180. </varlistentry>
  181. <varlistentry>
  182. <term><parameter>--disable-multilib</parameter></term>
  183. <listitem>
  184. <para>On x86_64, LFS does not yet support a multilib configuration.
  185. This switch is harmless for x86.</para>
  186. </listitem>
  187. </varlistentry>
  188. <varlistentry>
  189. <term><parameter>--enable-languages=c,c++</parameter></term>
  190. <listitem>
  191. <para>This option ensures that only the C and C++ compilers are built.
  192. These are the only languages needed now.</para>
  193. </listitem>
  194. </varlistentry>
  195. <varlistentry>
  196. <term><parameter>--with-mpfr-*</parameter></term>
  197. <listitem>
  198. <para>These options enable the build system to correctly use the
  199. in-tree copy of the MPFR sources.</para>
  200. </listitem>
  201. </varlistentry>
  202. </variablelist>
  203. <para>Compile GCC by running:</para>
  204. <screen><userinput remap="make">make</userinput></screen>
  205. <para>Compilation is now complete. At this point, the test suite would
  206. normally be run, but, as mentioned before, the test suite framework is
  207. not in place yet. The benefits of running the tests at this point
  208. are minimal since the programs from this first pass will soon be
  209. replaced.</para>
  210. <para>Install the package:</para>
  211. <screen><userinput remap="install">make install</userinput></screen>
  212. <!--
  213. <para>Using <parameter>- -disable-shared</parameter> means that the
  214. <filename>libgcc_eh.a</filename> file isn't created and installed. The
  215. Glibc package depends on this library as it uses
  216. <parameter>-lgcc_eh</parameter> within its build system. This dependency
  217. can be satisfied by creating a symlink to <filename>libgcc.a</filename>,
  218. since that file will end up containing the objects normally contained in
  219. <filename>libgcc_eh.a</filename>:</para>
  220. <screen><userinput remap="install">ln -sv libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | sed 's/libgcc/&amp;_eh/'`</userinput></screen>
  221. -->
  222. </sect2>
  223. <sect2 role="content">
  224. <title/>
  225. <para>Details on this package are located in
  226. <xref linkend="contents-gcc" role="."/></para>
  227. </sect2>
  228. </sect1>