Details on this package are located in Section 6.10.4, “Contents of Glibc.”
The Glibc package contains the main C library. This library provides the basic routines for allocating memory, searching directories, opening and closing files, reading and writing files, string handling, pattern matching, arithmetic, and so on.
User Notes: http://wiki.linuxfromscratch.org/hlfs/wiki/glibc
This package is known to have issues when its default optimization
flags (including the -march
and -mtune options) are
changed. If any environment variables that override default
optimizations have been defined, such as CFLAGS and CXXFLAGS,
unset them when building Glibc.
It should be noted that compiling Glibc in any way other than the method suggested in this book puts the stability of the system at risk.
The Linuxthreads add-on for Glibc adds multi-threading capabilities to the C library. This serves to save both processor power and physical memory. An FAQ for Linuxthreads is available here: http://tldp.org/FAQ/Threads-FAQ/. Unpack the Linuxthreads package from within the glibc-2.6.1/ sources directory with the following command:
tar xvf ../glibc-linuxthreads-2.5.tar.bz2
When building getcwd with
linuxthreads there is a header file missing which will cause the
build to fail. Include the header with the following command:
sed 's@#include <unistd.h>@&\n#include <sys/param.h>@' \
-i.orig sysdeps/unix/sysv/linux/getcwd.c
The next patches modify the iconvconfig and localedef programs so they do not use GCC Trampoline code, which relies on an executable stack to run. Without these patches the iconvconfig and localedef programs will either crash or be killed if they are run on a kernel with PaX (or Grsecurity), Exec Shield, SELinux, or Openwall memory protection. Details about this protection is available from each project's website and documentation. These patches are from the Glibc “fedora-branch” CVS branch, and are denied inclusion from the main Glibc project because the bugs they fix are caused by a modified kernel. These patches are added in this chapter in case your host system has memory protection, and so that these utilities will still function after booting into the final system. It should also be noted that the paxctl utility, which is installed in the next chapter, can mark the iconvconfig and localedef programs to allow them to execute trampoline code under the PaX memory protection, however it is considered more secure to modify these programs with these patches. Apply these patches with the following commands:
patch -Np1 -i ../glibc-2.6.1-iconvconfig_trampoline-1.patch patch -Np1 -i ../glibc-2.6.1-localedef_trampoline-1.patch
The next patch adds “PT_PAX_FLAGS” program header support to Glibc. This program header is added to programs and libraries by the “PT_PAX_FLAGS” Binutils patch, and contains attributes used by the PaX kernel, and paxctl program, to control the permited behaviour of programs and libraries. Apply this patch with the following command:
patch -Np1 -i ../glibc-2.6.1-pt_pax-1.patch
Glibc uses a hard coded path for /etc/ld.so.preload. To keep Glibc from preloading
libraries from the host machine perform the following command:
cp -v elf/rtld.c{,.orig}
sed 's@/etc/ld.so.preload@/tools&@' elf/rtld.c.orig > elf/rtld.c
The Glibc documentation recommends building Glibc outside of the source directory in a dedicated build directory:
mkdir -v ../glibc-build cd ../glibc-build
Prepare Glibc for compilation:
../glibc-2.6.1/configure --prefix=/tools \
--with-binutils=/tools/bin --with-headers=/tools/include \
--enable-kernel=2.4.0 --enable-bind-now --without-gd \
--disable-profile --enable-add-ons=linuxthreads \
--disable-sanity-checks --without-selinux
The meaning of the configure options:
--with-binutils=/tools/bin
While not required, this switch ensures that there are no errors pertaining to which Binutils programs get used during the Glibc build.
--with-headers=/tools/include
This tells Glibc to compile itself against the headers recently installed to the tools directory, so that it knows exactly what features the kernel has and can optimize itself accordingly.
--enable-kernel=2.4.0
This tells Glibc to add features to the library which this kernel version can support.
--enable-bind-now
This tells Glibc to enable non-lazy runtime bindings.
--without-gd
This prevents the build of the memusagestat program, which insists on linking against the host's libraries (libgd, libpng, libz, etc.).
--disable-profile
This builds the libraries without profiling information.
--enable-add-ons
This tells Glibc to use the NPTL threading library add-on.
--disable-sanity-checks
This tells Glibc to build with Linuxthreads even against the explicit objection of the Glibc maintainers, instead of NPTL. This is required for 2.4 kernels.
--without-selinux
When building from hosts that include SELinux functionality (e.g., Fedora Core 3), Glibc will build with support for SELinux. As the HLFS tools environment does not contain support for SELinux, a Glibc compiled with such support will fail to operate correctly.
Glibc no longer supports i386, and the developers suggest using
-march=i486. We can set
this inside the configparms file.
-march=i486 will also reset
the -mtune GCC option, so
we specify that as well:
echo "CFLAGS += -march=i486 -mtune=i486" > configparms
Compile the package:
make
Install the package:
install -vd /tools/etc touch /tools/etc/ld.so.conf make install
Details on this package are located in Section 6.10.4, “Contents of Glibc.”