gcc compiler software introduction
GCC’s external interface looks like a standard Unix compiler. The user types the gcc program name and some command parameters at the command line to determine the individual language compiler used for each input file, and to use the combined language compiler suitable for this hardware platform for the output program code, and optionally Execute the connector to make an executable program.
Each language compiler is an independent program that processes the input source code and outputs the combined language code. All language compilers have a common intermediary architecture: a front end that parses the source code conforming to the language and generates an abstract syntax tree, and a back end that translates this syntax tree into GCC's Register Transformation Language (RTL). Compilers and static code analysis techniques (such as FORTIFY_SOURCE, a compiler that attempts to find buffer overflows) are applied to the code at this stage. Finally, combinatorial language program code suitable for this hardware architecture was generated using an algorithm invented by Jack Davidson and Chris Fraser.
Almost all GCC is written in C, except for the Ada front-end, which is mostly written in Ada.
Front-end interface
The function of the front-end is to generate a syntax tree that can be processed by the back-end. This parser is a handwritten recursive parser.
Until 2004, the syntax tree structure of the program could not be decoupled from the processor architecture to be produced. The rules of syntax trees are sometimes different in different language front ends, and some front ends provide their own special syntax tree rules.
In 2005, two new types of syntax trees that were decoupled from the language were included in GCC. They are called GENERIC and GIMPLE. Syntax parsing becomes generating language-dependent temporary syntax trees and then converting them into GENERIC. Later, "gimplifier" technology was used to reduce the complex structure of GENERIC and become a simpler static form (Static Single Assignment form, SSA) based GIMPLE form. This form is a universal language that is decoupled from language and processor architecture and is applicable to most modern programming languages.
Mediation interface
Generally, compiler authors will place the syntax tree on the front end, but in fact this step does not depend on the type of language, and does not require the use of a syntax parser. Therefore the GCC authors group this step into what is commonly known as the mediation phase. This category includes dead code elimination, repeated operation elimination, and global numerical recoding.
backend interface
The behavior of the GCC backend varies due to different preprocessor macros and architecture-specific features, such as different character sizes, calling methods, and endianness. The first half of the back-end interface uses this information to determine the generation form of its RTL. Therefore, although GCC's RTL is theoretically not affected by the processor, its abstract instructions have been converted into the format of the target architecture at this stage.
GCC's techniques vary greatly depending on its release version, but they all include standard algorithms. RTL has fewer available situations and lacks higher-level information. Therefore, in comparison, the added GIMPLE syntax tree form, It seems less important.
After a re-read step, the backend uses the information obtained when describing the instruction set of the target processor to replace the abstract register with the real register of the processor. This stage is very complex because it must pay attention to the specifications and technical details of the processor instruction set of all GCC portable platforms.
The final steps of the backend are quite formulaic, just converting the assembly language code obtained in the previous stage into the corresponding machine code through simple subroutines.
GCC Compiler (Linux) Installation Tutorial
1. Get the source code
The source code can be obtained from ftp://mirrors.kernel.org/gnu/gcc/gcc-4.9.1/gcc-4.9.1.tar.gz
2. Preparation
Download and unzip the GCC compiler software package on this page of Huajun Software Park
Download the compilation preparation file and execute ./contrib/download_prerequisites. This command will download the dependency packages needed to compile gcc.
3. Create a compilation directory in the same level directory of gcc--4.9.1 (e.g. gcc-build-4.9.1)
4. Configuration
cd gcc-build-4.9.1
../gcc-4.9.1/configure --prefix=/usr/local/gcc-4.9.1 --enable-threads=posix --enable-stage1-checking=release --enable-stage1-languages=c, c++ --disable-multilib
5. Compile
make
6. Installation
Make install
7. Modify environment variables
export PATH=/usr/local/gcc-4.9.1/bin/:$PATH
8. Check gcc version
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.9.1/libexec/gcc/x86_64-unknown-linux-gnu/4.9.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.9.1/configure --prefix=/usr/local/gcc-4.9.1 --enable-threads=posix --enable-stage1-checking=release --enable-stage1-languages =c,c++ --disable-multilib
Thread model: posix
gcc version 4.9.1 (GCC)
How to use gcc compiler
When using the GCC compiler, we must give a series of necessary calling parameters and file names. There are approximately more than 100 calling parameters for the GCC compiler. Here we only introduce the most basic and commonly used parameters. Please refer to GCC Manual for details.
The most basic usage of GCC is: gcc [options] [filenames]
Where options are the parameters required by the compiler, and filenames gives the relevant file names.
-c, only compiles, does not link into an executable file. The compiler only generates an object file with an .o suffix from the input .c and other source code files. It is usually used to compile subprogram files that do not contain the main program.
-o output_filename, make sure the name of the output file is output_filename, and this name cannot have the same name as the source file. If this option is not given, gcc will give the default executable file a.out.
-g, generates the necessary symbol information for the symbolic debugging tool (GNU's gdb). If we want to debug the source code, we must add this option.
-O, optimize the compilation and linking of the program. With this option, the entire source code will be optimized during the compilation and linking process. The execution efficiency of the generated executable file can be improved, but the compilation and linking speed will be correspondingly reduced. The ground is slower.
-O2, better optimized compilation and linking than -O, of course the entire compilation and linking process will be slower.
-Idirname, adds the directory pointed by dirname to the program header file directory list. It is a parameter used in the pre-compilation process. The header file in the C program contains two situations:
A)#include
B)#include “myinc.h”
Among them, Class A uses angle brackets (< >), and Class B uses double quotes (" "). For category A, the preprocessor cpp searches for the corresponding file in the system's default include file directory (such as /usr/include), while for category B, the preprocessor searches for the corresponding file in the folder of the target file.
-v Detailed process of execution when gcc is executed, version number of gcc and its related programs
Original gcc manual English explanation of this option
Print (on standard error output) the commands executed to run the stages of compilation. Also print the version number of the compiler driver program and of the preprocessor and the compiler proper.
By adding this option when compiling the program, you can see the search path used by gcc when searching for header files/library files!
gcc compiler basic rules
Some of the conventions followed by gcc:
Files with .c suffix, C language source code files;
Files with the .a suffix are archive files composed of target files;
Files with the suffix .C, .cc or .cxx are C++ source code files and must be preprocessed;
The file with .h suffix is the header file included in the program;
Files with the .i suffix are C source code files and should not be preprocessed;
Files with the .ii suffix are C++ source code files and should not be preprocessed;
Files with the .m suffix are Objective-C source code files;
Files with the .mm suffix are Objective-C++ source code files;
Files with .o suffix are compiled target files;
Files with the .s suffix are assembly language source code files;
Files with the .S suffix are precompiled assembly language source code files.
gcc compiler update log
1: Brand new interface, refreshing, simple and efficient;
2: The performance is getting better and better.
Huajun editor recommends:
GCC For Linux is a good software. If you are interested, please download it and use it. I believe you will like it.Maven,OpenCart,Java2 Runtime Environment,Eclipse IDE for Java EE Developers For Linux(64-bit),Free PascalIt is also a good software and is recommended for students to download and use.
it works
it works
it works