This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi 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]

closure api return value types problem


Hello, dear libffi list!

Some time ago ghc project[1] switched to libffi to handle
foreign calls from/to external world. When I tried ghc on
powerpc64 I got some problems which I believe are result
of that switch.

In one of FFI call types ghc uses C code generation and produces
following code:

void haskell_closure_called_from_c(
    void *cif __UNUSED__,
    void* resp,
    void** args,
    void* haskell_runtime)
{
HaskellObj ret;
HsInt32 cret;

ret = RT_CALL(haskell_runtime(args));

cret=rts_getInt32(ret);
*(HsInt32*)resp = cret; /* <- is that corrct code? */
}

ghc passes pointer to HsInt32 as a 'resp' parameter when calls this function.

So I wrote some tests[2] and ask you, dear list, are those tests correct or they
use libffi incorrectly? (Similar example was added to yet-unapplied patches recently[3],
but it does not _check_ closure return value)

Those tests work on i386, x86_64, but do not work on powerpc64:

FAIL: libffi.call/closure_sint_retval.c -O0 -W -Wall output pattern test, is call 123: 444
res: -988098224
? should match call 123: 444
res: 444
FAIL: libffi.call/closure_uint16_retval.c -O0 -W -Wall output pattern test, is call 123: 444
res: 34576
? should match call 123: 444
res: 444
FAIL: libffi.call/closure_uint32_retval.c -O0 -W -Wall output pattern test, is call 123: 444
res: -740774672
? should match call 123: 444
res: 444

Thank you!

[1] http://haskell.org/ghc/
    The Glasgow Haskell Compiler
[2] http://github.com/trofi/libffi/commit/bf0633dede571789bd20dda84556f92b929d4834
    tests for simple return values
[3] http://github.com/atgreen/libffi/commit/edfdfd2e85b8d01d2455934f1d7f4d7eb2f3cf1c
    closure example

-- 

  Sergei

Attachment: signature.asc
Description: PGP signature


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