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]

Re: Also: problem with return value in ffi_call on PPC64.


On Sat, 27 May 2017 19:15:35 -0700
"Kaz Kylheku (libffi)" <382-725-6798@kylheku.com> wrote:

> > Are users supposed to assume that the return value has been widened to
> > a register-wide (8 byte) value regardless of its declared FFI type?  
> 
> Indeed, it seems yes.

Confusingly yes. But only for integral types smaller that ffi_arg.

TL;DR: 
   Instead of just reading out result as *(result_type*)r for any FFI
   type you need to use either *(ffi_arg*)r or *(result_type*)r depending
   on the type of the result.

A bit vague libffi thread:
    https://sourceware.org/ml/libffi-discuss/2010/msg00063.html

I discovered the same a few years ago debugging similar issue on GHC side
    https://ghc.haskell.org/trac/ghc/ticket/3516

The awkward fix on GHC side:
    https://git.haskell.org/ghc.git/commitdiff/3891512c4c770dadd0372ad84d2dec72b34652d2

Hope that helps.

-- 

  Sergei

Attachment: pgpkUKwX0HeIy.pgp
Description: Цифровая подпись OpenPGP


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