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:
I compiled it with:
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:
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.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.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.
Comments
Post a Comment