gcc-pass2.xml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. <title>GCC-&gcc-version; - Pass 2</title>
  10. <indexterm zone="ch-tools-gcc-pass2">
  11. <primary sortas="a-GCC">GCC</primary>
  12. <secondary>tools, pass 2</secondary>
  13. </indexterm>
  14. <sect2 role="package">
  15. <title/>
  16. <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
  17. href="../chapter06/gcc.xml"
  18. xpointer="xpointer(/sect1/sect2[1]/para[1])"/>
  19. <segmentedlist>
  20. <segtitle>&buildtime;</segtitle>
  21. <segtitle>&diskspace;</segtitle>
  22. <seglistitem>
  23. <seg>&gcc-ch5p2-sbu;</seg>
  24. <seg>&gcc-ch5p2-du;</seg>
  25. </seglistitem>
  26. </segmentedlist>
  27. </sect2>
  28. <sect2 role="installation">
  29. <title>Re-installation of GCC</title>
  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
  44. set up properly. In this case, there is no point in running the test
  45. suites for GCC and Binutils until this issue is resolved. Please consult
  46. the LFS FAQ at <ulink url="&lfs-root;/lfs/faq.html#no-ptys"/> for more
  47. information on how to get PTYs working.</para>
  48. <para>As previously explained in <xref linkend="ch-tools-adjusting"/>,
  49. under normal circumstances the GCC <command>fixincludes</command> script
  50. is run in order to fix potentially broken header files. As GCC-&gcc-version;
  51. and Glibc-&glibc-version; have already been installed at this point, and
  52. their respective header files are known to not require fixing, the
  53. <command>fixincludes</command> script is not required. As mentioned
  54. previously, the script may in fact pollute the build environment by
  55. installing fixed headers from the host system into GCC's private include
  56. directory. The running of the <command>fixincludes</command> script can
  57. be suppressed by issuing the following commands:</para>
  58. <screen><userinput>cp -v gcc/Makefile.in{,.orig}
  59. sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig &gt; gcc/Makefile.in</userinput></screen>
  60. <para>The bootstrap build performed in <xref linkend="ch-tools-gcc-pass1"/>
  61. built GCC with the <option>-fomit-frame-pointer</option> compiler flag.
  62. Non-bootstrap builds omit this flag by default, so apply the following
  63. <command>sed</command> to use it in order to ensure consistent compiler
  64. builds:</para>
  65. <screen><userinput>cp -v gcc/Makefile.in{,.tmp}
  66. sed 's/^XCFLAGS =$/&amp; -fomit-frame-pointer/' gcc/Makefile.in.tmp \
  67. &gt; gcc/Makefile.in</userinput></screen>
  68. <para>The following command will change the location of GCC's default
  69. dynamic linker to use the one we installed in
  70. <filename class="directory">/tools</filename>. It also removes <filename
  71. class="directory">/usr/include</filename> from GCC's include search path.
  72. Doing this now rather than adjusting the specs file after installation
  73. ensures that the new dynamic linker is used during the actual build of
  74. GCC. That is, all of the binaries created during the build will link
  75. against the new Glibc. Issue:</para>
  76. <screen><userinput>for file in $(find gcc/config -name linux64.h -o -name linux.h)
  77. do
  78. cp -uv $file{,.orig}
  79. sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&amp;@g' \
  80. -e 's@/usr@/tools@g' $file.orig &gt; $file
  81. echo "
  82. #undef STANDARD_INCLUDE_DIR
  83. #define STANDARD_INCLUDE_DIR 0" &gt;&gt; $file
  84. touch $file.orig
  85. done</userinput></screen>
  86. <para>In case the above seems hard to follow, let's break it down a bit.
  87. First we find all the files under the gcc/config directory that are named
  88. either <filename>linux.h</filename> or <filename>linux64.h</filename>.
  89. For each file found, we copy it to a file of the same name but with an added
  90. suffix of <quote>.orig</quote>. Then the first sed expression prepends
  91. <quote>/tools</quote> to every instance of <quote>/lib/ld</quote>,
  92. <quote>/lib64/ld</quote> or <quote>/lib32/ld</quote>, while the second one
  93. replaces hard-coded instances of <quote>/usr</quote>. Then we add our define
  94. statments altering the include search path to the end of the file. Finally,
  95. we use <command>touch</command> to update the timestamp on the copied files.
  96. When used in conjunction with <command>cp -u</command>, this prevents unexpected
  97. changes to the original files in case the command is inadvertently run twice.
  98. </para>
  99. <para>Unsetting the multlib spec for GCC ensures that it
  100. won't attempt to link against libraries on the host:</para>
  101. <screen><userinput>for file in $(find gcc/config -name t-linux64) ; do \
  102. cp -v $file{,.orig}
  103. sed '/MULTILIB_OSDIRNAMES/d' $file.orig &gt; $file
  104. done</userinput></screen>
  105. <para>Create a separate build directory again:</para>
  106. <screen><userinput>mkdir -v ../gcc-build
  107. cd ../gcc-build</userinput></screen>
  108. <para>Before starting to build GCC, remember to unset any environment
  109. variables that override the default optimization flags.</para>
  110. <para>Now prepare GCC for compilation:</para>
  111. <screen><userinput>../gcc-&gcc-version;/configure --prefix=/tools \
  112. --with-local-prefix=/tools --enable-clocale=gnu \
  113. --enable-shared --enable-threads=posix \
  114. --enable-__cxa_atexit --enable-languages=c,c++ \
  115. --disable-libstdcxx-pch --disable-multilib</userinput></screen>
  116. <variablelist>
  117. <title>The meaning of the new configure options:</title>
  118. <varlistentry>
  119. <term><parameter>--enable-clocale=gnu</parameter></term>
  120. <listitem>
  121. <para>This option ensures the correct locale model is selected
  122. for the C++ libraries under all circumstances. If the configure
  123. script finds the <emphasis>de_DE</emphasis> locale installed,
  124. it will select the correct gnu locale model. However, if the
  125. <emphasis>de_DE</emphasis> locale is not installed, there is the
  126. risk of building Application Binary Interface (ABI)-incompatible
  127. C++ libraries because the incorrect generic locale model may be
  128. selected.</para>
  129. </listitem>
  130. </varlistentry>
  131. <varlistentry>
  132. <term><parameter>--enable-threads=posix</parameter></term>
  133. <listitem>
  134. <para>This enables C++ exception handling for multi-threaded code.</para>
  135. </listitem>
  136. </varlistentry>
  137. <varlistentry>
  138. <term><parameter>--enable-__cxa_atexit</parameter></term>
  139. <listitem>
  140. <para>This option allows use of <function>__cxa_atexit</function>,
  141. rather than <function>atexit</function>, to register C++ destructors
  142. for local statics and global objects. This option is essential for
  143. fully standards-compliant handling of destructors. It also affects
  144. the C++ ABI, and therefore results in C++ shared libraries and C++
  145. programs that are interoperable with other Linux distributions.</para>
  146. </listitem>
  147. </varlistentry>
  148. <varlistentry>
  149. <term><parameter>--enable-languages=c,c++</parameter></term>
  150. <listitem>
  151. <para>This option ensures that both the C and C++ compilers are
  152. built.</para>
  153. </listitem>
  154. </varlistentry>
  155. <varlistentry>
  156. <term><parameter>--disable-libstdcxx-pch</parameter></term>
  157. <listitem>
  158. <para>Do not build the pre-compiled header (PCH) for
  159. <filename class="libraryfile">libstdc++</filename>. It takes up a
  160. lot of space, and we have no use for it.</para>
  161. </listitem>
  162. </varlistentry>
  163. </variablelist>
  164. <para>Compile the package:</para>
  165. <screen><userinput>make</userinput></screen>
  166. <para>There is no need to use the <parameter>bootstrap</parameter> target
  167. now because the compiler being used to compile this GCC was built from
  168. the exact same version of the GCC sources used earlier.</para>
  169. <para>Compilation is now complete. As previously mentioned, running the test
  170. suites for the temporary tools compiled in this chapter is not mandatory.
  171. To run the GCC test suite anyway, use the following command:</para>
  172. <screen><userinput>make -k check</userinput></screen>
  173. <para>The <parameter>-k</parameter> flag is used to make the test suite run
  174. through to completion and not stop at the first failure. The GCC test
  175. suite is very comprehensive and is almost guaranteed to generate a few
  176. failures.</para>
  177. <para>For a discussion of test failures that are of particular
  178. importance, please see <xref linkend="ch-system-gcc" role="."/></para>
  179. <para>Install the package:</para>
  180. <screen><userinput>make install</userinput></screen>
  181. <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
  182. href="adjusting.xml"
  183. xpointer="xpointer(/sect1/caution[1])"/>
  184. </sect2>
  185. <sect2 role="content">
  186. <title/>
  187. <para>Details on this package are located in
  188. <xref linkend="contents-gcc" role="."/></para>
  189. </sect2>
  190. </sect1>