Toolchains
The GNU toolchain consists of these components:
- Binutils: Assembler, linker, (ld) and other tools
- GCC: Compilers for C, C++, Objective-C, Objective-C++, Java, Fortran, Ada, and Go. They all use a common back-end which produces assembler code for the GNU assembler (GAS)
- C library: Standardized API based on POSIX (interface to the operating system kernel from applications)
GNU prefix tuple
GNU uses a prefix to identify the various combinations of it’s tools:
- CPU: The CPU architecture
arm,mips,x86_64, …- may add postfix for endianes
mipsel(little-endian MIPS),armeb(big-endian ARM), …
- Vendor: The provider of the toolchain
buildroot,poky,unknown, …- Sometimes it is left out
- Kernel:
linux, …
- Operating system (user space):
gnu,uclibcgnu, …- ABI can be appended (ARM):
gnueabi,gnueabihf,uclibcgnueabi,uclibcgnueabihf, …
Print the tuple: gcc -dumpmachine
C library
There are several C libraries
glibc: standard GNU C library. It is big and not very configurable, but it is the most complete implementationuClibc: initially for uClinux. Allows you to fine-tune its features, smaller than glibcmusl libc: small, new C library designed for embedded systems
gcc as Cross Compiler
gcc version: arm-cortex_a8-linux-gnueabi-gcc --version
How gcc was configured, use: arm-cortex_a8-linux-gnueabi-gcc -v
The output contains (among other information):
--with-sysroot=/home/luki/x-tools/arm-cortex_a8-linux-gnueabihf/arm-cortex_a8-linux-gnueabihf/sysroot: the default sysroot directory--enable-languages=c,c++: C and C++ languages are enabled--with-arch=armv7-a: code is generated using the ARM v7a instruction set--with-cpu=cortex-a8and--with-tune=cortex-a8: code is tweaked for Cortex A8--with-float=hard: Generate opcodes for the floating point unit and uses the VFP registers for parameters--enable-threads=posix: Enable POSIX threads
Print architecture-specific options: arm-cortex_a8-linux-gnueabihf-gcc --target-help
The sysroot, library, and header files
Sysroot directory contains
- libraries
- header files
- other configuration files.
Print default sysroot by using -print-sysroot
Sysroot can be changed
Subdirectories:
lib: shared objects for the C library and the dynamic linker/loader (ld-linux)usr/lib: the static library archives for the C library and other librariesusr/include: headers for all the librariesusr/bin: utility programs that run on the target (ldd, …)/usr/share: Used for localization and internationalizationsbin:ldconfigutility (and others)
Binutils and other tools
addr2line: Convert program addresses into filenames and numbers (decoding addresses from a crash report)ar: create static libraries (archives)as: assemblerc++filt: demangle C++ symbolscpp: C preprocessorelfedit: update ELF headersgcov: coverage toolgdb: debuggergprof: profilingld: linkernm: list symbols from object filesobjcopy: copy and translate object filesobjdump: display information from object filesranlib: creates or modifies an index in a static library (make the linking faster)readelf: display information in ELF object filessize: list section sizesstrings: display printable characters in filesstrip: strip the debug symbols
Looking at the components of the C library
libc: the main C librarylibm: math functionslibpthread: POSIX threadslibrt: real-time extensions for POSIX
libc is always linked, the others have to be explicitly linked.
Shared libraries
Compile with -fPIC and link with -shared option
See also: ldconfig