Bug#165992: gcc: __builtin_return_address doesn't work properly
On Wed, Oct 23, 2002 at 02:01:47AM -0400, gsstark@mit.edu wrote:
> Package: gcc
> Version: 2:2.95.4-17
> Severity: normal
>
> The following program illustrates that __builtin_return_address seg faults when
> you reach the top of the stack rather than returning 0 as it is specified in
> the gcc manual.
>
> I see the same behaviour with both gcc 2.95 and gcc 3.0.
GCC 3.2 says:
On some machines it may be impossible to determine the return
address of any function other than the current one; in such cases,
or when the top of the stack has been reached, this function will
return `0' or a random value. In addition,
`__builtin_frame_address' may be used to determine if the top of
the stack has been reached.
This function should only be used with a nonzero argument for
debugging purposes.
You're running it beyond the top of the stack. It returns a random
value, and then the following call crashes. The documentation is
correct and it really can't do any better.
>
>
> #include <stdio.h>
>
> int main () {a();}
> a() {b();}
> b() {c();}
> c()
> {
> printf("%d: %p\n", 0, __builtin_return_address(0));
> printf("%d: %p\n", 1, __builtin_return_address(1));
> printf("%d: %p\n", 2, __builtin_return_address(2));
> printf("%d: %p\n", 3, __builtin_return_address(3));
> printf("%d: %p\n", 4, __builtin_return_address(4));
> printf("%d: %p\n", 5, __builtin_return_address(5));
> }
>
>
> (gdb) run
> Starting program: /tmp/a.out
> 0: 0x804840f
> 1: 0x80483ff
> 2: 0x80483ef
> 3: 0x400450bf
> 4: 0x8048331
> (no debugging symbols found)...(no debugging symbols found)...
> Program received signal SIGSEGV, Segmentation fault.
> 0x080484ae in c ()
> (gdb) bt
> #0 0x080484ae in c ()
> #1 0x0804840f in b ()
> #2 0x080483ff in a ()
> #3 0x080483ef in main ()
> #4 0x400450bf in __libc_start_main () from /lib/libc.so.6
>
>
> -- System Information
> Debian Release: testing/unstable
> Kernel Version: Linux stark.dyndns.tv 2.4.19 #6 Tue Sep 10 22:08:51 EDT 2002 i686 unknown unknown GNU/Linux
>
> Versions of the packages gcc depends on:
> ii cpp 2.95.4-17 The GNU C preprocessor.
> ii cpp-2.95 2.95.4-12 The GNU C preprocessor.
> ii gcc-2.95 2.95.4-12 The GNU C compiler.
>
>
> --
> To UNSUBSCRIBE, email to debian-gcc-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
>
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
Reply to: