This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: The further question.

> 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
- 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
> file.

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]