1. Introduction to GCC
The GNU Compiler Collection, usually referred to as GCC, is a compiler collection developed by GNU. Why is it an editor collection instead of a compiler?
That's because it not only supports C language compilation, but also supports C++, Ada, Objective C and many other languages. In addition, GCC's support for hardware platforms is ubiquitous. It not only supports X86 processor architecture, but also supports ARM, Motorola 68000, Motorola 8800, AtmelAVR, MIPS and other processor architectures.
2. The composition structure of GCC
The internal structure of GCC is mainly composed of Binutils, gcc-core, Glibc and other software packages.
1. Binutils: It is a set of development tools, including connectors, assemblers and other tools for object files and archives. For an introduction to Binutils, please refer to the brief introduction to Binutils. This package depends on the platform of different target machines. Because the instruction sets of different target machines are different, for example, arm is different from x86.
2. gcc-core: Gu Mingzhi means the core part of GCC, which only includes the C compiler and common parts, while support packages for other languages (C++, Ada, etc.) need to be installed separately, which is also an important reason why GCC is so powerful. gcc-core depends on Binutils.
3. Glibc: Contains the main C library, which provides basic routines for allocating memory, searching directories, reading and writing files, string processing, etc. The kernel and bootloader do not require support from this library.
Let's take an example to describe how the above three packages work. There is a C source file test.c with the following source code:
1. #include 2. int main(int argc, char *argv[]) 3. { 4. printf("Hello Linux!!n"); 5. return 0; 6. } The compilation command is: gcc -o test test.c to compile and generate the test executable file. The gcc compilation process is divided into four steps: preprocessing, compilation, assembly, and linking. Preprocessing and compilation are mainly completed by gcc-core, and assembly and linking are mainly completed by Binutils. So when is glibc used? You can see that there is no printf function in the source code. This function exists in the form of a library function in GCC. This library function is in the glibc library and is declared in the stdio.h header file. In general, if you truly understand the functions of the above three software packages, you will naturally understand how GCC works. 3. Cross-compilation Cross-compiling (or cross-building) is the process of compiling software for one machine architecture to execute on an entirely different machine architecture. A common example is compiling software on a PC for an ARM-, PowerPC-, or MIPS-based target. Fortunately, GCC makes this process much less difficult than it sounds. The general tools in GCC are usually executed by calling a command (such as gcc) on the command line. In the case of cross-compilation, these tools will be named according to the target it compiles. For example, to compile a simple Hello World program for an ARM machine using a cross toolchain, you can run the command shown below: Compile and test this code using the following command: arm-linux-gcc -o hello hello.c. 4. arm-linux-gcc arm-linux-gcc is a cross-compilation software based on ARM target machine. The installation packages required by arm-linux-gcc and GCC are different, but only the names are different. Why is this? The instruction sets used by x86 and ARM are different, so the required binutils must be different; as mentioned above, gcc-core depends on binutils, so naturally the gcc-core packages used by ARM and x86 are also different; glibc is a C library, which ultimately exists in the form of a library in the compiler, so naturally the glibc library used by ARM is also different from that of x86, and so on. 5. arm-elf-gcc arm-elf-gcc is the same as arm-linux-gcc, which is also a cross-compilation software based on ARM target machine. However, they are not the same cross-compilation software, and there are differences between them. The main difference between the two is that they use different C library files. arm-linux-gcc uses GNU's Glibc, while arm-elf-gcc generally uses uClibc/uC-libc or uses the C library newlib developed by RedHat specifically for embedded systems. It's just that the application fields are different. Glibc is developed for PC, and uClibc/uC-libc is a small C language library compatible with Glibc API, which implements some functions of Glibc. 6. uClibc/uC-libc uClinux has two commonly used libc libraries: uC-libc and uClibc. Although the names are very similar, there are actually differences. The following is a brief introduction to the differences between the two. uC-libc is the earliest library developed for uClinux. It was ported by Jeff Dionne and Kenneth Albanowski on the Linux-8086 C library source code to support m68000 in the EKLs project. uC-libc is a complete libc implementation, but some of its APIs are non-standard, and some libc standards are not implemented. uC-libc stably supports m68000, ColdFire and ARM without MMU. Its main design goals are "small", "light", and try to be consistent with standards. Although its API is compatible with many libcs, it does not seem to be consistent with all standards as it expects. uClibc was developed from uC-libc to solve this problem. All its APIs are standard (correct return type, parameters, etc.), which makes up for the libc standards that are not implemented in uC-libc, and has now been ported to multiple architectures. Generally speaking, it tries to be compatible with glibc to make it easy to rewrite applications with uClibc. uClibc can be used on standard VM linux and uClinux. For the simplicity of the application, it can even be compiled into a shared library on many platforms that support MMU. Erik Anderson did a lot of the work behind uClibc. uClibc supports many series of processors: m68000, Coldfire, ARM, MIPS, v850, x86, i960, Sparc, SuperH, Alpha, PowerPC and Hitachi 8. The increasing platform support shows that uClibc can easily adapt to new architectures. The uClinux distribution provides an environment that allows you to choose to compile with uC-libc or uClibc. For m68000 and Coldfire platforms, uC-libc is a slightly better choice because it supports shared libraries, which are the libcs commonly used by these CPUs. uClibc also works well with almost all platforms. newlib is an open source C language library for embedded systems. It consists of two libraries, libc and libm. It is lightweight, fast, and portable to many CPU structures. Newlib implements many complex functions, including string support, floating point operations, memory allocation (such as malloc) and I/O stream functions (printf, fprinf(), etc.). Among them, libc provides the implementation of the C language library, and libm provides floating point operation support. 7. Selection of C language library When cross-compiling the gcc compiler for ARM, when different configuration options are specified for gcc, the C language library used is different. The gcc compiler uses Glibc by default, and can also use uClibc/uC-libc (basically compatible with Glibc API). When --with-newlib is used, the gcc compiler does not use Glibc. When Glibc is not cross-compiled, you can use --with-newlib to disable linking with Glibc and compile the bootstrap gcc compiler. From t-linux and t-arm-elf in config/arm under the gcc source directory, we can see that different --target also affects gcc's connection to the C language library. t-linux (--target=arm-linux) uses Glibc by default, and -arm-elf (--target=arm-elf) uses -Dinhibit_libc to prohibit connecting to Glibc. At this time, we can use other C language libraries such as newlib to compile the GCC tool chain. Although the GCC toolchain is configured with different C language libraries, since these C language libraries can be used to support GCC, there is no big difference in their processing of core data. Therefore, the difference between arm-linux-* and arm-elf-* is mainly reflected in the implementation of the C language library, such as different system calls, different function set implementations, different ABI/startup codes, and different system characteristics. There is no absolute standard for the use of arm-linux-* and arm-elf-*. Excluding the differences in different library implementations, gcc can compile any system. Both arm-linux-* and arm-elf-* can be used to compile bare metal programs and operating systems, but the system programs appear more coordinated when following the following description: arm-linux-* is targeted at ARM machines running Linux, and it depends on the specified C language library Glibc. Because Linux also uses Glibc, arm-linux-* is more harmonious when compiled on ARM machines running Linux. arm-elf-* is an independent compilation system that does not depend on the specified C language library Glibc. It can use other C language libraries such as newlib and does not require operating system support. When it uses some lightweight C language libraries designed for embedded systems, it compiles bare metal programs (programs without large operating systems such as Linux), such as monitoring programs and bootloaders, which can make system programs smaller and faster.
Previous article:JZ2440 Development Notes (1)——arm-linux-gcc environment construction
Next article:Application of 4G communication module on ARM platform
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Bluetooth Direction Finding Technology Overview
- How to automatically fan out BGA in Kicad
- Crazy Shell AI open source drone flight control firmware burning
- Problems affecting IC card reading distance
- Three considerations for selecting Ethernet for harsh industrial environments
- dB, why is it so important for RF engineers?
- [New Year's Flavor Competition] + Show off your New Year's Eve dinner and see where the Coke is. If you find it, you win a prize!
- 【RPi PICO】Calculate Mandelbrot Improved Version
- How to convert PWM signal into analog signal
- 【AT32WB415 Review】Serial Communication and MP3 Module Playback Control