This is the mail archive of the java@gcc.gnu.org mailing list for the Java 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]

Teaching libffi to stdcall


Anthony Green wrote:
On Wed, 2002-11-06 at 13:13, Tom Tromey wrote:

problem.  It seems to me that we'll need to teach libffi about
stdcall.
This shouldn't be so bad for someone to try.  libffi was designed to
support multiple ABIs at runtime.
All right - I took a shot at it and it seems to be working
in the libffi in GCJ 3.2 - I shall post a patch as soon as
I migrate it to GCJ 3.3. The smoke tests pass on Linux
as well as Win32 (see note #5 below though).

Here's a summary of what I did:

* Defined FFI_STDCALL ffi_abi enum for both X86 and X86_WIN32 (ffi.h.in)
  (GCC 2.95.x and 3.x on Linux also support stdcall - either via
  __attribute__((stdcall)) or globally via -mrtd.)

* Updated x86/sysv.S and x86/win32.S with definitions for
  ffi_call_STDCALL. This is merely copy/paste with label renaming
  and removing the two instructions that clean up the stack after
  the called function returns.

* Updated x86/ffi.c to recognise FFI_STDCALL and to call
  ffi_call_STDCALL when this ABI is specified.

* Updated ffitest.c with stdcall versions of my_strlen( ) and
  many_arg( ) and smoke tests for stdcall using these (X86 and
  X86_WIN32).

However, I've run into a few issues that I'd request you
guys to help me with/clarify:

1. For the sake of completeness, we should also teach libffi
   to call fastcall functions. fastcall functions are like
   stdcall except that the first two arguments are passed in
   ECX and EDX respectively.

2. In x86/sysv.S, I could not update the DW2 CIEs and FDEs as
   I have no clue on how to go about doing it.

3. I have not touched any of the "closure" functions as I do
   not know what these do and whether adding support for stdcall
   here would make any sense.

4. GCC 2.95.x and 3.x seem to go to great lengths to ensure a
   default stack alignment of 128 bits. At least the
   ffi_call_SYSV in x86/win32.S does not seem to give an
   aligned stack to the called function.

5. On Win32, the ffitest program fails while testing closures.
   Is this an expected failure?

Sincerely Yours,
Ranjit.

--
Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/




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