#3516: [PATCH] ppc64: broken 'foreign import wrapper'
------------------------------------------+---------------------------------
Reporter: slyfox | Type: bug
Status: new | Priority: low
Milestone: 6.12 branch | Component: Compiler (FFI)
Version: 6.10.4 | Keywords: ffi, wrapper, patch
Difficulty: Unknown | Os: Unknown/Multiple
Testcase: yet | Architecture: powerpc64
Failure: Incorrect result at runtime |
------------------------------------------+---------------------------------
Changes (by slyfox):
* keywords: ffi, wrapper => ffi, wrapper, patch
* failure: => Incorrect result at runtime
Comment:
I think I've tracked down the problem. The problem is incorrect assumption
about libFFI closure return value ABI.
The idea of the patch is to change _stub.c generator in such a way:
'''---''' - removed lines
'''+++''' - added lines
{{{
#define IN_STG_CODE 0
#include "Rts.h"
#include "Stg.h"
+++ #include "ffi.h"
#ifdef __cplusplus
extern "C" {
#endif
void Main_dSe(void *cif STG_UNUSED, void* resp, void** args, void*
the_stableptr)
{
Capability *cap;
HaskellObj ret;
HsInt32 cret;
cap = rts_lock();
cap=rts_evalIO(cap,rts_apply(cap,(HaskellObj)runIO_closure,rts_apply(cap,(StgClosure*)deRefStablePtr(the_stableptr),rts_mkPtr(c
ap,*(HsPtr*)args[0]))) ,&ret);
rts_checkSchedStatus("Main_dSe",cap);
cret=rts_getInt32(ret);
rts_unlock(cap);
--- *(HsInt32*)resp = cret;
+++ *(ffi_arg*)resp = cret;
}
#ifdef __cplusplus
}
#endif
}}}
NOTE: HsFloat and HsDouble were not affected.
As we see '''resp''' ABI is not just a pointer to user specified type,
but a pointer to largest available integral value (or something like that)
of type '''ffi_arg'''.
I tested this patch on attached sample on LIBFFI aware x86_64 and on
powerpc64 host. Both worked correctly.
The patch is available here(and in cvs-ghc ML):
http://code.haskell.org/~slyfox/ppc64-broken-foreign-import-wrapper.dpatch
I also tried to start discussion in view of this issue:
http://sourceware.org/ml/libffi-discuss/2010/msg00063.html
Sorry, I failed to attach this patch directly (firefox SIGSEGVs when I
click 'Attach file')
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3516#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs