Lab2B: Building glibc

     For part B of Lab 2 I was tasked with building my own version of glibc and then introducing a bug into it to ensure I am using my build instead of the installed version. Glibc is GNU's implementation on the standard C Library which underpins many functions of the Linux kernel, so it is very important that my build and tests don't affect the systems version of glibc or my classmates will not be happy with me.

     The first step is to get the source code for glibc. Since I used wget and tar for part A, I will use git this time to get a feel for both methods. So running git clone git://sourceware.org/git/glibc.git gave me the source code to build from but before I did there is an important step for glibc which is to create a separate directory to build in as glibc uses two parallel trees for source and build codes. This is nice so that if I have messed up my build I can just clear out that directory and still have the source code to start my build again without having to go get the source code again.

     To build glibc in my build directory I had to call the configure from the source directory: ~/src/glibc/configure -prefix=/usr. I was lucky and all required packages were already installed so a Makefile was successfully created and I was ready to build. I wasn't thinking and ran a simple make which resulted in a roughly 40 minute process, if I had thought a bit longer I would ahve used the -j option to take advantage of the core count available on AArchie. But the make was successful and I now have the executable I need to test my build, testrun.sh.

     For testing, I have changed the clock() function to just return 1 so by creating a simple program calling the clock function I can see if my glibc is being used.

#include <stdio.h>
#include <time.h>

int main() {
             printf("Broken Clock Says: %d\n", clock());
}

     By running the a.out with build/glibc/testrun.sh it returns Broken Clock Says: 1. Just to be sure I ran it again with the installed glibc and it returned 1133 so I know for sure that my build was successful and my program ran using it.

     Multiarch or Multiple Architectures, refers to software that is designed to run on more than one computer architecture. Glibc leverages multiarch in two ways. Firstly it is itself a multiarch software in that it has support for a variety of architectures like aarch64, arm and x86_64. Since this is case, the second multiarch aspect of glibc is C code that is compiled with it can be run on any of its supported architectures. This flexibility is one of the reasons it has been adopted so widely.

     Overriding for software generally means superseding the default functionality of the code with your own implementation. For glibc, overriding supports it's multiarch design by changing the implementations of certain functions based on the environment that it is deployed in. Overriding also allows glibc users to tailor default functions to suit their specific needs for better performance.

Comments

Popular posts from this blog

Lab 1: Investigating Open Source Development

Lab 3: Compiled C Code

Lab 4: Assembler