From patchwork Fri Apr 1 19:42:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 52589 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 8970F3858434 for ; Fri, 1 Apr 2022 19:47:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8970F3858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648842459; bh=r93Q+BegZ4lqTec1t+vB4ThUAa+34OfkgPvqObX0F8o=; 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=QPJClpKCwyrw7zm0GL4NRmXtuFrNkXn/1R+F89eJoEqvr6jEiBUipS7D7hIF8plB6 w2I3pSOi7AH7GX29vU8F+I0LgS3csEeXTz/JIztsLvx0DV/keZi2tRl9AgcLzj8LIO SWr79XbSaHyIxbkqtgiq9MCz6LTiQXngESrzaiMI= 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 0CF5E3858401 for ; Fri, 1 Apr 2022 19:43:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0CF5E3858401 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 231JgqVn018350; Fri, 1 Apr 2022 19:43:00 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1ucu04y4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 19:43:00 +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 231JgCWI025565; Fri, 1 Apr 2022 19:42:59 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2108.outbound.protection.outlook.com [104.47.55.108]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3f1tg9j7n7-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Apr 2022 19:42:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kLsYOHKNVH1tKV4r4Z7aM8IYvoB5BlbCEOGzBaNt+34L+xtOb48CUYYROxzcE84gX4r6/XGiQSqrp8CJJ0OSvjbejs3d2Y2JRlQZSM2ZxsARnZDtk7FNGdOn8WMf5P+iRfLBh7V7C7CglPfCjk/Ixp85/tPeyAg0ZaLibm91t4PmvfFxKBytjs9IRf7CfB3Bc2WLuO1nJdyQkojWSMmJ9HNj5RDOtNmx51VLk+SdnSHHD5he49URuXoyOlc+wxlZebTavnzhGMZsTzEEIAMhdcmJJBGLn7SWqkhaWcZEU0skja8Qwei4m8zRS8bFFvruP62MC0k+UXRlFsyXdE8M3Q== 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=r93Q+BegZ4lqTec1t+vB4ThUAa+34OfkgPvqObX0F8o=; b=VuGFqzRBGmA0Z+ljGrzcKCO/TZnt3aRcBHzCZ3T9DwvElvqNqUkDcP9QbLu9PCvXEC0pacGYUKKf3pYrIh2HLaMNWgjLL6AlAgTTP8Ex4n0yOPL0vsvY1pwK3LJLjPiHqNJMjeJ6ndjlCgt/0i7I5ydg/rZfcfVwdlAuDYZBZ8x/O7RPl84DyG/kBJxIrd+h17n2/v40ZdynVUVMQ1E/5b/0lfwcTQt5jXXsxazMbnMSrnl9AzAtSBsdo+3Ga2am0MYR3knxNaVHGr7wHSwaip77jdawmHOQLhq4RopY0q61xQwv9Hh+RLvFx2/HToWXZppc7Dl7dQkrFybNoalwBQ== 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:42:58 +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:42:58 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 4/8] dwarf: create BTF decl and type tag DIEs Date: Fri, 1 Apr 2022 12:42:12 -0700 Message-Id: <20220401194216.16469-5-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: 4ff4cd37-c0f6-471c-37bc-08da1417d2e0 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: XoHdvnuPZsTomCloKABHG499boDHErBe/hPDRDpJcpm+9lHFtIyu7GwUXuLH5f2EjzFju8Tf96S5iF91kivj561SvyK/bGo/YilQT8+2/RGPN3wpi7i6Vz5rOkPEHESELJmXg2U5UMueW1/1PeHofAzUE0yKTcEfG1f67FUDcJAjWxu1EXpH/rt53+Wy/3fA8K9mAJOVbS6G4hQS5JRT4AEMEiXNpUhp8TqcGsOs1rg+IgULb7IbGJso2U2T9HQS2loWBUwx0WONKFKifwE+hTOEZ/0kGgqm7qRPPoLyy53y/JrITyYe15QYWD9C3GTkasRstStpFJpw2OGlAYyrr72c/DpyLN892yaue/KfJDK9OWqNgKP518qRhZQWJUVlN9bLLniinXgo9EavXsMnAJBikFWOUt4dZLbt/rubVyOFFLIwqFyaGu94faA6MLXEeKJ72I70EGsC1sb/Yw6MIa/yuEiSUAt0zZ2NHw/4KibiyzeRwJzeHEdfeRS3jjyGa3EX8VhTi3a6M7ojOua/XC6E7byau5ayC13EFFtx41lv+VjX2Bc2d4JZiXqO9Jao1n9hTpSI+nF1C7nUZo1aAPjrzFC3beRAKVnlvAkJY6xyeECR+40H0f4qBMeFdw7pMisGzL9fV+nDhAtRG2xR4A== 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)(186003)(1076003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0uReVIpOrRyLYVzg6geI/vgb1Vbs/vHtO6SdW38itPPjDUarbslrO2UAcCOIxjfOkIbxz/4Y98URWK5r6L3Lxm5FWe+EWOLR2RrkT977mk5skUfMw05iR7o0wV5ij+jsETNAtpBA6y4sjhYuKwiLP8Ez8h1XZJ+b1XS7gzwKECwFzEeOw7GUysSvWTGWCqyQDQoW90v8s+b0fU8KvAQm4WULYadw6vxR1dmuP59rKuOmEliWbJZD2s5SEnEKGVO58Mw1Lao8QdFHtNEJod/HgutrY9GFupo2GoPH1igrcTbhHJijOobSIivy66UPMKgvGxL3HwiafzLcxv9P+CTP/G/tQsGuTcMXmNaGqdZPjtg+Ga3rR1v+D83BHQ4TKNjaAuZiZdP5rdCmn/fRMAx8MBfQQ08bbqhaY3dkkb4trI7RcXNexzidnFxeG+k9W72AmSL8P7dPsgOkDLh04MXIm8u8k342C/HAWqvSq3L65LJEfUB413RRW1aK47mJgN6UjL2oBM+DMUM4UEL+3AXxjyoDVFyB+2kWgYaDLkOgyd3dr52e9h56asLqoK7ji/teekoJMYvCmKBuN000I/8fflxWeXpYpa0yGq+8d5EnDK8glMuW8bqOjbvT/Yo8Jqure9mNNMYLu2ifUxss7zOlhsHy+yA1Z1OkSpy6yeFmJgNClHo+4co5j/mNOr4yX88QmvOWvvBVU2I655vUYNR8o7lb1FfR/saXGAUC1VQsyRSWh0xyN84caCLmaI8lbTfDlTH0R/TMX62+p16QadMOlgLkk88BHhVxsacICzLE02pQtInHYNhFrwl4pe733vQ/+jRUgHbtXv8hSFJyhxqHR38y8cxwE7EInkfkNRdy6kgbKbJ1GoiDiR7uCKiyh1euwpCs0hh7+H26t7hdoF9aef03s6304Xi4B6gnbf68bXlxWZePoi4gKN3+siJfa0NRow20AGjQbFwl2t5k4azlrB3wcwlrDVkSnUUWL7bHp8yFUGQSfGfThCLy61DhXvmPGYRGufd/naIx3Zy7+rJOFg7g1xXxtGVXsu58Ge6HnA6YZH+k8NtC7ZAzHYvpO/r3mEQUSxL4AnWamIjtT5BP/MC+DH+8/V3IQYDsr3iB1jJ4Pw66R+RXEFbxgMF7JKr8jUdv4zdNls3vOHHD5NjIZeY+jeUlHc303A1JLWRboyuGb1bS9B752IlD7AaGvSxP06ENz9RO+vOzD5rhnv2qov0efchzu+0iIfvsabULsyae+1ERz51FRVD5kwZy+izcIvxPuJEm/ecnZ1uY921hAR9+GeXhFy208Ze8wOm2b7IjKLR15lsnjwMr3QOVqRYCESap87i222G2scPDqnWWfkPPzHPcQvnf1xYT2/6oaxTW2e7PyU6aOBK1wDeCHSm12vwd1r2DTrjxlQOmFNSTiNT2FaBD8t3qwFmcc9rcqM1TO3vlFXk9Cdq48RScLw2o8uFStf6A7hyh0B60C16Uw/4V2OrjrDOsMDn1rf9xkcjWsy7qkjtFJNwSFfN2fuWD7B5ddl7X5oY2HXQK+93dfGCrmqG+T4EqTjmXgFqbWjNS4oHPn2nNVP6zPCWe8UpBpDtRS7sAN5T0DJcZ7fFGzJwo6WzjbokdQvcgjjn2+jJoY4478+2eDRFLbj5dwlqHxnrLlNgY55aXbdnvEfYJmKaBip1w1eiMlLE+Wu+zXF81sPeP8USPKDs7l9NR9vPQjHn49H8PtRj07bvQp98NnfTvyz4sPxleJIsIWfcoF3fGg3tNdtbkWbASannQlSgt X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ff4cd37-c0f6-471c-37bc-08da1417d2e0 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:42:58.2621 (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: IpknlVutImhoLuim7C9Fu+1vMpdvqSS8RfnfNajkXU0Cy+tdQe0Eec4WPk6NxpY4WCSC9b94p2CJLL8D4fyzMA== 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=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204010093 X-Proofpoint-ORIG-GUID: x7a2Q4P-tbxgRKJRTLa9tUnsZTN0KAoi X-Proofpoint-GUID: x7a2Q4P-tbxgRKJRTLa9tUnsZTN0KAoi X-Spam-Status: No, score=-13.5 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" The "btf_decl_tag" and "btf_type_tag" attributes are handled by constructing DW_TAG_LLVM_annotation DIEs. The DIEs are children of the declarations or types which they annotate, and convey the annotation via a string constant. Currently, all generation of these DIEs is gated behind btf_debuginfo_p (). That is, they will not be generated nor output unless BTF debug information is generated. The DIEs will be output in DWARF if both -gbtf and -gdwarf are supplied by the user. gcc/ * dwarf2out.cc (gen_btf_decl_tag_dies): New function. (gen_btf_type_tag_dies): Likewise. (modified_type_die): Call them here, if appropriate. (gen_formal_parameter_die): Likewise. (gen_typedef_die): Likewise. (gen_type_die): Likewise. (gen_decl_die): Likewise. --- gcc/dwarf2out.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 35322fb5f6e..8f59213f96e 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -13612,6 +13612,78 @@ long_double_as_float128 (tree type) return NULL_TREE; } +/* BTF support. Given a tree T, which may be a decl or a type, process any + "btf_decl_tag" attributes on T, provided in ATTR. Construct + DW_TAG_GNU_annotation DIEs appropriately as children of TARGET, usually + the DIE for T. */ + +static void +gen_btf_decl_tag_dies (tree t, dw_die_ref target) +{ + dw_die_ref die; + tree attr; + + if (t == NULL_TREE || !target) + return; + + if (TYPE_P (t)) + attr = lookup_attribute ("btf_decl_tag", TYPE_ATTRIBUTES (t)); + else if (DECL_P (t)) + attr = lookup_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t)); + else + /* This is an error. */ + gcc_unreachable (); + + while (attr != NULL_TREE) + { + die = new_die (DW_TAG_GNU_annotation, target, t); + add_name_attribute (die, IDENTIFIER_POINTER (get_attribute_name (attr))); + add_AT_string (die, DW_AT_const_value, + TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); + attr = TREE_CHAIN (attr); + } + + /* Strip the decl tag attribute to avoid creating multiple copies if we hit + this tree node again in some recursive call. */ + if (TYPE_P (t)) + TYPE_ATTRIBUTES (t) = + remove_attribute ("btf_decl_tag", TYPE_ATTRIBUTES (t)); + else if (DECL_P (t)) + DECL_ATTRIBUTES (t) = + remove_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t)); +} + +/* BTF support. Given a tree TYPE, process any "btf_type_tag" attributes on + TYPE. Construct DW_TAG_GNU_annotation DIEs appropriately as children of + TARGET, usually the DIE for TYPE. */ + +static void +gen_btf_type_tag_dies (tree type, dw_die_ref target) +{ + dw_die_ref die; + tree attr; + + if (type == NULL_TREE || !target) + return; + + gcc_assert (TYPE_P (type)); + + attr = lookup_attribute ("btf_type_tag", TYPE_ATTRIBUTES (type)); + while (attr != NULL_TREE) + { + die = new_die (DW_TAG_GNU_annotation, target, type); + add_name_attribute (die, IDENTIFIER_POINTER (get_attribute_name (attr))); + add_AT_string (die, DW_AT_const_value, + TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); + attr = TREE_CHAIN (attr); + } + + /* Strip the type tag attribute to avoid creating multiple copies if we hit + this type again in some recursive call. */ + TYPE_ATTRIBUTES (type) = + remove_attribute ("btf_type_tag", TYPE_ATTRIBUTES (type)); +} + /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging entry that chains the modifiers specified by CV_QUALS in front of the given type. REVERSE is true if the type is to be interpreted in the @@ -14010,6 +14082,10 @@ modified_type_die (tree type, int cv_quals, bool reverse, if (TYPE_ARTIFICIAL (type)) add_AT_flag (mod_type_die, DW_AT_artificial, 1); + /* BTF support. Handle any "btf_type_tag" attributes on the type. */ + if (btf_debuginfo_p ()) + gen_btf_type_tag_dies (type, mod_type_die); + return mod_type_die; } @@ -22986,6 +23062,10 @@ gen_formal_parameter_die (tree node, tree origin, bool emit_name_p, gcc_unreachable (); } + /* BTF Support */ + if (btf_debuginfo_p ()) + gen_btf_decl_tag_dies (node, parm_die); + return parm_die; } @@ -26060,6 +26140,10 @@ gen_typedef_die (tree decl, dw_die_ref context_die) if (get_AT (type_die, DW_AT_name)) add_pubtype (decl, type_die); + + /* BTF: handle attribute btf_decl_tag which may appear on the typedef. */ + if (btf_debuginfo_p ()) + gen_btf_decl_tag_dies (decl, type_die); } /* Generate a DIE for a struct, class, enum or union type. */ @@ -26373,6 +26457,20 @@ gen_type_die (tree type, dw_die_ref context_die) if (die) check_die (die); } + + /* BTF support. Handle any "btf_type_tag" or "btf_decl_tag" attributes + on the type, constructing annotation DIEs as appropriate. */ + if (btf_debuginfo_p ()) + { + dw_die_ref die = lookup_type_die (type); + if (die) + { + gen_btf_type_tag_dies (type, die); + + /* decl tags may also be attached to a type. */ + gen_btf_decl_tag_dies (type, die); + } + } } } @@ -27129,6 +27227,10 @@ gen_decl_die (tree decl, tree origin, struct vlr_context *ctx, break; } + /* BTF: handle attribute btf_decl_tag. */ + if (btf_debuginfo_p ()) + gen_btf_decl_tag_dies (decl, lookup_decl_die (decl)); + return NULL; }