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