gcc-pass2.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 \
  82. $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
  83. do
  84. cp -uv $file{,.orig}
  85. sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&amp;@g' \
  86. -e 's@/usr@/tools@g' $file.orig &gt; $file
  87. echo "
  88. #undef STANDARD_INCLUDE_DIR
  89. #define STANDARD_INCLUDE_DIR 0" &gt;&gt; $file
  90. touch $file.orig
  91. done</userinput></screen>
  92. <para>In case the above seems hard to follow, let's break it down a bit.
  93. First we find all the files under the gcc/config directory that are named
  94. either <filename>linux.h</filename>, <filename>linux64.h</filename> or
  95. <filename>sysv4.h</filename>.
  96. For each file found, we copy it to a file of the same name but with an added
  97. suffix of <quote>.orig</quote>. Then the first sed expression prepends
  98. <quote>/tools</quote> to every instance of <quote>/lib/ld</quote>,
  99. <quote>/lib64/ld</quote> or <quote>/lib32/ld</quote>, while the second one
  100. replaces hard-coded instances of <quote>/usr</quote>. Then we add our define
  101. statements which alter the include search path to the end of the file. Finally,
  102. we use <command>touch</command> to update the timestamp on the copied files.
  103. When used in conjunction with <command>cp -u</command>, this prevents unexpected
  104. changes to the original files in case the command is inadvertently run twice.
  105. </para>
  106. <para>Unsetting the multlib spec for GCC ensures that it
  107. won't attempt to link against libraries on the host:</para>
  108. <screen><userinput remap="pre">for file in $(find gcc/config -name t-linux64) ; do \
  109. cp -v $file{,.orig}
  110. sed '/MULTILIB_OSDIRNAMES/d' $file.orig &gt; $file
  111. done</userinput></screen>
  112. <para>As in the first build of GCC it requires the GMP and MPFR packages.
  113. Unpack the tarballs and move them into the required directory names:</para>
  114. <screen><userinput remap="pre">tar -jxf ../mpfr-&mpfr-version;.tar.bz2
  115. mv mpfr-&mpfr-version; mpfr
  116. tar -jxf ../gmp-&gmp-version;.tar.bz2
  117. mv gmp-&gmp-version; gmp</userinput></screen>
  118. <para>Create a separate build directory again:</para>
  119. <screen><userinput remap="pre">mkdir -v ../gcc-build
  120. cd ../gcc-build</userinput></screen>
  121. <para>Before starting to build GCC, remember to unset any environment
  122. variables that override the default optimization flags.</para>
  123. <para>Now prepare GCC for compilation:</para>
  124. <screen><userinput remap="configure">../gcc-&gcc-version;/configure --prefix=/tools \
  125. --with-local-prefix=/tools --enable-clocale=gnu \
  126. --enable-shared --enable-threads=posix \
  127. --enable-__cxa_atexit --enable-languages=c,c++ \
  128. --disable-libstdcxx-pch --disable-multilib \
  129. --disable-bootstrap</userinput></screen>
  130. <variablelist>
  131. <title>The meaning of the new configure options:</title>
  132. <varlistentry>
  133. <term><parameter>--enable-clocale=gnu</parameter></term>
  134. <listitem>
  135. <para>This option ensures the correct locale model is selected
  136. for the C++ libraries under all circumstances. If the configure
  137. script finds the <emphasis>de_DE</emphasis> locale installed,
  138. it will select the correct gnu locale model. However, if the
  139. <emphasis>de_DE</emphasis> locale is not installed, there is the
  140. risk of building Application Binary Interface (ABI)-incompatible
  141. C++ libraries because the incorrect generic locale model may be
  142. selected.</para>
  143. </listitem>
  144. </varlistentry>
  145. <varlistentry>
  146. <term><parameter>--enable-threads=posix</parameter></term>
  147. <listitem>
  148. <para>This enables C++ exception handling for multi-threaded code.</para>
  149. </listitem>
  150. </varlistentry>
  151. <varlistentry>
  152. <term><parameter>--enable-__cxa_atexit</parameter></term>
  153. <listitem>
  154. <para>This option allows use of <function>__cxa_atexit</function>,
  155. rather than <function>atexit</function>, to register C++ destructors
  156. for local statics and global objects. This option is essential for
  157. fully standards-compliant handling of destructors. It also affects
  158. the C++ ABI, and therefore results in C++ shared libraries and C++
  159. programs that are interoperable with other Linux distributions.</para>
  160. </listitem>
  161. </varlistentry>
  162. <varlistentry>
  163. <term><parameter>--enable-languages=c,c++</parameter></term>
  164. <listitem>
  165. <para>This option ensures that both the C and C++ compilers are
  166. built.</para>
  167. </listitem>
  168. </varlistentry>
  169. <varlistentry>
  170. <term><parameter>--disable-libstdcxx-pch</parameter></term>
  171. <listitem>
  172. <para>Do not build the pre-compiled header (PCH) for
  173. <filename class="libraryfile">libstdc++</filename>. It takes up a
  174. lot of space, and we have no use for it.</para>
  175. </listitem>
  176. </varlistentry>
  177. <varlistentry>
  178. <term><parameter>--disable-bootstrap</parameter></term>
  179. <listitem>
  180. <para>Bootstrapping the compiler is now the default for GCC. However,
  181. our build method should provide us with a solid compiler without the
  182. need to bootstrap each time.</para>
  183. </listitem>
  184. </varlistentry>
  185. </variablelist>
  186. <para>Compile the package:</para>
  187. <screen><userinput remap="make">make</userinput></screen>
  188. <para>Compilation is now complete. As previously mentioned, running the test
  189. suites for the temporary tools compiled in this chapter is not mandatory.
  190. To run the GCC test suite anyway, use the following command:</para>
  191. <screen><userinput remap="test">make -k check</userinput></screen>
  192. <para>The <parameter>-k</parameter> flag is used to make the test suite run
  193. through to completion and not stop at the first failure. The GCC test
  194. suite is very comprehensive and is almost guaranteed to generate a few
  195. failures.</para>
  196. <para>For a discussion of test failures that are of particular
  197. importance, please see <xref linkend="ch-system-gcc" role="."/></para>
  198. <para>Install the package:</para>
  199. <screen><userinput remap="install">make install</userinput></screen>
  200. <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
  201. href="adjusting.xml"
  202. xpointer="xpointer(/sect1/caution[1])"/>
  203. </sect2>
  204. <sect2 role="content">
  205. <title/>
  206. <para>Details on this package are located in
  207. <xref linkend="contents-gcc" role="."/></para>
  208. </sect2>
  209. </sect1>