gcc-pass1.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 arch="default">GCC now requires the GMP, MPFR, and MPC packages. As
  36. these packages may not be included in your host distribution, they will be
  37. built with GCC. Unpack each package into the GCC source directory and
  38. rename the resulting directories so the GCC build procedures will
  39. automatically use them:</para>
  40. <para arch="ml_32,ml_x32,ml_all">GCC now requires the GMP, ISL, MPFR, and MPC packages.
  41. As these packages may not be included in your host distribution, they will
  42. be built with GCC. Unpack each package into the GCC source directory and
  43. rename the resulting directories so the GCC build procedures will
  44. automatically use them:</para>
  45. <note><para>There are frequent misunderstandings about this chapter. The
  46. procedures are the same as every other chapter as explained earlier (<xref
  47. linkend='buildinstr'/>). First extract the gcc tarball from the sources
  48. directory and then change to the directory created. Only then should you
  49. proceed with the instructions below.</para></note>
  50. <screen arch="default"><userinput remap="pre">tar -xf ../mpfr-&mpfr-version;.tar.xz
  51. mv -v mpfr-&mpfr-version; mpfr
  52. tar -xf ../gmp-&gmp-version;.tar.xz
  53. mv -v gmp-&gmp-version; gmp
  54. tar -xf ../mpc-&mpc-version;.tar.gz
  55. mv -v mpc-&mpc-version; mpc</userinput></screen>
  56. <screen arch="ml_32,ml_x32,ml_all"><userinput remap="pre">tar -xf ../mpfr-&mpfr-version;.tar.xz
  57. mv -v mpfr-&mpfr-version; mpfr
  58. tar -xf ../gmp-&gmp-version;.tar.xz
  59. mv -v gmp-&gmp-version; gmp
  60. tar -xf ../mpc-&mpc-version;.tar.gz
  61. mv -v mpc-&mpc-version; mpc
  62. tar -xf ../isl-&isl-version;.tar.xz
  63. mv -v isl-&isl-version; isl</userinput></screen>
  64. <para>The following command will change the location of GCC's default
  65. dynamic linker to use the one installed in <filename
  66. class="directory">/tools</filename>. It also removes <filename
  67. class="directory">/usr/include</filename> from GCC's include search path.
  68. Issue:</para>
  69. <screen><userinput remap="pre">for file in gcc/config/{linux,i386/linux{,64}}.h
  70. do
  71. cp -uv $file{,.orig}
  72. sed -e 's@/lib\(64\)\?\(32\)\?\(x32\)\?/ld@/tools&amp;@g' \
  73. -e 's@/usr@/tools@g' $file.orig &gt; $file
  74. touch $file.orig
  75. done
  76. sed -e "/^#define[[:blank:]]*STANDARD_STARTFILE_PREFIX_1/ s;\".*\";\"/tools/lib/\";" \
  77. -e "/^#define[[:blank:]]*STANDARD_STARTFILE_PREFIX_2/ s;\".*\";\"\";" \
  78. -i gcc/gcc.c</userinput></screen>
  79. <para>In case the above seems hard to follow, let's break it down a bit.
  80. First we copy the files <filename>gcc/config/linux.h</filename>,
  81. <filename>gcc/config/i386/linux.h</filename>, and
  82. <filename>gcc/config/i386/linux64.h</filename> to a file of
  83. the same name but with an added suffix of <quote>.orig</quote>. Then the
  84. first sed expression prepends <quote>/tools</quote> to every instance of
  85. <quote>/lib/ld</quote>, <quote>/lib64/ld</quote> or
  86. <quote>/lib32/ld</quote>, while the second one replaces hard-coded
  87. instances of <quote>/usr</quote>. Next, we add our define statements which
  88. alter the default startfile prefix to the end of the file. Note that the
  89. trailing <quote>/</quote> in <quote>/tools/lib/</quote> is required.
  90. Finally, we use <command>touch</command> to update the timestamp on the
  91. copied files. When used in conjunction with <command>cp -u</command>, this
  92. prevents unexpected changes to the original files in case the commands are
  93. inadvertently run twice.</para>
  94. <para arch="default">Finally, on x86_64 hosts, set the default directory
  95. name for 64-bit libraries to <quote>lib</quote>:</para>
  96. <screen arch="default"><userinput remap="pre">case $(uname -m) in
  97. x86_64)
  98. sed -e '/m64=/s/lib64/lib/' \
  99. -i.orig gcc/config/i386/t-linux64
  100. ;;
  101. esac</userinput></screen>
  102. <screen arch="ml_32,ml_x32,ml_all"><userinput remap="pre">sed -e '/m64=/s/lib64/lib/' \
  103. -e '/m32=/s/m32=.*/m32=..\/lib32$(call if_multiarch,:i386-linux-gnu)/' \
  104. -i.orig gcc/config/i386/t-linux64</userinput></screen>
  105. <!--
  106. <para>GCC doesn't detect stack protection correctly, which causes problems
  107. for the build of Glibc-&glibc-version;, so fix that by issuing the following
  108. command:</para>
  109. <screen><userinput remap="pre">sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure</userinput></screen>
  110. -->
  111. <!--
  112. <para>Also fix a problem identified upstream:</para>
  113. <screen><userinput remap="pre">sed -i 's/if \((code.*))\)/if (\1 \&amp;\&amp; \!DEBUG_INSN_P (insn))/' gcc/sched-deps.c</userinput></screen>
  114. -->
  115. <!-- Following patch might be obsolete with gcc >= 8.2.1 -->
  116. <!-- see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86724 -->
  117. <!-- Fix applied in ch5-gcc-pass{1,2}, ch6-gcc -->
  118. <!--
  119. <para arch="ml_32,ml_x32,ml_all">Fix an issue with isl-&isl-version;:</para>
  120. <screen arch="ml_32,ml_x32,ml_all"><userinput remap="pre">sed -e "/#include &lt;isl\/schedule_node.h&gt;/ a#include &lt;isl/id.h&gt;\n#include &lt;isl/space.h&gt;" \
  121. -i gcc/graphite.h</userinput></screen>
  122. -->
  123. <para>The GCC documentation recommends building GCC
  124. in a dedicated build directory:</para>
  125. <screen><userinput remap="pre">mkdir -v build
  126. cd build</userinput></screen>
  127. <para>Prepare GCC for compilation:</para>
  128. <screen><userinput arch="default" remap="configure">mloptions="--disable-multilib"</userinput>
  129. <userinput arch="ml_32,ml_x32,ml_all" remap="configure">mloptions="--enable-multilib --with-multilib-list=m64"</userinput>
  130. <userinput arch="ml_32,ml_all" remap="configure">mloptions="$mloptions,m32"</userinput>
  131. <userinput arch="ml_x32,ml_all" remap="configure">mloptions="$mloptions,mx32"</userinput>
  132. <userinput remap="configure">../configure \
  133. --target=$LFS_TGT \
  134. --prefix=/tools \
  135. --with-glibc-version=2.11 \
  136. --with-sysroot=$LFS \
  137. --with-newlib \
  138. --without-headers \
  139. --with-local-prefix=/tools \
  140. --with-native-system-header-dir=/tools/include \
  141. --disable-nls \
  142. --disable-shared \
  143. --disable-decimal-float \
  144. --disable-threads \
  145. --disable-libatomic \
  146. --disable-libgomp \
  147. --disable-libquadmath \
  148. --disable-libssp \
  149. --disable-libvtv \
  150. --disable-libstdcxx \
  151. --enable-languages=c,c++ \
  152. $mloptions</userinput></screen>
  153. <variablelist>
  154. <title>The meaning of the configure options:</title>
  155. <varlistentry>
  156. <term><parameter>--with-glibc-version=2.11</parameter></term>
  157. <listitem>
  158. <para>This option ensures the package will be compatible with the host's
  159. version of glibc. It is set to the minimum glibc requirement
  160. specified in the <xref linkend="ch-partitioning-hostreqs"/>.</para>
  161. </listitem>
  162. </varlistentry>
  163. <varlistentry>
  164. <term><parameter>--with-newlib</parameter></term>
  165. <listitem>
  166. <para>Since a working C library is not yet available, this ensures
  167. that the inhibit_libc constant is defined when building libgcc. This prevents
  168. the compiling of any code that requires libc support.</para>
  169. </listitem>
  170. </varlistentry>
  171. <varlistentry>
  172. <term><parameter>--without-headers</parameter></term>
  173. <listitem>
  174. <para>When creating a complete cross-compiler, GCC requires
  175. standard headers compatible with the target system. For our
  176. purposes these headers will not be needed. This switch prevents
  177. GCC from looking for them.</para>
  178. </listitem>
  179. </varlistentry>
  180. <varlistentry>
  181. <term><parameter>--with-local-prefix=/tools</parameter></term>
  182. <listitem>
  183. <para>The local prefix is the location in the system that GCC will search
  184. for locally installed include files. The default is <filename>/usr/local</filename>.
  185. Setting this to <filename>/tools</filename> helps keep the host location of
  186. <filename>/usr/local</filename> out of this GCC's search path.</para>
  187. </listitem>
  188. </varlistentry>
  189. <varlistentry>
  190. <term><parameter>--with-native-system-header-dir=/tools/include</parameter></term>
  191. <listitem>
  192. <para>By default, GCC searches <filename>/usr/include</filename> for
  193. system headers. In conjunction with the sysroot switch, this would
  194. normally translate to <filename>$LFS/usr/include</filename>. However
  195. the headers that will be installed in the next two sections will go
  196. to <filename>$LFS/tools/include</filename>. This switch ensures that
  197. gcc will find them correctly. In the second pass of GCC, this same
  198. switch will ensure that no headers from the host system are
  199. found.</para>
  200. </listitem>
  201. </varlistentry>
  202. <varlistentry>
  203. <term><parameter>--disable-shared</parameter></term>
  204. <listitem>
  205. <para>This switch forces GCC to link its internal libraries
  206. statically. We do this to avoid possible issues with the host
  207. system.</para>
  208. </listitem>
  209. </varlistentry>
  210. <varlistentry>
  211. <term><parameter>--disable-decimal-float, --disable-threads,
  212. --disable-libatomic, --disable-libgomp, <!--- -disable-libmpx,-->
  213. --disable-libquadmath, --disable-libssp, --disable-libvtv,
  214. --disable-libstdcxx</parameter></term>
  215. <listitem>
  216. <para>These switches disable support for the decimal floating point
  217. extension, threading, libatomic, libgomp, <!--libmpx, --> libquadmath, libssp,
  218. libvtv, and the C++ standard library respectively. These features
  219. will fail to compile when building a cross-compiler and are not
  220. necessary for the task of cross-compiling the temporary libc.</para>
  221. </listitem>
  222. </varlistentry>
  223. <varlistentry arch="default">
  224. <term><parameter>--disable-multilib</parameter></term>
  225. <listitem>
  226. <para>On x86_64, LFS does not yet support a multilib configuration.
  227. This switch is harmless for x86.</para>
  228. </listitem>
  229. </varlistentry>
  230. <varlistentry arch="ml_32,ml_x32,ml_all">
  231. <term><parameter>--enable-multilib,
  232. --with-multilib-list=m32,m64,mx32</parameter></term>
  233. <listitem>
  234. <para>LFS now supports a multilib configuration. Enable it for the
  235. 32bit, the 64-bit, and the mixed mode.</para>
  236. </listitem>
  237. </varlistentry>
  238. <varlistentry>
  239. <term><parameter>--enable-languages=c,c++</parameter></term>
  240. <listitem>
  241. <para>This option ensures that only the C and C++ compilers are built.
  242. These are the only languages needed now.</para>
  243. </listitem>
  244. </varlistentry>
  245. </variablelist>
  246. <para>Compile GCC by running:</para>
  247. <screen><userinput remap="make">make</userinput></screen>
  248. <para>Compilation is now complete. At this point, the test suite would
  249. normally be run, but, as mentioned before, the test suite framework is
  250. not in place yet. The benefits of running the tests at this point
  251. are minimal since the programs from this first pass will soon be
  252. replaced.</para>
  253. <para>Install the package:</para>
  254. <screen><userinput remap="install">make install</userinput></screen>
  255. <!--
  256. <para>Using <parameter>- -disable-shared</parameter> means that the
  257. <filename>libgcc_eh.a</filename> file isn't created and installed. The
  258. Glibc package depends on this library as it uses
  259. <parameter>-lgcc_eh</parameter> within its build system. This dependency
  260. can be satisfied by creating a symlink to <filename>libgcc.a</filename>,
  261. since that file will end up containing the objects normally contained in
  262. <filename>libgcc_eh.a</filename>:</para>
  263. <screen><userinput remap="install">ln -sv libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | sed 's/libgcc/&amp;_eh/'`</userinput></screen>
  264. -->
  265. </sect2>
  266. <sect2 role="content">
  267. <title/>
  268. <para>Details on this package are located in
  269. <xref linkend="contents-gcc" role="."/></para>
  270. </sect2>
  271. </sect1>