From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id BEB573858D1E for ; Wed, 20 Mar 2024 20:31:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEB573858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BEB573858D1E Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1710966684; cv=pass; b=w4R6/mP0aa02H3GIFg9ERx8T0HAsJvHfXC2taztMBj7u3KuiFOO4gr8ik8QTQHB/z6pIz9qB2+ALx1yWpxlI2Tj57v4X5UJuErbNh5pVOnNR+marnjShLDvo9Oq9lAQBLMekid1z74tAM032afuJ2LTmCU5L6uc3apHq6RaE9hY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1710966684; c=relaxed/simple; bh=iGKQ1JVqhbisZAtjVszrDhZH4oNj2jTUXxEZo36/A1o=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=ISrwcRW33x+tNcX6Ny/Q0eXY7M+NHJEZ7q5ZTuaHmmMEFPr8+wpaMKvvbnkvz/yCHfOhvuLUVhQUKJCB8TX0wP5g4wJzVbiSBihK9CcDjRa/nTmy2gprawGDIK80ooPECBICQcGDdRIy9LNqMcNjOg5agTQSw0cB4Tz/N7zb0e8= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 42KITOrW025616 for ; Wed, 20 Mar 2024 20:31:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=references : from : to : cc : subject : in-reply-to : date : message-id : content-type : mime-version; s=corp-2023-11-20; bh=bqJkRIUBnnTj9Ase6CIYZ/DNV1LGCUsf1tTHAcCJXj0=; b=B97ZMYYaIuUofrgTW0xTMMImmyUkUENHnHBVRA+2oEfoTsr602KKpWN805kljCKtTHVo wEOIsm3TXIxcN0Z+HS4TdXoKX/uSwe6v10AuXHymefq92nlMsEdHF+Q7R6IPoE43J46o A8Uj1hT9AboQQngd1vlmSpv7ek/annCFEnNXdcBakIcZR5xIJw9/JlEUsATWi3sPwddJ isT0FJ4lqMgYjSqa54fKEhiTjtpOJXMCsVi4HCd5Vy6ibpng9dR0HPXnSWBnjti+zc48 IxzFNgx6iZgDt7qj3+/bLbNr4AVzn+Y9ObOWtVMnIVlvHcZpdT/3616YJvJ6uEO4VqbD 6Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ww211938q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 20 Mar 2024 20:31:20 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 42KJcldL007469 for ; Wed, 20 Mar 2024 20:31:19 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ww1v8w27f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 20 Mar 2024 20:31:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DtvtGABMhhnPsmnHaM66htC3isQEtd84dWanJ+6ym7VM1YD3Izwe3lliWiyWiMj2a28jqG9BO/GYEZyj5XZZIGDYdnt/gwDGTrbcaus3Gu2Kasw9+jjcTCgRSSW2NJ1tX2KbsARWO0v7uk4qIro0Mk1+dw1OWE0HYKaj7YqDCQmWfFKvnwMRONU0H8tTkdHM7iHu4i2EkFZWuR7DV3uK0ztYJj2C7HbUr0O7vI3+w0q+KsZUnrNQtXKDpVBjG0KyNajUYlZBt/8GagkIbkOHiutOwbmw31LmOYZQuECZOy/Wc0gjuGVmasfc4sh95eoijU6Z1s7Xx38YdBsqAoVgCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bqJkRIUBnnTj9Ase6CIYZ/DNV1LGCUsf1tTHAcCJXj0=; b=NrMQdB+jiKwOB6cbcYB5pD93MzOaWV42D5oeN41srZerr95LIqSYyZLU9/QsOYY+ODQ4nQoKr218wdbjwofs+RpPWG0+780/XmdazdxVjB2VhaxbJNKVoo1RKvRfZtN6JDrm1aurLivas6fAirPQp/j7I45OUjiai3/suedQkYfkw+5gKrr4OyqFlcrXsYS+hn6XcI+OkOA9lTOJAV+o6+aeImOzsO4nu77DU5vYRi0FcrdpnyGacH7Tc4Qe8qsJCdf3ISkDZ+KuFVGzLUArghWQHy6D9EtB28rFqiVBiZgNJEluhF2KqKndrPdcBtBwggTiWORtygNVIbFjMQo5FA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bqJkRIUBnnTj9Ase6CIYZ/DNV1LGCUsf1tTHAcCJXj0=; b=HtFZ8vOggnB9gycoIn9Xe/Ko0PpsfzRdXuDv8WM2BPLkFOTdamip5St6pD3fSnWF1OskS2Y8ks6HtkYBeSua0VxJg+kAS/aksj7QDaoaqbmaXVmrdCF8NH9E9WkfKJDLEwJpINRXzKf2D4xi4ffbwJ1UlQNozeX77TQ38oU3eYI= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by LV8PR10MB7798.namprd10.prod.outlook.com (2603:10b6:408:1f7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.31; Wed, 20 Mar 2024 20:31:14 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::8aee:c094:84e2:9401]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::8aee:c094:84e2:9401%5]) with mapi id 15.20.7386.030; Wed, 20 Mar 2024 20:31:14 +0000 References: <20240313142441.180242-1-cupertino.miranda@oracle.com> <878r2lyz13.fsf@oracle.com> <87wmq5ysuf.fsf@oracle.com> <8734stx802.fsf@oracle.com> <87wmq5vsfl.fsf@oracle.com> User-agent: mu4e 1.4.15; emacs 28.1 From: Cupertino Miranda To: "Jose E. Marchesi" Cc: gcc-patches@gcc.gnu.org, david.faust@oracle.com, elena.zannoni@oracle.com Subject: Re: [PATCH 1/3] bpf: Fix CO-RE field expression builtins In-reply-to: <87wmq5vsfl.fsf@oracle.com> Date: Wed, 20 Mar 2024 20:31:09 +0000 Message-ID: <87zfusfxwy.fsf@oracle.com> Content-Type: text/plain X-ClientProxiedBy: AM0PR02CA0228.eurprd02.prod.outlook.com (2603:10a6:20b:28f::35) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|LV8PR10MB7798:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ebcb00d-e94a-4ca0-c9f4-08dc491cb012 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DXwEAEE1avRE3UI8o4LpoTSRn7paInMpT+tLso1fHzW+g0HmLSrbXQakGjYv9gL+9YP0vf3ddbINpL1VRqX6Hmnqj69NY/WCAbRW+oeUii7iXknchY1qGAJoAq87j2EN+zVhP4ar4mxT8MGycEzwKVTobR5A/PhdD+zdVl/9vto/GY8un+sH3se4hHiMxn6cKQwdebLK/o0e+Re5sUEntxy0ohv8qNmFsJ7aXcy77pD+cv11QedXxX06SH6OgtTGN6XyDaOOtwRVHv6Y5xPxRGvrhwsxeUJKidFJMwZWK/ozik6lsRSoPNrXx++o3nOwSffeTMfIuNqwEAkoaW2EGjY7Ig3wsXQtS225gxbvGTsi+k75V3fnS2Lx3lMPSh6GXIUnZ0xjwsQNPUZ7/hRwL/ic2WxvbA+Nf4EAAYzyrkBoEP2DZvz+6IS5S49iEpEvg2arJUcRdt64hYsEotGh4Ehg+aHWveVjKHXCYDXzqti9u3TLboiCRWoSZazBvSy/bRNkElIx2wWOgKZmeQ22Eu1pYZDZ+kJ5YxK59oUJdoVpAcTZHRz0DIEbAF6bHopZf9SN6dkqNlG1fZgEWQpO7Cl+nvTcKzdrhwJuSeSiHzc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wPZSh+Tk/kvFs7Yim3uUecaDCslRxq5Rm6TxUyGE2INRBdtqVDav0mnjFN8V?= =?us-ascii?Q?jv/TvebFwL9qSw7DdQiz1PTCni5ve/1ENrVkH5aiLr0+VUvPhj2blrPor79G?= =?us-ascii?Q?4yD0JgnH8zUP+ketmztWNXnay1ZZc49hXJW1W4+deQpkwwNvEgpxIj1cTW44?= =?us-ascii?Q?OWLh+dvyWzTD+BNUvBbV07L4e3mwZsnDV36fe4LNyWl7HFITqAYj4TW8QSHb?= =?us-ascii?Q?GcV9Vk4xnrBrkQT4fk0piv9NjWxh5jnqpWyRRbcqG61PyOA5PgqTkaIMoXlG?= =?us-ascii?Q?pHSaDY1e8OpPkiWBISCprqvbmRcUOmh3HAa8x6YFt9I6TMoMfsUZMKlx+oBJ?= =?us-ascii?Q?OV4SuEAV8qGQDeHJylqVbt0ZKSSQhrfXnB3D+wTn5E89Spt4BKEtS/BIgPOu?= =?us-ascii?Q?RaSpW9XcD1tboOJa7vc8CYqlABNJpWrGBryqTZrWtYrRwhuSJe3BEDu72lW8?= =?us-ascii?Q?n5L/eYWe1JcpPieeScw8ov9NYHOH35RP5J5TMOuNQ8HHLLggsvReB0UlOuZB?= =?us-ascii?Q?OtIhDFpRhYIcyhi7StPPrtLJ9Yu1qsxIQdINJl8wV+OEA1ilP808569wfi06?= =?us-ascii?Q?3Nrk4vZN1wUd11+byyMhTtIKrDi76TVFchTSi5Ea5w8nrC5mszKp9qLRuDRp?= =?us-ascii?Q?A/1mXBq11RoE+MKZCMfuj7WPVhyNUpFSgAu/HnvurAJ/PmHMHHMFECV64jKA?= =?us-ascii?Q?XwXV283mbYypMkQBNj3RcZMVmCgpZm4Ua1W0LvjWbw3I0Ky8fCHnorUmbMss?= =?us-ascii?Q?esMXfAKj+Eqq2uWtHGc7+Zk0lZD3zgcXcdg808KTGyBD6eDatEgaNB3Fytxw?= =?us-ascii?Q?k6qBOFCGYpXh2A0nqKJTE+NqX5xiK5iWVWVF9d32LQSPV22hUpvBHoQJKySb?= =?us-ascii?Q?V6b11PaiWrZLncS4UEuh/Dc82m9+GV6Is8yYJMyxcyiEzm3J8FiUfEaKq2Rm?= =?us-ascii?Q?4+UdeGKv0pP/is2N5HOyAplg2T7lq74m/8pLFkiqJVt9T4Chfh2bBob36AI7?= =?us-ascii?Q?QFe6Oyg4kjFyRhVXrFKbTOsOrVh03WmLu7LK3iBJPmds/lyhEYp8d2fYkq+v?= =?us-ascii?Q?UCHmxIenDI3T7L/WOeW8vtbaBRhgSIVm9p7xQum7fnUvxkqktIOX1LHpkJXF?= =?us-ascii?Q?6Pep+/H4oU2LEhWPl9qgCaaCQFqyWvnrTauSsz81UJrYQmqSPsp1smphuDtq?= =?us-ascii?Q?lSHqADyGV0eetcykQz3r52mIkPh1u49dnpwNtT6ODY5hSONDlqhoXR1w9bj7?= =?us-ascii?Q?/SEXHvqIJCu07j4To2MapKxm1tPV+dQ3iW3ckMxVk9HlZTKswwVbdSImTzSH?= =?us-ascii?Q?TyPMbzmaNM7gJVsEiAHoTnkEL43vWVSSloLulwqs200QoEUwjvMHuJrjEyfg?= =?us-ascii?Q?bJ7dSqCD/PXcAnWRubzcr5ZgurSCanyTdfndIj4LLepBFywn1Qpz9RtRplte?= =?us-ascii?Q?ExL8ri0O/QlDiPF1xJiba3jF2WnvifWQS9zyZLRSPrWD6KZagD2XYIYjijMF?= =?us-ascii?Q?CkKovvKFV2ZZVQQHFrdwNk79oRn0j7rU1tmeGPDyPWaGZF+U7xeWbDSsjVwH?= =?us-ascii?Q?z8Hzj7iLP9tBYdI9vDlMWDMd2jbLgIKzxNhH0QHkET0W/10iaOvdgxhPseoZ?= =?us-ascii?Q?q7Z89gTDTcbBWIoqrBiJ+ek=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Y/LBGEdz6oXNVC/lQsda7DxgeNn1PQXD7veLMWBKiiLGYBDX6wSg1sH1QXJcwtE+FadDZJHEBMGbU2yoQCZp9S7jNRmPfRDsPHnZ02XACvB56yXTH0boBLptw6lfHVv88tK80vFYf7Ib53ahp+E3ho823NAxJvY0D7jCZqMNJj+Qo7tGBCfHzaNJYoRBVS1K3IsK4G+tX16qKwTcGo43zfRLdOaXhiDDjjc7nk46ACT8wqgstP/Wac2n5LRGluI6Q3sE/ekg0y3d2Mv1vs8I1yesWnk5wcWUjvRib9PUrGbvPatTPLgYaGFAI/s8dTcID6JkIOuvDRwuqBN+KO5qSWrPfgxQArDYCLBxcR2sAA/3gi4R9f14E+oLzvLh9iTOFio5+3UO811K38HJIuLV+3D+LraDrkitz5hA8i2sdWGXNE8Wq37bMZOlNHZZS634IbJ72tGqYzVC3ED2IaXbJ9j2/tMlU0r+TAuPHhnXp/c4pOlxUrc33WV9LgmFGpkslvhrvkIr8y19LZ5MjzY4kxffTAvwsOuZHn/Kzosi1xBYP1Kq/u/wi6/YeKY8O2k5z4+ZM7PfoQ2AOxb3LHrkvtKa4wKxmGJI6BLU4z4TBqI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ebcb00d-e94a-4ca0-c9f4-08dc491cb012 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2024 20:31:14.4027 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6UVfRnq5hHPPGp/WAVhZTyizH7PsqnWRl4z9hTdTcHE1S5a76uvxha74sC7c780GG2qiy6M9ghdzlG2elbCWhCMjrfi4DZ8jD8FeFFCxjvk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR10MB7798 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-20_10,2024-03-18_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403140000 definitions=main-2403200163 X-Proofpoint-GUID: A4Y6YFj02rh9GgW5DYP3UZkJplAOrTJu X-Proofpoint-ORIG-GUID: A4Y6YFj02rh9GgW5DYP3UZkJplAOrTJu X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: >>>>> This patch corrects bugs within the CO-RE builtin field expression >>>>> related builtins. >>>>> The following bugs were identified and corrected based on the expected >>>>> results of bpf-next selftests testsuite. >>>>> It addresses the following problems: >>>>> - Expressions with pointer dereferencing now point to the BTF structure >>>>> type, instead of the structure pointer type. >>>>> - Pointer addition to structure root is now identified and constructed >>>>> in CO-RE relocations as if it is an array access. For example, >>>>> "&(s+2)->b" generates "2:1" as an access string where "2" is >>>>> refering to the access for "s+2". >>>>> >>>>> gcc/ChangeLog: >>>>> * config/bpf/core-builtins.cc (core_field_info): Add >>>>> support for POINTER_PLUS_EXPR in the root of the field expression. >>>>> (bpf_core_get_index): Likewise. >>>>> (pack_field_expr): Make the BTF type to point to the structure >>>>> related node, instead of its pointer type. >>>>> (make_core_safe_access_index): Correct to new code. >>>>> >>>>> gcc/testsuite/ChangeLog: >>>>> * gcc.target/bpf/core-attr-5.c: Correct. >>>>> * gcc.target/bpf/core-attr-6.c: Likewise. >>>>> * gcc.target/bpf/core-attr-struct-as-array.c: Add test case for >>>>> pointer arithmetics as array access use case. >>>>> --- >>>>> gcc/config/bpf/core-builtins.cc | 54 +++++++++++++++---- >>>>> gcc/testsuite/gcc.target/bpf/core-attr-5.c | 4 +- >>>>> gcc/testsuite/gcc.target/bpf/core-attr-6.c | 4 +- >>>>> .../bpf/core-attr-struct-as-array.c | 35 ++++++++++++ >>>>> 4 files changed, 82 insertions(+), 15 deletions(-) >>>>> create mode 100644 gcc/testsuite/gcc.target/bpf/core-attr-struct-as-array.c >>>>> >>>>> diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc >>>>> index 8d8c54c1fb3d..4256fea15e49 100644 >>>>> --- a/gcc/config/bpf/core-builtins.cc >>>>> +++ b/gcc/config/bpf/core-builtins.cc >>>>> @@ -388,8 +388,8 @@ core_field_info (tree src, enum btf_core_reloc_kind kind) >>>>> >>>>> src = root_for_core_field_info (src); >>>>> >>>>> - get_inner_reference (src, &bitsize, &bitpos, &var_off, &mode, &unsignedp, >>>>> - &reversep, &volatilep); >>>>> + tree root = get_inner_reference (src, &bitsize, &bitpos, &var_off, &mode, >>>>> + &unsignedp, &reversep, &volatilep); >>>>> >>>>> /* Note: Use DECL_BIT_FIELD_TYPE rather than DECL_BIT_FIELD here, because it >>>>> remembers whether the field in question was originally declared as a >>>>> @@ -414,6 +414,23 @@ core_field_info (tree src, enum btf_core_reloc_kind kind) >>>>> { >>>>> case BPF_RELO_FIELD_BYTE_OFFSET: >>>>> { >>>>> + result = 0; >>>>> + if (var_off == NULL_TREE >>>>> + && TREE_CODE (root) == INDIRECT_REF >>>>> + && TREE_CODE (TREE_OPERAND (root, 0)) == POINTER_PLUS_EXPR) >>>>> + { >>>>> + tree node = TREE_OPERAND (root, 0); >>>>> + tree offset = TREE_OPERAND (node, 1); >>>>> + tree type = TREE_TYPE (TREE_OPERAND (node, 0)); >>>>> + type = TREE_TYPE (type); >>>>> + >>>>> + gcc_assert (TREE_CODE (offset) == INTEGER_CST && tree_fits_shwi_p (offset) >>>>> + && COMPLETE_TYPE_P (type) && tree_fits_shwi_p (TYPE_SIZE (type))); >>>> >>>> What if an expression with a non-constant offset (something like s+foo) >>>> is passed to the builtin? Wouldn't it be better to error there instead >>>> of ICEing? >>>> >>> In that case, var_off == NULL_TREE, and it did not reach the assert. >>> In any case, please notice that this code was copied from some different >>> code in the same file which in that case would actually produce the >>> error earlier. The assert is there as a safe guard just in case the >>> other function stops detecting this case. >>> >>> In core-builtins.cc:572 >>> >>> else if (code == POINTER_PLUS_EXPR) >>> { >>> tree offset = TREE_OPERAND (node, 1); >>> tree type = TREE_TYPE (TREE_OPERAND (node, 0)); >>> type = TREE_TYPE (type); >>> >>> if (TREE_CODE (offset) == INTEGER_CST && tree_fits_shwi_p (offset) >>> && COMPLETE_TYPE_P (type) && tree_fits_shwi_p (TYPE_SIZE (type))) >>> { >>> HOST_WIDE_INT offset_i = tree_to_shwi (offset); >>> HOST_WIDE_INT type_size_i = tree_to_shwi (TYPE_SIZE_UNIT (type)); >>> if ((offset_i % type_size_i) == 0) >>> return offset_i / type_size_i; >>> } >>> } >>> >>> if (valid != NULL) >>> *valid = false; >>> return -1; >>> } >>> >>> Because the code, although similar, is actually having different >>> purposes, I decided not to abstract this in an independent function. My >>> perception was that it would be more confusing. >>> >>> Without wanting to paste too much code, please notice that the function >>> with the assert is only called if the above function, does not return >>> with error (i.e. valid != false). >> >> Ok understood. >> Please submit upstream. >> Thanks! > > Heh this is already upstream, sorry. > The patch is OK. > Thanks! Pushed ! Thanks ! > >> >>> >>>> >>>>> + >>>>> + HOST_WIDE_INT offset_i = tree_to_shwi (offset); >>>>> + result += offset_i; >>>>> + } >>>>> + >>>>> type = unsigned_type_node; >>>>> if (var_off != NULL_TREE) >>>>> { >>>>> @@ -422,9 +439,9 @@ core_field_info (tree src, enum btf_core_reloc_kind kind) >>>>> } >>>>> >>>>> if (bitfieldp) >>>>> - result = start_bitpos / 8; >>>>> + result += start_bitpos / 8; >>>>> else >>>>> - result = bitpos / 8; >>>>> + result += bitpos / 8; >>>>> } >>>>> break; >>>>> >>>>> @@ -552,6 +569,7 @@ bpf_core_get_index (const tree node, bool *valid) >>>>> { >>>>> tree offset = TREE_OPERAND (node, 1); >>>>> tree type = TREE_TYPE (TREE_OPERAND (node, 0)); >>>>> + type = TREE_TYPE (type); >>>>> >>>>> if (TREE_CODE (offset) == INTEGER_CST && tree_fits_shwi_p (offset) >>>>> && COMPLETE_TYPE_P (type) && tree_fits_shwi_p (TYPE_SIZE (type))) >>>>> @@ -627,14 +645,18 @@ compute_field_expr (tree node, unsigned int *accessors, >>>>> >>>>> switch (TREE_CODE (node)) >>>>> { >>>>> - case ADDR_EXPR: >>>>> - return 0; >>>>> case INDIRECT_REF: >>>>> - accessors[0] = 0; >>>>> - return 1; >>>>> - case POINTER_PLUS_EXPR: >>>>> - accessors[0] = bpf_core_get_index (node, valid); >>>>> - return 1; >>>>> + if (TREE_CODE (node = TREE_OPERAND (node, 0)) == POINTER_PLUS_EXPR) >>>>> + { >>>>> + accessors[0] = bpf_core_get_index (node, valid); >>>>> + *access_node = TREE_OPERAND (node, 0); >>>>> + return 1; >>>>> + } >>>>> + else >>>>> + { >>>>> + accessors[0] = 0; >>>>> + return 1; >>>>> + } >>>>> case COMPONENT_REF: >>>>> n = compute_field_expr (TREE_OPERAND (node, 0), accessors, >>>>> valid, >>>>> @@ -660,6 +682,7 @@ compute_field_expr (tree node, unsigned int *accessors, >>>>> access_node, false); >>>>> return n; >>>>> >>>>> + case ADDR_EXPR: >>>>> case CALL_EXPR: >>>>> case SSA_NAME: >>>>> case VAR_DECL: >>>>> @@ -688,6 +711,9 @@ pack_field_expr (tree *args, >>>>> tree access_node = NULL_TREE; >>>>> tree type = NULL_TREE; >>>>> >>>>> + if (TREE_CODE (root) == ADDR_EXPR) >>>>> + root = TREE_OPERAND (root, 0); >>>>> + >>>>> ret.reloc_decision = REPLACE_CREATE_RELOCATION; >>>>> >>>>> unsigned int accessors[100]; >>>>> @@ -695,6 +721,8 @@ pack_field_expr (tree *args, >>>>> compute_field_expr (root, accessors, &valid, &access_node, false); >>>>> >>>>> type = TREE_TYPE (access_node); >>>>> + if (POINTER_TYPE_P (type)) >>>>> + type = TREE_TYPE (type); >>>>> >>>>> if (valid == true) >>>>> { >>>>> @@ -1351,6 +1379,8 @@ make_core_safe_access_index (tree expr, bool *changed, bool entry = true) >>>>> if (base == NULL_TREE || base == expr) >>>>> return expr; >>>>> >>>>> + base = expr; >>>>> + >>>>> tree ret = NULL_TREE; >>>>> int n; >>>>> bool valid = true; >>>>> @@ -1365,6 +1395,8 @@ make_core_safe_access_index (tree expr, bool *changed, bool entry = true) >>>>> { >>>>> if (TREE_CODE (access_node) == INDIRECT_REF) >>>>> base = TREE_OPERAND (access_node, 0); >>>>> + else >>>>> + base = access_node; >>>>> >>>>> bool local_changed = false; >>>>> ret = make_core_safe_access_index (base, &local_changed, false); >>>>> diff --git a/gcc/testsuite/gcc.target/bpf/core-attr-5.c b/gcc/testsuite/gcc.target/bpf/core-attr-5.c >>>>> index e71901d0d4d1..90734dab3a29 100644 >>>>> --- a/gcc/testsuite/gcc.target/bpf/core-attr-5.c >>>>> +++ b/gcc/testsuite/gcc.target/bpf/core-attr-5.c >>>>> @@ -63,5 +63,5 @@ func (struct T *t, int i) >>>>> /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:1:2\"\\)" 1 } } */ >>>>> /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:1:1:1\"\\)" 1 } } */ >>>>> /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:0\"\\)" 1 } } */ >>>>> -/* { dg-final { scan-assembler-times "bpfcr_type \\(struct T \\*\\)" 4 } } */ >>>>> -/* { dg-final { scan-assembler-times "bpfcr_type \\(struct U \\*\\)" 4 { xfail *-*-* } } } */ >>>>> +/* { dg-final { scan-assembler-times "bpfcr_type \\(struct T\\)" 4 } } */ >>>>> +/* { dg-final { scan-assembler-times "bpfcr_type \\(struct U\\)" 4 { xfail *-*-* } } } */ >>>>> diff --git a/gcc/testsuite/gcc.target/bpf/core-attr-6.c b/gcc/testsuite/gcc.target/bpf/core-attr-6.c >>>>> index 34a4c367e528..d0c5371b86e0 100644 >>>>> --- a/gcc/testsuite/gcc.target/bpf/core-attr-6.c >>>>> +++ b/gcc/testsuite/gcc.target/bpf/core-attr-6.c >>>>> @@ -45,6 +45,6 @@ func (struct T *t, int i) >>>>> /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:3\"\\)" 2 } } */ >>>>> /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:1:2\"\\)" 1 } } */ >>>>> /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:0\"\\)" 1 } } */ >>>>> -/* { dg-final { scan-assembler-times "bpfcr_type \\(struct T \\*\\)" 3 } } */ >>>>> -/* { dg-final { scan-assembler-times "bpfcr_type \\(struct U \\*\\)" 2 } } */ >>>>> +/* { dg-final { scan-assembler-times "bpfcr_type \\(struct T\\)" 3 } } */ >>>>> +/* { dg-final { scan-assembler-times "bpfcr_type \\(struct U\\)" 2 } } */ >>>>> >>>>> diff --git a/gcc/testsuite/gcc.target/bpf/core-attr-struct-as-array.c b/gcc/testsuite/gcc.target/bpf/core-attr-struct-as-array.c >>>>> new file mode 100644 >>>>> index 000000000000..3f6eb9cb97f8 >>>>> --- /dev/null >>>>> +++ b/gcc/testsuite/gcc.target/bpf/core-attr-struct-as-array.c >>>>> @@ -0,0 +1,35 @@ >>>>> +/* Basic test for struct __attribute__((preserve_access_index)) >>>>> + for BPF CO-RE support. */ >>>>> + >>>>> +/* { dg-do compile } */ >>>>> +/* { dg-options "-O0 -dA -gbtf -mco-re" } */ >>>>> + >>>>> +struct S { >>>>> + int a; >>>>> + int b; >>>>> + int c; >>>>> +} __attribute__((preserve_access_index)); >>>>> + >>>>> +void >>>>> +func (struct S * s) >>>>> +{ >>>>> + /* This test is marked as XFAIL since for the time being the CO-RE >>>>> + implementation is not able to disambiguate between a point manipulation >>>>> + and a CO-RE access when using preserve_access_index attribute. The >>>>> + current implemetantion is incorrect if we consider that STRUCT S might >>>>> + have different size within the kernel. >>>>> + This example demonstrates how the implementation of preserve_access_index >>>>> + as an attribute of the type is flagile. */ >>>>> + >>>>> + /* 2:2 */ >>>>> + int *x = &((s+2)->c); >>>>> + *x = 4; >>>>> + >>>>> + /* 2:1 */ >>>>> + int *y = __builtin_preserve_access_index (&((s+2)->b)); >>>>> + *y = 2; >>>>> +} >>>>> + >>>>> +/* { dg-final { scan-assembler-times "ascii \"2:2.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 { xfail *-*-* } } } */ >>>>> +/* { dg-final { scan-assembler-times "ascii \"2:1.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */ >>>>> +/* { dg-final { scan-assembler-times "bpfcr_type" 2 } } */