Building glibc

The next package to be build in this lab is glibc. Again building on a Fedora 28 VM.

This build process uses a directory for source code and a directory for building. This keep the source code cleaner, but requires a bit more attention to build. You can also delete and rebuild easily anytime.

To begin I clone the source code into ~/src.

Then create a ~/build/glibc directory to build into.

Running configure with the /usr prefix builds a system glibc.

The first run of configure fails as I need to install bison. After this configure works and gives us the Makefile and some logs about the configure.

Running make took significantly longer for this build then the previous build. I should have run make forcing it to use multiple cores. After 5 minutes I got impatient and stoped the build. I removed everything from the directory and started again.

make -j 5 will use all 4 cores (no hyper-threading) on this vm.

This build still took a few minutes, as this is a very large software package.

There is a large test suite built into glibc, however I am going to compile a small test program against this build location.


#include <stdio.h>

int main()
{
printf("Hello World\n");
return 0;
}

Building against the glibc build path and running:

I was trying to introduce a bug in the glibc to prove that it was the correct install. However I was unable to introduce a bug. So I wiped away my glibc install and tried to compile again.


GLIBC=<path to the GLIBC build directory>

gcc \
-Wl,-rpath=${GLIBC}:\
${GLIBC}/math:\
${GLIBC}/elf:\
${GLIBC}/dlfcn:\
${GLIBC}/nss:\
${GLIBC}/nis:\
${GLIBC}/rt:\
${GLIBC}/resolv:\
${GLIBC}/crypt:\
${GLIBC}/nptl:\
${GLIBC}/dfp \
-Wl,–dynamic-linker=${GLIBC}/elf/ld.so
-o test test.c

This is the build command I have been using and it comes from here. Under the compile against glibc build tree section.

I would have expected this to not produce a executable when run, as there is not glibc in that directory. However it ran and produced a file called test. When attempting to run this the system said the file could not be run. Running objdump on the file shows that while it did produce a elf64-x86-64 file. This file is almost empty with no recognizable parts like other output files.

This was not the output I expected but it does show that it was building against the correct build tree.

Overriding library implementations and multiarch

Overriding a library in the glibc compiler can be done by pointing the compiler to the library.
gcc -L/path/to/lib -l library
This overriding will force the compiler to use this implementation of the library instead of the default one for the target architecture.

Multiarch is the ability for a system to run code compiled for different architectures. Disabling this functionality when compiling can improve performance, allowing the compiler to use optimized version of the library for your architecture. This will however reduce the portability of that build.