public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/34001] New: Incorrect __attribute__ fastcall behavior
@ 2007-11-05 23:40 zia at aracnet dot com
2007-11-05 23:58 ` [Bug target/34001] " pinskia at gcc dot gnu dot org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: zia at aracnet dot com @ 2007-11-05 23:40 UTC (permalink / raw)
To: gcc-bugs
4byte structures that are passed as parameters to a fastcall routine will get
passed as registers. This does not match the original fastcall convention,
which passes such structures on the stack.
Compiling this code:
#include <stdio.h>
typedef struct {
int a;
} my_struct;
int __attribute__((fastcall)) foo(my_struct s, int b)
{
return s.a + b;
}
main()
{
my_struct ss;
ss.a = 1;
printf("\nfoo = %d.\n",foo(ss,2));
}
Results in:
.
.
movl $1, -12(%ebp)
movl -12(%ebp), %ecx
movl $2, %edx
call _foo
.
.
and
.
.
.globl _foo
_foo:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
movl %ecx, -12(%ebp)
movl %edx, -16(%ebp)
movl -12(%ebp), %eax
addl -16(%ebp), %eax
leave
ret
With GCC.
Using other compilers that support fastcall will pass the struct value on the
stack.
--
Summary: Incorrect __attribute__ fastcall behavior
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: zia at aracnet dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/34001] Incorrect __attribute__ fastcall behavior
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
@ 2007-11-05 23:58 ` pinskia at gcc dot gnu dot org
2007-11-08 17:12 ` hjl at lucon dot org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-11-05 23:58 UTC (permalink / raw)
To: gcc-bugs
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|major |normal
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/34001] Incorrect __attribute__ fastcall behavior
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
2007-11-05 23:58 ` [Bug target/34001] " pinskia at gcc dot gnu dot org
@ 2007-11-08 17:12 ` hjl at lucon dot org
2007-11-09 16:55 ` hjl at lucon dot org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl at lucon dot org @ 2007-11-08 17:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from hjl at lucon dot org 2007-11-08 17:12 -------
I verified that it isn't fixed in gcc 4.3.0.
--
hjl at lucon dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2007-11-08 17:12:05
date| |
Target Milestone|--- |4.3.0
Version|4.0.1 |4.3.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/34001] Incorrect __attribute__ fastcall behavior
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
2007-11-05 23:58 ` [Bug target/34001] " pinskia at gcc dot gnu dot org
2007-11-08 17:12 ` hjl at lucon dot org
@ 2007-11-09 16:55 ` hjl at lucon dot org
2007-11-09 17:34 ` hjl at lucon dot org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl at lucon dot org @ 2007-11-09 16:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from hjl at lucon dot org 2007-11-09 16:55 -------
From
http://msdn2.microsoft.com/en-us/library/6xa169sk(VS.80).aspx
"The first two DWORD or smaller arguments are passed in ECX and EDX registers;
all other arguments are passed right to left."
But it isn't clear if it applies to structure/union. We tested all MS compilers
we have and verified that the above doesn't apply to structure/union. To make
fastcall compatible with MS compilers, we should only put scalar arguments
in ECX and EDX.
--
hjl at lucon dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |hjl at lucon dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2007-11-08 17:12:05 |2007-11-09 16:55:09
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/34001] Incorrect __attribute__ fastcall behavior
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
` (2 preceding siblings ...)
2007-11-09 16:55 ` hjl at lucon dot org
@ 2007-11-09 17:34 ` hjl at lucon dot org
2007-11-12 3:27 ` [Bug target/34001] Incorrect x86 " hjl at lucon dot org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl at lucon dot org @ 2007-11-09 17:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from hjl at lucon dot org 2007-11-09 17:34 -------
A patch is posted at
http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00531.html
--
hjl at lucon dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |http://gcc.gnu.org/ml/gcc-
| |patches/2007-
| |11/msg00531.html
Keywords| |patch
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/34001] Incorrect x86 fastcall behavior
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
` (3 preceding siblings ...)
2007-11-09 17:34 ` hjl at lucon dot org
@ 2007-11-12 3:27 ` hjl at lucon dot org
2007-11-16 4:52 ` hjl at lucon dot org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl at lucon dot org @ 2007-11-12 3:27 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from hjl at lucon dot org 2007-11-12 03:27 -------
>From "info gcc",
`fastcall'
On the Intel 386, the `fastcall' attribute causes the compiler to
pass the first argument (if of integral type) in the register ECX
^^^^^^^^^^^^^^^^^^^
and the second argument (if of integral type) in the register EDX.
^^^^^^^^^^^^^^^^^^^
Subsequent and other typed arguments are passed on the stack.
The called function will pop the arguments off the stack. If the
number of arguments is variable all arguments are pushed on the
stack.
It looks like gcc document follows MS compiler and we didn't implement
it correctly.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/34001] Incorrect x86 fastcall behavior
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
` (4 preceding siblings ...)
2007-11-12 3:27 ` [Bug target/34001] Incorrect x86 " hjl at lucon dot org
@ 2007-11-16 4:52 ` hjl at lucon dot org
2007-11-26 23:19 ` hjl at lucon dot org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl at lucon dot org @ 2007-11-16 4:52 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from hjl at lucon dot org 2007-11-16 04:52 -------
The correct patch is at
http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00885.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/34001] Incorrect x86 fastcall behavior
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
` (5 preceding siblings ...)
2007-11-16 4:52 ` hjl at lucon dot org
@ 2007-11-26 23:19 ` hjl at lucon dot org
2007-11-27 2:36 ` hjl at lucon dot org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl at lucon dot org @ 2007-11-26 23:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from hjl at lucon dot org 2007-11-26 23:19 -------
We have changed fastcall behavior from gcc 3.4 to 4.1. For
---
#define FASTCALL __attribute((fastcall))
double FASTCALL f_dii( double p1d, int p2i, int p3i ){ return p1d +
(double)p2
i + (double)p3i; }
int test_x;
int test_y;
double test_d1;
void caller( void ){
f_dii( test_d1, test_x, test_y );
}
---
Gcc 3.4 doesn't pass the first 2 integral parameters in ecx/edx and gcc
4.1 does.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/34001] Incorrect x86 fastcall behavior
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
` (6 preceding siblings ...)
2007-11-26 23:19 ` hjl at lucon dot org
@ 2007-11-27 2:36 ` hjl at lucon dot org
2007-11-28 1:20 ` hjl at gcc dot gnu dot org
2007-11-28 1:25 ` hjl at lucon dot org
9 siblings, 0 replies; 11+ messages in thread
From: hjl at lucon dot org @ 2007-11-27 2:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from hjl at lucon dot org 2007-11-27 02:36 -------
(In reply to comment #6)
> We have changed fastcall behavior from gcc 3.4 to 4.1. For
>
> ---
> #define FASTCALL __attribute((fastcall))
>
> double FASTCALL f_dii( double p1d, int p2i, int p3i ){ return p1d +
> (double)p2
> i + (double)p3i; }
>
> int test_x;
> int test_y;
> double test_d1;
>
> void caller( void ){
> f_dii( test_d1, test_x, test_y );
> }
> ---
>
> Gcc 3.4 doesn't pass the first 2 integral parameters in ecx/edx and gcc
> 4.1 does.
>
This patch
http://gcc.gnu.org/ml/gcc-patches/2005-01/msg00541.html
fixes this fast call bug by changing the abi.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/34001] Incorrect x86 fastcall behavior
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
` (7 preceding siblings ...)
2007-11-27 2:36 ` hjl at lucon dot org
@ 2007-11-28 1:20 ` hjl at gcc dot gnu dot org
2007-11-28 1:25 ` hjl at lucon dot org
9 siblings, 0 replies; 11+ messages in thread
From: hjl at gcc dot gnu dot org @ 2007-11-28 1:20 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from hjl at gcc dot gnu dot org 2007-11-28 01:20 -------
Subject: Bug 34001
Author: hjl
Date: Wed Nov 28 01:20:34 2007
New Revision: 130488
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130488
Log:
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.
Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/i386/i386.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/34001] Incorrect x86 fastcall behavior
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
` (8 preceding siblings ...)
2007-11-28 1:20 ` hjl at gcc dot gnu dot org
@ 2007-11-28 1:25 ` hjl at lucon dot org
9 siblings, 0 replies; 11+ messages in thread
From: hjl at lucon dot org @ 2007-11-28 1:25 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from hjl at lucon dot org 2007-11-28 01:25 -------
Fixed in gcc 4.3.
--
hjl at lucon dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34001
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-11-28 1:25 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-05 23:40 [Bug c/34001] New: Incorrect __attribute__ fastcall behavior zia at aracnet dot com
2007-11-05 23:58 ` [Bug target/34001] " pinskia at gcc dot gnu dot org
2007-11-08 17:12 ` hjl at lucon dot org
2007-11-09 16:55 ` hjl at lucon dot org
2007-11-09 17:34 ` hjl at lucon dot org
2007-11-12 3:27 ` [Bug target/34001] Incorrect x86 " hjl at lucon dot org
2007-11-16 4:52 ` hjl at lucon dot org
2007-11-26 23:19 ` hjl at lucon dot org
2007-11-27 2:36 ` hjl at lucon dot org
2007-11-28 1:20 ` hjl at gcc dot gnu dot org
2007-11-28 1:25 ` hjl at lucon dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).