About GCC Compilation

Source: Internet
Author: User
Tags gcov

GCC parameters in a detailed


GCC is the abbreviation for GNU Compiler Collection, which contains compilers for many languages, such as C, C + +, objective-c, objective-c++, Java, Fortran, and Ada. But each compiler's name is different, GCC and g++ are GNU C & C + + compilers, respectively
gcc/g++ a total of 4 steps in the process of compiling
1. Preprocessing, generating. i files [invoking preprocessor CPP]
2. Convert the preprocessed file into assembly language and generate the file. s[call compiler Gcc/egcs]
3. There is a compilation into the target code (machine code) to generate. o file [call assembler as]
4. Connect target code, generate executable program [CALL Linker LD]
Introduction to Common GCC parameters
-X language filename
Sets the language used by the file, invalidates the suffix name, and is valid for later multiple. That is the root
It is agreed that the C language suffix name is. c, while the C + + suffix is. C or. cpp, if
You are very personality, decide your C code file suffix name is. Pig Haha, then you need to use this
parameter, which works on the file name behind him unless the next parameter
The use of.
Can I use the parameters that have the following
' C ', ' objective-c ', ' c-header ', ' C + + ', ' cpp-output ',
' Assembler ', and ' assembler-with-cpp '.
It should be understandable to see English.
Example usage:
Gcc-x C Hello.pig
-X None filename
Turn off the previous option, which is to have GCC automatically identify file types based on the filename suffix
Example usage:
Gcc-x c Hello.pig-x None hello2.c
-C
Only activates preprocessing, compilation, and assembly, that is, he only makes the program obj file
Example usage:
Gcc-c hello.c
He will generate the. O obj file
-S
Only pre-processing and compilation are activated, which means compiling the files into assembly code.
Example usage
Gcc-s hello.c
He will generate the assembly code for. S, which you can view with a text editor
-E
Just activate preprocessing, this does not generate files, you need to redirect it to an output file
Surface.
Example usage:
GCC-E hello.c > Pianoapan.txt
GCC-E hello.c | More
Look slowly, a Hello word also wants to work with code that is processed into 800 lines
-O
Set the target name, by default, the GCC compiled file is a.out, it is difficult to listen, if
You and I have the same feeling, get rid of it, haha
Example usage
Gcc-o hello.exe hello.c (Oh, Windows is used to it)
Gcc-o hello.asm-s hello.c
-pipe
Using pipelines instead of temporary files in the compilation, there may be some questions when using non-GNU assembler tools
Problem
Gcc-pipe-o Hello.exe hello.c
-ansi
Turn off the features in GNU C that are incompatible with ANSI C and activate the exclusive features of ANSI C (including the prohibition of a
ASM Inline typeof keywords, as well as preprocessing macros such as Unix,vax,
-STD C99
Indicates that the compiler supports the C99 standard, mainly has the c89,c99,gnu89,gnu99, has the C + + part of c++98, c++0x, gnu++98, gnu++0x
-rdynamic
Notifies the linker to add all compliance to the dynamic symbol table
-lxx
Represents a dynamically loaded libxx.so library
-lxx
Indicates adding the directory xx, so that the compiler can find the library file under XX
-ixx
Indicates adding the directory xx, so that the compiler can look for the header file under XX
Optimization options
-O FILE
Generates the specified output file. Used when generating an executable file.
-o0
No optimization processing is performed.
-O or-o1
Optimize the generated code.
-o2
Further optimization.
-o3
Further optimizations than-O2, including inline functions.
-shared
Generate a shared destination file. Typically used when building a shared library.
-static
Use of shared connections is prohibited.
-W
No warning messages are generated.
-wall
Generates all warning messages. is the specific option that can be used alone
'-wcomment ' This option warns about nested comments.
'-wformat ' This option warns on the incorrect use of the format strings in functions
such as printf and scanf, where the format specifier does not agree with the
Type of the corresponding function argument.
'-wunused ' This option warns about unused variables.
'-wimplicit ' This option warns on any functions that is used without being declared.
'-wreturn-type ' This option warns on functions that is defined without a return
Type but not declared void. It also catches empty return statements in
Functions that is not declared void.

Some other warn compilation options (not included in wall)
'-W ' this was a general option similar to '-wall ' which warns about a selection of
Common programming errors, such as functions which can return without a value
(also known as "falling off the end of the function body"), and comparisons
In general,-W and-wall are used simultaneously
'-wconversion ' This option warns about implicit type conversions that could cause
Unexpected results.
'-wshadow ' This option warns on the redeclaration of a variable name in a scope where
It has already been declared.
'-wcast-qual ' This option warns about pointers that is cast to remove a type qualifier,
such as Const.
'-wwrite-strings ' This option implicitly gives any string constants defined in the program
A const qualifier, causing a compile-time warning if there is an attempt
to overwrite them.
'-wtraditional ' This option warns on parts of the code which would be interpreted
Differently by an Ansi/iso compiler and a "traditional" pre-ansi
Compiler. (5)
These warn options only produce warn and do not stop the compilation process, and the following options can treat warn as an error and stop compiling
'-werror ' changes the default behavior by converting warnings into errors, stopping
The compilation whenever a warning occurs.
Between signed and unsigned values.

In general,-W and-wall are used simultaneously
Options for macro Definitions
There are two ways to define macros: 1: Other original files; 2: Using-dxxx in the GCC command line
When these macros are defined (#define XXX)
When used in the system: #ifdef XXX will be extended to valid code by the preprocessor;

Some macros within the System namespace have been defined in the system, starting with __ (two underline)
Use the command: Cpp-dm/dev/null to see all of the predefined macros

(Note: Some of these macros are GCC system-level macros that do not start with __, and these non-standard macros can be used
GCC's compile option-ansi invalidate it)
(In fact, the use of-dxxx to define XXX, that is, XXX is assigned to a value of 1)
-dmacro
Equivalent to # define macro in C language
  
-umacro
Equivalent to #undef macro in C language
-undef
Cancel the definition of all non-standard macros
It's also a way to use-dxxx=value to define
If you use-dname= "" (empty) to define a macro, the macro is also considered defined, but if it is expanded by value,
is empty;
-dmarco=3
The equivalent of # define macro 3 in the source file
-G
Just the compiler, at compile time, generates debug information.
-M
Choose a different hardware model or configuration---for example, 68010 or 68020, there is no floating-point coprocessor. By specifying options, installing a version of the compiler can compile for all models or configurations. There are many options, not listed here, such as-mshort, that the int type is 16bit
-xlinker option
Pass the option to the linker, and if option has two arguments, we must use the-xlinker two times because it can only pass one string at a time. For example-assert definitions, we need-xlinker-assert-xlinker definitions.
If it's a GNU linker, we can write-xlinker-assert=definitions like this, while other linker might not support this way of writing
Program Performance test Tool-gprof
To use profiling, the program must is compiled and linked with the '-PG '
Profiling option:
$ gcc-wall-c-PG collatz.c
$ GCC-WALL-PG COLLATZ.O
Add option-PG when compiling and linking to use GPROF to test program performance
Then run the compiled program to generate the gprof required files gmon.out (in the current directory)
Then execute:
$ gprof a.out (assuming executable files are generated by default)
Program Overlay Test Tool-Gcov
The GNU coverage Testing tool Gcov analyses the number of times each
Line of a program is executed during a run. This makes it possible to
Find areas of the code which is not used, or which is not exercised
In testing. When combined with profiling information from Gprof the
Information from coverage testing allows efforts
Be concentrated on specific lines of the source code.
Compile and link must use the relevant options before you can use the Gcov tool.
For example:
$ gcc-wall-fprofile-arcs-ftest-coverage COV.C
which
'-ftest-coverage ' adds instructions for counting the number of times
Individual lines is executed,
'-fprofile-arcs ' incorporates instrumentation code for each branch of
The program. Branch Instrumentation Records how frequently
Different paths is taken through ' if ' statements and
Other conditionals.
Run a compiled program that generates files for Gcov to use:
With suffix: '. bb '. BBG ' and '. Da ' in the current directory
And then run
$ Gcov COV.C (note: is a source code file)
This produces a copy of the source file with the callout, with a suffix of. Gcov
In this file, the number of executions of each line of code is marked, and the statement labeled ' ###### ' is
The statement that was not executed.
You can use the command:
grep ' ###### ' *.gcov finds all statements that have not been executed



1. What is the information?

The information is "bit + context". That is, the information is expressed in the calculation as a whole, consisting of multiple ordered bits (bit) and their values (0 or 1).

2. Approximate process of compiling the system

Figure 1 Compiling the system

1. Pre-compilation phase

The source file for the C language is entered, usually *.c. They usually include files with a header file such as. h. This phase mainly deals with #ifdef, #include和 # define commands in the source file. This phase generates an intermediate file *.i, but usually does not have to be generated specifically for this type of file, because it is basically not available, but you can take advantage of the following example command if you do not want to generate such a file:

GCC-E Test.c-o test.i

2. Compile Stage

Input is the intermediate file *.i, compiled after compiling assembly language file *.S. The GCC command corresponding to this phase is as follows:

Gcc-s Test.i-o Test.s

3. Assembly phase

Converts the input assembly file *.s to machine language *.o. The GCC command corresponding to this phase is as follows:

Gcc-c Test.s-o TEST.O

4. Link Stage

The input machine code file *.S (with other machine code files and library files) is compiled into an executable binary code file. This step can be accomplished using the following example command:

GCC Test.o-o Test

Representation and processing of information

3. Size of each type

4. "Size End" (Big-edian and Little-endian)

Endian:the ordering of bytes in a multi-byte number. [3]
End: Used in the architecture of a computer system to describe the order in which each byte is stored in a multi-byte number.

Figure 2 Mapping registers to memory locations

From:

Http://www.cnblogs.com/facingwaller/archive/2013/03/18/2966770.html

Http://blog.sina.com.cn/s/blog_531bb76301013lyq.html

About GCC Compilation

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.