This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: PR target/34001: Incorrect x86 fastcall behavior
On Tue, Nov 27, 2007 at 11:43:01PM +0100, Jan Hubicka wrote:
> > On Nov 27, 2007 3:41 AM, H.J. Lu <hjl@lucon.org> wrote:
> >
> > > > It depends on how you see it. To me, the current behavior is binary
> > > > incompatible with MS compilers, for which this feature is designed
> > > > for. My patch makes it binary incompatible with older gcc, but
> > > > makes the new gcc binary compatible with all assembly codes and
> > > > object files which conform to gcc document as well as MS compilers.
> > > >
> > >
> > > We have changed the i386 fastcall abi between gcc 3.4 and gcc 4.0:
> > >
> > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001#c7
> > >
> > > I think we should fix it for gcc 4.3. Jan, Uros, can you take a look
> > > at it?
> >
> > Jan is an expert for ABI issues, so IMO he should have the last word.
>
> I was participating in the x86-64 ABI decisions so I can give some
> insight there, but i386 well predates me :)
>
> My understanding is that fastcall was invented for compatibility with
> "standard" conventions used by MS and Watcom compilers, so we should
> follow what they do (ie not pass aggregates in registers) more if it
> actually is documented in our texinfo.
>
> I don't like much the idea of changing behaviour for Windows targets
> only, it seems like good trap for code trying to be portable across
> both. So I personally would vote for changing default behaviour and
> documenting it in NEWS document as suggested.
>
> I would not expect much fallout - it is uncommon to pass little
> aggregates to assembly code and using fastcall in library API would be
> quite silly.
>
> Honza
This is the change I checked in. I also checked in the change for
gcc 4.3 change document.
H.J.
---
2007-11-27 H.J. Lu <hongjiu.lu@intel.com>
Joey Ye <joey.ye@intel.com>
PR target/34001
* config/i386/i386.c (function_arg_32): Don't pass aggregate
arguments in ECX/EDX for fastcall.
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c (revision 130486)
+++ config/i386/i386.c (working copy)
@@ -4253,10 +4253,13 @@ function_arg_32 (CUMULATIVE_ARGS *cum, e
int regno = cum->regno;
/* Fastcall allocates the first two DWORD (SImode) or
- smaller arguments to ECX and EDX. */
+ smaller arguments to ECX and EDX if it isn't an
+ aggregate type . */
if (cum->fastcall)
{
- if (mode == BLKmode || mode == DImode)
+ if (mode == BLKmode
+ || mode == DImode
+ || (type && AGGREGATE_TYPE_P (type)))
break;
/* ECX not EAX is the first allocated register. */