6.11. Glibc-2.21

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.

Approximate build time: 16.3 SBU
Required disk space: 1.1 GB

6.11.1. Installation of Glibc

[Note]

Note

Some packages outside of LFS suggest installing GNU libiconv in order to translate data from one encoding to another. The project's home page (http://www.gnu.org/software/libiconv/) says This library provides an iconv() implementation, for use on systems which don't have one, or whose implementation cannot convert from/to Unicode. Glibc provides an iconv() implementation and can convert from/to Unicode, therefore libiconv is not required on an LFS system.

Some of the Glibc programs use non-FHS compilant /var/db directory to store their runtime data. Apply the following patch to make such programs store their runtime data in the FHS-compliant locations:

patch -Np1 -i ../glibc-2.21-fhs-1.patch

The Glibc build system is self-contained and will install perfectly, even though the compiler specs file and linker are still pointing at /tools. The specs and linker cannot be adjusted before the Glibc install because the Glibc autoconf tests would give false results and defeat the goal of achieving a clean build.

Fix a regression in the package that affects 32-bit architectures:

sed -e '/ia32/s/^/1:/' \
    -e '/SSE2/s/^1://' \
    -i  sysdeps/i386/i686/multiarch/mempcpy_chk.S

Fix a potential security issue identified upstream:

sed -i '/glibc.*pad/{i\  buflen = buflen > pad ? buflen - pad : 0;
                     s/ + pad//}' resolv/nss_dns/dns-host.c

Fix a test case that fails when built using GCC 5:

sed -e '/tst-audit2-ENV/i CFLAGS-tst-audit2.c += -fno-builtin' \
    -i elf/Makefile

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.21/configure    \
    --prefix=/usr          \
    --disable-profile      \
    --enable-kernel=2.6.32 \
    --enable-obsolete-rpc

Compile the package:

make
[Important]

Important

In this section, the test suite for Glibc is considered critical. Do not skip it under any circumstance.

Generally a few tests do not pass, but you can generally ignore any of the test failures listed below. Now test the build results:

make check

You will probably see some test failures. The Glibc test suite is somewhat dependent on the host system. This is a list of the most common issues seen for this version of LFS:

  • posix/tst-getaddrinfo4 will always fail due to not having a network connection when the tests are run.

  • The tst/tst-cputimer1 and rt/tst-cpuclock2 tests have been known to fail. The reason is not completely understood, but indications are that minor timing issues can trigger these failures.

  • The math tests sometimes fail when running on systems where the CPU is not a relatively new genuine Intel or authentic AMD processor.

  • Other tests known to fail on some architectures are malloc/tst-malloc-usable and nptl/tst-cleanupx4.

Install the package to a temporary directory:

make install DESTDIR=$(pwd)/debian/tmp

Remove the dynamic linker cache file, which will be regenerated upon installation of the package. This will prevent Dpkg from getting confused about the status of this file on future upgrades or reinstallations of the package.

rm -f debian/tmp/etc/ld.so.cache

Install the configuration file and runtime directory for nscd:

cp -v ../glibc-2.21/nscd/nscd.conf debian/tmp/etc/nscd.conf
mkdir -pv debian/tmp/var/cache/nscd

Install the systemd support files for nscd:

install -v -Dm644 ../glibc-2.21/nscd/nscd.tmpfiles debian/tmp/usr/lib/tmpfiles.d/nscd.conf
install -v -Dm644 ../glibc-2.21/nscd/nscd.service debian/tmp/lib/systemd/system/nscd.service

Optionally, install all locales listed in the glibc-2.21/localedata/SUPPORTED file (it includes every locale listed below and many more) at once with the following time-consuming command:

make localedata/install-locales DESTDIR=$(pwd)/debian/tmp

6.11.2. Configuring Glibc

6.11.2.1. Adding nsswitch.conf

The /etc/nsswitch.conf file needs to be created because the Glibc defaults do not work well in a networked environment.

Create a new file /etc/nsswitch.conf by running the following:

cat > debian/tmp/etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf

passwd: files
group: files
shadow: files

hosts: files dns myhostname
networks: files

protocols: files
services: files
ethers: files
rpc: files

# End /etc/nsswitch.conf
EOF

6.11.2.2. Configuring the Dynamic Loader

By default, the dynamic loader (/lib/ld-linux.so.2) searches through /lib and /usr/lib for dynamic libraries that are needed by programs as they are run. However, if there are libraries in directories other than /lib and /usr/lib, these need to be added to the /etc/ld.so.conf file in order for the dynamic loader to find them. Two directories that are commonly known to contain additional libraries are /usr/local/lib and /opt/lib, so add those directories to the dynamic loader's search path.

Create a new file /etc/ld.so.conf by running the following:

cat > debian/tmp/etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf
/usr/local/lib
/opt/lib

EOF

If desired, the dynamic loader can also search a directory and include the contents of files found there. Generally the files in this include directory are one line specifying the desired library path. To add this capability run the following commands:

cat >> debian/tmp/etc/ld.so.conf << "EOF"
# Add an include directory
include /etc/ld.so.conf.d/*.conf

EOF
mkdir -pv debian/tmp/etc/ld.so.conf.d

6.11.2.3. Adding ldconfig Trigger Support

The post-installation and post-removal scripts generated by the LFS-Dpkg-Wrapper for packages containing shared libraries call a Dpkg trigger named "ldconfig". This ensures that if you remove or reinstall multiple such packages at once, ldconfig will only be called once at the end. In order to add the glibc package support for this trigger, run:

mkdir -pv debian/tmp/DEBIAN
cat > debian/tmp/DEBIAN/triggers << "EOF"
interest ldconfig
EOF
cat > debian/tmp/DEBIAN/postinst << "EOF"
if [ "$1" = "triggered" ]; then
  ldconfig || ldconfig --verbose
  exit 0
fi
dpkg-trigger --no-await ldconfig
EOF

6.11.3. Building and Installing the Glibc Package

Build the package archive:

buildpkg --version=2.21

Install the package:

dpkg -i ../glibc_2.21_*.deb
[Note]

Note

glibc-pass1 cannot be removed until all other packages from the previous chapter are rebuilt.

6.11.4. Post-installation Configuration of Glibc

If you did not install the full set of locales above, you should generate a minimal set of locales now. None of the locales are required, but if some of them are missing, test suites of the future packages would skip important testcases.

Individual locales can be installed using the localedef program. E.g., the first localedef command below combines the /usr/share/i18n/locales/cs_CZ charset-independent locale definition with the /usr/share/i18n/charmaps/UTF-8.gz charmap definition and appends the result to the /usr/lib/locale/locale-archive file. The following instructions will install the minimum set of locales necessary for the optimal coverage of tests:

mkdir -pv /usr/lib/locale
localedef -i cs_CZ -f UTF-8 cs_CZ.UTF-8
localedef -i de_DE -f ISO-8859-1 de_DE
localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
localedef -i de_DE -f UTF-8 de_DE.UTF-8
localedef -i en_GB -f UTF-8 en_GB.UTF-8
localedef -i en_HK -f ISO-8859-1 en_HK
localedef -i en_PH -f ISO-8859-1 en_PH
localedef -i en_US -f ISO-8859-1 en_US
localedef -i en_US -f UTF-8 en_US.UTF-8
localedef -i es_MX -f ISO-8859-1 es_MX
localedef -i fa_IR -f UTF-8 fa_IR
localedef -i fr_FR -f ISO-8859-1 fr_FR
localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
localedef -i fr_FR -f UTF-8 fr_FR.UTF-8
localedef -i it_IT -f ISO-8859-1 it_IT
localedef -i it_IT -f UTF-8 it_IT.UTF-8
localedef -i ja_JP -f EUC-JP ja_JP
localedef -i ru_RU -f KOI8-R ru_RU.KOI8-R
localedef -i ru_RU -f UTF-8 ru_RU.UTF-8
localedef -i tr_TR -f UTF-8 tr_TR.UTF-8
localedef -i zh_CN -f GB18030 zh_CN.GB18030

In addition, install the locale for your own country, language and character set.

6.11.5. Contents of Glibc

Installed programs: catchsegv, gencat, getconf, getent, iconv, iconvconfig, ldconfig, ldd, lddlibc4, locale, localedef, makedb, mtrace, nscd, pcprofiledump, pldd, rpcgen, sln, sotruss, sprof, tzselect, xtrace, zdump, and zic
Installed libraries: ld-2.21.so, libBrokenLocale.{a,so}, libSegFault.so, libanl.{a,so}, libc.{a,so}, libc_nonshared.a, libcidn.so, libcrypt.{a,so}, libdl.{a,so}, libg.a, libieee.a, libm.{a,so}, libmcheck.a, libmemusage.so, libnsl.{a,so}, libnss_compat.so, libnss_dns.so, libnss_files.so, libnss_hesiod.so, libnss_nis.so, libnss_nisplus.so, libpcprofile.so, libpthread.{a,so}, libpthread_nonshared.a, libresolv.{a,so}, librpcsvc.a, librt.{a,so}, libthread_db.so, and libutil.{a,so}
Installed directories: /usr/include/arpa, /usr/include/bits, /usr/include/gnu, /usr/include/net, /usr/include/netash, /usr/include/netatalk, /usr/include/netax25, /usr/include/neteconet, /usr/include/netinet, /usr/include/netipx, /usr/include/netiucv, /usr/include/netpacket, /usr/include/netrom, /usr/include/netrose, /usr/include/nfs, /usr/include/protocols, /usr/include/rpc, /usr/include/rpcsvc, /usr/include/sys, /usr/lib/audit, /usr/lib/gconv, /usr/lib/locale, /usr/libexec/getconf, /usr/share/i18n, /usr/share/zoneinfo, /var/cache/nscd, and /var/lib/nss_db

Short Descriptions

catchsegv

Can be used to create a stack trace when a program terminates with a segmentation fault

gencat

Generates message catalogues

getconf

Displays the system configuration values for file system specific variables

getent

Gets entries from an administrative database

iconv

Performs character set conversion

iconvconfig

Creates fastloading iconv module configuration files

ldconfig

Configures the dynamic linker runtime bindings

ldd

Reports which shared libraries are required by each given program or shared library

lddlibc4

Assists ldd with object files

locale

Prints various information about the current locale

localedef

Compiles locale specifications

makedb

Creates a simple database from textual input

mtrace

Reads and interprets a memory trace file and displays a summary in human-readable format

nscd

A daemon that provides a cache for the most common name service requests

pcprofiledump

Dumps information generated by PC profiling

pldd

Lists dynamic shared objects used by running processes

rpcgen

Generates C code to implement the Remote Procedure Call (RPC) protocol

sln

A statically linked ln program

sotruss

Traces shared library procedure calls of a specified command

sprof

Reads and displays shared object profiling data

tzselect

Asks the user about the location of the system and reports the corresponding time zone description

xtrace

Traces the execution of a program by printing the currently executed function

zdump

The time zone dumper

zic

The time zone compiler

ld-2.21.so

The helper program for shared library executables

libBrokenLocale

Used internally by Glibc as a gross hack to get broken programs (e.g., some Motif applications) running. See comments in glibc-2.21/locale/broken_cur_max.c for more information

libSegFault

The segmentation fault signal handler, used by catchsegv

libanl

An asynchronous name lookup library

libc

The main C library

libcidn

Used internally by Glibc for handling internationalized domain names in the getaddrinfo() function

libcrypt

The cryptography library

libdl

The dynamic linking interface library

libg

Dummy library containing no functions. Previously was a runtime library for g++

libieee

Linking in this module forces error handling rules for math functions as defined by the Institute of Electrical and Electronic Engineers (IEEE). The default is POSIX.1 error handling

libm

The mathematical library

libmcheck

Turns on memory allocation checking when linked to

libmemusage

Used by memusage to help collect information about the memory usage of a program

libnsl

The network services library

libnss

The Name Service Switch libraries, containing functions for resolving host names, user names, group names, aliases, services, protocols, etc.

libpcprofile

Contains profiling functions used to track the amount of CPU time spent in specific source code lines

libpthread

The POSIX threads library

libresolv

Contains functions for creating, sending, and interpreting packets to the Internet domain name servers

librpcsvc

Contains functions providing miscellaneous RPC services

librt

Contains functions providing most of the interfaces specified by the POSIX.1b Realtime Extension

libthread_db

Contains functions useful for building debuggers for multi-threaded programs

libutil

Contains code for standard functions used in many different Unix utilities