gcc-pass2.xml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  3. <!ENTITY % general-entities SYSTEM "../general.ent">
  4. <!ENTITY % patches-entities SYSTEM "../patches.ent">
  5. %general-entities;
  6. %patches-entities;
  7. ]>
  8. <sect1 id="ch-tools-gcc-pass2" role="wrap">
  9. <title>GCC-&gcc-version; - Pass 2</title>
  10. <?dbhtml filename="gcc-pass2.html"?>
  11. <indexterm zone="ch-tools-gcc-pass2">
  12. <primary sortas="a-GCC">GCC</primary>
  13. <secondary>tools, pass 2</secondary></indexterm>
  14. <sect2 role="package"><title/>
  15. <segmentedlist>
  16. <segtitle>&buildtime;</segtitle>
  17. <segtitle>&diskspace;</segtitle>
  18. <seglistitem><seg>11.0 SBU</seg><seg>292 MB</seg></seglistitem>
  19. </segmentedlist>
  20. <xi:include xmlns:xi="http://www.w3.org/2003/XInclude" href="../chapter06/gcc.xml" xpointer="xpointer(/sect1/sect2[1]/segmentedlist[2])"/>
  21. </sect2>
  22. <sect2 role="installation">
  23. <title>Re-installation of GCC</title>
  24. <para>This package is known to have issues when its default
  25. optimization flags (including the <parameter>-march</parameter> and
  26. <parameter>-mcpu</parameter> options) are changed. If any environment
  27. variables that override default optimizations have been defined, such
  28. as <envar>CFLAGS</envar> and <envar>CXXFLAGS</envar>,
  29. unset them when building GCC.</para>
  30. <para>The tools required to test GCC and Binutils&mdash;Tcl, Expect
  31. and DejaGNU&mdash;are installed now. GCC and Binutils can now be
  32. rebuilt, linking them against the new Glibc and testing them properly
  33. (if running the test suites in this chapter). Please note that these
  34. test suites are highly dependent on properly functioning PTYs which
  35. are provided by the host. PTYs are most commonly implemented via the
  36. <systemitem class="filesystem">devpts</systemitem> file system. Check
  37. to see if the host system is set up correctly in this regard by
  38. performing a quick test:</para>
  39. <screen><userinput>expect -c "spawn ls"</userinput></screen>
  40. <para>The response might be:</para>
  41. <screen><computeroutput>The system has no more ptys.
  42. Ask your system administrator to create more.</computeroutput></screen>
  43. <para>If the above message is received, the host does not have its PTYs set up
  44. properly. In this case, there is no point in running the test suites for GCC and
  45. Binutils until this issue is resolved. Please consult the LFS FAQ at <ulink
  46. url="&lfs-root;/lfs/faq.html#no-ptys"/> for more information on how to get PTYs
  47. working.</para>
  48. <para>Under normal circumstances, the GCC <command>fixincludes</command> script
  49. scans the system for header files that need to be fixed (they may contain syntax
  50. errors, for example). The script might find that some Glibc header files on the
  51. host system need to be fixed, so fixes them and puts them in the GCC private
  52. include directory. In <xref linkend="chapter-building-system"/>, after the
  53. newer Glibc has been installed, this private include directory will be searched
  54. before the system include directory. This may result in GCC finding the fixed
  55. headers from the host system, which most likely will not match the Glibc version
  56. used for the LFS system.</para>
  57. <para>The following command adjusts where the GCC <command>fixincludes</command>
  58. script searches for headers, so that it fixes only the new headers under
  59. <filename class="directory">/tools</filename>, not the ones from your host
  60. system.</para>
  61. <screen><userinput>cp -v gcc/Makefile.in{,.orig} &amp;&amp;
  62. sed 's@\(^NATIVE_SYSTEM_HEADER_DIR =\).*@\1 /tools/include@g' \
  63. gcc/Makefile.in.orig &gt; gcc/Makefile.in</userinput></screen>
  64. <para>The bootstrap build performed in <xref linkend="ch-tools-gcc-pass1"/>
  65. built GCC with the <option>-fomit-frame-pointer</option> compiler flag.
  66. Non-bootstrap builds omit this flag by default, so apply the following
  67. <command>sed</command> to use it in order to ensure consistent compiler builds.
  68. </para>
  69. <screen><userinput>cp -v gcc/Makefile.in{,.tmp} &amp;&amp;
  70. sed 's/^XCFLAGS =$/&amp; -fomit-frame-pointer/' gcc/Makefile.in.tmp \
  71. &gt; gcc/Makefile.in</userinput></screen>
  72. <para>Apply the following patch to change the location of GCC's default dynamic
  73. linker (typically <filename class="libraryfile">ld-linux.so.2</filename>):</para>
  74. <screen><userinput>patch -Np1 -i ../&gcc-specs-patch;</userinput></screen>
  75. <para>The above patch also removes
  76. <filename class="directory">/usr/include</filename> from GCC's include search
  77. path. Patching now rather than adjusting the specs file after installation
  78. ensures that the new dynamic linker is used during the actual build of GCC. That
  79. is, all of the binaries created during the build will link against the new
  80. Glibc.</para>
  81. <important><para>The above patch is critical in ensuring a
  82. successful overall build. Do not forget to apply
  83. it.</para></important>
  84. <para>Create a separate build directory again:</para>
  85. <screen><userinput>mkdir -v ../gcc-build
  86. cd ../gcc-build</userinput></screen>
  87. <para>Before starting to build GCC, remember to unset any environment
  88. variables that override the default optimization flags.</para>
  89. <para>Now prepare GCC for compilation:</para>
  90. <screen><userinput>../gcc-&gcc-version;/configure --prefix=/tools \
  91. --libexecdir=/tools/lib --with-local-prefix=/tools \
  92. --enable-clocale=gnu --enable-shared \
  93. --enable-threads=posix --enable-__cxa_atexit \
  94. --enable-languages=c,c++ --disable-libstdcxx-pch</userinput></screen>
  95. <para>The meaning of the new configure options:</para>
  96. <variablelist>
  97. <varlistentry>
  98. <term><parameter>--enable-clocale=gnu</parameter></term>
  99. <listitem><para>This option ensures the correct locale model is
  100. selected for the C++ libraries under all circumstances. If the
  101. configure script finds the <emphasis>de_DE</emphasis> locale installed, it will select the
  102. correct gnu locale model. However, if the <emphasis>de_DE</emphasis> locale is not
  103. installed, there is the risk of building Application Binary Interface
  104. (ABI)-incompatible C++ libraries because the incorrect generic locale
  105. model may be selected.</para></listitem>
  106. </varlistentry>
  107. <varlistentry>
  108. <term><parameter>--enable-threads=posix</parameter></term>
  109. <listitem><para>This enables C++ exception handling for multi-threaded
  110. code.</para></listitem>
  111. </varlistentry>
  112. <varlistentry>
  113. <term><parameter>--enable-__cxa_atexit</parameter></term>
  114. <listitem><para>This option allows use of
  115. <emphasis>__cxa_atexit</emphasis>, rather than
  116. <emphasis>atexit</emphasis>, to register C++ destructors for local
  117. statics and global objects. This option is essential for fully
  118. standards-compliant handling of destructors. It also affects the C++
  119. ABI, and therefore results in C++ shared libraries and C++ programs
  120. that are interoperable with other Linux
  121. distributions.</para></listitem>
  122. </varlistentry>
  123. <varlistentry>
  124. <term><parameter>--enable-languages=c,c++</parameter></term>
  125. <listitem><para>This option
  126. ensures that both the C and C++ compilers are built.</para></listitem>
  127. </varlistentry>
  128. <varlistentry>
  129. <term><parameter>--disable-libstdcxx-pch</parameter></term>
  130. <listitem><para>Do not build the pre-compiled header (PCH) for
  131. <filename class="libraryfile">libstdc++</filename>. It takes up a lot of space,
  132. and we have no use for it.</para></listitem>
  133. </varlistentry>
  134. </variablelist>
  135. <para>Compile the package:</para>
  136. <screen><userinput>make</userinput></screen>
  137. <para>There is no need to use the <parameter>bootstrap</parameter>
  138. target now because the compiler being used to compile this GCC was
  139. built from the exact same version of the GCC sources used
  140. earlier.</para>
  141. <para>Compilation is now complete. As previously mentioned, running
  142. the test suites for the temporary tools compiled in this chapter is
  143. not mandatory. To run the GCC test suite anyway, use the following
  144. command:</para>
  145. <screen><userinput>make -k check</userinput></screen>
  146. <para>The <parameter>-k</parameter> flag is used to make the test suite run
  147. through to completion and not stop at the first failure. The GCC test
  148. suite is very comprehensive and is almost guaranteed to generate a few
  149. failures. To receive a summary of the test suite results, run:</para>
  150. <screen><userinput>../gcc-&gcc-version;/contrib/test_summary</userinput></screen>
  151. <para>For only the summaries, pipe the output through
  152. <userinput>grep -A7 Summ</userinput>.</para>
  153. <para>Results can be compared with those located at <ulink
  154. url="&test-results;"/>.</para>
  155. <para>A few unexpected failures cannot always be avoided. The GCC developers are
  156. usually aware of these issues, but have not resolved them yet. In particular,
  157. the <filename class="libraryfile">libmudflap</filename> tests are known be
  158. particularly problematic as a result of a bug in GCC (<ulink
  159. url="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20003"/>). Unless the test
  160. results are vastly different from those at the above URL, it is safe to
  161. continue.</para>
  162. <para>Install the package:</para>
  163. <screen><userinput>make install</userinput></screen>
  164. <note><para>At this point it is strongly recommended to repeat the
  165. sanity check we performed earlier in this chapter. Refer back to <xref
  166. linkend="ch-tools-adjusting" role=","/> and repeat the test compilation. If
  167. the result is wrong, the most likely reason is that the GCC Specs
  168. patch was not properly applied.</para></note>
  169. </sect2>
  170. <sect2 role="content"><title/>
  171. <para>Details on this package are located in <xref
  172. linkend="contents-gcc" role="."/></para>
  173. </sect2>
  174. </sect1>