Building GCC

In my last blog, I talked about contributing to the GCC compiler by helping out with the Automatic Function Multi-versioning (AFMV) for aarch64. In order to do that I must first learn how to build GCC myself.

Unfortunately, since I do not have an aarch64 machine, I have to rely on the aarch64 systems my professor has setup in order to build/work with GCC. The system I decided to start my GGC build is an ARMv8 machine with 4 cores and 16 GiB ram.

Now to start, the first step we must do is to clone the GCC git repository. Following the steps from my class wiki page I cloned the repo to my spo600 directory using the following command.

$ git clone git://gcc.gnu.org/git/gcc.git ~/spo600/

After cloning, the next step is to create a build directory and configure our build to use that directory. Here are the commands I used to do so.

$ mkdir ~/spo600/gcc-build-001
$ cd ~/spo600/gcc-build-001
$ ~/spo600/gcc/configure --prefix=$HOME/spo600/gcc-build-001

Now we can start the build process. One thing to note is that GCC takes a really long time to build, so I will be using the time command to record how long my build takes just for the metrics, as well as record the logs just in case. To build GCC, I ran the following command inside my gcc-build-001 directory.

$ time make -j 5 |& tee build.log

I used make -j 5 to tell make to run 5 jobs in parallel. Our class wiki page states that it is recommended to use a range between (num cores + 1) to (num cores * 2 + 1) as the number of jobs to run. Since this system has 4 cores, I decided to use the lower end of this range, i.e. 5, just to be safe because this is a shared server.

On this server, builds take around 84 minutes. For my case, my build took around 77 minutes which was nice.

Now that we have compiled the source code, we can install it. I run the following command to install gcc to the directory I specified earlier with --prefix.

$ make install

To use the newly built gcc instead of the system gcc, we have to make sure that our $PATH searches for binaries in our build directory first before the system bins.

# In .bashrc in home directory
PATH=$HOME/spo600/gcc-build-001/bin:$PATH
export PATH 

Then reload our config by running source .bashrcin the home directory.

Now when I run which gcc, I see that it is found in our build directory

$ which gcc
~/spo600/gcc-build-001/bin/gcc

Running gcc --version also now shows us that we are using an experimental version.

$ gcc --version
gcc (GCC) 15.0.0 20241024 (experimental)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

We now have successfully built the gcc compiler ourselves.

Now, where do I even begin making changes? This codebase is huge! Stay tuned for my next blog once I figure that out :,)

And as always, thanks for reading :)

Comments

Popular posts from this blog

Lab 03 - Breakout Game

Lab 04 - Diving into 64-bit Assembly