Version 10.1
[linux_from_scratch.git] / chapter05 / glibc.xml
blob4c020de3bc6257ad5234a60ae9396eec6a165887
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 ]>
8 <sect1 id="ch-tools-glibc" role="wrap">
9   <?dbhtml filename="glibc.html"?>
11   <sect1info condition="script">
12     <productname>glibc</productname>
13     <productnumber>&glibc-version;</productnumber>
14     <address>&glibc-url;</address>
15   </sect1info>
17   <title>Glibc-&glibc-version;</title>
19   <indexterm zone="ch-tools-glibc">
20     <primary sortas="a-Glibc">Glibc</primary>
21     <secondary>tools</secondary>
22   </indexterm>
24   <sect2 role="package">
25     <title/>
27     <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
28     href="../chapter08/glibc.xml"
29     xpointer="xpointer(/sect1/sect2[1]/para[1])"/>
31     <segmentedlist>
32       <segtitle>&buildtime;</segtitle>
33       <segtitle>&diskspace;</segtitle>
35       <seglistitem>
36         <seg>&glibc-tmp-sbu;</seg>
37         <seg>&glibc-tmp-du;</seg>
38       </seglistitem>
39     </segmentedlist>
41   </sect2>
43   <sect2 role="installation">
44     <title>Installation of Glibc</title>
46     <para arch="default">First, create a symbolic link for LSB compliance. Additionally,
47     for x86_64, create a compatibility symbolic link required for proper
48     operation of the dynamic library loader:</para>
50 <screen arch="default"><userinput remap="pre">case $(uname -m) in
51     i?86)   ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3
52     ;;
53     x86_64) ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64
54             ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3
55     ;;
56 esac</userinput></screen>
58     <para arch="ml_32,ml_x32,ml_all">First, create symbolic links for LSB compliance
59     and compatibility symbolic links required for proper
60     operation of the dynamic library loader:</para>
62 <!-- no ld-linux.so.2 here as multilib is based on x86_64, not on i686 -->
63 <screen arch="ml_32,ml_x32,ml_all"><userinput remap="pre">ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64
64 ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3</userinput></screen>
66     <para>Some of the Glibc programs use the non-FHS compliant
67     <filename class="directory">/var/db</filename> directory to store their
68     runtime data. Apply the following patch to make such programs store their
69     runtime data in the FHS-compliant locations:</para>
71 <screen><userinput remap="pre">patch -Np1 -i ../glibc-&glibc-version;-fhs-1.patch</userinput></screen>
73     <para>The Glibc documentation recommends building Glibc 
74     in a dedicated build directory:</para>
76 <screen><userinput remap="pre">mkdir -v build
77 cd       build</userinput></screen>
79     <para>Next, prepare Glibc for compilation:</para>
81 <screen arch="default"><userinput remap="configure">../configure                             \
82       --prefix=/usr                      \
83       --host=$LFS_TGT                    \
84       --build=$(../scripts/config.guess) \
85       --enable-kernel=&min-kernel;                \
86       --with-headers=$LFS/usr/include    \
87       libc_cv_slibdir=/lib</userinput></screen>
88 <screen arch="ml_32,ml_x32,ml_all"><userinput remap="configure">../configure                             \
89       --prefix=/usr                      \
90       --host=$LFS_TGT                    \
91       --build=$(../scripts/config.guess) \
92       --enable-kernel=&min-kernel;                \
93       --with-headers=$LFS/usr/include    \
94       --enable-multi-arch                \
95       --libdir=/usr/lib                  \
96       --libexecdir=/usr/lib              \
97       libc_cv_slibdir=/lib</userinput></screen>
98 <!--
99       libc_cv_forced_unwind=yes          \
100       libc_cv_c_cleanup=yes</userinput></screen> -->
102     <variablelist>
103       <title>The meaning of the configure options:</title>
105       <varlistentry>
106         <term><parameter>--host=$LFS_TGT, --build=$(../scripts/config.guess)</parameter></term>
107         <listitem>
108           <para>The combined effect of these switches is that Glibc's build system
109           configures itself to be cross-compiled, using the cross-linker and
110           cross-compiler in <filename class="directory">$LFS/tools</filename>.</para>
111         </listitem>
112       </varlistentry>
114       <varlistentry>
115         <term><parameter>--enable-kernel=&min-kernel;</parameter></term>
116         <listitem>
117           <para>This tells Glibc to compile the library with support
118           for &min-kernel; and later Linux kernels.  Workarounds for older
119           kernels are not enabled.</para>
120         </listitem>
121       </varlistentry>
123       <varlistentry>
124         <term><parameter>--with-headers=$LFS/usr/include</parameter></term>
125         <listitem>
126           <para>This tells Glibc to compile itself against the headers
127           recently installed to the $LFS/usr/include directory, so that
128           it knows exactly what features the kernel has and can optimize
129           itself accordingly.</para>
130         </listitem>
131       </varlistentry>
133       <varlistentry>
134         <term><parameter>libc_cv_slibdir=/lib</parameter></term>
135         <listitem>
136           <para>This ensures that the library is installed in /lib instead
137           of the default /lib64 on 64 bit machines.</para>
138         </listitem>
139       </varlistentry>
141       <varlistentry>
142         <term><option>libc_cv_include_x86_isa_level=no</option></term>
143         <listitem>
144           <para>This disables <quote>x86 ISA needed</quote> property in
145           Glibc libraries.  Use it <emphasis role="bold">if</emphasis>
146           you are building Glibc with <option>-march</option> option in
147           <envar>CFLAGS</envar>, to workaround an issue in Glibc-2.33
148           breaking it.</para>
149         </listitem>
150       </varlistentry>
152     </variablelist>
154     <para>During this stage the following warning might appear:</para>
156     <blockquote>
157 <screen><computeroutput>configure: WARNING:
158 *** These auxiliary programs are missing or
159 *** incompatible versions: msgfmt
160 *** some features will be disabled.
161 *** Check the INSTALL file for required versions.</computeroutput></screen>
162     </blockquote>
164     <para>The missing or incompatible <command>msgfmt</command> program is
165     generally harmless. This <command>msgfmt</command> program is part of the
166     Gettext package which the host distribution should provide.</para>
168     <note><para>There have been reports that this package may fail when 
169     building as a "parallel make".  If this occurs, rerun the make command
170     with a "-j1" option.</para></note>
172     <para>Compile the package:</para>
174 <screen><userinput remap="make">make</userinput></screen>
176     <para>Install the package:</para>
178     <warning><para>If <envar>LFS</envar> is not properly set, and despite the
179     recommendations, you are building as
180     <systemitem class="username">root</systemitem>, the next command will
181     install the newly built glibc to your host system, which most likely
182     will render it unusable. So double check that the environment is
183     correctly set, before running the following command.</para></warning>
185 <screen><userinput remap="install">make DESTDIR=$LFS install</userinput></screen>
187     <variablelist>
188       <title>The meaning of the <command>make install</command> option:</title>
190       <varlistentry>
191         <term><parameter>DESTDIR=$LFS</parameter></term>
192         <listitem>
193           <para>The <envar>DESTDIR</envar> make variable is used by almost all
194           packages to define the location where the package should be
195           installed. If it is not set, it defaults to the root (<filename
196           class="directory">/</filename>) directory. Here we specify that
197           the package be installed in <filename class="directory">$LFS
198           </filename>, which will become the root after <xref linkend=
199           "ch-tools-chroot"/>.</para>
200         </listitem>
201       </varlistentry>
203     </variablelist>
205     <caution>
206       <para>At this point, it is imperative to stop and ensure that the basic
207       functions (compiling and linking) of the new toolchain are working as
208       expected. To perform a sanity check, run the following commands:</para>
210 <screen><userinput>echo 'int main(){}' &gt; dummy.c
211 $LFS_TGT-gcc dummy.c
212 readelf -l a.out | grep '/ld-linux'</userinput></screen>
214       <para>If everything is working correctly, there should be no errors,
215       and the output of the last command will be of the form:</para>
217 <screen><computeroutput>[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]</computeroutput></screen>
219       <para arch="default">Note that for 32-bit machines, the interpreter name will be
220       <filename>/lib/ld-linux.so.2</filename>.</para>
222       <para>If the output is not shown as above or there was no output at all,
223       then something is wrong. Investigate and retrace the steps to find out
224       where the problem is and correct it. This issue must be resolved before
225       continuing on.</para>
227       <para>Once all is well, clean up the test files:</para>
229 <screen><userinput>rm -v dummy.c a.out</userinput></screen>
231     </caution>
233     <note><para>Building packages in the next chapter will serve as an
234     additional check that the toolchain has been built properly. If some
235     package, especially binutils-pass2 or gcc-pass2, fails to build, it is
236     an indication that something has gone wrong with the
237     previous Binutils, GCC, or Glibc installations.</para></note>
239     <para>Now that our cross-toolchain is complete, finalize the installation
240     of the limits.h header. For doing so, run a utility provided by the GCC
241     developers:</para>
243 <screen><userinput>$LFS/tools/libexec/gcc/$LFS_TGT/&gcc-version;/install-tools/mkheaders</userinput></screen>
245   </sect2>
247   <!-- - - - - - - - - - -->
248   <!-- Multilib - 32bit  -->
249   <!-- - - - - - - - - - -->
250   <sect2 arch="ml_32,ml_all">
251     <title>Building Glibc - 32bit</title>
253     <para>Now recompile for m32. The extracted source can be
254     reused but needs to cleaned before installing the m32
255     version of Glibc.</para>
257     <para>Clear the build directory and remove artefacts from
258     previous build:</para>
259       
260 <screen><userinput remap="pre">make clean
261 find .. -name "*.a" -delete</userinput></screen>
263     <para>Configure Glibc for m32 with the following commands:</para>
265 <screen><userinput remap="configure">CC="$LFS_TGT-gcc -m32" \
266 CXX="$LFS_TGT-g++ -m32" \
267 ../configure                             \
268       --prefix=/usr                      \
269       --host=$LFS_TGT32                  \
270       --build=$(../scripts/config.guess) \
271       --enable-kernel=&min-kernel;                \
272       --with-headers=$LFS/usr/include    \
273       --enable-multi-arch                \
274       --libdir=&usr-lib-m32;                \
275       --libexecdir=&usr-lib-m32;            \
276       libc_cv_slibdir=&lib-m32;</userinput></screen>
278     <para>Compile the package:</para>
280 <screen><userinput remap="make">make</userinput></screen>
282     <para>Install the package:</para>
284 <screen><userinput remap="install">make DESTDIR=$PWD/DESTDIR install
285 cp -a DESTDIR&lib-m32;/*     $LFS&lib-m32;/
286 cp -a DESTDIR&usr-lib-m32; $LFS/usr/
287 install -vm644 DESTDIR/usr/include/gnu/{lib-names,stubs}-32.h \
288                $LFS/usr/include/gnu/
289 ln -svf ..&lib-m32;/ld-linux.so.2 $LFS/lib/ld-linux.so.2</userinput></screen>
291     <caution>
292       <para>At this point, it is imperative to stop and ensure that the basic
293       functions (compiling and linking) of the new toolchain are working as
294       expected. To perform a sanity check, run the following commands:</para>
296 <screen><userinput>echo 'int main(){}' &gt; dummy.c
297 $LFS_TGT-gcc -m32 dummy.c
298 readelf -l a.out | grep '/ld-linux'</userinput></screen>
300       <para>If everything is working correctly, there should be no errors,
301       and the output of the last command will be of the form:</para>
303 <screen><computeroutput>[Requesting program interpreter: /lib/ld-linux.so.2]</computeroutput></screen>
305       <para>If the output is not shown as above or there was no output at all,
306       then something is wrong. Investigate and retrace the steps to find out
307       where the problem is and correct it. This issue must be resolved before
308       continuing on.</para>
310       <para>Once all is well, clean up the test files:</para>
312 <screen><userinput>rm -v dummy.c a.out</userinput></screen>
314     </caution>
316   </sect2><!-- m32 -->
318   <!-- - - - - - - - - - -->
319   <!-- Multilib - x32bit -->
320   <!-- - - - - - - - - - -->
321   
322   <sect2 arch="ml_x32,ml_all">
323     <title>Building Glibc - x32bit</title>
325     <para>Now recompile for mx32. The extracted source can be
326     reused but needs to cleaned before installing the mx32
327     version of Glibc.</para>
329     <para>Clear the build directory and remove artefacts from
330     previous build:</para>
331       
332 <screen><userinput remap="pre">make clean
333 find .. -name "*.a" -delete</userinput></screen>
335     <para>Configure Glibc for mx32 with the following commands:</para>
337 <screen><userinput remap="configure">CC="$LFS_TGT-gcc -mx32" \
338 CXX="$LFS_TGT-g++ -mx32" \
339 ../configure                             \
340       --prefix=/usr                      \
341       --host=$LFS_TGTX32                 \
342       --build=$(../scripts/config.guess) \
343       --enable-kernel=&min-kernel;                \
344       --with-headers=$LFS/usr/include    \
345       --enable-multi-arch                \
346       --libdir=&usr-lib-mx32;               \
347       --libexecdir=&usr-lib-mx32;           \
348       libc_cv_slibdir=&lib-mx32;</userinput></screen>
350     <para>Compile the package:</para>
352 <screen><userinput remap="make">make</userinput></screen>
354     <para>Install the package:</para>
356 <screen><userinput remap="install">make DESTDIR=$PWD/DESTDIR install
357 cp -a DESTDIR&lib-mx32;/*     $LFS&lib-mx32;/
358 cp -a DESTDIR&usr-lib-mx32; $LFS/usr/
359 install -vm644 DESTDIR/usr/include/gnu/{lib-names,stubs}-x32.h \
360                $LFS/usr/include/gnu/
361 ln -svf ..&lib-mx32;/ld-linux-x32.so.2 $LFS/lib/ld-linux-x32.so.2</userinput></screen>
363     <caution>
364       <para>At this point, it is imperative to stop and ensure that the basic
365       functions (compiling and linking) of the new toolchain are working as
366       expected. To perform a sanity check, run the following commands:</para>
368 <screen><userinput>echo 'int main(){}' &gt; dummy.c
369 $LFS_TGT-gcc -mx32 dummy.c
370 readelf -l a.out | grep '/ld-linux-x32'</userinput></screen>
372       <para>If everything is working correctly, there should be no errors,
373       and the output of the last command will be of the form:</para>
375 <screen><computeroutput>[Requesting program interpreter: /libx32/ld-linux-x32.so.2]</computeroutput></screen>
377       <para>If the output is not shown as above or there was no output at all,
378       then something is wrong. Investigate and retrace the steps to find out
379       where the problem is and correct it. This issue must be resolved before
380       continuing on.</para>
382       <para>Once all is well, clean up the test files:</para>
384 <screen><userinput>rm -v dummy.c a.out</userinput></screen>
386     </caution>
388   </sect2><!-- mx32 -->
390   <sect2 role="content">
391     <title/>
393     <para>Details on this package are located in
394     <xref linkend="contents-glibc" role="."/></para>
396   </sect2>
398 </sect1>