Brooks Patola

Build and Testing GNU Standard C Library

For our next build process, we are going to test out the GNU C Library (glibc), which provides the core libraries for the the GNU system and many more that use Linux as the kernel.

First we must find and install the source code on our system. A quick glance at their website informs me the latest released version is version 2.26 (2017-08-02), so this is what we will download now…

As usual, with our wget and tar commands…

wget:tar.png

Extraction complete! As with our last open source build (gnugo) this one also has an INSTALL file ¬† , so lets take a look at it and see what we have to do to build this beast…

INSTALL.png

A bit more confusing than building the gnugo source as its talking about configuring into different directory paths…

First we must make a new directory entitled “glibc-build” at the same directory level as were we downloaded the source files. Once that is complete, from our new build directory we can issue a configure command using the mandatory –prefix option with our current build directory appended. Finally once this is done, we can issue a make command to build the source. Lets give it a try now…

configure.png

Seems as everything has configured properly, onto the make!…

make.png

After a long 14 minute process it finally finished….

After another lengthy amount of time wondering why I couldn’t locate the .c files and could only see .o, I realized I had to navigate back into the downloaded new versions directory.

We are now asked to test the library that we have built by introducing a bug in the behaviour of a function. After browsing many functions it seems the simplest one to test is rand() found in rand.c located in the stdlib folder. So lets make a simple program that uses the function…

random program.png

This will generate ten random numbers as follows…

expected rand output

Notice the use of the testrun.sh¬†executable provided to us in our glibc-build directory that makes our ¬†programs source code use our custom built library functions. Lets now introduce a small bug in the rand file…

rand bug.png

Now we will have to re configure and make our library…

The build took much less time this go around thankfully (sub 60 seconds).

Lets see what happens when we run our random program again…

rand bug output.png

Our bug has worked! It only prints the number “1”!

For now it seems there are many functions to explore in this library that may be fun to play with and implement even more bugs! or possibly even find some bugs to fix!

 

Leave a Comment