From patchwork Mon Aug 29 18:52:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1545146wro; Mon, 29 Aug 2022 11:54:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR6MpUpRXzR1jbpEq9E/PegPN3p6FrIS1wCP/j4Snq/t/tIVBu+RtX3upZBFKGvXBBISGR0c X-Received: by 2002:a17:907:781a:b0:730:ccea:7c29 with SMTP id la26-20020a170907781a00b00730ccea7c29mr14449380ejc.85.1661799241724; Mon, 29 Aug 2022 11:54:01 -0700 (PDT) Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dp17-20020a170906c15100b00711988b5919si7439391ejc.810.2022.08.29.11.54.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 11:54:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Vw23UfUq; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 7A6F33857B85 for ; Mon, 29 Aug 2022 18:53:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A6F33857B85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661799238; bh=OIbavq2lD+Z0/yCHA7/fMWeczhJoDgfRpn/Uii8Dkxs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Vw23UfUq56XKGySQRmZS7e3ojaO+tjJCWRmYJpqHIlaLTlJxqCvUausBI0/0bjLVP 7cGZ5aosRLzsP4opegLTvWabPdw69oDBCTZ9yCDZvreQzc5Yfu7Ao16HhbZwGd/xYs bPQbYd3ikecYOIcTmGymtho+L4Str2tP/OALgZSY= 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 424653858C20 for ; Mon, 29 Aug 2022 18:53:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 424653858C20 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27TIi13h030144 for ; Mon, 29 Aug 2022 18:53:05 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 3j7btt4806-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 29 Aug 2022 18:53:05 +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 27THoYNp002926 for ; Mon, 29 Aug 2022 18:53:03 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3j79q32uwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 29 Aug 2022 18:53:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SZ/ghraJrYF80lfHmZg9Fp5x3sMfNzsDYbZ1TOj+7t8GJk5HDZddj2Rr759lj1NEZs3U65ee2P1kp5HwQCieCnhZAg53y341pIVJCTqh96SnFlDAGZ5YOI8MeUzh/nz79qIIU9BFk1ecMsSAt4ki2J5SoNGX9KruBBM0ok8HsFP19/DhXSzzN7UKmKekgJczSo3JPpfhmyE4CV7hZu/r8SWO/Glfud0TvreCH9OrSwMMMXNtvEADe3aad8Q7i0WlIl4GWsZIGZcbZV4znguCFuk+Qs0OPva9+ps4Hbt1KBhW585ptPibVkgml1qrT8KWP1BMmj8Pwu2rOHQn8/aSFw== 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=OIbavq2lD+Z0/yCHA7/fMWeczhJoDgfRpn/Uii8Dkxs=; b=PnpcgNmV7SfYDNZzvyXTRQ/lWZBE8+PR0SYyMp4sDIV2Qb5rGqpazln7L0a5ngzDZiUWqigB/ufGFadz0XI29s82T9HTVJEWbWPQ3Xh4qkQuVTz5jnk98wr7OuBYKWS+d8p+Qau2fqkJ5pScMaXxF7zIOp6DEJeiYwAgismnCwldhKB9Uxe7emr2bQuCCH2D2qp6c9KYkSCrrLTpHd6hNfzXUWIgVwAHGr6R/4Xw0JMxNkLrCjy8Np5GPFUTUlShkwBDrlvive/hP/3YbP1kycWUEbPmxTYtM7FMH7XGK9tMwhsnLfBg6bie0JElGyQfptRMcDJ7B4xGJeiWDqKAyQ== 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 CO6PR10MB5553.namprd10.prod.outlook.com (2603:10b6:303:140::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.19; Mon, 29 Aug 2022 18:53:02 +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 18:53:02 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH] bpf: handle anonymous members in CO-RE reloc [PR106745] Date: Mon, 29 Aug 2022 11:52:55 -0700 Message-Id: <20220829185255.5550-1-david.faust@oracle.com> X-Mailer: git-send-email 2.37.2 X-ClientProxiedBy: BY3PR10CA0022.namprd10.prod.outlook.com (2603:10b6:a03:255::27) 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: e3d6ff8e-3f62-4ab2-5a32-08da89efb2e4 X-MS-TrafficTypeDiagnostic: CO6PR10MB5553:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uQx6hZpQ9yld01t9hLMNM6RPgzG84x7vY2j5N/P7Nf+So6SukBi9LUubzjn04tdx3MTm3aw3bhrzSyf7tm+UuIp6Iz5Hv4gETCuH9FcAVFPqZN/12eKAHAzsfv63MztX9gR0Ga0szgCDYpgcJQO6IAes1D0xgIknH2X8Dq/04xqPEjirAOoHJiXAaMx496EMN6jEuzJczLdWpAhXdf69LxHsC8df9yOTyFEj2QKHL2GIMorM4uiu2twZXvLeUMazpcoOpRzZhl8GyJmd0NHzWWaTeAzycW1TLwG5eWNn7zc9jUriMyqT6DT2OLA272dthDZhUIvjgx+sztxkyHqcNNp7FtV+UJtrvjNYgELuw/Rfyctc3EjR845HdKZOX8ZW2kMkCc4ey2YVQuL/3ZoLsFBIzzZS7HwP6JdjK6EPyECuDbuCmhHVVAFetXhPW5g+CWyxmK2N+DucMvyu1HIVctPlI3kGYyGYExbIDGhSXy3iCei0DBsdKYhh5lvd02Gryd89ybr1wkdZB+keBXEAs3ndYF8/zm9az78rJ/NUZAhJtImJc6zPwbHhotCt8gWRD3w6V4Vn/698drHtzPvsFOz1LaYntU47a42jXFGBQKHYa1fSYSGFPRvua2ZRe4qG/Ri9Qw111fyW+WL4OqfoQZjge7op9Ao2ygEcbjeg2pfvVml05Qtg2lIrG17j6xj0Dff0ikEh2zU0PkxaDnqjryTLhQ79WsPiGMDU5ryeth8= 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)(39860400002)(376002)(346002)(396003)(136003)(366004)(83380400001)(8676002)(36756003)(316002)(4326008)(66556008)(66476007)(66946007)(86362001)(6916009)(38100700002)(84970400001)(6486002)(6666004)(26005)(6512007)(6506007)(478600001)(41300700001)(107886003)(44832011)(186003)(1076003)(2616005)(8936002)(5660300002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CswNoZ/rVCavnK/zLiHZbIl/etifvm7IUu08C8ngBtvUYsfVct8je6iE003U1H6AZHWqyiY90BYY7I9z+mRXhT5I3x18UqXtvYAUzgG2CQ2V/fqK7hrpoKWRNm4l07A3xpl78EOu0vdWlDQHxUjaa14SORhbOK3AbH9AO/NYxtIkm45p8hOcafSY61mg1KvouJZ8qhIhrcWxTGKQmCQ5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BCYrQIZIF0x+UyzV9gafSt1ocMl2OWprlL5WbHVS2X0rAx5JBzxevPQvi4Tk+qdWJ7v+bveozY9K1ZjMlrqwGR6vimSk7WUFdL/QUfMMVzVCQspkMZJNQrlxO5kb6742gR+da4SBOK0xwTCS7FJKFWUU3682zpwEk8nH4S546WgPnXmmu2D8Eu4HB/Y1XoFBQ6NpLcA7ki7SfRyMTGRIaHe7ormQekJaExvtKR9OoS/vOAVdCp5otql3KVkxb5ieMAYgcq/4vKFYTC7v3PqADTt2l010xJ73zFmEQ86fsHUjxrD2YKBGPt93b X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3d6ff8e-3f62-4ab2-5a32-08da89efb2e4 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2022 18:53:01.9251 (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: 8aTuHvvdxEbJXJbwfrFWWSXrRj5Kbf3Afg8dNgJAvKFiz++OeE5CCT7jy+TXuO6Li0tdngyjq+bEq0QDosUK4g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR10MB5553 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-2208290087 X-Proofpoint-ORIG-GUID: FdWfFiwDKTa2anllAfFhwscNQi0JEC6n X-Proofpoint-GUID: FdWfFiwDKTa2anllAfFhwscNQi0JEC6n X-Spam-Status: No, score=-12.9 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Faust via Gcc-patches From: David Faust Reply-To: David Faust Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742522801643179268?= X-GMAIL-MSGID: =?utf-8?q?1742522801643179268?= 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 | 19 +++++++++---- gcc/testsuite/gcc.target/bpf/core-pr106745.c | 30 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 5 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..caad4380fa1 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,26 @@ 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++; + { + /* This field does not have a BTF representation. */ + if (field == node) + return -1; + } + else + { + if (field == node) + return i; + 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 } } */