gcc-pass1.xml 15 KB

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