Installing Glibc-2.3.1

Estimated build time:           14.71 SBU
Estimated required disk space:  369 MB

Contents of Glibc

Last checked against version 2.2.5.

Glibc is the C library that provides the system calls and basic functions such as open, malloc, printf, etc. The C library is used by all dynamically linked programs.

Glibc installs the following files:

Program Files

catchsegv, gencat, getconf, getent, glibcbug, iconv, iconvconfig, ldconfig, ldd, lddlibc4, locale, localedef, mtrace, nscd, nscd_nischeck, pcprofiledump, pt_chown, rpcgen, rpcinfo, sln, sprof, tzselect, xtrace, zdump and zic

Library Files

ld.so, libBrokenLocale.[a,so], libSegFault.so, libanl.[a,so], libbsd-compat.a, libc.[a,so], libc_nonshared.a, libcrypt.[a,so], libdl.[a,so], libg.a, libieee.a, libm.[a,so], libmcheck.a, libmemusage.so, libnsl.a, libnss_compat.so, libnss_dns.so, libnss_files.so, libnss_hesiod.so, libnss_nis.so, libnss_nisplus.so, libpcprofile.so, libpthread.[a,so], libresolv.[a,so], librpcsvc.a, librt.[a,so], libthread_db.so and libutil.[a,so]

Glibc Installation Dependencies

Last checked against version 2.2.5.

Bash: sh
Binutils: ar, as, ld, ranlib, readelf
Diffutils: cmp
Fileutils: chmod, cp, install, ln, mknod, mv, mkdir, rm, touch
Gcc: cc, cc1, collect2, cpp, gcc
Grep: egrep, grep
Gzip: gzip
Make: make
Gawk: gawk
Sed: sed
Sh-utils: date, expr, hostname, pwd, uname
Texinfo: install-info, makeinfo
Textutils: cat, cut, sort, tr

Glibc installation

Before starting to install Glibc, you must cd into the glibc-2.3.1 directory and unpack Glibc-linuxthreads in that directory, not in /usr/src as you would normally do.

This package is known to behave badly when you have changed its default optimization flags (including the -march and -mcpu options). Therefore, if you have defined any environment variables that override default optimizations, such as CFLAGS and CXXFLAGS, we recommend unsetting them when building Glibc.

Basically, compiling Glibc in any other way than the book suggests is putting your system at a very high risk.

We'll start by applying a patch that does the following:

patch -Np1 -i ../glibc-2.3.1-root-perl.patch

There is a potential problem that causes statically linked binaries to crash that were linked against Glibc-2.2 or older libraries. Even though static binaries have all the necessary parts of Glibc built-in, they still rely on one external library set: Glibc's NSS libraries. These libraries, among other things, tell programs where the system's password database is (in /etc/password, NIS, or whatever other scheme has been configured).

Glibc has undergone some changes since version 2.2.x and the new NSS code is incompatible with the old one. So when Glibc is installed it will install its new NSS libraries, and static programs will load these new NSS libraries and will abort with a segmentation fault error. This patch undoes some of the changes to overcome the problem.

If you started chapter 5 with a host system that uses Glibc-2.2.x or older, you must apply the following patch. We will install Glibc again at the end of this chapter to remove this patch so you'll have a pristine Glibc as the developers intended it.

patch -Np1 -i ../glibc-2.3.1-libnss.patch

Glibc will check for the /etc/ld.so.conf file and abort with an error if the file is missing, so we must create it:

touch /etc/ld.so.conf

The documentation that comes with Glibc recommends to build the package not in the source directory but in a separate, dedicated directory:

mkdir ../glibc-build &&
cd ../glibc-build

Next, prepare Glibc to be compiled:

../glibc-2.3.1/configure --prefix=/usr \
����--disable-profile --enable-add-ons \
����--libexecdir=/usr/bin

The meaning of the configure options are:

During this stage you will see the following warning:

configure: warning:
*** These auxiliary programs are missing or too old: msgfmt
*** some features will be disabled.
*** Check the INSTALL file for required versions.

The missing msgfmt program (from the Gettext package, which we'll install later) won't cause any problems. The msgfmt is used to generate the binary translation files that can make your system talk in a different language. Because these translation files have already been generated for you, there is no need for msgfmt. You'd only need the program if you change the translation source files (the *.po files in the po subdirectory), which would require you to regenerate the binary files.

Because Glibc hasn't been installed yet, one of the tests that was run by the configure script has failed. This test is supposed to test gcc to determine whether a cross-compiler is installed. However, Glibc needs to be already installed to run this test. Since the test failed, the configure script assumes we have a cross-compiler. We override that assumption by explicitly telling Glibc we're not cross-compiling. Not doing this would have a couple of unintended side effects, such as the timezone files not being installed.

echo "cross-compiling = no" > configparms

Continue with compiling the package:

make

We'll continue with installing the package. The Linuxthreads man pages are not going to be installed at this point because it requires a working Perl installation. We'll install Perl later on in this chapter, and the man pages will be installed when Glibc is installed for the second time at the end of this chapter.

make install

The locales (used by Glibc to make your Linux system talk in a different language) weren't installed when you ran the previous command, so we have to do that ourselves now:

make localedata/install-locales

An alternative to running the previous command is to install only those locales which you need or want. This can be achieved using the localedef command. Information on this can be found in the INSTALL file in the glibc-2.3.1 tree.

To finish off the installation we'll reload Bash so it will use the new libnss_* files. This will also get rid of the I have no name! message in the command prompt:

exec /static/bin/bash --login

Configuring Glibc

We need to create the /etc/nsswitch.conf file, because, although Glibc provides defaults when this file is missing or corrupt, the Glibc defaults don't work well with networking. Also, our timezone needs to be set up.

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

publickey: files

hosts: files dns
networks: files

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

netgroup: db files

# End /etc/nsswitch.conf
EOF

To find out what timezone you're in, run the following script:

tzselect

When you've answered a few questions about your location, the script will output the name of your timezone, something like EST5EDT or Canada/Eastern. Then create the /etc/localtime symlink by running:

ln -sf ../usr/share/zoneinfo/Canada/Eastern /etc/localtime 

Of course, instead of Canada/Eastern, fill in the name of the timezone that the tzselect script gave you.

Configuring 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 when you run them. However, if there are libraries in directories other than /lib and /usr/lib, you need to add them to the /etc/ld.so.conf file 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 we 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

/usr/local/lib
/opt/lib

# End /etc/ld.so.conf
EOF