ARM stack alignment on hand called functions
Richard Earnshaw
rearnsha@arm.com
Wed Nov 20 10:37:00 GMT 2002
> The problem arises only with functions which return structures whose size is
> not evenly divisible by 4. Below is what I did to solve it.
>
> Index: arm-tdep.c
> ===================================================================
> RCS file: /product/tools/gdb/gdb/arm-tdep.c,v
> retrieving revision 1.9
> retrieving revision 1.10
> diff -c -r1.9 -r1.10
> *** arm-tdep.c 20 Sep 2002 17:11:31 -0000 1.9
> --- arm-tdep.c 19 Nov 2002 18:33:37 -0000 1.10
> ***************
> *** 1480,1485 ****
> --- 1480,1486 ----
> }
> }
>
> + sp = (sp + 3) & ~3;
> /* Return adjusted stack pointer. */
> return sp;
> }
>
OK, but with this change the alignment is being done *after* any arguments
that have to go onto the stack have been pushed. It should happen
*before*. What happens if you have?
struct f { char a; char b; char c;};
struct f g = {1,2,3};
struct f h (int a, int b, int c, int d, int e)
{
g.c = e;
return g;
}
and then call h from within the debugger. Is g.c set correctly?
My guess is that it won't, because the integer value for e will have been
pushed onto the stack incorrectly.
R.
More information about the Gdb
mailing list