From patchwork Tue Jul 11 21:57:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 118725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp765217vqm; Tue, 11 Jul 2023 15:03:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlGvb0FahpPQ3pkTcyTXjuWlm2MbEfiR6goeNLO6KtW+5zsBymLau+D5DJvXrSnH2+nP9igD X-Received: by 2002:aa7:c98a:0:b0:51e:227c:9492 with SMTP id c10-20020aa7c98a000000b0051e227c9492mr57506edt.20.1689112982781; Tue, 11 Jul 2023 15:03:02 -0700 (PDT) Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u8-20020aa7d0c8000000b0051e2757995esi2745784edo.628.2023.07.11.15.03.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 15:03:02 -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=jT1jncYg; 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 1B3B53848171 for ; Tue, 11 Jul 2023 22:00:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B3B53848171 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689112843; bh=EcqY8q1V/r7ZBnCuOB7MSRps8qxG162F8+EO9sfhGpY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=jT1jncYgKW6sxPkLlinfXB3vU0Ddq1nkXFdC6Cg+qFA2NjotRNxAOn9WZ2gBwfLFL Hx1dZxtcrTv/py4dtMfv2HA9D0yAuDWELJwybgWNa5XKhB6UHNij6e4hCtSRG522Cg 3zzJEv3/1nrql67qx6WWFna7KR4LQVzRv7+Yi8Vs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id E86C63858C2D for ; Tue, 11 Jul 2023 21:58:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E86C63858C2D Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36BID4UZ015542; Tue, 11 Jul 2023 21:58:52 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3rr8xumfn9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Jul 2023 21:58:52 +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 36BLw8RL027105; Tue, 11 Jul 2023 21:58:51 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2046.outbound.protection.outlook.com [104.47.56.46]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3rpx85hhuw-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Jul 2023 21:58:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nqyZWrywtadjAsrBC62dHdAaSm32h2ICbLT8zUbZoURJOMRrE5xmEkgFUY9682y/6LAgzYAQqVPgNM2p+jO4q7bifh3itvqFKWC+2zQJ3PrWi3mTzZAUHQmiXVVBvTWIh/Jwtr4eu6CdfWKjOt1p92VXOgho3D4dDgN6XUNySNWm04TGgkkYer84w117y+BfvCqo4Z3Ru06z0QSw+5LOZ5tII1SAB4RXaCKfEIqQksdz1zzUALfSJwONltWgfLVt4jGFZnlaegMC/dRd6OZpgFFcd/J9o1CfoNO8vZvvKeL9z8vCHgU8LNm2bsMI2UXNjjHNlsAZDEhqYazXAg6v0w== 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=EcqY8q1V/r7ZBnCuOB7MSRps8qxG162F8+EO9sfhGpY=; b=TQtcov9yt6b+Hcfyqe2Y6duUHz8NC2Guh6BgpoiAnxeowBISLjQNTzRKKW1HDm716R7mr/A19siw9KxVVcwoeX0j4RDWsDAhb7lXSUO8q595Wv9D0v5ZxT/7A9RuIl+phE4eR0vtGQl8+Z7v1x7hrv9GFUjZeKcyiqFFkzxp6uRsjB2D1N0fbrxFdLpkPSFcD0N5NlBWU3mT/kOO6vB7JFPrB2ChUkovSJ0+8Np6kGc3cuNuW4KhdAx/ou6jxFl98L7hlqzIt12gaVrju53dJLZ/NqQC9qycRa86swxaV9vuXCq0tBeJZZwTiK9lK5Bzg7dWQ2HN/Fx/B2aWoe4oBA== 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 CO6PR10MB5650.namprd10.prod.outlook.com (2603:10b6:303:14f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.30; Tue, 11 Jul 2023 21:58:48 +0000 Received: from MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::1797:59c3:a40e:f8ab]) by MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::1797:59c3:a40e:f8ab%4]) with mapi id 15.20.6565.028; Tue, 11 Jul 2023 21:58:48 +0000 To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, yhs@meta.com Subject: [PATCH 6/9] dwarf2ctf: convert annotation DIEs to CTF types Date: Tue, 11 Jul 2023 14:57:13 -0700 Message-Id: <20230711215716.12980-7-david.faust@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230711215716.12980-1-david.faust@oracle.com> References: <20230711215716.12980-1-david.faust@oracle.com> X-ClientProxiedBy: SA0PR13CA0025.namprd13.prod.outlook.com (2603:10b6:806:130::30) To MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3213:EE_|CO6PR10MB5650:EE_ X-MS-Office365-Filtering-Correlation-Id: dcb6a588-6f56-49ec-c178-08db825a0105 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GZfvx2YzQaIqp2S5nhH44aoxgzCI2geVTs6izw95aWikUcQmgMAkYVB7GFsIGhOKWB3nCHJPWgxksh6rpH6eSQMQpGMekjaEJjSK6CQ6TREvHHOc4PoAHBTAxUVf7w6ryKX6Lld8WSXYCGBSScV+B/0aIQnw7fml/n877kwdDK8mRVHF4m4Ame5dfE6RnycEu5iooQ5J2NZ+xCogI35VS3OmnpN7uxDtsKydbpQuJGXTi3b1B4umEVPuC+nZn83c2RsJ6YcjI3tfEd8MG89/b5PqG1nBFC70K795xdwfG9yetscTbOPE+pBZXiKZ6rMaJFf5OUe77KYrLoqFge9T7b+8FeMr2YaqjHOa0EaI7ZOObJJYOY2pPH1fprUwepvBOpORA0TNuQEEbLYcwb/Ql6WHwtY4BgjZ9vyYJFXz+kWcgofppvmsHFmCz2fodvE2dAgv7teMEiYYJsGecuiG/yqEjU9C0YvKZhz4HwSmX7YkfbQZxemALRYZbkGP7fhtQgv8IdgqwIIybESMKrFVzhCbesv7kDfvggpOg+3o236z7aKUaowk9hTcf0MsNYCS 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:(13230028)(39860400002)(346002)(136003)(376002)(396003)(366004)(451199021)(86362001)(38100700002)(36756003)(6486002)(6666004)(6506007)(26005)(186003)(1076003)(6512007)(2616005)(5660300002)(2906002)(316002)(66556008)(66946007)(66476007)(8676002)(44832011)(8936002)(83380400001)(4326008)(478600001)(6916009)(41300700001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 75B7NAe/mkRlmpnY0DdsdxjCXlgz7m8e4iWizY5dzKZf7MblNxAw4O3apu60dwbsaf6OXzlZgUzZNPkobpgz6I+tRb2SzjbDtuJQMVeCVvZRPLiItuh+uJlco2XTIdPnozuHtwCysw2SQ17VkSdmbLtPMfUT7x6HPSzafB+w04hvhmhfZr/cAMb/0Yg/COaVKqwksQLlWiNT3NOTOArxh6+/2ea9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7DmHoTY+WDFutGjndniEz2tkS9XtSTT5LVN93TIL7uF1o3NOcZN30OSqjFz4+y9tBVPM8VN978XGqgqN3WA8Qkdx6F6WOx30b0sG5HwEMmrO22p63kA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: dcb6a588-6f56-49ec-c178-08db825a0105 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jul 2023 21:58:48.1196 (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: niWVOiMgyr43ytfCRNIHXxp3UxSi6WnPozNwEUXm552VB5Mxp463awxuRKnVNkFezq+AjGgD4WbWre7JU8mzqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR10MB5650 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-11_12,2023-07-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 bulkscore=0 suspectscore=0 spamscore=0 phishscore=0 mlxlogscore=832 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307110200 X-Proofpoint-GUID: GW7P7c167FduYjEFZ0SiruMSKQmBWP5k X-Proofpoint-ORIG-GUID: GW7P7c167FduYjEFZ0SiruMSKQmBWP5k X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, 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 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: INBOX X-GMAIL-THRID: 1771163334918241128 X-GMAIL-MSGID: 1771163334918241128 This patch makes the DWARF-to-CTF conversion process aware of the new DW_TAG_GNU_annotation DIEs. The DIEs are converted to CTF_K_DECL_TAG types and added to the compilation unit CTF container to be translated to BTF and output. gcc/ * dwarf2ctf.cc (handle_btf_tags): New function. (gen_ctf_sou_type): Don't try to create member types for children which are not DW_TAG_member. Call handle_btf_tags if appropriate. (gen_ctf_function_type): Call handle_btf_tags if appropriate. (gen_ctf_variable): Likewise. (gen_ctf_type): Likewise. --- gcc/dwarf2ctf.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index 549b0cb2dc1..b051aef45a8 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -32,6 +32,9 @@ along with GCC; see the file COPYING3. If not see static ctf_id_t gen_ctf_type (ctf_container_ref, dw_die_ref); +static void +handle_btf_tags (ctf_container_ref, dw_die_ref, ctf_id_t, int); + /* All the DIE structures we handle come from the DWARF information generated by GCC. However, there are three situations where we need to create our own created DIE structures because GCC doesn't @@ -547,6 +550,7 @@ gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) /* Now process the struct members. */ { dw_die_ref c; + int idx = 0; c = dw_get_die_child (sou); if (c) @@ -559,6 +563,9 @@ gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) c = dw_get_die_sib (c); + if (dw_get_die_tag (c) != DW_TAG_member) + continue; + field_name = get_AT_string (c, DW_AT_name); field_type = ctf_get_AT_type (c); field_location = ctf_get_AT_data_member_location (c); @@ -626,6 +633,12 @@ gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) field_name, field_type_id, field_location); + + /* Handle BTF tags on the member. */ + if (btf_debuginfo_p ()) + handle_btf_tags (ctfc, c, sou_type_id, idx); + + idx++; } while (c != dw_get_die_child (sou)); } @@ -718,6 +731,9 @@ gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, arg_type = gen_ctf_type (ctfc, ctf_get_AT_type (c)); /* Add the argument to the existing CTF function type. */ ctf_add_function_arg (ctfc, function, arg_name, arg_type); + + if (btf_debuginfo_p ()) + handle_btf_tags (ctfc, c, function_type_id, i - 1); } else /* This is a local variable. Ignore. */ @@ -833,6 +849,11 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die) /* Skip updating the number of global objects at this time. This is updated later after pre-processing as some CTF variable records although generated now, will not be emitted later. [PR105089]. */ + + /* Handle any BTF tags on the variable. */ + if (btf_debuginfo_p ()) + handle_btf_tags (ctfc, die, CTF_NULL_TYPEID, -1); + } /* Add a CTF function record for the given input DWARF DIE. */ @@ -850,8 +871,13 @@ gen_ctf_function (ctf_container_ref ctfc, dw_die_ref die) counter. Note that DWARF encodes function types in both DW_TAG_subroutine_type and DW_TAG_subprogram in exactly the same way. */ - (void) gen_ctf_function_type (ctfc, die, true /* from_global_func */); + function_type_id + = gen_ctf_function_type (ctfc, die, true /* from_global_func */); ctfc->ctfc_num_global_funcs += 1; + + /* Handle any BTF tags on the function itself. */ + if (btf_debuginfo_p ()) + handle_btf_tags (ctfc, die, function_type_id, -1); } /* Add CTF type record(s) for the given input DWARF DIE and return its type id. @@ -928,6 +954,10 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) break; } + /* Handle any BTF tags on the type. */ + if (btf_debuginfo_p () && !unrecog_die) + handle_btf_tags (ctfc, die, type_id, -1); + /* For all types unrepresented in CTF, use an explicit CTF type of kind CTF_K_UNKNOWN. */ if ((type_id == CTF_NULL_TYPEID) && (!unrecog_die)) @@ -936,6 +966,45 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) return type_id; } +/* BTF support. Handle any BTF tags attached to a given DIE, and generate + intermediate CTF types for them. */ + +static void +handle_btf_tags (ctf_container_ref ctfc, dw_die_ref die, ctf_id_t type_id, + int component_idx) +{ + dw_die_ref c; + const char * name = NULL; + const char * value = NULL; + + c = dw_get_die_child (die); + if (c) + do + { + if (dw_get_die_tag (c) != DW_TAG_GNU_annotation) + { + c = dw_get_die_sib (c); + continue; + } + + name = get_AT_string (c, DW_AT_name); + + /* BTF decl tags add an arbitrary annotation to the thing they + annotate. The annotated thing could be a variable or a type. */ + if (strcmp (name, "btf_decl_tag") == 0) + { + value = get_AT_string (c, DW_AT_const_value); + if (!ctf_type_exists (ctfc, c, NULL)) + (void) ctf_add_reftype (ctfc, CTF_ADD_ROOT, value, + type_id, CTFC_INT_K_DECL_TAG, c); + ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, c); + dtd->dtd_u.dtu_btfnote.component_idx = component_idx; + } + c = dw_get_die_sib (c); + } + while (c != dw_get_die_child (die)); +} + /* Prepare for output and write out the CTF debug information. */ static void