This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

optimization/8008: gcc pushes arguments without updating SP

>Number:         8008
>Category:       optimization
>Synopsis:       gcc pushes arguments without updating SP
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 23 00:16:01 PDT 2002
>Originator:     Matt Thomas
>Release:        3.3 20020922 (experimental)
3am Software Foundry
System: NetBSD pilot.local 1.6F NetBSD 1.6F (PILOT.MP) #8: Mon Aug 19 01:55:52 PDT 2002 matt@pilot.local:/export/i386/kobj/PILOT.MP i386

host: i386-pc-netbsdelf
build: i386-pc-netbsdelf
target: vax-dec-netbsdelf
configured with: /export/toolchain/gcc/configure --target=vax-netbsdelf --host=i386-netbsdelf --build=i386-netbsdelf --disable-shared --enable-static : (reconfigured)  : (reconfigured)  : (reconfigured) 
Gcc is generating code which is incorrectly substituting the use of a general
register in place of the stack pointer when the use of the stack pointer is
Compile gcc.c-torture/execute/20020412-1.c as -O1 and -O2 and compare
generated assembly.

Note the following section of assembly:

        pushl %r8
-       pushl %r1
-       pushl %r7
-       calls $3,memcpy
+       movl %r1,-(%r7)
+       movl %r7,-(%r7)
+       movab memcpy,%r11
+       calls $3,(%r11)

In the -O2 complied version, two arguments are pushed via %r7 instead of %sp.
This is incorrect in two ways.  The first way is that %sp is not pointing at
the bottom of the stack, and hence, the start of the arguments.  The second
problem is that before the pushl %r8, %r7 == %sp, so the first movl
obliterates the value pushed by the pushl %r8.  The second movl saves the
wrong value (%r7 - 4) on the stack (where at point it should have been 
%sp + 8).

The fix is to tell gcc to *never* mung the stack (or below the stack)
without using the stack pointer.  How ones does that is beyond me.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]