From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id A7AB73857C4F for ; Wed, 9 Jun 2021 17:53:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A7AB73857C4F Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 159HgtJs045016; Wed, 9 Jun 2021 13:53:37 -0400 Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 392xjb068g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Jun 2021 13:53:36 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 159Hkp3v028008; Wed, 9 Jun 2021 17:53:35 GMT Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by ppma05wdc.us.ibm.com with ESMTP id 3900w9sk7s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Jun 2021 17:53:35 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 159HrZkt36700510 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Jun 2021 17:53:35 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 630A1B205F; Wed, 9 Jun 2021 17:53:35 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 28C09B206A; Wed, 9 Jun 2021 17:53:35 +0000 (GMT) Received: from mww0171.wdc07m.mail.ibm.com (unknown [9.208.70.164]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 9 Jun 2021 17:53:35 +0000 (GMT) In-Reply-To: To: Anthony Green Cc: libffi-discuss Message-ID: From: "Cheng Jin" Date: Wed, 9 Jun 2021 13:53:32 -0400 Content-type: multipart/related; Boundary="0__=8FBB0C7CDFF1BA7B8f9e8a93df938690918c8FBB0C7CDFF1BA7B" References: X-KeepSent: F6D0F33B:B956BA21-002586EF:00623CEB; name=$KeepSent; type=4 X-Mailer: IBM Notes Release 10.0.1 November 29, 2018 X-Disclaimed: 14883 X-MIMETrack: CD-MIME by Router on MWW0171/01/M/IBM at 06/09/2021 17:53:35, CD-MIME complete at 06/09/2021 17:53:35,Itemize by Router on MWW0171/01/M/IBM at 06/09/2021 17:53:35 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vvT5Hse_QO9mag5Lcab68NnFzD_c6yS9 X-Proofpoint-ORIG-GUID: vvT5Hse_QO9mag5Lcab68NnFzD_c6yS9 X-Proofpoint-UnRewURL: 1 URL was un-rewritten MIME-Version: 1.0 Subject: RE: Incorrect data detected in the nested float struct with x86/libffi on Linux/64bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-06-09_07:2021-06-04, 2021-06-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 spamscore=0 clxscore=1015 malwarescore=0 impostorscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106090087 X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, HTML_FONT_LOW_CONTRAST, HTML_MESSAGE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TVD_FW_GRAPHIC_NAME_MID, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libffi-discuss@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libffi-discuss mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Jun 2021 17:53:40 -0000 --0__=8FBB0C7CDFF1BA7B8f9e8a93df938690918c8FBB0C7CDFF1BA7B Content-type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable Hi Anthony, Many thanks for the quick response. The PR has been created at https://github.com/libffi/libffi/pull/640 as requested. Thanks and Best Regards Cheng Jin From: Anthony Green To: Cheng Jin Cc: libffi-discuss Date: 2021-06-09 12:50 PM Subject: [EXTERNAL] Re: Incorrect data detected in the nested float struct with x86/libffi on Linux/64bit Thank you, Cheng.=A0 Are you able to submit this test case as a github pull request?=A0 The resulting CI testing will give us a broader picture of where we have problems. Thanks, AG On Wed, Jun 9, 2021 at 12:41 PM Cheng Jin via Libffi-discuss < ZjQcmQRYFpfptBannerStart This Message Is From an External Sender This message came from outside your organization. ZjQcmQRYFpfptBannerEnd Thank you, Cheng.=A0 Are you able to submit this test case as a github pull request?=A0 The resulting CI testing will give us a broader picture of where we have problems. Thanks, AG On Wed, Jun 9, 2021 at 12:41 PM Cheng Jin via Libffi-discuss < libffi-discuss@sourceware.org> wrote: Hi, We found that the nested struct [[float, float], float] works good with x86/libffi (at https://github.com/libffi/libffi/tree/master/src/x86) on Linux/64bit (verified on Ubuntu 19) while a variant of it like [float,[float,float]] was messed up at the 3rd element when invoking ffi_call() in the following test: typedef struct stru_Nested_F stru_Nested_F; struct stru_FF { =A0 =A0 =A0 =A0 float elem1; =A0 =A0 =A0 =A0 float elem2; }; struct stru_Nested_F { =A0 =A0 =A0 =A0 float elem1; =A0 =A0 =A0 =A0 stru_FF elem2; }; static float testNestedFloatStruct(float arg1, stru_Nested_F arg2) { =A0 =A0 =A0 =A0 float floatSum =3D arg1 + arg2.elem1 + arg2.elem2.elem1 + arg2.elem2.elem2; =A0 =A0 =A0 =A0 return floatSum; } int main() { =A0 =A0 =A0 =A0 =A0 float returnValue =3D 0; =A0 =A0 =A0 =A0 =A0 ffi_cif cif_temp; =A0 =A0 =A0 =A0 =A0 UDATA structElemNum =3D 2; =A0 =A0 =A0 =A0 =A0 UDATA nestedStructElemNum =3D 2; =A0 =A0 =A0 =A0 =A0 UDATA argNum =3D 2; =A0 =A0 =A0 =A0 =A0 ffi_type **cls_struct_fields1 =3D (ffi_type **)malloc(sizeof(ffi_type *) * (structElemNum + 1)); =A0 =A0 =A0 =A0 =A0 ffi_type **cls_struct_fields2 =3D (ffi_type **)malloc(sizeof(ffi_type *) * (nestedStructElemNum + 1)); =A0 =A0 =A0 =A0 =A0 ffi_type **dbl_arg_types =3D (ffi_type **)malloc(size= of(ffi_type *) * (argNum + 1)); =A0 =A0 =A0 =A0 =A0 void **args_db =3D (void **)malloc(sizeof(void *) * (= argNum + 1)); =A0 =A0 =A0 =A0 =A0 ffi_type cls_struct_type1, cls_struct_type2; =A0 =A0 =A0 =A0 =A0 ffi_type *retType =3D &ffi_type_float; =A0 =A0 =A0 =A0 =A0 float arg1; =A0 =A0 =A0 =A0 =A0 float *arg2 =3D (float *)malloc(sizeof(stru_Nested_F)= ); =A0 =A0 =A0 =A0 =A0 cls_struct_fields2[0] =3D &ffi_type_float; =A0 =A0 =A0 =A0 =A0 cls_struct_fields2[1] =3D &ffi_type_float; =A0 =A0 =A0 =A0 =A0 cls_struct_fields2[2] =3D NULL; =A0 =A0 =A0 =A0 =A0 cls_struct_type2.size =3D 0; =A0 =A0 =A0 =A0 =A0 cls_struct_type2.alignment =3D 0; =A0 =A0 =A0 =A0 =A0 cls_struct_type2.type =3D FFI_TYPE_STRUCT; =A0 =A0 =A0 =A0 =A0 cls_struct_type2.elements =3D cls_struct_fields2; =A0 =A0 =A0 =A0 =A0 cls_struct_fields1[0] =3D &ffi_type_float; =A0 =A0 =A0 =A0 =A0 cls_struct_fields1[1] =3D &cls_struct_type2; =A0 =A0 =A0 =A0 =A0 cls_struct_fields1[2] =3D NULL; =A0 =A0 =A0 =A0 =A0 cls_struct_type1.size =3D 0; =A0 =A0 =A0 =A0 =A0 cls_struct_type1.alignment =3D 0; =A0 =A0 =A0 =A0 =A0 cls_struct_type1.type =3D FFI_TYPE_STRUCT; =A0 =A0 =A0 =A0 =A0 cls_struct_type1.elements =3D cls_struct_fields1; =A0 =A0 =A0 =A0 =A0 dbl_arg_types[0] =3D &ffi_type_float; =A0 =A0 =A0 =A0 =A0 dbl_arg_types[1] =3D &cls_struct_type1; =A0 =A0 =A0 =A0 =A0 dbl_arg_types[2] =3D NULL; =A0 =A0 =A0 =A0 =A0ffi_prep_cif(&cif_temp, FFI_DEFAULT_ABI, 2, retType, dbl_arg_types); =A0 =A0 =A0 =A0 =A0arg1 =3D 37.88; =A0 =A0 =A0 =A0 =A0arg2[0] =3D 31.22; =A0 =A0 =A0 =A0 =A0arg2[1] =3D 33.44; =A0 =A0 =A0 =A0 =A0arg2[2] =3D 35.66; =A0 =A0 =A0 =A0 =A0args_db[0] =3D &arg1; =A0 =A0 =A0 =A0 =A0args_db[1] =3D arg2; =A0 =A0 =A0 =A0 =A0args_db[2] =3D NULL; =A0 =A0 =A0 =A0 ffi_call(&cif_temp, FFI_FN(testNestedFloatStruct), &retur= nValue, args_db); =A0 =A0 =A0 =A0 free(cls_struct_fields1); =A0 =A0 =A0 =A0 free(cls_struct_fields2); =A0 =A0 =A0 =A0 free(dbl_arg_types); =A0 =A0 =A0 =A0 free(args_db); =A0 =A0 =A0return 0; } with the debugging output as follows: (gdb) p arg2[0] $1 =3D 31.2199993 (gdb) p arg2[1] $2 =3D 33.4399986 (gdb) p arg2[2] $3 =3D 35.6599998 (gdb) x/10x=A0 arg2 0x7ffff025b540: 0x41f9c28f=A0 =A0 =A0 0x4205c28f=A0 =A0 =A0 0x420ea3d7 0xdddddddd 0x7ffff025b550: 0xb7654321=A0 =A0 =A0 0x475d4352=A0 =A0 =A0 0x0000000c 0x00000000 0x7ffff025b560: 0xf749c970=A0 =A0 =A0 0x00007fff (gdb) bt #0=A0 testNestedFloatStruct(arg1=3D37.8800011, arg2=3D...) at main.c:xxx #1=A0 0x00007ffff746e4e0 in ffi_call_unix64 () at x86/unix64.S:xxx #2=A0 0x00007ffff746dac8 in ffi_call (cif=3D0x7ffff7d44e90, fn=3D0x7ffff7f9e060, rvalue=3D0x16818, avalue=3D0x7ffff7d44f30) at x86/ffi64.c:xxx Thread 2 "main" hit Breakpoint 2, testNestedFloatStruct(arg1=3D37.8800011, arg2=3D...) at main.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 float floatSum =3D arg1 + arg2.elem1 + ar= g2.elem2.elem1 + arg2.elem2.elem2; (gdb) p arg2 $4 =3D { =A0 elem1 =3D 31.2199993, =A0 elem2 =3D { =A0 =A0 elem1 =3D 33.4399986, =A0 =A0 elem2 =3D 4.20389539e-45=A0 <------------------ messed up =A0 } } (gdb) x/10x=A0 &arg2 0x7ffff7d44458: 0x41f9c28f=A0 =A0 =A0 0x4205c28f=A0 =A0 =A0 0x00000003 0x00007fff 0x7ffff7d44468: 0xf70cf1e6=A0 =A0 =A0 0x4217851f=A0 =A0 =A0 0xf7d44510 0x00007fff 0x7ffff7d44478: 0xf7d44660=A0 =A0 =A0 0x00007fff ------------------------------------------- It looks like there is something wrong in dealing with the nested stuct on Linux/64bit in x86/libffi as the test above works good on Windows/64bit. Thanks and Best Regards Cheng Jin --0__=8FBB0C7CDFF1BA7B8f9e8a93df938690918c8FBB0C7CDFF1BA7B Content-type: image/gif; name="graycol.gif" Content-Disposition: inline; filename="graycol.gif" Content-ID: <1__=8FBB0C7CDFF1BA7B8f9e8a93df938690@ibm.com> Content-Transfer-Encoding: base64 R0lGODlhEAAQAKECAMzMzAAAAP///wAAACH5BAEAAAIALAAAAAAQABAAAAIXlI+py+0PopwxUbpu ZRfKZ2zgSJbmSRYAIf4fT3B0aW1pemVkIGJ5IFVsZWFkIFNtYXJ0U2F2ZXIhAAA7 --0__=8FBB0C7CDFF1BA7B8f9e8a93df938690918c8FBB0C7CDFF1BA7B--