From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 621293858C3A for ; Wed, 13 Mar 2024 14:25:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 621293858C3A 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 621293858C3A Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1710339940; cv=pass; b=CE4N7LJHhyyOHt6S/bSQ0nul/0PmFQaN/gpdHLWrROWPyzQZ/+foBMuH2dTZL1cO15IhIp1vOnU5BAQk5syekzUoNjtQR2ClvxIMivqEorg0ziUwVOfDRpNVqdFVIg1/xr+PnyQlaJ5c4jsjjOpEkVPk2K7t+XVOrr+cSp8mtX4= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1710339940; c=relaxed/simple; bh=y+Lg99wBI7g6ZfXSknrqTVbApioTjb8gYt90TT2gr7Q=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=TUkGKR1Py8UcqftLGFXj/R/egFadWm8fkLOQY0i7Rcici2hOOk7BCTb8FXk33WG77HT/JryNlDM/tX71NlKu4CuvW6JUBPwkpB4xIoWnAH5rEQW4RAhdpWhPwAuO+S8t1WQ3NEukyDgLNnwCS1rBNO2G7hvPD0HrEoHssvBM0+0= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 42D8hrqp000680 for ; Wed, 13 Mar 2024 14:25:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=y2EuxRfqPMG5QkGo7gw+x+W39S0hjVC/y3sUD2o6mys=; b=bRuZano2TG/VRdDKfF334MDAsnfzgY9MvRhKfnoAbd+Hg8omP4cm2L95L1kV055YxVMA jbp4EsNKKr0cTWBR53qijd1HtUWxJP1cYAA2l9a7EBkujjedv1QVbC5OZmau0xsPK1xg pwhxU5MwdFvqAHFNDP6PDfbsLolokeRE6sRhJaJqbQ+LPLUzEvDkOg6IlXOjcOe4QhlK IwHfPKJhdjHvCLbskYxc1WYOgrLXFehxzkUPIovPs9NH9czuJzRRYswIu5YqwrmbxAiv xD9Whp1L6xAOIJLArR5ClXJsKoW5235CYo7Mn8e6SVvlrNhs02M0b78h+BYv4ZRycYZb Ag== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wrftdh7b7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 13 Mar 2024 14:25:37 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 42DE9UPZ033788 for ; Wed, 13 Mar 2024 14:25:35 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wre78mmhm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 13 Mar 2024 14:25:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HzXYgauvSGW9gIhzbAfuf/FKzP1YG1DRO3EQ5EdrZVKcmy8ROmFM5iED8Hyp7XTM9Tiwl2aXs7ho6HK0ayMpAKBbxad2dmSG59xyOKl2ZJpyLGDxOC+ncbraemZ8IknNvisbOtxnYNUKlB+oQcnp051ixq21PSdJvV0nklmCntdElG3QvVCjKlh6PG/O85coGU7zwSndoz3PZ1kZzOECZxb961PfWgo4JfIXQKqQ54qtEe+C37cdYI1eCAAwicEC1vdu1l0md+IBsNX6Jyw4LFJFSzaaAZcy2xaq0d0ELES6heznuin2fADPFR3obhrUPwtAmQt/FUT/nETLzj4E6w== 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=y2EuxRfqPMG5QkGo7gw+x+W39S0hjVC/y3sUD2o6mys=; b=j30t6GdmsLoIQoDEiQJ1eMQne7OaF4+JoXP432tL3OE30QbosWdfgvZN9RXcZ4n9Kvm/kBsh5O7xcZc4omintf7pxF2zUQCbf5NZxnJ3GUTRy7/1l+YT0zmUGiBfkBGWaN5yyV0PX1Zv/nck8laNKeOTQGnJW7v5zwprcF9ALnBampAtmFSrcQBS0y3q0nEQeFNOQ9PW2qdUKCyXDufMvTnbkL7/64CMGQRO3vEkXEClAM488p4EV2+t11gCWJ8t5BOY5lLglN43qrNWa9TPLYHoIXys4qZLldYZ1b9qIMcGJfKR35t6BgzH0my+k+WewtD7So/sw5ewH5ETekMgXQ== 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=y2EuxRfqPMG5QkGo7gw+x+W39S0hjVC/y3sUD2o6mys=; b=tZBCBDgOn97t0TvWOFk887KwppWgbWRG3vpUAZcnpa9WUUIN6Sr/MrEVdkoF7KOAlicOUaEOc3pbu68QH+73nXAyo90Vjc8a+bVkR4j8y1xHxOBUIwQP/P4NKlQCl0I7FGg7dK3r7Y91Hhqoz+FNXrYpxof39KK2T/OzBaQXTD8= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by BN0PR10MB4888.namprd10.prod.outlook.com (2603:10b6:408:115::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.21; Wed, 13 Mar 2024 14:25:33 +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.017; Wed, 13 Mar 2024 14:25:33 +0000 From: Cupertino Miranda To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, david.faust@oracle.com, elena.zannoni@oracle.com, Cupertino Miranda Subject: [PATCH 1/3] bpf: Fix CO-RE field expression builtins Date: Wed, 13 Mar 2024 14:24:39 +0000 Message-Id: <20240313142441.180242-1-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: AM4PR0302CA0036.eurprd03.prod.outlook.com (2603:10a6:205:2::49) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|BN0PR10MB4888:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e62bd44-9a09-498a-c67b-08dc4369714b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CqDn7c+2Yk8n4Q9VRCBmks1/gEZqjTcBYrvCsjGDEwBNeeNUVXyi/qPaIWgLDQrtwqRJ3J59s/8dclZPTGUDbH9dcmtVN1FT9QdpKX/xT7Jba/Ss2PKqTXTs/jvQuRQTHt4LS8zoV/GVZC63vq77yve2mzoNtrVP7IUF82eclvrGo9cxHF9OeSWMNU8xKgIIleBYvCiIbXlfpueJM+KKRxefA9on5hgGrbycYn7HvvBKFYU7gj1Ry6nh8pvTQoXi4j8n6274G4qqI+1WmnNf3PkpeeX+Ea9MaO0JUqFT7hg8dggasgCbPDO0gWDXwVgFomBhp9XckTKDzrlxr1NJEztBi5pAsTdDE/iu6Fp1Mr85qsGuk45immztNa/bcCJ/KojuNOQzjyFRA88E/ZBxv5/GbFScG/bgdoKLodVc3I3qFjI1jD4I5C3M8Wn2HZCVTHJ6I2KYr1VfdFeDgM2Hq7Gua6Bt5YtfkhXAA4XDybW9SW0D9WdNiXocyONyyJ6GqSVjAf8Ld5zA3uSNLAif+N61CGRnm5qG7Y+unJxPXVU6saqJdBSCdwt3NwOJPxCVOtKnGAmvSnG7gbuqKNQvy9R+pjKnGgDrEP3wY8gvlSsfJZSC5ksh5aFLyGRHTykO 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)(1800799015)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CM55e5Yxn71EfwC3m2CN/ONuTvQcTBx3c/K6QNeRDWdoSjvmg/RJeSwuQ05w?= =?us-ascii?Q?8Wih5qa8+dR3Wl8n2dvfQPx2mebY3pYCcdUZvDTMSdjw8MtnB/+PqYE1othC?= =?us-ascii?Q?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+wIHplGDBKbld9NbtVV6Fya0hKcCKsGDKcI43+fFMlhyBc5T0gKmg0opmzBPwDInpVgkyLQSD60Nl7KMENnQF+wGFH0k+SWADG4WTgkqnqREL4Y8z9FuFPTTRa+qFjSeC0oylsrzG1x+1AG0YANNGpvs7RsUrRqCTrSz/7JLirWTh5WL1PSmqMYqC0DhMusB9vLOSLXuVFMetOcOuA/bqfSUN8BqVWPz1PgwKQuuZVVwuthvb7ZilqaPUYVxoNZhnUG4CmorKTiYvATx9CO8cWJu7DzSRiXmr7pv44VvobboGjxfHJ6tvU8lxJOeK+UQqyOqqeceTirdioqwNdCVpq2xZ40BrkOQ/4+OyNJ8tFNsX2z8fo1E/GbJfW5Nn5chyF+gvRSUXXQ3Bc2emMm/0RRDFnUmf0J+UVMsFpU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e62bd44-9a09-498a-c67b-08dc4369714b X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2024 14:25:33.3204 (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: gnHXR/Yr5z11w6UjuXyjMP4OnB4xlGMoK9xlg4SAEBNCd5yvxnunoonQdp5vQgzXJPZ0Jwz0pNePGlJ8WecLlRXSJmdosqbtYyj5J9gk0cE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB4888 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-13_09,2024-03-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2403130108 X-Proofpoint-ORIG-GUID: uSxcP7nUlkX8GpJDgf070zESPtTgaSXq X-Proofpoint-GUID: uSxcP7nUlkX8GpJDgf070zESPtTgaSXq X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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))); + + 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 } } */ -- 2.30.2