This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
__builtin_return_address doesn't return 0
- To: gcc-bugs at gcc dot gnu dot org
- Subject: __builtin_return_address doesn't return 0
- From: "H . J . Lu" <hjl at lucon dot org>
- Date: Mon, 4 Jun 2001 16:09:41 -0700
Under Linux/x86, __builtin_return_address doesn't always return 0 when
top of the stack is reached. But __builtin_frame_address seems to
work ok. Should we update the manual saying __builtin_return_address
may not always detect the top of the stack reliably?
H.J.
---
#include <stdio.h>
void
foo(void)
{
printf("Stack trace:\n");
printf("0: %p\n", __builtin_return_address(0));
printf("1: %p\n", __builtin_return_address(1));
printf("2: %p\n", __builtin_return_address(2));
printf("3: %p\n", __builtin_return_address(3));
printf("4: %p\n", __builtin_return_address(4));
printf("5: %p\n", __builtin_return_address(5));
printf("6: %p\n", __builtin_return_address(6));
printf("7: %p\n", __builtin_return_address(7));
}
int
main(void)
{
foo();
return 0;
}
./foo
Stack trace:
0: 0x80484b4
1: 0x400301eb
2: 0x8048341
Segmentation fault (core dumped)