Lab2 Code Building Part 2 - glibc

In this post I built glibc (Standard C Library). To see the difference between the system glibc and my build I made a change to one of its functions.

These are the steps I went through to build, make and test the glibc.

1.  First I need a directory to download the glibc source and separate directory for build.
     mkdir -p ~/spo600/lab2/src
     git clone git://sourceware.org/git/glibc.git

2.  Read the instruction written in the INSTALL file. The file states that glibc requires separate build directory to build. Run configure with --prefix option to install GNU C Library. --prefix option tells the configure where to install GNU C Library.

3.  Before running configure and make I went ahead and made a change to div function inside the stdlib.
     cd ~/spo600/lab2/src/stdlib
     vi div.c
I changed this function to return 66 / 2 all the time.

4.  Now let's install GNU C Library in our separate build directory. To do this we need to make the directory first then run configure and run make.
mkdir -p ~/spo600/lab2/build/
cd ~/spo600/lab2/build/
~/spo600/lab2/src/glibc/configure --prefix=/home/hojungan/spo600/lab2/build/
make

5. Let's make a test file to compare the test results
cd ~/spo600
touch lab2testfile.c
This program dives 6 by i

6. Let's compile this and compare the results.
gcc lab2testfile.c -o lab2testfile
==SYSTEM RESULT==

==MY BUILD RESULT==

**
./testrun.sh runs the compiled program using my version of build

**
The separate build path should be ~/path/build/glibc
Obviously I made a mistake and installed it in ~/path/build
oops

Override
Override is often referred to overriding a function with another function in many programming languages. In the context of glibc, the override refers to which function is given preference during the runtime. LD_PRELOAD allows to override standard glibc functions by inserting your own shared library. LD_PRELOAD accesses shared library before loading the standard library, allowing your override functions inside the shared library to be loaded before any other libraries.
For example, if one was to create a function to override standard printf() then the new "printf()" library is inserted in the shared library and LD_PRELOAD is set to this shared library. Now this shared library will be loaded first and the new "printf()" function will be used.
For more information visit stackoverflow and this blog post.

Multiarch
Multiarch is a capability to install and run applications on more than one system architecture.
In another words, VS Code is a software with multiarch capability (it can be used on Windows, macOS, Linux, etc), and Visual Studio is a software that does not have multiarch capability(currently can only be used on Windows. Visual Studio 2019 will be available on macOS).
We can see that glibc is multiarch package from the contents inside the sysdeps directory. sysdeps directory contains directories of different architecture and each architecture directory contains functions for that architecture. We can also see that each architecture directory contains 'multiarch' directory, which contains another functions to support different architecture of same system (32bit, 64bit).
When configure script is ran, it searches for the architecture specific directory to prepare install script to install functions that are specific to the system it's being installed on to.

Comments