Lädt...

🔧 GCC Building - Lab 4


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

In this lab, we will be utilizing make/ makefiles to get ourselves comfortable with compiling files for large software.

The GCC (GNU Compiler Collection) will be used for building as it is the standard compiler for Unix-like operating systems. The GCC compiler refers specifically to the compiler that compiles C programs.

Please note that I will be executing instructions in x86-001 and aarch64-002 servers, as they are the working environments of this SPO600 course.

I will be following the lab instructions step-by-step, which will be easy to follow.

📌 0. Login to Servers

First, we will login to both x86-001 and aarch64-002 servers. Please note that I have set up my account and passphrase before starting this lab.

📌 1. Obtain the Source Code

We will be cloning the source code from the official Git repository. Please refer to gcc.gnu.org.

On my servers, I will clone it to a new directory ~/git/gcc. This makes sure that the gcc source code is stored in a separate directory. The whole process could take around 3-6 minutes.

git clone git://gcc.gnu.org/git/gcc.git ~/git/gcc

📌 2. Configure Build

We will have to configure the build before installing it.

👉 Make a new build directory:

It is recommended to create a new separate directory for your build. From this build directory, we will invoke the configure script, which is in the root of the gcc source repository.

mkdir ~/gcc-build-001
cd ~/gcc-build-001

👉 Run the configure script

We will run the configure script using the --prefix option. This option makes sure to set our custom installation directory: $HOME/gcc-test-001.'

~/git/gcc/configure --prefix=$HOME/gcc-test-001

After running the script, you will see that there are new files in the ~/gcc-build-001, including a Makefile.

[user-name@aarch64-002 gcc-build-001]$ ls
config.log  config.status  Makefile

📌 3. Build GCC Compiler

Now that we have confirmed there is a Makefile in the directory, we will run the build command.

👉 screen Utility

However, it is important to note that the build can take from 20 minutes to several hours. We will use the screen utility before running any command to make sure the operation is not forced to start over even if we disconnect from our system or there is a break in the internet connection.

screen -RaD

After this, we will run our build command below. Ctrl A + D will be pressed to disconnect while our build is running so we can safely exit.

We can check on progress by running the screen command again.

👉 Record Build Time

The built-in time command can be used to record the time taken. We will also use the tee command to redirect our stdin and stdout to a log file (build.log) and the screen.

With all of these in mind, the final command to build becomes:

time make -j 24 |& tee build.log

📌 3. Install GCC Compiler

Next, we will install the compiler using this command.

time make install |& tee install.log

At the end of the process, you will see this text, which records the time taken for the process to finish. In my case, this is what it shows to me:

For aarch64:
Code

For x86:
Code

Validating My GCC Build

Now that we have successfully built and installed our gcc compiler. We will check 3 things:

✅ 1. It is different from the system's C compiler

Check the system's GCC version

which gcc
gcc --version

Check your newly installed GCC version

$HOME/gcc-test-001/bin/gcc --version

Results
For aarch64:
Code

For x86:
Code

As you can see, both the paths and *versions * are different!

✅ 2. It is the current development version

From the command above you can see that the version number is higher than the Red Hat version. This is true as we got our compiler from the git repo.

✅ 3. It can successfully build a C program

  • In your root directory, create a hello.c file with this code inside.
#include <stdio.h>
int main() {
    printf("Hello, world!\n");
    return 0;
}
  • Compile the program using your new GCC
$HOME/gcc-test-001/bin/gcc hello.c -o hello
  • Run the compiled program
./hello

Results
For aarch64:
Code

For x86:
Code

📌 4. Update Timestamp on passes.cc

Locate the file passes.c which is located in the gcc subdirectory of your source tree.

cd ~/git/gcc/gcc

Update the timestamp by running this command

touch passes.cc

📌 5. Rebuild

We will now go to our build directory to rebuild the compiler after changing passes.c.

Return to build directory

cd ~/gcc-build-001

Rebuild using make

time make |& tee rebuild.log

Results
For aarch64:
Code

For x86:
Code

We can see that the build time is significantly less than the initial full build since only passes.cc has a changed timestamp.

📌 6. Perform a Null Rebuild

Without making any additional changes, run make again. This is called a null rebuild.

time make |& tee null_rebuild.log

Results
For aarch64:
Code

For x86:
Code

This null rebuild completed almost immediately, as make determined no source files require rebuilding.

Conclusion

After completing this lab, I have gotten useful insights about building and installing a complex codebase like GCC. Obtaining the latest development source and configuring a build environment is actually very useful in helping me understand how GCC compilers work. Not only that, I learnt the process of incremental builds where subsequent rebuilds do not take as much time as the initial build, making make very efficient.

Thank you for reading and see you next time! 😄

...

📰 Ausführen beliebiger Kommandos in gcc-toolset-13-gcc (Red Hat)


📈 27.38 Punkte
📰 IT Security Nachrichten

📰 Ausführen beliebiger Kommandos in gcc-toolset-13-gcc (Red Hat)


📈 27.38 Punkte
📰 IT Security Nachrichten

📰 Security: Ausführen beliebiger Kommandos in gcc-toolset-13-gcc (Red Hat)


📈 27.38 Punkte
🐧 Unix Server

🔧 Unveiling the Battle for Government Cloud Dominance: GCC vs. GCC High


📈 27.38 Punkte
🔧 Programmierung

📰 Pros and Cons to a “Hybrid Approach” to Microsoft 365 Commercial and GCC/GCC High


📈 27.38 Punkte
📰 IT Security Nachrichten

📰 The “Feature Factor” in Moving to Microsoft 365 GCC or GCC High


📈 27.38 Punkte
📰 IT Security Nachrichten

📰 Should we be in Microsoft 365 GCC, GCC High, or Commercial?


📈 27.38 Punkte
📰 IT Security Nachrichten

🕵️ CVE-2020-35537 | GNU gcc g++ gcc/ipa-cp.c ipcp_store_vr_results denial of service


📈 27.38 Punkte
🕵️ Sicherheitslücken

🐧 GCC x86 Performance Hints: Optimize Options - Using the GNU Compiler Collection (GCC)


📈 27.38 Punkte
🐧 Linux Tipps

🐧 [[email protected]] Good news, bad news on the repository conversion (esr)


📈 27.38 Punkte
🐧 Linux Tipps

📰 GCC (GNU Compiler Collection) 7.1 Released to Celebrate 30 Years Since GCC 1.0


📈 27.38 Punkte
📰 IT Security Nachrichten

📰 Ausführen beliebiger Kommandos in gcc-toolset-14-gcc (Red Hat)


📈 27.38 Punkte
📰 IT Security Nachrichten

🔧 Answer: How to detect if building with address sanitizer when building with gcc 4.8?


📈 24.23 Punkte
🔧 Programmierung

🔧 Building GCC from Source on AArch64


📈 18.96 Punkte
🔧 Programmierung

🐧 Even more fun with building and benchmarking Firefox with GCC and Clang


📈 18.96 Punkte
🐧 Linux Tipps

🔧 SPO-GCC - Final post


📈 13.69 Punkte
🔧 Programmierung

🐧 How to Compile a C++ Program with GCC


📈 13.69 Punkte
🐧 Linux Tipps

🐧 Made a wrapper for gcc with Bash


📈 13.69 Punkte
🐧 Linux Tipps

🐧 How to install GCC on Ubuntu


📈 13.69 Punkte
🐧 Linux Tipps

📰 Wegen GPLv3: FreeBSD wirft GCC raus


📈 13.69 Punkte
📰 IT Nachrichten

📰 News: GCC: Umstieg auf Git weiter ungewiss


📈 13.69 Punkte
🐧 Unix Server

🐧 Minimum GCC Version Likely to Jump from 3.2 to 4.8


📈 13.69 Punkte
🐧 Linux Tipps

📰 Compiler: GCC 7.1 kennt die Sprachfeatures von C++17


📈 13.69 Punkte
📰 IT Nachrichten

🕵️ CVE-2000-1219 | GNU gcc 3.3.3 Integer Overflow -ftrapv integer coercion (ID 540517)


📈 13.69 Punkte
🕵️ Sicherheitslücken

📰 USN-5770-1: GCC vulnerability


📈 13.69 Punkte
🐧 Unix Server

🐧 GCC 12.1 Released


📈 13.69 Punkte
🐧 Linux Tipps

📰 Compiler: GCC 10.1 bringt Code-Analyse und Radeon GPU-Offload


📈 13.69 Punkte
📰 IT Nachrichten

🕵️ GNU gcc up to 6.3 i386.c ix86_expand_builtin privilege escalation


📈 13.69 Punkte
🕵️ Sicherheitslücken

🐧 Is the GCC assembly output enough for a project to be considered open source?


📈 13.69 Punkte
🐧 Linux Tipps

📰 openSUSE Tumbleweed Linux OS Patched Against WPA2 KRACK Bug, GCC 6 Now Removed


📈 13.69 Punkte
📰 IT Security Nachrichten

📰 SUSE Linux Enterprise 12 Now Includes GCC 6.2, GNU Binutils 2.26.1 &amp; GDB 7.11.1


📈 13.69 Punkte
📰 IT Security

🔧 GCC: Automatic Function Multi-Versioning Pt.1


📈 13.69 Punkte
🔧 Programmierung

📰 [Unstable Update] 2023-05-03 - Python 3.11, GCC 13


📈 13.69 Punkte
🐧 Unix Server

matomo