gcc-pass2.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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-pass2" role="wrap">
  8. <?dbhtml filename="gcc-pass2.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 2</title>
  15. <indexterm zone="ch-tools-gcc-pass2">
  16. <primary sortas="a-GCC">GCC</primary>
  17. <secondary>tools, pass 2</secondary>
  18. </indexterm>
  19. <sect2 role="package">
  20. <title/>
  21. <xi:include xmlns:xi="http://www.w3.org/2003/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-ch5p2-sbu;</seg>
  29. <seg>&gcc-ch5p2-du;</seg>
  30. </seglistitem>
  31. </segmentedlist>
  32. </sect2>
  33. <sect2 role="installation">
  34. <title>Re-installation of GCC</title>
  35. <para>The tools required to test GCC and Binutils&mdash;Tcl, Expect
  36. and DejaGNU&mdash;are installed now. GCC and Binutils can now be
  37. rebuilt, linking them against the new Glibc and testing them properly
  38. (if running the test suites in this chapter). Please note that these
  39. test suites are highly dependent on properly functioning PTYs which
  40. are provided by the host. PTYs are most commonly implemented via the
  41. <systemitem class="filesystem">devpts</systemitem> file system. Check
  42. to see if the host system is set up correctly in this regard by
  43. performing a quick test:</para>
  44. <screen><userinput remap="test">expect -c "spawn ls"</userinput></screen>
  45. <para>The response might be:</para>
  46. <screen><computeroutput>The system has no more ptys.
  47. Ask your system administrator to create more.</computeroutput></screen>
  48. <para>If the above message is received, the host does not have its PTYs
  49. set up properly. In this case, there is no point in running the test
  50. suites for GCC and Binutils until this issue is resolved. Please consult
  51. the LFS FAQ at <ulink url="&lfs-root;/lfs/faq.html#no-ptys"/> for more
  52. information on how to get PTYs working.</para>
  53. <para>As previously explained in <xref linkend="ch-tools-adjusting"/>,
  54. under normal circumstances the GCC <command>fixincludes</command> script
  55. is run in order to fix potentially broken header files. As GCC-&gcc-version;
  56. and Glibc-&glibc-version; have already been installed at this point, and
  57. their respective header files are known to not require fixing, the
  58. <command>fixincludes</command> script is not required. As mentioned
  59. previously, the script may in fact pollute the build environment by
  60. installing fixed headers from the host system into GCC's private include
  61. directory. The running of the <command>fixincludes</command> script can
  62. be suppressed by issuing the following commands:</para>
  63. <screen><userinput remap="pre">cp -v gcc/Makefile.in{,.orig}
  64. sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig &gt; gcc/Makefile.in</userinput></screen>
  65. <para>The following command will change the location of GCC's default
  66. dynamic linker to use the one we installed in
  67. <filename class="directory">/tools</filename>. It also removes <filename
  68. class="directory">/usr/include</filename> from GCC's include search path.
  69. Doing this now rather than adjusting the specs file after installation
  70. ensures that the new dynamic linker is used during the actual build of
  71. GCC. That is, all of the binaries created during the build will link
  72. against the new Glibc. Issue:</para>
  73. <screen><userinput remap="pre">for file in \
  74. $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
  75. do
  76. cp -uv $file{,.orig}
  77. sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&amp;@g' \
  78. -e 's@/usr@/tools@g' $file.orig &gt; $file
  79. echo "
  80. #undef STANDARD_INCLUDE_DIR
  81. #define STANDARD_INCLUDE_DIR 0" &gt;&gt; $file
  82. touch $file.orig
  83. done</userinput></screen>
  84. <para>In case the above seems hard to follow, let's break it down a bit.
  85. First we find all the files under the gcc/config directory that are named
  86. either <filename>linux.h</filename>, <filename>linux64.h</filename> or
  87. <filename>sysv4.h</filename>.
  88. For each file found, we copy it to a file of the same name but with an added
  89. suffix of <quote>.orig</quote>. Then the first sed expression prepends
  90. <quote>/tools</quote> to every instance of <quote>/lib/ld</quote>,
  91. <quote>/lib64/ld</quote> or <quote>/lib32/ld</quote>, while the second one
  92. replaces hard-coded instances of <quote>/usr</quote>. Then we add our define
  93. statements which alter the include search path to the end of the file. Finally,
  94. we use <command>touch</command> to update the timestamp on the copied files.
  95. When used in conjunction with <command>cp -u</command>, this prevents unexpected
  96. changes to the original files in case the command is inadvertently run twice.
  97. </para>
  98. <para>Unsetting the multlib spec for GCC ensures that it
  99. won't attempt to link against libraries on the host:</para>
  100. <screen><userinput remap="pre">for file in $(find gcc/config -name t-linux64) ; do \
  101. cp -v $file{,.orig}
  102. sed '/MULTILIB_OSDIRNAMES/d' $file.orig &gt; $file
  103. done</userinput></screen>
  104. <para>As in the first build of GCC it requires the GMP and MPFR packages.
  105. Unpack the tarballs and move them into the required directory names:</para>
  106. <screen><userinput remap="pre">tar -jxf ../mpfr-&mpfr-version;.tar.bz2
  107. mv mpfr-&mpfr-version; mpfr
  108. tar -jxf ../gmp-&gmp-version;.tar.bz2
  109. mv gmp-&gmp-version; gmp</userinput></screen>
  110. <para>Create a separate build directory again:</para>
  111. <screen><userinput remap="pre">mkdir -v ../gcc-build
  112. cd ../gcc-build</userinput></screen>
  113. <para>Before starting to build GCC, remember to unset any environment
  114. variables that override the default optimization flags.</para>
  115. <para>Now prepare GCC for compilation:</para>
  116. <screen><userinput remap="configure">../gcc-&gcc-version;/configure --prefix=/tools \
  117. --with-local-prefix=/tools --enable-clocale=gnu \
  118. --enable-shared --enable-threads=posix \
  119. --enable-__cxa_atexit --enable-languages=c,c++ \
  120. --disable-libstdcxx-pch --disable-multilib</userinput></screen>
  121. <variablelist>
  122. <title>The meaning of the new configure options:</title>
  123. <varlistentry>
  124. <term><parameter>--enable-clocale=gnu</parameter></term>
  125. <listitem>
  126. <para>This option ensures the correct locale model is selected
  127. for the C++ libraries under all circumstances. If the configure
  128. script finds the <emphasis>de_DE</emphasis> locale installed,
  129. it will select the correct gnu locale model. However, if the
  130. <emphasis>de_DE</emphasis> locale is not installed, there is the
  131. risk of building Application Binary Interface (ABI)-incompatible
  132. C++ libraries because the incorrect generic locale model may be
  133. selected.</para>
  134. </listitem>
  135. </varlistentry>
  136. <varlistentry>
  137. <term><parameter>--enable-threads=posix</parameter></term>
  138. <listitem>
  139. <para>This enables C++ exception handling for multi-threaded code.</para>
  140. </listitem>
  141. </varlistentry>
  142. <varlistentry>
  143. <term><parameter>--enable-__cxa_atexit</parameter></term>
  144. <listitem>
  145. <para>This option allows use of <function>__cxa_atexit</function>,
  146. rather than <function>atexit</function>, to register C++ destructors
  147. for local statics and global objects. This option is essential for
  148. fully standards-compliant handling of destructors. It also affects
  149. the C++ ABI, and therefore results in C++ shared libraries and C++
  150. programs that are interoperable with other Linux distributions.</para>
  151. </listitem>
  152. </varlistentry>
  153. <varlistentry>
  154. <term><parameter>--enable-languages=c,c++</parameter></term>
  155. <listitem>
  156. <para>This option ensures that both the C and C++ compilers are
  157. built.</para>
  158. </listitem>
  159. </varlistentry>
  160. <varlistentry>
  161. <term><parameter>--disable-libstdcxx-pch</parameter></term>
  162. <listitem>
  163. <para>Do not build the pre-compiled header (PCH) for
  164. <filename class="libraryfile">libstdc++</filename>. It takes up a
  165. lot of space, and we have no use for it.</para>
  166. </listitem>
  167. </varlistentry>
  168. </variablelist>
  169. <para>The following command will compile GCC not once, but several times. It
  170. uses the programs compiled in a first round to compile itself a second time,
  171. and then again a third time. It then compares these second and third compiles
  172. to make sure it can reproduce itself flawlessly. This is called
  173. <quote>bootstrapping</quote>. Building GCC in this way ensures that it was
  174. compiled correctly and is now the default configuration for the released
  175. package. Continue with compiling by running:</para>
  176. <screen><userinput remap="make">make</userinput></screen>
  177. <para>Compilation is now complete. As previously mentioned, running the test
  178. suites for the temporary tools compiled in this chapter is not mandatory.
  179. To run the GCC test suite anyway, use the following command:</para>
  180. <screen><userinput remap="test">make -k check</userinput></screen>
  181. <para>The <parameter>-k</parameter> flag is used to make the test suite run
  182. through to completion and not stop at the first failure. The GCC test
  183. suite is very comprehensive and is almost guaranteed to generate a few
  184. failures.</para>
  185. <para>For a discussion of test failures that are of particular
  186. importance, please see <xref linkend="ch-system-gcc" role="."/></para>
  187. <para>Install the package:</para>
  188. <screen><userinput remap="install">make install</userinput></screen>
  189. <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
  190. href="adjusting.xml"
  191. xpointer="xpointer(/sect1/caution[1])"/>
  192. </sect2>
  193. <sect2 role="content">
  194. <title/>
  195. <para>Details on this package are located in
  196. <xref linkend="contents-gcc" role="."/></para>
  197. </sect2>
  198. </sect1>