[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Incorrect function call code on ARMv6
From: |
Balazs Kezes |
Subject: |
Re: [Tinycc-devel] Incorrect function call code on ARMv6 |
Date: |
Thu, 11 Aug 2016 09:24:02 +0100 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
On 2016-08-11 01:17 +0200, Daniel Glöckner wrote:
> On Wed, Aug 10, 2016 at 06:59:46AM +0100, Balazs Kezes wrote:
> > 90: e5912000 ldr r2, [r1] ; <-- This is the y argument.
> > 94: e50b2018 str r2, [fp, #-24]
> > 98: e5901000 ldr r1, [r0]
> > 9c: e2800004 add r0, r0, #4
> > a0: e5902000 ldr r2, [r0] ; <-- The clobbering happens here.
> > a4: e50b101c str r1, [fp, #-28]
> > a8: e1a01002 mov r1, r2
> > ac: e51b001c ldr r0, [fp, #-28]
> > b0: ebfffffe bl 0 <foo>
>
> I think the error is caused by the "vtop--;" lines in copy_params().
> The former gfunc_call() implementation for ARM rotated the elements
> on the parameter stack to let get_reg() know that the registers are
> still in use. The current implementation drops each element directly
> after it has been moved to the final register.
Thanks for the pointer but looking through the code I'm not so sure
about that. At 0x94 you can see that it actually saves the register to
the stack in order to free up r2. I can see this in the stacktrace when
I put a breakpoint to the output function like this:
(gdb) b o if ind == 0x94
Breakpoint 1 at 0x331b0: file arm-gen.c, line 205.
(gdb) r
Starting program: /home/rlblaster/proj/tcc/tinycc/tcc -c callbug.c
Breakpoint 1, o (i=3842711576) at arm-gen.c:205
205 ind1 = ind + 4;
(gdb) bt
#0 o (i=3842711576) at arm-gen.c:205
#1 0x00034d28 in store (r=2, sv=0xbefff340) at arm-gen.c:704
#2 0x0001def8 in save_reg (r=2) at tccgen.c:526
#3 0x0001e2f0 in save_regs (n=1) at tccgen.c:630
#4 0x0001e8bc in gv (rc=1) at tccgen.c:825
#5 0x0001eca4 in lexpand () at tccgen.c:951
#6 0x0001ee60 in lexpand_nr () at tccgen.c:980
#7 0x00035d64 in copy_params (nb_args=2, plan=0xbefff4a4, todo=0) at
arm-gen.c:1098
#8 0x000360f4 in gfunc_call (nb_args=2) at arm-gen.c:1159
...
I think it's just that that copy_params() never restores the spilled
registers. Maybe it needs some extra code at the end to see if any
parameters have been spilled to stack and then restore them?
--
Balazs