Наши партнеры

Книги по Linux (с отзывами читателей)

Библиотека сайта rus-linux.net

6.9. Glibc-2.12.1

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.9 SBU
Required disk space: 637 MB

6.9.1. Installation of Glibc



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.

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.

When running make install, a script called test-installation.pl performs a small sanity test on our newly installed Glibc. However, because our toolchain still points to the /tools directory, the sanity test would be carried out against the wrong Glibc. We can force the script to check the Glibc we have just installed with the following:

DL=$(readelf -l /bin/sh | sed -n 's@.*interpret.*/tools\(.*\)]$@\1@p')
sed -i "s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=$DL -o|" \
unset DL

The ldd shell script contains Bash-specific syntax. Change its default program interpreter to /bin/bash in case another /bin/sh is installed as described in the Shells chapter of the BLFS book:

sed -i 's|@BASH@|/bin/bash|' elf/ldd.bash.in

Fix a bug that prevents Glibc from building with GCC-4.5.1:

patch -Np1 -i ../glibc-2.12.1-gcc_fix-1.patch

Fix a bug that prevents Glibc from building with versions of Make newer than 3.81.

patch -Np1 -i ../glibc-2.12.1-makefile_fix-1.patch

The Glibc documentation recommends building Glibc outside of the source directory in a dedicated build directory:

mkdir -v ../glibc-build
cd ../glibc-build

As in Chapter 5, add the needed compiler flags to CFLAGS for x86 machines. Here, the optimization of the library is also set for the gcc compiler to enhance compilation speed (-pipe) and package performance (-O3).

case `uname -m` in
  i?86) echo "CFLAGS += -march=i486 -mtune=native -O3 -pipe" > configparms ;;

Prepare Glibc for compilation:

../glibc-2.12.1/configure --prefix=/usr \
    --disable-profile --enable-add-ons \
    --enable-kernel= --libexecdir=/usr/lib/glibc

The meaning of the new configure options:


This changes the location of the pt_chown program from its default of /usr/libexec to /usr/lib/glibc.

Compile the package:



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

Before running the tests, copy a file from the source tree into our build tree to prevent a couple of test failures, then test the results:

cp -v ../glibc-2.12.1/iconvdata/gconv-modules iconvdata
make -k check 2>&1 | tee glibc-check-log
grep Error glibc-check-log

You will probably see an expected (ignored) failure in the posix/annexc test. In addition the Glibc test suite is somewhat dependent on the host system. This is a list of the most common issues:

  • The nptl/tst-clock2, nptl/tst-attr3, 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.

  • If you have mounted the LFS partition with the noatime option, the atime test will fail. As mentioned in Section 2.4, “Mounting the New Partition”, do not use the noatime option while building LFS.

  • When running on older and slower hardware or on systems under load, some tests can fail because of test timeouts being exceeded. Modifying the make check command to set a TIMEOUTFACTOR is reported to help eliminate these errors (e.g. TIMEOUTFACTOR=16 make -k check).

Though it is a harmless message, the install stage of Glibc will complain about the absence of /etc/ld.so.conf. Prevent this warning with:

touch /etc/ld.so.conf

Install the package:

make install

The locales that can make the system respond in a different language were not installed by the above command. 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_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 ja_JP -f EUC-JP ja_JP
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.

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

make localedata/install-locales

Then use the localedef command to create and install locales not listed in the glibc-2.12.1/localedata/SUPPORTED file in the unlikely case you need them.

6.9.2. Configuring Glibc

The /etc/nsswitch.conf file needs to be created because, although Glibc provides defaults when this file is missing or corrupt, the Glibc defaults do not work well in a networked environment. The time zone also needs to be configured.

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

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

passwd: files
group: files
shadow: files

hosts: files dns
networks: files

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

# End /etc/nsswitch.conf

One way to determine the local time zone, run the following script:


After answering a few questions about the location, the script will output the name of the time zone (e.g., America/Edmonton). There are also some other possible timezones listed in /usr/share/zoneinfo such as Canada/Eastern or EST5EDT that are not identified by the script but can be used.

Then create the /etc/localtime file by running:

cp -v --remove-destination /usr/share/zoneinfo/<xxx> \

Replace <xxx> with the name of the time zone selected (e.g., Canada/Eastern).

The meaning of the cp option:


This is needed to force removal of the already existing symbolic link. The reason for copying the file instead of using a symlink is to cover the situation where /usr is on a separate partition. This could be important when booted into single user mode.

6.9.3. 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 > /etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf


# End /etc/ld.so.conf

6.9.4. Contents of Glibc

Installed programs: catchsegv, gencat, getconf, getent, iconv, iconvconfig, ldconfig, ldd, lddlibc4, locale, localedef, mtrace, nscd, pcprofiledump, pt_chown, rpcgen, rpcinfo, sln, sprof, tzselect, xtrace, zdump, and zic
Installed libraries: ld.so, libBrokenLocale.{a,so}, libSegFault.so, libanl.{a,so}, libbsd-compat.a, 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/gconv, /usr/lib/glibc, /usr/lib/locale, /usr/share/i18n, /usr/share/zoneinfo

Short Descriptions


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


Generates message catalogues


Displays the system configuration values for file system specific variables


Gets entries from an administrative database


Performs character set conversion


Creates fastloading iconv module configuration files


Configures the dynamic linker runtime bindings


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


Assists ldd with object files


Prints various information about the current locale


Compiles locale specifications


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


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


Dumps information generated by PC profiling


A helper program for grantpt to set the owner, group and access permissions of a slave pseudo terminal


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


Makes an RPC call to an RPC server


A statically linked ln program


Reads and displays shared object profiling data


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


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


The time zone dumper


The time zone compiler


The helper program for shared library executables


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


The segmentation fault signal handler, used by catchsegv


An asynchronous name lookup library


Provides the portability needed in order to run certain Berkeley Software Distribution (BSD) programs under Linux


The main C library


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


The cryptography library


The dynamic linking interface library


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


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


The mathematical library


Turns on memory allocation checking when linked to


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


The network services library


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


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


The POSIX threads library


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


Contains functions providing miscellaneous RPC services


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


Contains functions useful for building debuggers for multi-threaded programs


Contains code for “standard” functions used in many different Unix utilities