C various compilers (GCC clang)

Source: Internet
Author: User
Tags call back

Most of the time, there are some similar to the compiler, such as GNU,GCC,CLANG,LLVM and other nouns, are not very clear what it is to do, understand these things, for many of the configuration of Xcode needs to be modified to be handy, so it is necessary to understand their direct relationship and differences.
1 GUN"GNU, named from GNU's not Unix abbreviation, a UNIX -like operating system , driven by the GNU program , aims to create a free software environment that is fully compatible with UNIX . " because the UNIX system was commercial software at that time, it was charged, and a part of the source code was not open, so in 1983, Richard Stallman proposed the GNU program , hoping to develop a complete open-source operating system to replace UNIX, The planned operating system, named GNU. Therefore, the purpose of GNU's appearance is to replace the UNIX system. But the operating system includes a lot of software, in addition to the operating system kernel, there are editors, compilers,shell and so on some software to support. in 1989,other parts of the GNU project, such as editors, compilers, shells, and so on, have been completed, and the core of the operating system is missing. In 1990, the Free Software Foundation began to formally develop Hurdas an operating system in the GNU project.
Note: Linux is not part of the GNU program. Linux only uses many GNU program software (including GCC compilers, text compilers, etc.).
In 1991, Linux appeared, and all GNU projects, software running in user space, could be used on Linux. Many developers are turning to linux,linux to become the common GNU program software operating platform. Richard Stallman that the Linux operating system used many GNU program software, should be renamed as Gnu/linux, but did not get the consensus of the Linux community, the formation of Gnu/linux naming controversy . In the 1992, Linux was formally born with a combination of other GNU software and a completely free operating system. Many programmers are involved in the development and modification of Linux and often use Linux as a platform to develop GNU program software. The operating system is often referred to as "Gnu/linux" or simply Linux. But Linux itself is not part of the GNU program, and the GNU program's own kernel Hurd is still under development, but until 2013, no stable version was released.
The GNU project has been a major influence on software development for more than more than 10 years, creating countless important tools such as robust compilers , powerful text editors, and even a full-featured operating system. The project came from the idea of a 1984 MIT programmer, Richard Stallman, who wanted to create a free, Unix-like operating environment. Since then, many programmers have come together to develop a free, high-quality, easy-to-understand software.
The GNU program uses parts of the software that were already freely available, such as the Tex typesetting system and the X Window window System. But the GNU program has also developed a large number of other free software that has been ported to other operating system platforms, such as Microsoft Windows, BSD family, Solaris, and Mac OS. GNU software is also installed on many UNIX systems because the quality of GNU software is better than that of previous Unix software.as a result, many of the GNU program's software is currently widely used in all operating systems (Unix,mac,linux,windows,bsd ...), and the best known is GCC .
Summary:The GNU program was intended to develop a free system to replace UNIX, but since the development of the kernel Hurd has not been very good, the system has not yet developed a stable version, but the GNU program developed some other free software, such as the GCC compiler, but very well, has been widely used in porting to the major operating systems so far. Note one thing:The article said free software, do not confuse with free software, freedom is that you can use freely, of course, the premise is to obtain the source code to free use. For example, if you use the GCC program software in an application, you will have to sell your own app for the amount of money you own. Free software is not necessarily open source.

2. GCC
The GCCgnu Compiler Collection, GNU compiler set programming language compiler developed and LGPL free software released by license   Operating system standard compiler. GCC (especially the C language compiler) is also often considered a de facto standard for cross-platform compilers.

GCC was formerly the GNU C language compiler (GNU C Compiler) because it could only handle the C language. GCC expands quickly to become able to handle C + +. It also became available to process Fortran, Pascal, Objective-c, Java, Ada, and go with other languages.

originally developed with C, later, because of the rise of LLVM and Clang, GCC quickly converted the development language to C + +. Many C enthusiasts in the case of C + + smattering subjective recognition C + + performance will be lost to C, but Taylor gave a different opinion, and show that C + + performance is not lost to C, but also to design a better, easier to maintain the program "

Since GCC has become the official compiler for the GNU system (including the Gnu/linux family), it has also become the main compiler for compiling and creating other operating systems, including the BSD family, Mac OS X, NeXTSTEP and BeOS.

GCC is typically the compiler's first choice for cross-platform software. Unlike compilers that are generally confined to specific systems and operating environments, GCC uses the same front-end handler on all platforms to produce the same intermediary code, so that this code is compiled with GCC on every other platform and has a great chance of getting the correct output program.
Summary:The Cocoa Framework before Mac was compiled with GCC, so both iOS and Mac OS are the GCC compilers that are used by default (now Clang and LLVM, as described below)Android's system layer because it is a Linux kernel, is naturally also GCC compiled, but the Android app because it is running on the Dalvik virtual machine , so it is not using GCC. most of the Windows apps use the VS Series compiler, after all, the Windows Home compiler, not much of GCC.
3.Clang

Let's take a look at the official note on the Wiki encyclopedia: Http://zh.wikipedia.org/wiki/Clang "clang  is a c C++, Objective-c front. It uses the underlying virtual machine its goal is to provide a replacement for the GNU Compiler Suite (GCC). clang projects include clang front end and clang static analyzers.

This software project, launched by Apple in 2005, is the front end of the LLVM compiler toolset (front-end), which is designed to output the abstract syntax tree (abstract Syntax tree, AST) for the code and compiles the code into LLVM Bitcode. Then the backend (back-end) uses LLVM to compile the platform-related machine language. Clang supports C, C + +, Objective c.

Clang itself has excellent performance, and its generated AST consumes only about 20% of the memory of GCC. FreeBSD 10 CLANG/LLVM as the default compiler.The test proves that clang compiles the OBJECTIVE-C code at 3 times times the speed of GCC, and is able to give accurate advice on the compiler errors that occur to the user .

Summary:GCC currently as a cross-platform compiler for its compatibility is the strongest, compatible with the strongest certainly at the expense of a certain performance-based, Apple in order to improve performance, so specifically for the MAC system developed a dedicated compiler clang and Llvm,clang for the compiler front section, The LLVM is used for the back end.
3.LLVM
LLVM, It is a compiler -based infrastructure, written in C + + . It is for any programming language written in the program, the use of virtual technology , to create a compile time , link period , Operation period and "Idle period" optimization.
after Xcode4, Apple turned Xcode's default compiler into LLVM, why?

LLVM history

Apple has been using GCC as the official compiler, including the next in the middle and later. GCC has been doing a good job as a compiler standard for the open source world, but Apple has made higher demands on the build tools.

On the one hand, Apple has added many features to the Objective-c language (and even later to c), but GCC developers do not buy Apple's accounts-not to be implemented, so they are then split into two separate branches, This also causes Apple's compiler version to lag far behind the official version of GCC. On the other hand, GCC's code coupling is too high, not independent, and the later version, the lower the quality of the code, but many of the features Apple wants to do (such as better IDE support) require a modular way to invoke GCC, but GCC has not been able to do so, fundamentally limiting the development of LLVM-GCC. So, this does not make Apple have been looking for an efficient, modular, negotiated and more relaxed open source alternative, so Apple came to the compiler, the high-level Chris Lattner, LLVM was created.
Clang history

Apple's goal of absorbing Chris Lattner is much bigger and cumbersome than improving the GCC code optimization--GCC system, while Apple's heavily used objective-c has a low priority in GCC. In addition, GCC, as a purely compiled system, works poorly with the IDE. In addition to licensing requirements, Apple cannot continue to improve the quality of GCC code using LLVM. As a result, Apple decided to write the front-end Clang of C, C + + and Objective-c languages from scratch, completely replacing GCC.

As the name says, Clang only supports the three C-family languages of c,c++ and Objective-c. Starting in 2007, the C compiler was first completed, and because Objective-c is relatively simple, it is just a simple extension of C, and in many cases can even be rewritten as a C language to the OBJECTIVE-C runtime function call, so in 2009, is fully available for production environments. The support of C + + is also being carried out enthusiastically.

More detailed reasons: The Xcode compiler describes: http://www.cnblogs.com/ydhliphonedev/archive/2012/08/29/2661726.html
Summary:since the GCC compiler is slowly failing to meet Apple's needs, Apple's default compiler is already LLVM after it developed clang and LLVM to completely replace GCC,XCODE4. Clang as the compiler front-end, LLVM as the compiler backend. to view the default compiler in Xcode6.0:
4. Compiler-related knowledge
Question: Apple takes clang as the compiler front end, LLVM as the compiler backend, so what exactly is the front and back of the compiler?let's go back to a common-sense question, what is a compiler? Simply put, the compiler can be seen as a language translator. Just like translating Chinese into English, compilers can translate high-level languages into machine languages that computers can perform. In this way, GCC can be considered to be a high-level translation officer with a multi-lingual proficiency. The simplest GCC usage directives are as follows:
gcc hello.c-o Hello
GCC accepts hello.c as input and finally produces the target executable code hello. This simple process actually goes through a lot of steps, as shown in the following: Although we completed the compilation with just one command, the GCC command called CPP,GCC itself, gas, and LD in turn to complete the compilation process, finally generating the final executable hello.

Students who have learned the principles of compiling this course should be familiar with the following diagram, which is the classic compilation process.

The following is a GCC compiler example, gcc as a classic compiler, it is natural to follow this textbook process (actual GCC processing more complex, but essentially the same). Let us simplify the above image, with the intermediate code as the demarcation, the previous lexical analysis, syntax analysis, semantic analysis we call it front-end processing, the following optimization and target code generation we call back-end processing.

Imagine if you could write a single front end for different high-level languages, and then write a separate backend for different processor architectures.

GCC is basically the same, but do not misunderstand, and not a unified GCC execution program can handle so many front end and back end, each language compiler is a separate program (such as C compiler is gcc,c++ compiler is g++), The different backend should also correspond to different executable programs. You can download a separate copy of the GCC source code to generate the compiler you need with different configure.

Furthermore, the implementation of the compiler is much more complex, the main function of the front end is to produce a syntax tree for the backend processing, and the syntax tree structure is actually difficult to decouple from the processor architecture, these are the problems that need to be solved in the compiler application.

What is the real reason for GCC's strength? Is it because it supports a multitude of front-end and back-end? These are just a representation. GCC is a really free compiler, and we can always get the code to modify it to achieve the functionality we need. What if your hardware platform adds some instructions and the normal compiler doesn't produce these instructions? Add these instructions to the GCC backend. If you think C language is not very handy, want to add some features to it? Modify the front-end of GCC. With GCC, we have the freedom and the ability to quickly realize what we think is the foundation behind GCC's power.

In more detail about gcc:http://blog.csdn.net/itianyi/article/details/43054199

C various compilers (GCC clang)

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.