The composition and difference of gcc, arm-Linux-gcc and arm-elf-gcc

Publisher:EtherealHeartLatest update time:2020-02-22 Source: eefocusKeywords:GCC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:GCC Reference address:The composition and difference of gcc, arm-Linux-gcc and arm-elf-gcc

Previous article:JZ2440 Development Notes (1)——arm-linux-gcc environment construction
Next article:Application of 4G communication module on ARM platform

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号