Analysis on the Relationship between GCC, arm-Linux-GCC, and arm-elf-gcc

Source: Internet
Author: User

Analysis on the Relationship between GCC, arm-Linux-GCC, and arm-elf-gcc

Embedded Development Exchange Group 280352802, welcome to join!

1. Introduction to GCC

The GNU Compiler Collection, usually GCC for short, is a set of compilers developed by GNU. Why is it an editor set rather than a compiler? This is because it not only supports C language compilation, but also supports many languages such as C ++, Ada, and Objective C. In addition, GCC's support for the hardware platform can be ubiquitous. It not only supports the x86 processor architecture, but also supports arm, Motorola 68000, Motorola 8800, atmelavr, MIPS and other processor architectures.

Ii. Composition of GCC

The internal structure of GCC is mainly composed of binutils, GCC-core, glibc, and other software packages.

  1. Binutils: it is a group of development tools, including connectors, compilers, and other tools used for target files and archives. For more information about binutils, see binutils. This software package depends on platforms of different target machines. Because the instruction sets of different target machines are different, for example, arm and x86 are different.
  2. Gcc-core: Gu Ming refers to the core part of GCC. This part only contains the C compiler and public part, while for other languages (C ++, Ada, etc) the support package needs 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, and string processing. Kernel and bootloader do not need the support of this library.

The following example describes how the preceding three packages work. There is a C source file test. c Source Code as follows:

#include<stdio.h>int main(int argc, char *argv[]){printf("Hello Linux!!\n");return 0;}

Compile the command gcc-O test. C to generate the test executable file. The GCC compilation process consists of four steps: preprocessing, compilation, assembly, and link. In my opinion, preprocessing and compilation are mainly completed by GCC-core, and compilation and linking are mainly completed by binutils. So when will glibc be used? The printf function in the source code does not exist. This function exists as a library function in GCC. This library function is declared in the glibc library and in the stdio. h header file.
In general, if you really understand the role of the above three software packages, you will naturally understand how GCC works.

Iii. Cross-Compilation

Cross-compilation (or cross-creation) is a process in which the software compiled under one machine structure is executed under another completely different machine structure. A common example is to compile software on a PC for a target machine running on arm, PowerPC, or MIPS. Fortunately, GCC makes the process much less difficult than it sounds. Generally, tools in GCC are executed by calling commands (such as GCC) on the command line. When cross-compilation is used, these tools will be named based on the Compilation goal. For example, to compile a simple hello World Program for an arm machine using the cross tool chain, you can run the following command: Compile and test the code using the following command: arm-Linux-gcc-O hello. c.

Iv. Arm-Linux-gcc

Arm-Linux-GCC is a cross-compiling software based on the arm target machine. Arm-Linux-GCC and GCC have different installation packages, but only have different names. Why?

X86 and arm use different instruction sets, so the binutils needed must be different. As mentioned above, GCC-core depends on binutils, naturally, the GCC-core packages used by arm and x86 are different. a c library of glibc exists in the compiler as a library, the glibc library used by natural arm is also different from x86, and so on.

V. Arm-elf-gcc

Like arm-elf-GCC and arm-Linux-GCC, arm-elf-GCC is also a cross-compilation software based on ARM target machines. However, they are not the same cross-compiling software. The two are different. The main difference is that they use different C-library files. Arm-Linux-GCC uses GNU glibc, while arm-elf-GCC generally uses uclibc/UC-libc or the C library newlib specially developed for Embedded Systems Using RedHat. Glibc is developed for PC, and uclibc/UC-libc is a small C language library compatible with glibc APIs, implementing some glibc functions.

6. uclibc/UC-libc

UClinux has two frequently used libc libraries: UC-libc and uclibc. Although the two names are very similar, there are actually differences. Next we will briefly introduce the differences between the two. UC-libc is the first library developed for uClinux and is supported by Jeff Dionne and kenth albanowski to port m68000 on Linux-8086 C library source code in the ekls project. UC-libc is a complete libc implementation, but some 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" and "light", and try to be consistent with the standard, although its API is compatible with many libc, but it does not seem to be as consistent with all standards as it expects.

Uclibc is developed from UC-libc to solve this problem. All its APIs are standard (correct return types, parameters, and so on). It makes up for the libc standard that is not implemented in UC-libc and has now been transplanted to multiple architectures. Generally, it is compatible with glibc as much as possible to make it easier for applications to rewrite with uclibc. Uclibc can be used in standard VM Linux and uClinux. To simplify the application, it can even be compiled into a shared library on many platforms that support MMU. Erik Anderson has done a lot of work behind uclibc. Uclibc supports many series of processors: m68000, ColdFire, arm, MIPS, v850, x86, i960, iSCSI, superh, Alpha, PowerPC, and Hitachi 8. The increasing platform support shows that uclibc can easily adapt to new architectures. The uClinux release provides an environment for you to choose to use UC-libc or uclibc for compilation. For m68000 and ColdFire platforms, it is better to choose UC-libc because it supports shared libraries, which are frequently used by these CPUs. Uclibc 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 features lightweight, fast, and can be transplanted to many CPU Structures. Newlib implements many complex functions, including String Support, floating point operations, memory allocation (such as malloc) and I/O flow functions (printf, fprinf ). Among them, libc provides the implementation of the C language library, while libm provides floating point operation support.

VII. C language library selection

When the GCC compiler is compiled for ARM, different configuration options are specified for GCC, And the C language library is different. By default, the GCC compiler uses glibc, you can also use uclibc/UC-libc (basically compatible with the glibc API). When you use -- With-newlib, the GCC compiler does not use glibc. When glibc is not cross-compiled, you can use -- With-newlib to disable glibc connection and compile the bootstrap GCC compiler. From the T-Linux and T-arm-elf in the config/ARM directory under the GCC source directory, we can see that different -- targets also affect GCC 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 disable glibc connection, in this case, we can use newlib and other C language libraries to compile the GCC tool chain.

Although the GCC tool chain is configured with different C language libraries, these C language libraries can be used to support GCC, and there is no major difference in the processing of core data. Therefore, the differences between ARM-Linux-* and arm-elf-* are mainly manifested in the implementation of the C language library, such as the implementation of different system calls and different function sets, different Abi/startup codes and different system features are slightly different.

There is no absolute standard for the use of arm-Linux-* and arm-elf-* To eliminate implementation differences between different libraries. 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 are more coordinated when following the descriptions below:

  • Arm-Linux-* For LINUX-running arm machines, it depends on the specified C language library glibc, because glibc Linux is also used, the compilation of arm-Linux-* on the arm machine running Linux is more harmonious.
  • Arm-elf-* is an independent compilation system. It does not rely on the specified C language library glibc. It can use other C language libraries such as newlib and does not require support from the operating system, when using some lightweight C language libraries designed for embedded systems, it compiles bare metal programs (without programs for large operating systems such as Linux), such as monitoring programs, bootloader and so on can make the system program more compact and fast.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.