Http://www.lingcc.com/2011/06/27/11679/
Recently I have studied a GCC option. It is interesting to select it and learn it. CompilerProgramAs the most widely used tool in the compiler, GCC is an important tool for developers. It is fully reflected in considerate design and function support.
Table of contents
- 1-dumpmachine
- 2-XC
- 3-DM
- 4-print-file-name = include
- 5-isystem dir
- 6-nostdinc/-nostdinc ++
- 7-WP/-Wa/-wl
- 8-El/-EB
- 9-dmacro/-umacro
- 10-G num
- 11-msym32/-mnosym32
- 12
-Fdelete-Null-pointer-Checks/-fno-delete-Null-pointer-Checks
- 13-mcheck-Zero-Division/-MnO-check-Zero-Division
- 14-mabicils/-MnO-abicils
- 15-mbranch-likely/-MnO-branch-likely
- 16-fstack-Protector
- 17-fstrict-Overflow
- 18-fconserve-Stack
- 19 references
1 -Dumpmachine
The GCC information is provided. On Debian amd64 of erlv, the result is as follows.
For more information about the meaning of these fields in GCC, see this blog:
$ Gcc-dumpmachinex86_64-linux-gnu
2 -XC
In fact,-XC is equivalent to "-x C.
- X is used to specify the language of the input program. If this option is used, GCC no longer determines the language type based on the file suffix.
3 -DM
Without actual preprocessing, only list all # define macros, which are related to the architecture and GNU, or from the contained header files.
#The program output is too long and will not be listed here$Gcc-E-DM hello. c
In addition, there are some combined options of-dchars:
- -DD: similar to-DM, but only contains the macros defined in the header file. It does not output the default macros defined in the Preprocessor. In addition, the source programCodeIt also pre-processes the output.
- -DN: similar to-dd, but only outputs The Name Of The Defined Macro, without outputting the macro value.
- -DI: The # include header file is provided, and the pre-processing result is expected.
- -Du: similar to-dd, but only outputs the macros that need to be expanded in the source code or their definitions will be tested.
4 -Print-file-name = include
Print the GCC default path to search for the include header file
$ Gcc-print-file-name = include/usr/lib/x86_64-linux-gnu/GCC/x86_64-linux-gnu/4.6.1/include
5 -Isystem dir
Use the Dir path as one of the header file search paths. Search Order:-I specified folder => isystem specified folder = standard system header folder.
6 -Nostdinc/-nostdinc ++
Do not search for the standard system header file directory. Only search for the path specified by-I.
7 -WP/-Wa/-wl
These three parameters are used to specify the parameters passed to the preprocessing start, assembler, and linker respectively.
- -WP, option is equivalent to-xpreprocessor Option
- -Wa, option is equivalent to-xassembler Option
- -Wl, option is equivalent to-xlinker Option
8 -El/-EB
Compile the Code for the System at the lower end or greater end. The default value is a small tail end.
9 -Dmacro/-umacro
Define macro/Revoke macro definition
10 -G num
Divides the global and static objects into smaller data bytes than num into small data at the BSS end, rather than abnormal data.
The default value of num is 8.
When MIPS obtains an address from a symbol, it needs to retrieve the 16-bit high first, then the 16-bit low, and splice it to get the final address. Therefore, it needs two access operations.
This method slows down the program when a large amount of static and global data is used in the program.
Therefore, the method of using the GP register for optimization is to use the method of relative offset with the GP register for memory access, so as to reduce the number of memory access times.
The key issue is that the compiler and assembler need to determine which variables can be accessed using the GP register at the time of compilation.
The common practice is to allow variables smaller than a certain value to be accessed through the GP register.
If num is 0, this optimization is disabled.
11 -Msym32/-mnosym32
Regardless of the Abi, assume/do not assume that all symbols are 32-bit values.
This option works with-mabi = 64
And-MnO-abicall are very useful, because it can be assumed that both 32-bit data can generate a smaller and faster symbol address.
12
-Fdelete-Null-pointer-Checks/-fno-delete-Null-pointer-Checks
Delete-Null-pointer-checks is an optimization method that identifies and deletes all NULL pointer detection operations through global data flow analysis.
The compiler assumes that the program is terminated if the NULL pointer is unreferenced. However, in some environments, this conclusion is not necessarily true, and O2, O3, and OS enable this optimization.
Therefore, GCC adds the option-fno-delete-Null-pointer-checks.
13
-Mcheck-Zero-Division/-MnO-check-Zero-Division
If the integer is not 0
14
-Mabicils/-MnO-abicils
Dynamic Object code in the form of svr4 is generated/not generated by default.
15
-Mbranch-likely/-MnO-branch-likely
Use/use the branch likely command, regardless of whether the specified architecture is supported by default.
By default, GCC supports branch.
The system structure of the likely command generates the branch likely command.
This type of instruction is introduced to introduce a very likely jump instruction, so that the compiler can make full use of the delay slot in MIPS.
16 -Fstack-Protector
Generates additional detection code for possible buffer overflow.
17 -Fstrict-Overflow
Allow the compiler to use strict signed overflow rules.
18 -Fconserve-Stack
Minimize stack usage.
19 Reference
- Http://gcc.gnu.org/ml/gcc-help/2006-10/msg00191.html
- See MIPS run Linux, 2ed, by Dominic Sweetman, page 273
- GCC man pages