This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
__builtin_frame_address on MIPS
- From: Ranjit Deshpande <ranjit at kenati dot com>
- To: <gcc at gcc dot gnu dot org>
- Date: Fri, 25 Feb 2005 13:45:59 -0800
- Subject: __builtin_frame_address on MIPS
Hello,
It seems as if __builtin_return_address() with arguments > 1 does not work
correctly on GCC 3.3.x. My compiler version is 3.3.4.
Here is a snippet of the source code:
int boo()
{
int i = 10; /* Create a local variable */
printf("%p\n", __builtin_frame_address(1));
}
int main()
{
boo();
}
Here's the assembly code that gets generated:
00400840 <boo>:
400840: 3c1c0fc0 lui gp,0xfc0
400844: 279c77e0 addiu gp,gp,30688
400848: 0399e021 addu gp,gp,t9
40084c: 27bdffd8 addiu sp,sp,-40
400850: afbc0010 sw gp,16(sp)
400854: afbf0020 sw ra,32(sp)
400858: afbe001c sw s8,28(sp) <====== old FP
40085c: afbc0018 sw gp,24(sp)
400860: 03a0f021 move s8,sp <===== new FP
400864: 8fc20000 lw v0,0(s8) <===== get old FP
400868: 8f84801c lw a0,-32740(gp)
40086c: 00000000 nop
400870: 24840a80 addiu a0,a0,2688
400874: 00402821 move a1,v0
400878: 8f99804c lw t9,-32692(gp)
40087c: 00000000 nop
400880: 0320f809 jalr t9 /* printf */
>From the disassembly above, it seems that __builtin_frame_address(1) assumes
that the previous frame pointer is at offset 0 in the current stack frame,
but the code to save the previous frame pointer puts it at offset 28 within
the stack frame. Obviously, the output printed by the C code is wrong.
Has this problem been addressed in gcc 3.4.x ? I confess that I have not
checked if this is fixed in the 3.4.x series.
Thanks,
-Ranjit