This is the mail archive of the
mailing list for the GCC project.
Re: The further question.
- To: meggie dot yang at intel dot com
- Subject: Re: The further question.
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Mon, 29 Nov 1999 10:34:23 +0100
- CC: gcc at gcc dot gnu dot org
- References: <A577A8CE35DBD211AC3F00A0C9E011540FFFDB@BJSMSX90>
> From greeting.s, i can see the complier will call mcount. But in the
> function mcount , it doesn't call monstartup( profiling
> start),_mcleanup(profiling stop).I notice declaration of these two
> functions in gmon.h. But i don't know how they are linked together
> when running gcc -pg.
This is "magic", in the sense that it works in a platform-specific
way. If you search for monstartup in the gcc/config/*/* files, you'll
find a number of different ways to do that:
- on win32/cygwin, a call to monstartup is implicitly compiled into
main(), via SUBTARGET_PROLOGUE
- on Solaris, mcount is replaced and invokes monstartup if it was
not already started
On other systems (like Linux), a special startup file (gcrt1.o) is
provided by the system (csu/gmon-start.c in the glibc sources), which
calls monstartup. This file, in turn, is linked into the executable via
the gcc spec file:
(from config/svr3.h). Use "gcc -v" on your platform to see how the
compiler proper is invoked.
> I tried to read gcc.c. But it's difficult for me to read. Can you
> give me some suggestions about how to read gcc.c and other source
Not really. This is C code, so the usual ways to understand it apply.
If you don't want to miss a single step, it is best to debug the
compiler and see what it does.
> I'd like to know what does gcc do when add pg parameter?
As indiciated above, it controls a number of linker options via the
specfile mechanism. In addition, the variable profile_flag is set
inside the language back-ends (cc1, cc1plus,...), see toplev.c. With
that information, you can search for profile_flag in the rest of the