Lab 4 Building GCC on My Linux VM

 

Lab 4 Building GCC on My Linux VM (ft. My M2 MacBook Air)

For this lab, I took a dive into the world of large software builds, specifically building the GCC compiler from source. The goal was to get hands-on experience using tools like make and autotools, since we’ll be working with GCC during our course project. Instead of using the SPO600 servers (x86-001 and aarch64-002), I decided to try something a little different and ran everything inside a Linux VM on my M2 MacBook Air (which is arm64 under the hood). Spoiler alert: it actually worked out great!

Step 1: Cloning the Source Code

First things first, I needed the latest development version of GCC. I SSH’d into my Linux VM and cloned the official GCC Git repo:

git clone git://gcc.gnu.org/git/gcc.git gcc-source

This gave me a folder full of source code, ready to be built.

Step 2: Configuring the Build

I’ve learned it's a bad idea to build inside the source directory, so I created a separate directory for building:

mkdir gcc-build

cd gcc-build


Then, I ran the configure script from the source directory, specifying a prefix where the final compiler would be installed:

../gcc-source/configure --prefix=$HOME/gcc-install


At first, I made a small mistake and got an error (make: *** No rule to make target). Turns out I had misreferenced the path to the source directory. Once I corrected it, everything was configured smoothly.

Step 3: Building GCC (Let the Waiting Game Begin)

Time for the heavy lifting. I ran the build process using 8 parallel jobs (since my VM wasn’t very beefy):

time make -j8 |& tee build.log


Build time:

real    92m12.543s

user    735m20.110s

sys     24m33.004s


This was a real test of patience. The fan on my MacBook didn’t kick in (because, well, it’s fanless), but I could definitely feel the heat!

Step 4: Testing the Build

After building, I installed the compiler:

make install


To make sure everything worked, I compiled a simple test C program using the new GCC binary:

test.c:

#include <stdio.h>


int main() {

    printf("GCC is working fine!\n");

    return 0;

}


Compile and run:

$HOME/gcc-install/bin/gcc test.c -o test

./test

Output:

GCC is working fine!

Success!

Step 5: Modify a Source File and Rebuild

To simulate a small code change, I used touch to update the timestamp on passes.cc:

touch ../gcc-source/gcc/passes.cc


Then I re-ran the build:

time make -j8


Rebuild time (after one file change):

real    1m52.983s

user    10m15.423s

sys     0m37.552s


Pretty fast! Only the modified files were recompiled.

Step 6: Null Rebuild

Just to test what happens when nothing has changed, I ran make one more time:

time make


Null rebuild time:

real    0m10.448s

user    0m3.315s

sys     0m2.113s


As expected, make quickly realized that everything was up to date and skipped the actual build steps.

Summary

Action

Time (real)

Initial Build

92m12s

Rebuild (1 file)

1m53s

Null Rebuild

10s


Reflections & Takeaways

Running this lab on my own Linux VM (hosted on my M2 MacBook) was an interesting twist. I had to troubleshoot a few minor issues along the way like directory paths and memory allocation but overall, the experience was smooth. It really helped me understand the difference between full, incremental, and null builds.

The biggest thing I took away from this lab was how powerful and flexible the GNU build system is. Tools like make and autotools can be intimidating at first, but once you get the hang of them, they make working on massive projects like GCC way more manageable.

I also gained a deeper appreciation for how much work goes into compiling something as complex as a compiler. I mean, building a tool that builds other tools? That’s pretty wild.

Final Thoughts

Building GCC from source felt like assembling a giant, intricate machine out of raw parts. It was challenging, fun, and surprisingly satisfying to see it all come together. I’m glad I decided to try this on my own setup. It gave me more freedom to explore and troubleshoot, and I now feel way more confident about working with large open-source projects.

Can’t wait to dive into the actual compiler work in the course project!


Comments

Popular posts from this blog

Project Stage 2.A

Project Stage 3

Project Stage 2.C

Welcome to My SPO600 Journey

Lab1 6502 Assembly Language

Stage 1 Completed

Project Stage 2.B

Lab 2 Adventures in 6502 Assembly

Project Stage 1 Diving In!