libffi problem

Bo Thorsen bo@sonofthor.dk
Wed Jul 17 14:32:00 GMT 2002


On Wednesday 17 July 2002 16:09, Jeff Sturm wrote:
> On Mon, 15 Jul 2002, Bo Thorsen wrote:
> > I have a problem in the port of libffi.
>
> On what platform?

The x86-64 port I'm almost done with. I'm testing the patch right now and 
hopefully you'll get it very soon.

> > In the testsuite, there is a test that calls a function with a signed
> > char. This function simply returns the signed char, and the testsuite
> > checks that the returned number is equal to the one given.
> >
> > The problem here is that the testcase is giving a long long to fill the
> > return value in. I wanted to do a memcpy(&rvalue, &value, size), but size
> > here is 1, so when giving a negative number to return, this writes the -
> > flag in the wrong position (actually returns 129 instead of -127).
>
> For integer return values, ffi_call promotes to word size (ffi_arg).  From
> libffi/README:
>
>     RVALUE is a pointer to a chunk of memory that is to hold the
>         result of the function call. Currently, it must be
>         at least one word in size (except for the n32 version
>         under Irix 6.x, which must be a pointer to an 8 byte
>         aligned value (a long long). It must also be at least
>         word aligned (depending on the return type, and the
>         system's alignment requirements). If RTYPE is
>         &ffi_type_void, this is ignored. If RVALUE is NULL,
>         the return value is discarded.
>
> See e.g. ffi_prep_cif_machdep in src/x86/ffi.c for special handling of
> rtype.

Great! I must have missed this info. Thanks for the pointer.

> > What is wrong here? Does libffi always assume that there is a word of
> > pointersize to write numbers into? Or is the testsuite wrong?
>
> Not always pointersize, e.g. MIPS n32.  (That's why I introduced the
> ffi_arg typedef, to reduce the need for conditional compilation in
> portable code.)

Thanks,

Bo.

-- 

     Bo Thorsen                 |   Praestevejen 4
     Free software developer    |   5290 Marslev
     SuSE Labs                  |   Denmark



More information about the Gcc mailing list