From patchwork Fri Apr 1 19:42:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 52591 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CFDB1383943F for ; Fri, 1 Apr 2022 19:49:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFDB1383943F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648842575; bh=PkApH+UnCWiP1PNZqplDWBcdRlcQRJiyft09hQfDGK8=; 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=c+nrvj8WY7rM7TTdFehC9gVXBEOeaiof6NN7q8MJZ/C59fqAP27L8M4CwjtwPqfqX ru39JLBlakVI+7GyvBLBjIehdpATFow3vXILS1pWMKHBWtP8UzxttlR0R59b/V5GLS wnygLYT40uw6Hi37E1bmaUavnKaPWWKDLoIxCHe4= 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 561CD385DC3B for ; Fri, 1 Apr 2022 19:43:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 561CD385DC3B Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 231FvH4c018522; Fri, 1 Apr 2022 19:43:03 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1se0qw7a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 19:43:02 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 231JgCKo025532; Fri, 1 Apr 2022 19:43:02 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2103.outbound.protection.outlook.com [104.47.55.103]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3f1tg9j7nv-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 19:43:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y+hZ7E7hdTl9szzC8X801C91l0Y24SJcqWamM1wT88K3chmKV5QlBjtOikC5kRIc4V8rwgQoulbhQ7jmyJtdTF06mvk+YYmPNIMy1bkVvohxOURyIoYTHUkoNNAuK/MNEgXLloG/hIe9++m7NpsP47dukIqu/LV9D+8Ql5bSRmBvkTrwYfEbNb54fSwc9Y7ivUSjyxx5sFFAIet1DqJXxl+VX9n83LyD04cWKrHMtXuDN/pcCitdhOawsc2P219Ge3JA2y+cP7MG0gZ3mmvpds0Z7YP587R+nzQ/+q9LAaIohvt5CX0x98EHkj/0cfW9T/VznheDChIkAiRe+W5k/A== 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=PkApH+UnCWiP1PNZqplDWBcdRlcQRJiyft09hQfDGK8=; b=S5IPMPKFd350Lzut6u3mYU4+b4Sr/1jyz+GGU3F5OWTgdBjs8xx0rWgggcbFFdtwjTGShTLYl3E54910oKM/npvDjBgwEm4QLxQQT38wVaGGguBCFHIx4NoKZrCQw73Qb0AkHA6KYadEdofY5cIcmKBjxuwsNv4AImkNPaj4AwSGHA+YBleTjle1X3NOzoVq3zn/osMaxzfii0aeP2cAVTbSBTP57ieu9Id5u/QmzS5hLuqSAocQLUivxUmaHI6eUNkukdoxGjIe17yKt/+j2Ywk/c6vKBBYBuoM8lMnChqygdj06rMa6wWtH6phTXvNATzQYlWFL53B7Sd2OQMrHg== 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 MWHPR1001MB2286.namprd10.prod.outlook.com (2603:10b6:301:2d::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.19; Fri, 1 Apr 2022 19:43:00 +0000 Received: from MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::705e:a465:c30b:fec6]) by MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::705e:a465:c30b:fec6%6]) with mapi id 15.20.5123.021; Fri, 1 Apr 2022 19:43:00 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 6/8] dwarf2ctf: convert tag DIEs to CTF types Date: Fri, 1 Apr 2022 12:42:14 -0700 Message-Id: <20220401194216.16469-7-david.faust@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401194216.16469-1-david.faust@oracle.com> References: <20220401194216.16469-1-david.faust@oracle.com> X-ClientProxiedBy: DM6PR03CA0052.namprd03.prod.outlook.com (2603:10b6:5:100::29) 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: eef0513e-19a5-40bf-1f76-08da1417d454 X-MS-TrafficTypeDiagnostic: MWHPR1001MB2286:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 88e0lX39rUnGlbhb0HxbPEVJWTsogkXXFDGJN+MJDTKAF3jSmpithzdQT5O64HcAEBTtAOSI55pvUujnukgJIMCm08edeTcGMYk+qBfXpNTS8AN10OgdtitP+87ytR5h0RuKUZAg9uYEoJ5+hpx23heOPDPhKEmGTLCQIYUFCj/ob3UZqpj9J+JPNOnkJR+zx7QbvFQiXnDrLw4PNRTbub4pDAC+C5LY6pAKZUCEUoLemBk3PC2gWRrc1afjPB6hWdYTFZ7tDR04BfVZrWwndKIDWiZpigrRPx++cJ+9GYHnmKDqMtrAwbUZGvsCzX8mU25q4/4SfZVDMhnwv0rFT7Hb3gK+o4KgYjUiwFctscS9Oipx46vWHT0iplQOY9/J0PJdkm0DF6EoMdtehOdV+/P+8SrKDJvT5NTJUEtuLk3SAsjzaAJmFA4DbzG45NX7EdBK9CGBi8tjQBPYZVIC9fosJzPQ0gFsgiDl8hiOSKIXmA2tc5CrxUZUSdDItt+/gbqQWepsBTqjK136SV2Mt8LaYlC8yQXIp0bNv+4keTNMqjA2PK+TEDny2HnhoJ7LxSKvV4LvojS+KsXG/Mxb25UvgJINGNTfovuQCDUqsGcrwUcbj5CAIbDodcwxFOIp+j8FaDgulVN1pPuhFX5qkA== 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:(13230001)(366004)(66946007)(6916009)(316002)(36756003)(66556008)(5660300002)(66476007)(508600001)(38100700002)(86362001)(6666004)(8676002)(44832011)(4326008)(8936002)(6486002)(6512007)(107886003)(52116002)(2906002)(6506007)(2616005)(83380400001)(186003)(1076003); DIR:OUT; SFP:1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9aD5qYIDWrjIfyPmKPfSgVk4Ey6y8FfkSzV0+rbtKaJFS5SiAGOI1cNXOIuytPq2rGZ8+kHSEgJMXAyQ5dy4cbaEyU6tG/w3nTmvMugv8bXi/pUQWwwkyaWVPHmw9fiTNzpt+TRSKFnrtkaKyA8jRM2rkx0qVNd51U73rQ7OQIGjIAHCpc4gGiQbRbG/BNVkvtIOnOB8UPCTXAd81hJA03po9Y3EIc+eliBnZlxaSimmYddQDWdIB9hXr7OGQwv6RW3iXm7zV8pWdkn7RNJ0HSJch8Fd6mGsOuxdKJRgjH3F+MwjU7qdOK1MRXZBAXbmFy+RnT9PFnZZohJVMF80L3GM8xDGpomVM7hMnlTOzK5oWfrUP0yiQ4p7ha88bWygcZkeCUU+imxFBCbevK+nkAR52ZeJHDTAz6NPe3MbvKO8RGkJrSwNt1aFpwjgTSTmlWcEcVKKXTCjFaKNT2Ya29gy1Kcp/HIsqGpDU3/ygFEBt3G8xuX6ZKcKJSdmCJ9ILt6EIUg/1Zw1/xBrtAct3ASA2OPjcgf92rkbCLXVB86FfiGpVvznltMFudyC7NfFN6hjJ3DQqY9+Hc6AoedoNqGyHefGSHbfYNXVuLVbSPrdOUrxNCejndyP2QTCJfXbi1N4AjVi0GdTwhlmfnnwoKklutCsUjdYq0hUvTZVWN1NW/PNsNoL5ySl4Hkj8K3fyAZwRciqevNFTTaFxQrJiscYHJM9E7t6yZjdd+clFeEvm05Uf7vl29TJMeOiSFfHZmIe5JSnH5fJ+5lv3KG X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eef0513e-19a5-40bf-1f76-08da1417d454 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 19:43:00.7463 (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: fYDybvQr9SvFbEf7sdCamG9Z1uW6vgr9m2M8iDpAcQxeHuDo7GFKMLYwK2PThdR1re8dxhxwsSVMZdQB89SYwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1001MB2286 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-04-01_05:2022-03-30, 2022-04-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 spamscore=0 suspectscore=0 bulkscore=0 mlxlogscore=805 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204010093 X-Proofpoint-ORIG-GUID: zxQU6xX5dpM_l_sAEfQ5ZZS4Z0mvW6ZW X-Proofpoint-GUID: zxQU6xX5dpM_l_sAEfQ5ZZS4Z0mvW6ZW X-Spam-Status: No, score=-13.6 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Cc: yhs@fb.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 or CTF_K_TYPE_TAG types as approprate and added to the compilation unit CTF container. gcc/ * dwarf2ctf.cc (handle_btf_tags): New function. (gen_ctf_sou_type): Call it here, if appropriate. Don't try to create member types for children that are not DW_TAG_member. (gen_ctf_function_type): Call handle_btf_tags if appropriate. (gen_ctf_variable): Likewise. (gen_ctf_function): Likewise. (gen_ctf_type): Likewise. --- gcc/dwarf2ctf.cc | 113 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index 32495cf4307..8811ec3e878 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -32,6 +32,12 @@ 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 +gen_ctf_variable (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 +553,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 +566,12 @@ 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; + + if (c == dw_get_die_child (sou)) + idx = 0; + 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 +639,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)); } @@ -716,6 +735,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. */ @@ -814,6 +836,11 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die) /* Generate the new CTF variable and update global counter. */ (void) ctf_add_variable (ctfc, var_name, var_type_id, die, external_vis); ctfc->ctfc_num_global_objts += 1; + + /* 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. */ @@ -831,8 +858,12 @@ 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. @@ -909,6 +940,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)) @@ -917,6 +952,82 @@ 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. Type tags are inserted into the type chain + at this point. The return value is the CTF type ID of the last type tag + created (for type chaining), or the same as the argument TYPE_ID if there are + no type tags. + Note that despite the name, the BTF spec seems to allow decl tags on types + as well as declarations. */ + +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; + ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, die); + ctf_id_t target_id, tag_id; + + if (dtd) + target_id = dtd->dtd_data.ctti_type; + else + target_id = CTF_NULL_TYPEID; + + 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, &tag_id)) + (void) ctf_add_reftype (ctfc, CTF_ADD_ROOT, value, + type_id, CTF_K_DECL_TAG, c); + ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, c); + dtd->dtd_u.dtu_btfnote.component_idx = component_idx; + } + + /* BTF type tags are part of the type chain similar to cvr quals. + But the type tag DIEs are children of the DIEs they annotate. + + For each type tag on this type, create a CTF type for it and + insert it into the type chain: + - The first tag refers to the type referred to by the parent. + - Each subsequent tag refers to the prior tag. + - The parent type is updated to refer to the last tag. */ + + /* TODO: given this type chain requirement, the representation of type + tags in BTF only makes sense for pointer types. Should this be + enforced here? */ + else if (strcmp (name, "btf_type_tag") == 0) + { + gcc_assert (dtd); + value = get_AT_string (c, DW_AT_const_value); + + if (!ctf_type_exists (ctfc, c, &tag_id)) + tag_id = ctf_add_reftype (ctfc, CTF_ADD_ROOT, value, + target_id, CTF_K_TYPE_TAG, c); + + dtd->dtd_data.ctti_type = tag_id; + target_id = tag_id; + } + 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