[Fortran] RFC: Patch to support STDCALL etc. (PR 34112)
Tobias Burnus
burnus@net-b.de
Fri Jun 19 22:17:00 GMT 2009
Attached is the first version of a patch which allows to use
!GCC$ ATTRIBUTES attribute :: symbol-list
where attribute is one of:
- CDECL
- STDCALL
- FASTCALL
- DLLEXPORT
- DLLIMPORT
The effect of the attribute is target dependent. For instance,
using STDCALL on x86-64-linux will only produce a warning that
STDCALL is ignored. On x86-32-linux, the effect is that the
called procedure and not the calling procedure pops the stack.
And on x86-32-windows the stack effect is the same, but the
symbol also gets a @<n> attached (n = number of bytes to pop
from the stack).
CDECL, STDCALL and FASTCALL can be used for procedures and
procedure pointers, DLLIMPORT/DLLEXPORT for procedures and
global variables (common blocks, module variables). There is
no attempt made to ensure the attributes are used sensible,
in some cases the middle end gives a warning, but not always.
However, for procedure-pointer assignment, a rather strict
check has been implemented. In principle, CDECL is (usually)
compatible with "no attribute" -- except -mrtd is used;
in that case STDCALL is equivalent to "no attribute".
Thus, one could consider to change the error into a warning.
The proper check would operate on TREE and has therefore to
be placed into trans-expr.c.
As a near-term TODO, one should allow an attribute list
rather than a single attribute, e.g. "DLLEXPORT, STDCALL"
is a reasonable combination; currently, one has to use
two "!GNU$ ATTRIBUTES" statements.
A longer term TODO could be to support all GCC attributes,
including ALIAS, ALIGN, WEAK, ...
The attributes are only sensible together with BIND(C) as
otherwise the normal gfortran symbol names are used
(dressed according to target and calling convention). One
could also support !DEC$ but that will be a significant
work as some of attributes are handled slightly different,
the attributes are partially incompatible with BIND(C) and
the attributes are not well defined. Maybe a subset could
be useful together with a "-fdec-attributes" option?
The patch is based on FX's patch, but it has been significantly
extended, fixed and modified.
I have tested it lightly on x86-64-linux with -m64 (gives some
nice warnings) and -m32 (supports stdcall but has no mangling).
However, I would be happy if someone could test it on
Cygwin/Mingwin (with 32bit Windows). Or on every other system.
I am also looking forward to your comments.
Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stdcall.diff
Type: text/x-patch
Size: 27840 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20090619/b4e37a89/attachment.bin>
More information about the Fortran
mailing list