Mastering GCC: Core Components, Cross‑Compilation and ARM Toolchains
This article explains the GCC compiler suite, its internal packages (Binutils, gcc‑core, Glibc), demonstrates a simple C build, and details cross‑compilation techniques for ARM, including differences between arm‑linux‑gcc, arm‑elf‑gcc, and various C libraries such as uClibc and newlib.
GCC Overview
The GNU Compiler Collection (GCC) is a set of compilers developed by the GNU project that supports many languages (C, C++, Ada, Objective‑C, etc.) and a wide range of hardware architectures such as x86, ARM, MIPS, and more.
GCC Internal Structure
GCC consists mainly of three packages:
Binutils : a collection of development tools including the assembler, linker, and other utilities for handling object files and archives. It varies per target architecture.
gcc‑core : the core C compiler and common front‑end; support for other languages (C++, Ada, …) is provided by additional packages. It depends on Binutils.
glibc : the GNU C library that implements standard functions such as memory allocation, file I/O, and string handling. It is required by user‑space programs but not by the kernel or bootloader.
Simple Compilation Example
Given the following source file test.c:
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello Linux!!
");
return 0;
}Compiling with gcc -o test test.c produces an executable. The GCC compilation flow consists of four stages: preprocessing, compilation, assembly, and linking. Preprocessing and compilation are handled mainly by gcc‑core, while assembly and linking are performed by Binutils. The standard library function printf is provided by glibc via stdio.h.
Cross‑Compilation
Cross‑compilation builds software on one machine architecture to run on a different target architecture (e.g., building ARM binaries on an x86 host). GCC simplifies this process; the tools are invoked with the appropriate target prefix.
Example command for an ARM “Hello World” program:
arm-linux-gcc -o hello hello.carm‑linux‑gcc vs. arm‑elf‑gcc
arm‑linux‑gcc targets Linux‑based ARM systems and links against the GNU C library (glibc). It requires Binutils and gcc‑core built for the ARM architecture.
arm‑elf‑gcc also targets ARM but is intended for bare‑metal or non‑Linux environments. It typically uses lightweight C libraries such as uClibc, uC‑libc, or newlib instead of glibc.
uClibc / uC‑libc
Both are small C libraries designed for embedded systems. uC‑libc was the original library for uClinux, supporting architectures like m68k, ColdFire, and ARM without an MMU. uClibc evolved from uC‑libc, providing a more complete, glibc‑compatible API and broader architecture support.
newlib
newlib is an open‑source C library for embedded systems, consisting of libc and libm. It offers lightweight implementations of standard functions, including I/O and floating‑point operations.
Choosing a C Library for ARM Toolchains
When configuring GCC for ARM cross‑compilation, the default C library is glibc. Using --with-newlib disables glibc and links against newlib. The target triplet influences the choice: arm‑linux (or arm‑linux‑gnueabihf) selects glibc, while arm‑elf disables glibc, allowing newlib, uClibc, or uC‑libc.
Although the underlying libraries differ, they all provide the necessary interfaces for GCC‑generated code. The main practical differences between arm‑linux‑* and arm‑elf‑* are the C library implementation, system call conventions, and suitability for Linux versus bare‑metal environments.
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.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
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.
