Building GCC Part 2

This is my attempt to learn and work with GCC as part of my SPO600 course. I’m working on Stage 2 of the project, where I have to create and test a Clone-Pruning Analysis Pass. You can find the first part in my blog page.

Creating the Dummy Pass

I started by creating a basic pass that should iterates through the program functions and output their names to a dump file. 

Iterating Through GIMPLE Statements

Next, I added logic to traverse the GIMPLE representation of each function. GIMPLE is an intermediate language used by GCC, and understanding it was crucial for the project. By iterating over the GIMPLE statements within each basic block, I could analyze the structure of functions.

This step highlighted the importance of diagnostic dumps, as they provided a detailed view of what the pass was processing. While the GIMPLE code initially felt overwhelming, breaking it down into smaller sections made it easier.


Setting Up

The first step was to get the provided files into my working directory. Here’s how I did it:


$ cp /public/spo600-gcc-pass-demo.tgz 

$ cp /public/spo600-test-clone.tgz 


I then extracted the files into the GCC source code folder:


$ tar -xvzf ./spo600-gcc-pass-demo.tgz


The tar file had everything I needed to modify GCC. My professor provided details about which files to change, and I updated four of them:


passes.def: Added NEXT_PASS (pass_ctyler);

tree-ctyler.cc: Contained the actual pass code.

tree-pass.h: Added extern gimple_opt_pass *make_pass_ctyler (gcc::context *ctxt);

Makefile.in: Added tree-ctyler.o to the OBJS definition.


After making these changes, I built GCC with these commands:


$ cd gcc1build

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

$ make install


Building GCC was slower than part 1 and took almost 2hrs and 13mins, but it was finally completed successfully.


Testing the Pass

I used the hello.c program to test if my pass was included:

#include <stdio.h> int main() { printf("Hello World\n"); return 0; }

I compiled it with:

$ gcc -fdump-tree-ctyler hello.c -o hello

A dump file with ctyler in the name was created. It proved my pass was active


Challenges I Faced

This project has been really hard and overwhelming. Here are some of the problems I faced:

  1. Function Matching
    Identifying clones was tricky because some functions were similar but had minor differences, like extra comments or slight variations in their logic. My pass couldn’t always distinguish real clones from these variations.

  2. Network Delays on the Server
    Since I was working on the school-provided servers, I occasionally faced network latency issues, especially when running resource-heavy builds. Waiting for jobs to finish felt like an eternity on busy days.

  3. Debugging Dump Files
    The diagnostic dump files were massive and hard to read. Scanning through them to find issues with my pass required patience and a lot of trial and error. I often overlooked subtle issues in GIMPLE representations.


Lessons Learned

I learned so much while working with these gcc builds:

  1. Debugging is a Skill: I learned to rely on diagnostic dumps to track down where my pass was going wrong. This helped me develop a better debugging strategy for large-scale systems.

  2. Optimizing Small Changes Matters: Even tiny improvements, like finding faster ways to compare functions, can make a big difference in performance. This gave me an appreciation for efficiency.

Comments

Popular posts from this blog

Wrapping Up Project : Stage 3