Message ID | 20220829201827.7419-1-david.faust@oracle.com |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1573739wro; Mon, 29 Aug 2022 13:20:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR4po6kkS4fgQvIB1AU5/hsu3zsxhQiMrw4MG+74v7SJ+l87spGg4NDC77ln8S3Pe64eb/pn X-Received: by 2002:a17:906:a0d3:b0:73d:be5b:2b52 with SMTP id bh19-20020a170906a0d300b0073dbe5b2b52mr14992706ejb.727.1661804406950; Mon, 29 Aug 2022 13:20:06 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hs4-20020a1709073e8400b007317ce725aesi8140798ejc.976.2022.08.29.13.20.06 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 13:20:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lJgRjbKX; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45E16385AC1B for <ouuuleilei@gmail.com>; Mon, 29 Aug 2022 20:20:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45E16385AC1B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661804401; bh=INARqg6JOKRBgOhaYDcKL7l0v3wnEQeRWMpF5sdpHQ0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=lJgRjbKXecQSmbIiXkxMmJjGeejzNjRa8OMZVR8S54J4f0Mc/GxHhG0NCDlI2mUJT OgvdS1h8L8bicwSN93Nx0pbXVgxgqgioXlrZ4n0MQq2J3LbO3oFe1ervBAbvMRM+Nz ndGnAU90cnxnmsDD8rUTzpb48uzACHOksNxcN5fE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 213FF3857022 for <gcc-patches@gcc.gnu.org>; Mon, 29 Aug 2022 20:19:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 213FF3857022 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27TKFtZO000585 for <gcc-patches@gcc.gnu.org>; Mon, 29 Aug 2022 20:19:13 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3j79v0mgj8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <gcc-patches@gcc.gnu.org>; Mon, 29 Aug 2022 20:19:13 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 27TJnpbV003449 for <gcc-patches@gcc.gnu.org>; Mon, 29 Aug 2022 20:19:11 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2172.outbound.protection.outlook.com [104.47.56.172]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3j79q36kwy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <gcc-patches@gcc.gnu.org>; Mon, 29 Aug 2022 20:19:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lntiYnkjktY92r07uFGtyED/J2IMKn5YA+x5NvgfcVweCpRvaHiXEBtDJjEmMfUXfgaWzPk/ydS7avp0euJw6runNSv+410orCtOBDg3/X+VXiFDvuPeUoZfMkYKfVJEm5rVbcbDTGu2SQN/N3caQY2QLTNgZw0J67bf0hb1ehdyNuXVNxbOcfXdzGGMDZrP2m/GbN+lyvYYRkBPJ24PiIF0yF7PvLvK9Z65ltAJA+KulHCLTU+OJxOJAivWk2lThTAoZuLV3VYkatjKjzJaf6ule1k4WKwtKlVgZx1GjCTJUO0WxPYAACl5/8UquEFAp1ruy2OZqFg5Tt0yR3jb2g== 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=INARqg6JOKRBgOhaYDcKL7l0v3wnEQeRWMpF5sdpHQ0=; b=J5u+w5wTuFaTLpgmAdAdqwSPx0JS0A82UrcM1dDpFqQK9qsl5tQA0YrVgzjtAOROVIrMsKVwcEAQddf8heg6miMC97KOSPqM7/3y1mzhkRKpD0bmDSn9Fm9uCJ9rmc/k5kYmFdMQPvKrNYZJYpQmeNuFwBUUbrk/zgHOVl2e6tO5+vbCeIxQ/FQpmqWSSzn6eWZVx+1DQQLnNwKBqFHYfSHsGxkayYdGG51kQHQamPPjRyeoM4XLUjJQcnWU2JQBWkXqZqhPY/W1fiuSDi/TJ6n/yaI/mk6c8UpxrAvDBBP7xsgXOyGQyYsSZ+7W/PKovW0Ptas77V4bNohXAWBhsA== 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 Received: from MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) by BLAPR10MB5380.namprd10.prod.outlook.com (2603:10b6:208:333::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.14; Mon, 29 Aug 2022 20:19:09 +0000 Received: from MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::815f:640c:8792:186b]) by MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::815f:640c:8792:186b%5]) with mapi id 15.20.5566.021; Mon, 29 Aug 2022 20:19:09 +0000 To: jose.marchesi@oracle.com Subject: [PATCH v2] bpf: handle anonymous members in CO-RE reloc [PR106745] Date: Mon, 29 Aug 2022 13:18:27 -0700 Message-Id: <20220829201827.7419-1-david.faust@oracle.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <874jxuu8jx.fsf@oracle.com> References: <874jxuu8jx.fsf@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ0PR05CA0170.namprd05.prod.outlook.com (2603:10b6:a03:339::25) To MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8b65ddc7-a788-44c6-90d1-08da89fbbab6 X-MS-TrafficTypeDiagnostic: BLAPR10MB5380:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S8yDecbAGITnaOdYr+WbWbVQBlZADSmEWvU8PgysJuvejQZRr6AHajeOFDP52xvsXRtDbXey+j/IZCSv14lD7Y5eu+WXvbGeaOokEnWvGfajD5oKZenULagWEi+hZBpFClHAgiPabGk3bUBF4rlIhl8yg58Wbgh41pXtMdQj2O7w7siVgiQ+4ImLCJNJrecZU93hFOHofV92+5L+vAopmz4HiRP3mWMHAi2JKFqUs9A49YpzcMWJUljesxozzRXy8POjj2wU93cQxTofWhfynPaPX7+nDa0w0jGlI3ZTxbl7eCp5AMOhv/N21p5WVdb8SDoi4yRqw+H7rp49dKR0SvNg58ZvWbPKEGhq7j21c5PmmGnIADCO7mQLXqzb9dDsprv4IWCjY7syLaZfyvx4DEssO9mJH8vFIJ5S7UoU1YamLkxybAK2SWLTmHK+xD7uhc5lPRgJRmzu396ooe7cS3IoY9Nag+/p7cREBV0Sfv1t+E6r8ooujAxnSt9AJEDOS1AhY4zh67IbAynb4Tu0TNOCS8BEZ9f5O7iio4Ki2Ff2PRy+Dzs5GNWqa3SYEESgOxv2TaQatVoZBNay3CNw53UI6coTQTZ0snorMdOjDjnb2mAyLHmbIV3Tc4YIOAIhmBexYw+sOKA/jxXdTsNO1DIqUPIPuLPUYwhJmM2583QaX7WLDeaKYJ7nYLgFW/XMVvME1X5ypP3/cZWGqM8dLvxvYBiV/6EvbOGiH51pqAs= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB3213.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(376002)(136003)(366004)(39860400002)(346002)(396003)(4326008)(44832011)(38100700002)(66556008)(186003)(316002)(8676002)(83380400001)(84970400001)(6636002)(6486002)(478600001)(6666004)(41300700001)(26005)(86362001)(6512007)(1076003)(37006003)(66476007)(66946007)(2616005)(36756003)(6506007)(2906002)(5660300002)(8936002)(34206002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LXiCsvI/CteO5qUJdbST6lrPH/iUqgD+FXoPUaCRKn5ptVejqwqopzQLg5ZEarnvnc1ugo9pmZWWs2rXSZdNnALHLSkE6IXcOvQtd8wwSbkK7pZdMZOxR4J21XtUJ0KsdqLGR9hksCc/XZNl4TEHzbM7BVWB9skCzhm+L+pwyLvfbIgHgsvrJXl3pXfc+W8Ddga/WCQP4YqEd7yYcmHmG7kPcl7G37Flk8uOx8PBL1CL6w+HwtK8EQBo64Kph8748uPd3fbhblcRQuJGoQo5OYEWPW8HIOZbsPlQ6/0WndZaGxf4Hhg7WR2b8Nk6MJGUbolDEo7+iljq19J90LY+xyIEE08OdiH6UTQe4GlJsih5dZ95yr4exzNSBtlJapnZUlekSoKp7Zqzn2wmunEFs/aKnXNHipsxyTRiq2MYJMxFTjurUY8PFwR7sI3oRRNx8DbFpXOMHBvWlWWXpm5hu7bWU3/C78K9jhCbf/gdo4PVSqDaja0+98odboYnVfL5EMksqz8avhmMuEOMffTriCyiVM4ryVuK8Bcv/qYY7YeJG907BKxDtaFNooZ+M6/MCCJXmcqhrZHZ2F0juC4XbL9i4nbOuEdfviWTo3kv8ValI4GAKXNAPUeSLQzOZ7ymPybLMK9jq1G29jpHpLmwy868qPb7jllbTx+hMg/nZQlEv3j438L//hf7BOU+BZ6/TiHFJQxenhPuXM/0mrsE66IZHWJboV5uQq3Bv6M2sDdpA+yFM7QAXcdUU53v46SmtsSo7kM8phj5WZwQTIQJojmPhiqt4TUdshlRnR+E/hNxQPfP4QkLjktnhORapd9mX2zzyZuwIhCSej0dabUhHVVxKUJbYK7kOcTDFuurqoqnZA8HWpCTCkeU4dqcVnlUiOtFKcK9yZsx+BWvNs4GzrPC6sUpNSbM2zcpPDR5wGA/jhrIb0ql2+X5xM8hUtmCjqlV2ar46my1GuKKCk512IkJC0rCIqg2YT+rtCy9Se9ZOkPLkr5unfIiyNJ9NgkmtfFCwrVbQyR6ZBTe0APpG5can0/2uH0sNJZNQ9RwuBr3pOjxUExNv2JF6BN0wGU3mUIxmF3mxF3OFw2FuZT+wpsvcttEIMJDKKmAqi+BXM479uk/+6o6BEo8gFW+vbAfSUv4DUam0K/kmVoakyJBfd4P7BRK4XOki5b11o1oPYi5ZT5iYTSdm/qAslMjAMQ6abR/knR43SEBU1Lu9CT3hLpcOjBjTOsZYHGikfwb1Y2KML6KlguBfCFUwre2sXOj6fKjSA/o1QlbeWkz9FZB1otMLDqjZxLRGAQVhXmkjdpjkNE1cERRO3vOxc5i7MlOuy3cIaVhnxZHdysXiQuJM3LI8fhfEIjKCQXmSETSgrp/w0q1tdQdpAnhtgSh+q9w6mbTiKqbu08qHa80nb69Sz6SLsSHxVt2iSGo/KEEHT/bcS7P2Ou9SR+5Aw1uT7tDJYQ+rhWNyHFgmcwlW+7tAfmALMdmwxAw3H25PZvvbmQBH9PY16RbyvDJLoncuthLwz3kmsjzf2W6/gLmwo8XHADCDcV6vFoSDZSMYeAFh7bbRRnXf+VAkvvriPt3AwGR X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b65ddc7-a788-44c6-90d1-08da89fbbab6 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2022 20:19:09.2107 (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: Ag6nsG+RjNHJGQi5dwNwICsVAtKWu/4WqGvIGyVyY5OrQW85RUn1f9tEE4zj8UeBgFHKROq4sNPXVT9qojx8UA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB5380 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-29_09,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxlogscore=999 suspectscore=0 adultscore=0 bulkscore=0 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208290092 X-Proofpoint-GUID: l-7UbwCDuWFGebzSBaHBA-G2p9kd3cEM X-Proofpoint-ORIG-GUID: l-7UbwCDuWFGebzSBaHBA-G2p9kd3cEM X-Spam-Status: No, score=-13.0 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_H2, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: David Faust via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: David Faust <david.faust@oracle.com> Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742522801643179268?= X-GMAIL-MSGID: =?utf-8?q?1742528217881785894?= |
Series |
[v2] bpf: handle anonymous members in CO-RE reloc [PR106745]
|
|
Commit Message
David Faust
Aug. 29, 2022, 8:18 p.m. UTC
[changes from v1: simplify the new conditional logic as suggested.] The old method for computing a member index for a CO-RE relocation relied on a name comparison, which could SEGV if the member in question is itself part of an anonymous inner struct or union. This patch changes the index computation to not rely on a name, while maintaining the ability to account for other sibling fields which may not have a representation in BTF. Tested in bpf-unknown-none, no known regressions. OK? Thanks. gcc/ChangeLog: PR target/106745 * config/bpf/coreout.cc (bpf_core_get_sou_member_index): Fix computation of index for anonymous members. gcc/testsuite/ChangeLog: PR target/106745 * gcc.target/bpf/core-pr106745.c: New test. --- gcc/config/bpf/coreout.cc | 16 +++++++---- gcc/testsuite/gcc.target/bpf/core-pr106745.c | 30 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.target/bpf/core-pr106745.c
Comments
> [changes from v1: simplify the new conditional logic as suggested.] > > The old method for computing a member index for a CO-RE relocation > relied on a name comparison, which could SEGV if the member in question > is itself part of an anonymous inner struct or union. > > This patch changes the index computation to not rely on a name, while > maintaining the ability to account for other sibling fields which may > not have a representation in BTF. > > Tested in bpf-unknown-none, no known regressions. > OK? OK, thank you. > Thanks. > > gcc/ChangeLog: > > PR target/106745 > * config/bpf/coreout.cc (bpf_core_get_sou_member_index): Fix > computation of index for anonymous members. > > gcc/testsuite/ChangeLog: > > PR target/106745 > * gcc.target/bpf/core-pr106745.c: New test. > --- > gcc/config/bpf/coreout.cc | 16 +++++++---- > gcc/testsuite/gcc.target/bpf/core-pr106745.c | 30 ++++++++++++++++++++ > 2 files changed, 40 insertions(+), 6 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/bpf/core-pr106745.c > > diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc > index cceaaa969cc..8897a045ea1 100644 > --- a/gcc/config/bpf/coreout.cc > +++ b/gcc/config/bpf/coreout.cc > @@ -207,7 +207,6 @@ bpf_core_get_sou_member_index (ctf_container_ref ctfc, const tree node) > if (TREE_CODE (node) == FIELD_DECL) > { > const tree container = DECL_CONTEXT (node); > - const char * name = IDENTIFIER_POINTER (DECL_NAME (node)); > > /* Lookup the CTF type info for the containing type. */ > dw_die_ref die = lookup_type_die (container); > @@ -222,16 +221,21 @@ bpf_core_get_sou_member_index (ctf_container_ref ctfc, const tree node) > if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) > return -1; > > + tree field = TYPE_FIELDS (container); > int i = 0; > ctf_dmdef_t * dmd; > for (dmd = dtd->dtd_u.dtu_members; > dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd)) > { > - if (get_btf_id (dmd->dmd_type) > BTF_MAX_TYPE) > - continue; > - if (strcmp (dmd->dmd_name, name) == 0) > - return i; > - i++; > + bool field_has_btf = get_btf_id (dmd->dmd_type) <= BTF_MAX_TYPE; > + > + if (field == node) > + return field_has_btf ? i : -1; > + > + if (field_has_btf) > + i++; > + > + field = DECL_CHAIN (field); > } > } > return -1; > diff --git a/gcc/testsuite/gcc.target/bpf/core-pr106745.c b/gcc/testsuite/gcc.target/bpf/core-pr106745.c > new file mode 100644 > index 00000000000..9d347006a69 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/bpf/core-pr106745.c > @@ -0,0 +1,30 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O0 -gbtf -dA -mco-re" } */ > + > +struct weird > +{ > + struct > + { > + int b; > + }; > + > + char x; > + > + union > + { > + int a; > + int c; > + }; > +}; > + > + > +int test (struct weird *arg) { > + int *x = __builtin_preserve_access_index (&arg->b); > + int *y = __builtin_preserve_access_index (&arg->c); > + > + return *x + *y; > +} > + > + > +/* { dg-final { scan-assembler-times "ascii \"0:0:0.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */ > +/* { dg-final { scan-assembler-times "ascii \"0:2:1.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc index cceaaa969cc..8897a045ea1 100644 --- a/gcc/config/bpf/coreout.cc +++ b/gcc/config/bpf/coreout.cc @@ -207,7 +207,6 @@ bpf_core_get_sou_member_index (ctf_container_ref ctfc, const tree node) if (TREE_CODE (node) == FIELD_DECL) { const tree container = DECL_CONTEXT (node); - const char * name = IDENTIFIER_POINTER (DECL_NAME (node)); /* Lookup the CTF type info for the containing type. */ dw_die_ref die = lookup_type_die (container); @@ -222,16 +221,21 @@ bpf_core_get_sou_member_index (ctf_container_ref ctfc, const tree node) if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) return -1; + tree field = TYPE_FIELDS (container); int i = 0; ctf_dmdef_t * dmd; for (dmd = dtd->dtd_u.dtu_members; dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd)) { - if (get_btf_id (dmd->dmd_type) > BTF_MAX_TYPE) - continue; - if (strcmp (dmd->dmd_name, name) == 0) - return i; - i++; + bool field_has_btf = get_btf_id (dmd->dmd_type) <= BTF_MAX_TYPE; + + if (field == node) + return field_has_btf ? i : -1; + + if (field_has_btf) + i++; + + field = DECL_CHAIN (field); } } return -1; diff --git a/gcc/testsuite/gcc.target/bpf/core-pr106745.c b/gcc/testsuite/gcc.target/bpf/core-pr106745.c new file mode 100644 index 00000000000..9d347006a69 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/core-pr106745.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA -mco-re" } */ + +struct weird +{ + struct + { + int b; + }; + + char x; + + union + { + int a; + int c; + }; +}; + + +int test (struct weird *arg) { + int *x = __builtin_preserve_access_index (&arg->b); + int *y = __builtin_preserve_access_index (&arg->c); + + return *x + *y; +} + + +/* { dg-final { scan-assembler-times "ascii \"0:0:0.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */ +/* { dg-final { scan-assembler-times "ascii \"0:2:1.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */