gcc-pass2-inst.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <sect2><title>&nbsp;</title><para>&nbsp;</para></sect2>
  2. <sect2>
  3. <title>Re-installation of GCC</title>
  4. <para>The tools required to test GCC and Binutils are installed now (Tcl, Expect
  5. and DejaGnu). We can continue on rebuilding GCC and Binutils, link them against
  6. the new Glibc, and test them properly. One thing to note, however, is that these
  7. test suites are highly dependent on properly functioning pseudo terminals (PTYs)
  8. which are provided by your host distribution. These days, PTYs are most commonly
  9. implemented via the <emphasis>devpts</emphasis> file system. You can quickly
  10. check if your host system is set up correctly in this regard by performing a
  11. simple test:</para>
  12. <screen><userinput>expect -c "spawn ls"</userinput></screen>
  13. <para>If you receive the message:</para>
  14. <blockquote><screen>The system has no more ptys. Ask your system administrator to create more.</screen></blockquote>
  15. <para>Your host distribution is not set up for proper PTY operation. In this
  16. case there is no point in running the test suites for GCC and Binutils until you
  17. are able to resolve the issue. You can consult the LFS Wiki at
  18. <ulink url="http://wiki.linuxfromscratch.org/"/> for more information on how to
  19. get PTYs working.</para>
  20. <para>Unpack all three GCC tarballs (-core, -g++, and -testsuite) in one and the
  21. same working directory. They will all unfold into a single
  22. <filename>gcc-&gcc-version;/</filename> subdirectory.</para>
  23. <para>First correct one problem and make an essential adjustment:</para>
  24. <screen><userinput>patch -Np1 -i ../&gcc-nofixincludes-patch;
  25. patch -Np1 -i ../&gcc-specs-patch;</userinput></screen>
  26. <para>The first patch disables the GCC "fixincludes" script. We mentioned this
  27. briefly earlier, but a slightly more in-depth explanation of the fixincludes
  28. process is warranted here. Under normal circumstances, the GCC fixincludes
  29. script scans your system for header files that need to be fixed. It might find
  30. that some Glibc header files on your host system need to be fixed, fix them and
  31. put them in the GCC private include directory. Then, later on in
  32. <xref linkend="chapter06"/>, after we've installed the newer Glibc, this
  33. private include directory would be searched before the system include
  34. directory, resulting in GCC finding the fixed headers from the host system,
  35. which would most likely not match the Glibc version actually used for the LFS
  36. system.</para>
  37. <para>The last patch changes GCC's default location of the dynamic linker
  38. (typically <filename>ld-linux.so.2</filename>). It also removes
  39. <filename class="directory">/usr/include</filename> from GCC's include search
  40. path. Patching now rather than adjusting the specs file after installation
  41. ensures that our new dynamic linker gets used during the actual build of GCC.
  42. That is, all the final (and temporary) binaries created during the build will
  43. link against the new Glibc.</para>
  44. <important><para>These patches are <emphasis>critical</emphasis> in ensuring a
  45. successful overall build. Do not forget to apply them.</para></important>
  46. <para>Create a separate build directory again:</para>
  47. <screen><userinput>mkdir ../gcc-build
  48. cd ../gcc-build</userinput></screen>
  49. <para>Before starting to build GCC, remember to unset any environment
  50. variables that override the default optimization flags.</para>
  51. <para>Now prepare GCC to be compiled:</para>
  52. <screen><userinput>../gcc-&gcc-version;/configure --prefix=/tools \
  53. &nbsp;&nbsp;&nbsp;&nbsp;--with-local-prefix=/tools \
  54. &nbsp;&nbsp;&nbsp;&nbsp;--enable-clocale=gnu --enable-shared \
  55. &nbsp;&nbsp;&nbsp;&nbsp;--enable-threads=posix --enable-__cxa_atexit \
  56. &nbsp;&nbsp;&nbsp;&nbsp;--enable-languages=c,c++</userinput></screen>
  57. <para>The meaning of the new configure options:</para>
  58. <itemizedlist>
  59. <listitem><para><userinput>--enable-threads=posix</userinput>: This enables
  60. C++ exception handling for multi-threaded code.</para></listitem>
  61. <listitem><para><userinput>--enable-__cxa_atexit</userinput>: This option
  62. allows use of __cxa_atexit, rather than atexit, to register C++ destructors for
  63. local statics and global objects and is essential for fully standards-compliant
  64. handling of destructors. It also affects the C++ ABI and therefore results in
  65. C++ shared libraries and C++ programs that are interoperable with other Linux
  66. distributions.</para></listitem>
  67. <listitem><para><userinput>--enable-clocale=gnu</userinput>: This option ensures
  68. the correct locale model is selected for the C++ libraries under all
  69. circumstances. If the configure script finds the <emphasis>de_DE</emphasis>
  70. locale installed, it will select the correct model of <emphasis>gnu</emphasis>.
  71. However, people who don't install the <emphasis>de_DE</emphasis> locale, run the
  72. risk of building ABI incompatible C++ libraries due to the wrong locale model of
  73. <emphasis>generic</emphasis> being selected.</para></listitem>
  74. <listitem><para><userinput>--enable-languages=c,c++</userinput>: This option is
  75. needed to ensure that both C and C++ compilers are built.</para></listitem>
  76. </itemizedlist>
  77. <para>Compile the package:</para>
  78. <screen><userinput>make</userinput></screen>
  79. <para>There is no need to use the <userinput>bootstrap</userinput> target now,
  80. as the compiler we're using to compile this GCC was built from the exact same
  81. version of the GCC sources we used earlier.</para>
  82. <note><para>It's worth pointing out that running the GCC test suite here
  83. is considered not as important as running it in
  84. <xref linkend="chapter06"/>.</para></note>
  85. <para>Test the results:</para>
  86. <screen><userinput>make -k check</userinput></screen>
  87. <para>The <userinput>-k</userinput> flag is used to make the test suite run
  88. through to completion and not stop at the first failure. The GCC test suite is
  89. very comprehensive and is almost guaranteed to generate a few failures. To get
  90. a summary of the test suite results, run this:</para>
  91. <screen><userinput>../gcc-&gcc-version;/contrib/test_summary | less</userinput></screen>
  92. <para>You can compare your results to those posted to the gcc-testresults
  93. mailing list for similar configurations to your own. For an example of how
  94. current GCC-&gcc-version; should look on i686-pc-linux-gnu, see
  95. <ulink url="http://gcc.gnu.org/ml/gcc-testresults/2003-08/msg01612.html"/>.</para>
  96. <para>Note that the results contain:</para>
  97. <screen>* 1 XPASS (unexpected pass) for g++
  98. * 1 FAIL (unexpected failure) for g++
  99. * 2 FAIL for gcc
  100. * 26 XPASS's for libstdc++</screen>
  101. <para>The unexpected pass for g++ is due to the use of
  102. <userinput>--enable-__cxa_atexit</userinput>. Apparently not all platforms
  103. supported by GCC have support for "__cxa_atexit" in their C libraries, so this
  104. test is not always expected to pass.</para>
  105. <para>The 26 unexpected passes for libstdc++ are due to the use of
  106. <userinput>--enable-clocale=gnu</userinput>, which is the correct choice on
  107. Glibc-based systems of versions 2.2.5 and above. The underlying locale support
  108. in the GNU C library is superior to that of the otherwise selected "generic"
  109. model (which may be applicable if for instance you were using Newlibc, Sun-libc
  110. or whatever libc). The libstdc++ test suite is apparently expecting the
  111. "generic" model, hence those tests are not always expected to pass.</para>
  112. <para>Unexpected failures often cannot be avoided. The GCC developers are
  113. usually aware of them but haven't yet gotten around to fixing them. In short,
  114. unless your results are vastly different from those at the above URL, it is safe
  115. to continue on.</para>
  116. <para>And finally install the package:</para>
  117. <screen><userinput>make install</userinput></screen>
  118. <note><para>At this point it is strongly recommended to repeat the sanity check
  119. we performed earlier in the chapter. Refer back to
  120. <xref linkend="ch05-locking-glibc"/> and repeat the check. If the results are
  121. wrong, then most likely you forgot to apply the above mentioned GCC Specs
  122. patch.</para></note>
  123. </sect2>