Project Stage 2
This blog is about my journey into learning GCC. It’s been a mix of downloading the source code, fixing directory problems, and trying to add a custom pass. Honestly, I’ve learned more about compilers in the past few days than I ever thought I would. Let me share my experience with you.
Step 1: Setting Up the Project
First, I created a project directory to keep things organized. I wanted separate folders for the GCC source code, the build files, and the final installation. Here’s what my structure looked like:
mkdir -p ~/gcc-project/{src,build,install}
Downloading the Source Code
Next, I cloned the GCC repository. This took some time because the GCC codebase is huge:
git clone git://gcc.gnu.org/git/gcc.git ~/gcc-project/src
When the cloning finished, I was ready to configure and build GCC. Or so I thought.
Step 2: It showed No Such File
When I tried to configure GCC, I hit my first big roadblock. Running ../src/configure
from the build
directory didn’t work:
-bash: ../src/configure: No such file or directory
After some digging, I realized that the configure
script wasn’t in the src
directory. Instead, the source code was nested one level deeper in a gcc-src
folder. So, I moved everything up:
mv ~/gcc-project/src/gcc-src/* ~/gcc-project/src/
mv ~/gcc-project/src/gcc-src/.* ~/gcc-project/src/ 2>/dev/null
rmdir ~/gcc-project/src/gcc-src
This fixed the issue, and now the configure
script was in the right place. Finally, I could move on.
Step 3: Configuring and Building GCC
Configuration
From the build
directory, I ran:
../src/configure --disable-bootstrap --enable-languages=c,c++ --prefix=$HOME/gcc-project/install
--disable-bootstrap
: This skips the multi-stage build process, making things faster.--enable-languages=c,c++
: I only needed C and C++ support for this project.--prefix
: This tells GCC where to install the final binaries.
The configuration went smoothly, and I was ready to build.
Building
I started the build with:
make -j$(nproc)
The -j$(nproc)
flag lets GCC use all available CPU cores. Even then, it took a long time. (Lesson learned: patience is key when working with compilers.)
Installing
After the build finished, I installed GCC:
make install
install
directory. I verified the installation by checking the GCC version:Now came the fun (and challenging) part: adding a custom pass to GCC.
Creating the Pass
I created a new file called tree-ctyler.cc in the src
directory. This file contained the logic for my pass. Here’s what it does:
- Iterates over basic blocks and GIMPLE statements (an intermediate representation in GCC).
- Prints diagnostic information to a dump file.
Here’s the core of the pass:
Integrating the Pass
I updated three files to integrate my pass:
- Makefile.in: Added tree-ctyler.o to the list of object files.
- passes.def: Registered the pass:
NEXT_PASS(pass_ctyler) - tree-pass.h: Declared the pass:
extern gimple_opt_pass *make_pass_ctyler(gcc::context *ctxt);
Comments
Post a Comment