gcc scalar evolution
MacJournal at hand

gcc phases

dancefish posted @ 2010年8月31日 22:49 in 书摘 , 1920 阅读

入门,入门。 转贴,转贴。

 

This post is part of a series about GCC internals and specifically about howto create a new language front-end for GCC. For a list of related posts, please check this page.

If I would ask many people what the executable gcc is doing, most of the people would answer, “Well, it’s a compiler, though … it’s compiling the source file into a target file”. But that is NOT correct. The executable gcc is not a compiler although the abbreviation means GNU C compiler. gcc represents what is generally called a compiler driver or more generic a compilation driver, in the following just called driver. If you now think, this guy is completely insane, please add the -v option to one of your gcc commands and and check what gcc is really doing.

While a compiler really is only responsible for transforming the source file into (possibly optimized) target machine code, the driver is the high-level organizer in the overall compilation process creating a object/shared/executable file from one or more source files. Thereby, the driver divides the compilation process into several phases which greatly depend on the capabilities of the used programs. gcc in newer versions (for example 4.4.0 and newer) uses the following phases assuming that an executable is created from a single source file (gcc source.c -o exec):

1. compiler (cc1)
2. assembler (as; from GNU binutils)
3. collect2 (collect2; part of GCC)
   3.1. linker (ld; from GNU binutils)

Just a note: in earlier versions of gcc, the driver added a separate pre-processing phase before the compiler phase, but in the recent versions the pre-processor is omitted, because the compiler (cc1) incorporates the pre-processor, at least when using the default options. By using the -no-integrated-cpp option, you instruct the driver to split the compiler phase into 2 distinct phases: pre-processing and compiler.

Each of the phases above produces intermediate or temporary files (assuming that the -pipe option is not specified) as output files which then serve as input files for the subsequent phase, in detail:

  • pre-processor (if separate phase)
    • input: *.c
    • output: *.i
  • compiler
    • input: *.c & *.i files
    • output: *.s
  • assembler
    • input: *.s
    • output: *.o
  • collect2/linker
    • input: *.o
    • output: self-defined pattern, e.g. *.exe

Based on the file extension, the driver knows which phase to start with when processing the file. Though, if a *.s file is given as input file along with a *.o and *.c file to produce an executable in a single gcc command, gcc would run the *.s file through the assembler phase, the *.c file through the compiler and assembler phase and the resulting three *.o files finally through the collect2/linker phase. By the way, if an input file extension matches none of the defined extensions, the file is taken is collect2/linker input!

The default behavior of gcc is to try to produce an executable file from the input files. But, gcc could be instructed to stop after any of the above phases by using specific driver options:

-E : stop after pre-processing, produce a *.i file
-S : stop after compiler, produce a *.s file
-c : stop after assembler, produce a *.o file
none : stop after collect2/linker

Hint: If you want to run through all the phases with a single gcc command but neverthess keep the intermediate files, use the -save-temps option.

You may ask, why all this is important for a new language front-end in gcc? Right! Because your new language might require different or additional phases than the described ones and then you should know where to start with to bring your new language front-end driver to execute your specific phases. For this purpose, GCC (capital letters are used to distinguish the complete compiler project from the C-specific driver) is designed in a modular way to allow the front-ends to “register” new phases, but the addition/modification of the phases will be discussed in a later post. However, for the already interested reader, please take a look at the file gcc-x.y.z/gcc/gcc.c and one of the the files of an already existing front-end, for example of C++ ingcc-x.y.z/gcc/cp/lang-specs.h.

Avatar_small
borian 说:
2018年9月03日 08:20

The blog look good and I have been hearing about them for a long time. I think writing more on them using proper https://ukessaysreviews.com/descriptive-essay/ will be a good thing to count their work in the field.

Avatar_small
dissertation writing 说:
2018年10月13日 04:06

Nice post! I think that it is really important for you to feel positive. I would like to see more focus as well as organisation in my life, Thanks again!

Avatar_small
Cheap tig welder 说:
2020年4月23日 03:32

Believe it or not, it is the kind of detail I've long been attempting to find. It matches my needs a whole lot. Thank you for composing this details.

Avatar_small
Jason Matt 说:
2020年4月28日 04:21

First You got a fantastic blog site. I will want even more comparable topics. I see you obtained actually extremely beneficial subjects, I will be constantly examining your blog thanks. change wifi name and password

Avatar_small
Ric Thomas 说:
2020年5月01日 08:48

I can not wait to dig kickoff and deep utilizing sources that I got from you. Your liveliness is refreshing. kbc winner

Avatar_small
Ric Thomas 说:
2020年5月02日 05:08

Thank you for this astounding message,
I rejoice I observed this web site on yahoo.  jio lottery winner,kbc lottery

Avatar_small
Ric Thomas 说:
2020年5月02日 20:00

Your work is absolutely appreciated round the clock as well as the world.

It is a handy and also incredibly thorough blog. jio lottery winner

Avatar_small
Ric Thomas 说:
2020年5月02日 20:51

Hi there,
I found your website through Google while looking for an associated subject,
your internet site turned up, it looks fantastic.
I have bookmarked it in my google bookmarks. kbc head office number

Avatar_small
Ric Thomas 说:
2020年5月07日 16:45

You actually make it look so very easy with your performance but
I find this matter to be really something which I think I would certainly never comprehend.
It appears extremely broad and also complicated for me. I'm expecting your next post,
I'll try to master it!  soft dog food for bad teeth

Avatar_small
Ric Thomas 说:
2020年5月07日 16:52

Really great article,
I appreciated reading your article, very great share,
I want to twit this to my followers. Many thanks!  assignment代写

Avatar_small
Ric Thomas 说:
2020年5月08日 14:05

Wonderful task below on. I check out a great deal of post, but I never ever heard a topic such as this. I Love this subject you made regarding the blogger's pail list. Extremely resourceful. kbc head office number

Avatar_small
Ric Thomas 说:
2020年5月08日 14:36

Amazing blog post. This isn't typically a hideous blog post and offers complete info. I such as to evaluate this blog post considering I met such a great deal of new genuine parts concerning it really. Thanks, loads. I bookmark your internet log in light of I discovered dumbfounding details on your weblog, Thanks for sharing. kbc winner

Avatar_small
Ric Thomas 说:
2020年5月08日 14:57

Exceptional message.

Thanks to this blog site my expedition has finished. kbc lottery winner

Avatar_small
Ric Thomas 说:
2020年5月08日 15:49

Due to the fact that of the offer it, this is a remarkable article I have actually seen. It is truly what I anticipated to see trust in the future you will continue in sharing such a mind-blowing blog post. kbc lottery

Avatar_small
Ric Thomas 说:
2020年5月09日 15:39

It is really a well-researched web content as well as outstanding phrasing. I got so taken part in this material that I couldn't wait to read. I am amazed with your work as well as ability. Thanks. assignment代写

Avatar_small
Ric Thomas 说:
2020年5月11日 20:06

Thanks for sharing wonderful information with us. I like your message and all you show to us depends on date as well as quite interesting, I would love to bookmark the page so I can come here once more to read you, as you have actually done a remarkable task. kbc

Avatar_small
Ric Thomas 说:
2020年5月11日 20:14

Outstanding article. Many thanks to this blog site my expedition has ended. kbc live

Avatar_small
Ric Thomas 说:
2020年5月11日 20:22

No question this is an outstanding blog post I got a great deal of understanding after checking out best of luck. The motif of the blog site is outstanding there is almost every little thing to check out, Brilliant blog post. kbc lottery winner

Avatar_small
Ric Thomas 说:
2020年5月11日 20:33

Wonderful blog! I'm intending to start my very own site soon yet I'm a little lost on every little thing. Many thanks! kbc game

Avatar_small
Andrew Strauch 说:
2020年5月24日 05:58

Due to the fact that of the deal it, this is an amazing message I have actually seen. It is actually what I expected to see count on the future you will continue in sharing such a wonderful message. kbc lottery winner

Avatar_small
Andrew Strauch 说:
2020年5月24日 06:01

First You got a fantastic blog.
I will certainly have an interest in even more similar topics.
I see you got truly extremely helpful subjects,
i will be constantly examining your blog site many thanks. kbc official website

Avatar_small
Andrew Strauch 说:
2020年5月24日 08:27

These specific papers fantastic, and My partner as well as I delight in each of the carry out that you have positioned right into this. I'm sure that you will certainly be making a really useful location. I have actually been additionally pleased. Excellent do! kbc head office number

Avatar_small
Andrew Strauch 说:
2020年5月24日 08:33

I got so involved in this product that I couldn't wait to read.
Thanks. kbc head office number

Avatar_small
Andrew Strauch 说:
2020年5月24日 08:37

I can not wait to dig kickoff as well as deep making use of resources that I obtained from you.
Your vitality is refreshing. kbc head office number

Avatar_small
Andrew Strauch 说:
2020年5月25日 14:07

You obtained a terrific blog site. I will be interested in even more comparable topics.
I see you got truly very useful topics,
i will certainly be always inspecting your blog thanks.  best email marketing software

Avatar_small
Andrew Strauch 说:
2020年5月28日 11:33

I got so engaged in this product that I couldn't wait to review. Many thanks. jio lottery 2020

Avatar_small
Andrew Strauch 说:
2020年5月28日 11:37

I can not wait to dig deep and also kickoff utilizing resources that I received from you.
Your exuberance is refreshing. kbc winner 2020


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter