Understanding GCC: Components, Cross‑Compilation, and ARM Toolchains
This article explains the GNU Compiler Collection (GCC) architecture, its core packages (Binutils, gcc‑core, Glibc), demonstrates a simple C compilation workflow, and details cross‑compilation techniques for ARM including arm‑linux‑gcc, arm‑elf‑gcc, and various C libraries such as uClibc and newlib.
1. Overview of GCC
The GNU Compiler Collection (GCC) is a suite of compilers that supports C, C++, Ada, Objective‑C and many other languages. It runs on a wide range of hardware architectures such as x86, ARM, MIPS, PowerPC, and more.
2. GCC Component Structure
Binutils – a set of low‑level development tools (assembler, linker, objcopy, etc.) that operate on object files. Binutils is built separately for each target architecture.
gcc‑core – the core front‑end and optimizer for the C language. Language‑specific front‑ends (C++, Ada, …) are provided by additional packages. gcc‑core depends on Binutils for assembly and linking.
glibc – the GNU C standard library that implements functions such as malloc, printf, file I/O, string handling, etc. It is linked into user programs on Linux systems but is not required by the kernel or bootloader.
3. Simple Compilation Example
Source file test.c:
#include <stdio.h>
int main(int argc, char *argv[]){
printf("Hello Linux!!
");
return 0;
}Compile with: gcc -o test test.c GCC performs four distinct phases:
Preprocessing – expands macros and includes header files.
Compilation – translates the preprocessed source into assembly language (handled by gcc‑core).
Assembly – converts assembly to object code (handled by Binutils).
Linking – combines object files with libraries such as glibc to produce the final executable (handled by Binutils).
The printf call is resolved at link time against glibc; its prototype is declared in the header <stdio.h>.
4. Cross‑Compilation
Cross‑compilation builds binaries on a host architecture (e.g., x86) that will run on a different target architecture (e.g., ARM, PowerPC, MIPS). GCC provides target‑specific toolchain prefixes so that the correct Binutils, gcc‑core and C library are invoked automatically.
Example for an ARM Linux target:
arm-linux-gcc -o hello hello.c5. arm-linux-gcc Toolchain
arm-linux-gccis a GCC front‑end configured for the arm-linux-* triplet. It links against the GNU C library (glibc) and therefore requires:
ARM‑specific Binutils (assembler, linker, etc.)
An ARM‑built gcc‑core
An ARM‑built glibc
This toolchain is intended for Linux‑based ARM systems where the full glibc runtime is available.
6. arm-elf-gcc and Lightweight C Libraries
arm-elf-gcctargets the arm-elf-* triplet, which is typically used for bare‑metal or minimal‑OS environments. Instead of glibc it can be linked with lightweight libraries such as:
uClibc – a small, glibc‑compatible library for embedded Linux.
uC‑libc – an even smaller library originally written for uClinux.
newlib – a portable C library that provides libc and libm for embedded systems without an operating system.
These libraries reduce binary size and remove dependencies on Linux system calls, making them suitable for bootloaders, firmware, or microcontroller applications.
7. Selecting a C Library for ARM Cross‑Compilation
The choice is driven by the GCC configuration options used when building the toolchain:
Targets matching arm-linux-* default to glibc.
Targets matching arm-elf-* can be built with --with-newlib, --with-uclibc, or -Dinhibit_libc to suppress glibc and link against newlib, uClibc, or uC‑libc.
Configuration files in the GCC source tree (e.g., config/arm/t-linux and config/arm/t-arm-elf) illustrate these defaults and the flags that control library selection.
8. Practical Guidance
Use arm-linux-* when building applications that will run on a full Linux distribution on ARM. Glibc provides complete POSIX support and matches the kernel’s ABI.
Use arm-elf-* for bare‑metal firmware, bootloaders, or other environments without a Linux kernel. Selecting newlib, uClibc, or uC‑libc yields smaller executables and removes the need for an OS.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
