Re: further..

Ralf Baechle (ralf@julia.de)
Wed, 31 Jul 1996 17:20:50 +0200 (MET DST)


Hi,

> I've only tried the above on sparc, but I believe
> __builtin_return_address() is available on intel boxes.

__builtin_return_address() is a pretty dangerous thing. On many
architectures is returns useless data with -fomit-frame-pointer (Intel and
68k also, I think), hasn't been implemented at all (among those GCC <= 2.7.2
for MIPS) or fails silently for certain cases and/or arguments (among those
GCC >= 2.8.0 for MIPS). In short check your object code if you don't
exactly know what __builtin_return_address() will really do.

So far I made good experiences using the hook provided by GCC's -p option.
GCC will emit in the prologue of every function a call to mcount or _mcount
(depends of your architecture/OS/object file format). GCC passes the
called function's address to mcount (beware - on some CPUs the calling
convention for mcount is unusual); just perfect for counting the number
of calls to a function. For the __builtin_return_address() reason it's
unfortunately impossible to implement mcount completly portable, but
what is perfect on this world ...

Ralf