__builtin_return_address doesn't return 0

H . J . Lu hjl@lucon.org
Mon Jun 4 16:09:00 GMT 2001


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)



More information about the Gcc-bugs mailing list