From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71424 invoked by alias); 28 May 2017 18:23:01 -0000 Mailing-List: contact libffi-discuss-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libffi-discuss-owner@sourceware.org Received: (qmail 71396 invoked by uid 89); 28 May 2017 18:22:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=H*Ad:U*libffi-discuss, HAuthentication-Results:smtp.auth, vague, UD:ru X-HELO: smtp49.i.mail.ru Received: from smtp49.i.mail.ru (HELO smtp49.i.mail.ru) (94.100.177.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 28 May 2017 18:22:57 +0000 Received: from host81-154-9-172.range81-154.btcentralplus.com ([81.154.9.172]:49546 helo=sf) by smtp49.i.mail.ru with esmtpa (envelope-from ) id 1dF2q8-0002OU-NC; Sun, 28 May 2017 21:22:58 +0300 Date: Sun, 28 May 2017 18:23:00 -0000 From: "Sergei Trofimovich via libffi-discuss" Reply-To: Sergei Trofimovich To: "Kaz Kylheku (libffi)" <382-725-6798@kylheku.com> Cc: libffi-discuss@sourceware.org Subject: Re: Also: problem with return value in ffi_call on PPC64. Message-ID: <20170528192241.464e7ebe@sf> In-Reply-To: <3b9c322ddca2e20fa30c7eba0e5ebda2@mail.kylheku.com> References: <3b9c322ddca2e20fa30c7eba0e5ebda2@mail.kylheku.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; boundary="Sig_/.69WuJ16FIf3X4HLeWB=IP8"; protocol="application/pgp-signature" Authentication-Results: smtp49.i.mail.ru; auth=pass smtp.auth=slyfox@inbox.ru smtp.mailfrom=slyfox@inbox.ru X-7FA49CB5: 0D63561A33F958A584CEACC6F5F4D9E9AB7E925BBBFD1B4C8317D92693558284725E5C173C3A84C3F82DE84504A19E5E6AD51D5DE852FC072629B07FD02F83A6C4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0FF045C6A0F83C8214574AF45C6390F7469DAA53EE0834AAEE X-Mailru-Sender: FA4CBDC5470C32070EE9EFE54BAA98C9A8B3E245C1717DC3B33D623D5BC86605E6EFB8CE3492255638F48B1DF051BE983DDE9B364B0DF28966D7C7C3F77E58D71B4ECFBB0E18FD14AE208404248635DF X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00009.txt.bz2 --Sig_/.69WuJ16FIf3X4HLeWB=IP8 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-length: 901 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?=20= =20 >=20 > Indeed, it seems yes. Confusingly yes. But only for integral types smaller that ffi_arg. TL;DR:=20 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/3891512c4c770dadd0372ad84d2d= ec72b34652d2 Hope that helps. --=20 Sergei --Sig_/.69WuJ16FIf3X4HLeWB=IP8 Content-Type: application/pgp-signature Content-Description: Цифровая подпись OpenPGP Content-length: 195 -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQSZKa0VG5avZRlY01hxoe52YR/zqgUCWSsVcQAKCRBxoe52YR/z qvMIAJ4p6KcYEWwC+ONQh9pvbyLVF+y5ggCeOWEQl7pBYHF2vF1lb9AReVuBhxk= =dR6j -----END PGP SIGNATURE----- --Sig_/.69WuJ16FIf3X4HLeWB=IP8--