Read some material about GCC internals. First the wikipage on GCC. Then, you could play with the MELT probe (you may want a Linux system to use it).
Then read the GCC manual. And the GCC resource center
Use gcc -v -Wall
to compile, it will show what cc1
is running (and -Wall
is always useful). So try compiling with gcc -v -Wall hello.c -o helloworld.bin
the cc1
program don't sit in your PATH
or in /usr/bin/
but -on my system- in /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1
The command gcc -print-prog-name=cc1
will tell you which cc1
is used by your gcc
. See GCC debugging options for more.
The preprocessing is now inside cc1
.
The gcc
program is just a driver, starting cc1
(which does most of the compiling work), then as
, ld
etc...
The MELT site contains some documentation, and some slides explaining GCC, which you could find interesting. MELT is a domain specific language to extend GCC.
See also the picture on http://starynkevitch.net/Basile/gcc-melt/cc1-internals.svg and the below picture
picture from http://starynkevitch.net/Basile/gcc-melt/gcc-MELT-inside.png, done by me, CC BY SA
The cc1
is producing a .s
assembly file; the as
(started by gcc
) is transforming it into .o
. The ld
linker (started by gcc
) will produce a library or an executable.
PS. I have a Linux system, but things are very similar on MacOSX.
reference on linking
A good book about linking is Levine's Linkers & loaders book.
PS. MELT is obsolete in 2021, but I am working on the Bismon static source code analyzer and on RefPerSys (which generates C++ code).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…