Bug#165992: gcc: __builtin_return_address doesn't work properly
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.
#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.
Reply to: