Project Stage 2 (Part 2): Set Up GCC for My Clone-Pruning Pass
A Journey Into GCC
When I started this project, I knew it was going to be a challenge. The GCC compiler is a massive and complex system, and diving into its internals felt daunting. My task was to build GCC from source, integrate a custom pass to analyze function clones, and test everything on the SPO600 AArch64 server.
Setting Up the Environment
1. Cloning the Source Code The first step was to clone the GCC source code into my home directory. Thankfully, the repository was straightforward to access:
git clone git://gcc.gnu.org/git/gcc.git ~/gcc-src
Once the clone was complete, I checked for the configure
script in ~/gcc-src
, which confirmed that the source was ready for building.
2. Preparing the Build I created separate directories to keep everything organized: one for building GCC and another for installing it locally:
mkdir ~/gcc-build ~/gcc-install
3. Adding the Demo Pass
To save time, I copied and extracted the demo files provided in /public/spo600-gcc-pass-demo.tgz
into the GCC source directory:
cp /public/spo600-gcc-pass-demo.tgz ~/gcc-src/
cd ~/gcc-src
tar -xvf spo600-gcc-pass-demo.tgz
These files added a basic pass to the GCC pipeline as a starting point, saving me from building one completely from scratch.
4. Configuring and Building GCC Configuring GCC was straightforward. I ran:
cd ~/gcc-build
../gcc-src/configure --disable-bootstrap --enable-languages=c,c++ --prefix=$HOME/gcc-install
This configured GCC to build only the C and C++ frontends and install locally in ~/gcc-install
.
The actual build process took quite a while:
make -j$(nproc)
It took just over an hour on the server, but using tmux
saved me from having to restart if my connection dropped.
5. Installing GCC Once the build completed, I installed GCC:
make install
The new GCC was installed in ~/gcc-install
, and I verified it worked:
~/gcc-install/bin/gcc --version
Challenges
1. Connection Interruptions
One of the most frustrating parts of this stage was losing my connection to the server during the build process. I had to restart the build twice before realizing I could use tmux
to keep the process running in the background.
2. Slow Build Times Although the server was reasonably fast, building GCC still took over an hour. This was manageable but taught me the importance of rebuilding only the parts that change after making modifications.
Reflections
This stage was a great introduction to GCC’s structure and build process. By the end of it, I felt more confident navigating GCC’s source code and modifying it. Seeing the custom pass integrated into the build gave me a real sense of accomplishment.
Next, I would dive into implementing the clone-pruning logic, which I knew would be the real challenge.
Nhận xét
Đăng nhận xét