Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the relationship between gcc and arm-linux-gcc and arm-elf-gcc

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

What is the relationship between gcc and arm-linux-gcc and arm-elf-gcc, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Transferred from:

Https://blog.csdn.net/ce123_zhouwei/article/details/8220664

A brief introduction to GCC

The GNU Compiler Collection, usually referred to as GCC, is a set of compilers developed by GNU. Why is it an editor set instead of a compiler? That's because it not only supports C language compilation, but also supports many languages, such as Clover, Ada,Objective C, and so on. In addition, GCC supports hardware platform everywhere. It not only supports X86 processor architecture, but also supports ARM, Motorola 68000, Motorola 8800 Magi 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. Binutils: it is a set of development tools, including connectors, assemblers, and other tools for target files and archives. For an introduction to Binutils, please refer to the brief introduction of Binutils. This package depends on the platforms of different target machines. Because different target machines have different instruction sets, for example, arm is different from x86.

Gcc-core: gu Ming means the core part of GCC, which only contains the compiler and the common part of c, while the support packages for other languages (C++, Ada, etc.) need to be installed separately, which is an important reason why GCC is so powerful. Gcc-core depends on Binutils.

Glibc: contains the main c library, which provides basic routines for allocating memory, searching directories, reading and writing files, string processing, and so on. Kernel and bootloader do not need support for this library.

Give an example of how the above three packages work. There is a c source file test.c source code as follows:

# includeint main (int argc, char * argv []) {printf ("Hello Linux!\ n"); return 0;}

The compilation command is: gcc-o test test.c compiles to generate the test executable file. The gcc compilation process is divided into four steps: preprocessing, compilation, assembly, and linking. Personally, I think preprocessing and compilation are mainly done by gcc-core, while assembly and linking are mainly done by Binutils.

So when do you use glibc? See the printf function in the source code. This function exists in GCC as a library function, which 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 packages, you will naturally understand how GCC works.

III. Cross compilation

Cross-compilation (or cross-build) is a process in which software compiled under one machine structure will be executed in a completely different machine structure. A common example is compiled software on a PC machine for running on a target machine based on ARM, PowerPC, or MIPS.

Fortunately, GCC makes this process much less difficult than it sounds. General tools in GCC are usually executed by invoking commands, such as gcc, on the command line. In the case of cross-compilation, these tools will be named according to the target for which they are compiled.

For example, to compile a simple Hello World program for an ARM machine using a cross-tool chain, you can run a command like this: compile and test the code with the following command: arm-linux-gcc-o hello hello.c.

IV. Arm-linux-gcc

Arm-linux-gcc is a cross-compiling software based on the ARM target machine. The installation package required for arm-linux-gcc is different from that for GCC:

X86 and ARM use different instruction sets, so the required binutils is definitely different; it is mentioned above that gcc-core depends on binutils, and the natural ARM is not the same as the gcc-core package used by x86; glibc, a c library, is ultimately in the compiler in the form of a library, and the glibc library used by natural ARM is also different from x86, and so on.

5. Arm-elf-gcc

Arm-elf-gcc, like arm-linux-gcc, is cross-compiling software based on the ARM target. But they are not the same cross-compiler software, there is a difference between the two, the main difference lies in the use of different C library files.

Arm-linux-gcc uses GNU's Glibc, while arm-elf-gcc generally uses uClibc/uC-libc or newlib, the C library developed specifically for embedded systems by RedHat. It's just that the application fields are different. Glibc is developed for PC. UClibc/uC-libc is a miniaturized C language library compatible with Glibc API, which realizes some functions of Glibc.

VI. UClibc/uC-libc

UClinux has two commonly used libc libraries: uC-libc and uClibc. Although the two names are very similar, in fact, there are differences, here is a brief introduction to the differences between the two. UC-libc is the earliest library developed for uClinux and was migrated to the Linux-8086 C library source code by Jeff Dionne and Kenneth Albanowski to support m68000 in the EKLs project.

UC-libc is a full libc implementation, but some of the api is non-standard and some of the libc standards are not implemented. UC-libc stably supports m68000 ColdFire and ARM without MMU. Its main design goals are "small", "light" and as consistent as possible with standards, and although its API is compatible with many libc, 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 of its API is standard (correct return types, parameters, etc.), it makes up for the libc standard that is not implemented in uC-libc, and has now been ported to a variety of architectures. Generally speaking, it is compatible with glibc as much as possible to make it easy for applications to rewrite with uClibc.

UClibc can be used on standard VM linux and uClinux. For the sake of simplicity of the application, it can even be compiled into a shared library on many platforms that support MMU. Erik Anderson does a lot of work behind uClibc. UClibc supports many series of processors: m68000, Coldfire, arm, MIPs, v850, x86, i960, Sparc, SuperHhaweight, PowerPC and Hitachi 8.

Increasing platform support shows that uClibc can easily adapt to the new architecture. The uClinux distribution provides an environment that allows you to choose to compile using uC-libc or uClibc. For the m68000 and Coldfire platforms, uC-libc is slightly better because it supports shared libraries, which are the libc often used by these cpu. UClibc also works well with almost all platforms.

Newlib is an open source C language library for embedded systems, which is composed of libc and libm libraries. It is lightweight, fast and portable to many CPU structures. Newlib implements a number of complex functions, including string support, floating-point operations, memory allocation (such as malloc) and the Imax O stream function (printf,fprinf (), etc.). Libc provides the implementation of c language library, while libm provides floating-point operation support.

VII. The selection of C language library

When cross-compiling gcc compilers for ARM, different C language libraries are used when you specify different configuration options for gcc. Gcc compilers use Glibc by default, or you can use uClibc/uC-libc (basically compatible with Glibc API). When using-- with-newlib, the gcc compiler does not use Glibc. When there is no cross-compilation of Glibc, you can use-- with-newlib to disable connections to Glibc and compile the bootstrap gcc compiler.

From the t-linux and t-arm-elf in config/arm under the gcc source directory, we can see that different-- target also affects gcc connecting to C language libraries. T-linux (--target=arm-linux) defaults to Glibc,-arm-elf (--target=arm-elf) and uses-Dinhibit_libc to disable connecting to Glibc. Then we can use other C language libraries such as newlib to compile the GCC toolchain.

Although the GCC toolchain is equipped with different C language libraries, because 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 C language library, such as different system calls, different function set implementation, different ABI/ startup code and different system characteristics and so on.

There is no absolute standard for the use of arm-linux-* and arm-elf-*. Excluding 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 are more coordinated when following the description below:

Arm-linux-* is targeted at ARM machines running linux, which relies on the specified C language library Glibc, and because it also uses Glibc's linux, arm-linux-* compiles more harmoniously on ARM machines running linux.

Arm-elf-* is an independent compilation system, which does not depend on the specified C language library Glibc, and can use other C language libraries such as newlib without operating system support. When it uses some lightweight C language libraries designed for embedded systems, it compiles bare metal programs (without programs such as linux and other large operating systems), such as monitoring programs, bootloader, etc., which can make the system programs more compact and faster.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report