__builtin_return_address

Zack Weinberg zackw@Stanford.EDU
Thu Nov 2 00:20:00 GMT 2000


On Thu, Nov 02, 2000 at 02:41:07AM -0500, Eli Zaretskii wrote:
> > From: Michael Meissner <meissner@cygnus.com>
> > Date: Wed, 1 Nov 2000 16:03:44 -0500
> > > 
> > > Also, is the platform the OP was talking about (Red Hat GNU/Linux)
> > > really one of those where __builtin_return_address doesn't work?
> > 
> > Ummm, Red Hat GNU/Linux runs on 3 different target hardwares.  For the x86,
> > __builtin_return_address with a non-zero argument only has a chance of working
> > if the caller was not called with -fomit-frame-pointer.
> 
> The original message indicates that it was an x86-based system:
...

You're missing the point here.  Yes, on x86/linux without
-fomit-frame-pointer, __builtin_return_address(N) for N>0 is more
likely to work than on some other platforms.  It still isn't
guaranteed.  It might return zero back when there's still stack
frames, skip over active frames, surprise you with frames you didn't
expect, or crash instead of returning 0 when you run out of frames.
And I wouldn't be too shocked if it made demons fly out of my nose,
either.

>     400349cb
>     8048361

400349cb is the libc routine that calls main (__libc_start_main on my
system) and 80483c1 is the routine in crt1.o that called it (_start).
I get similar results when I try __b_r_a(0) and (1) from main.  With
gcc 2.95, __b_r_a(2) from main segfaults.

zw


More information about the Gcc-bugs mailing list