gcc-pass2.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 bootstrap build performed in <xref linkend="ch-tools-gcc-pass1"/>
  66. built GCC with the <option>-fomit-frame-pointer</option> compiler flag.
  67. Non-bootstrap builds omit this flag by default, so apply the following
  68. <command>sed</command> to use it in order to ensure consistent compiler
  69. builds:</para>
  70. <screen><userinput remap="pre">cp -v gcc/Makefile.in{,.tmp}
  71. sed 's/^XCFLAGS =$/&amp; -fomit-frame-pointer/' gcc/Makefile.in.tmp \
  72. &gt; gcc/Makefile.in</userinput></screen>
  73. <para>The following command will change the location of GCC's default
  74. dynamic linker to use the one we installed in
  75. <filename class="directory">/tools</filename>. It also removes <filename
  76. class="directory">/usr/include</filename> from GCC's include search path.
  77. Doing this now rather than adjusting the specs file after installation
  78. ensures that the new dynamic linker is used during the actual build of
  79. GCC. That is, all of the binaries created during the build will link
  80. against the new Glibc. Issue:</para>
  81. <screen><userinput remap="pre">for file in $(find gcc/config -name linux64.h -o -name linux.h)
  82. do
  83. cp -uv $file{,.orig}
  84. sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&amp;@g' \
  85. -e 's@/usr@/tools@g' $file.orig &gt; $file
  86. echo "
  87. #undef STANDARD_INCLUDE_DIR
  88. #define STANDARD_INCLUDE_DIR 0" &gt;&gt; $file
  89. touch $file.orig
  90. done</userinput></screen>
  91. <para>In case the above seems hard to follow, let's break it down a bit.
  92. First we find all the files under the gcc/config directory that are named
  93. either <filename>linux.h</filename> or <filename>linux64.h</filename>.
  94. For each file found, we copy it to a file of the same name but with an added
  95. suffix of <quote>.orig</quote>. Then the first sed expression prepends
  96. <quote>/tools</quote> to every instance of <quote>/lib/ld</quote>,
  97. <quote>/lib64/ld</quote> or <quote>/lib32/ld</quote>, while the second one
  98. replaces hard-coded instances of <quote>/usr</quote>. Then we add our define
  99. statements which alter the include search path to the end of the file. Finally,
  100. we use <command>touch</command> to update the timestamp on the copied files.
  101. When used in conjunction with <command>cp -u</command>, this prevents unexpected
  102. changes to the original files in case the command is inadvertently run twice.
  103. </para>
  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-bootstrap</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. <varlistentry>
  169. <term><parameter>--disable-bootstrap</parameter></term>
  170. <listitem>
  171. <para>Bootstrapping the compiler is now the default for GCC. However,
  172. our build method should provide us with a solid compiler without the
  173. need to bootstrap each time.</para>
  174. </listitem>
  175. </varlistentry>
  176. </variablelist>
  177. <para>Compile the package:</para>
  178. <screen><userinput remap="make">make</userinput></screen>
  179. <para>Compilation is now complete. As previously mentioned, running the test
  180. suites for the temporary tools compiled in this chapter is not mandatory.
  181. To run the GCC test suite anyway, use the following command:</para>
  182. <screen><userinput remap="test">make -k check</userinput></screen>
  183. <para>The <parameter>-k</parameter> flag is used to make the test suite run
  184. through to completion and not stop at the first failure. The GCC test
  185. suite is very comprehensive and is almost guaranteed to generate a few
  186. failures.</para>
  187. <para>For a discussion of test failures that are of particular
  188. importance, please see <xref linkend="ch-system-gcc" role="."/></para>
  189. <para>Install the package:</para>
  190. <screen><userinput remap="install">make install</userinput></screen>
  191. <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
  192. href="adjusting.xml"
  193. xpointer="xpointer(/sect1/caution[1])"/>
  194. </sect2>
  195. <sect2 role="content">
  196. <title/>
  197. <para>Details on this package are located in
  198. <xref linkend="contents-gcc" role="."/></para>
  199. </sect2>
  200. </sect1>