From patchwork Wed Oct 30 18:31:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 99841 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 C8092385783B for ; Wed, 30 Oct 2024 18:34:15 +0000 (GMT) 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 4AFEF3857C6E for ; Wed, 30 Oct 2024 18:32:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4AFEF3857C6E Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4AFEF3857C6E Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313144; cv=pass; b=IFhNWcJVKJsJaIYeNchZNKZlQR615ZXKLxngrTEaUshnCqHNj7W8fbuA8xDUwjkzsg7YWskxgKuGWO6DBYYwYUaLs65iMdXncJAzRg4CXKkHF4raRYmvE8c2nAMx8jl+vWx2g7uCf3lu+9hwRoTbenakfMm7ltqmNichv/aBB7o= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313144; c=relaxed/simple; bh=OkE62SzvIIBUpX9DxPSUypWeFQmAVJmZpPVoxVpdLd4=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=FQdzPkHhSvhkLYLjcSQLNPcpAGEiTM70hMEq48zhfo5MDI7wjINGHZHNAd+MAXBN39WkXZqapspb99XqvHb7jM1rLvZWa5XAn1aONYFaPoiUHOhAYOtaTglnbhW1yUHbNUNyp10BLMI9tXi/dYiPfVSR5SmLxp8ib4ztsLDXaFg= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49UGXYX8017359; Wed, 30 Oct 2024 18:32:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=2I2nGJCrSNGlix2tK72vpDplalsn6tvrolm7Fdi+J4o=; b= DJu0rTDoynRr36GzU+vAxwSG8P0AloDx3wRIAe7qfdZJdkwd7Jqwmdma4H4odhNX GxaVz3dhFvs+XgeYYLgNBn84QcJiY8eZ5TZHpGcWFLgGI+zYmKCNLR5+WFR4wfEh FomqdOIj/9hEWE6+XCb7EGWOnnupZddvO3RyZcP37I+CiYc5si5t9BtAPyGqTUZv wvB4k99ZftV+CLexEiZhi/odXnOuYkwX4JeXLV+iHgwk3hIcpmNLIL6getMW3KhC d83Hlv0V9OGdDksHl57dv2HRYcyGgGnR+AiZYoIW8d7HL1goHlD7x2uFmATWrVNn YPXugwU8V3To+iMC/ia1qA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdxrr3x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:18 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49UHiNhr034961; Wed, 30 Oct 2024 18:32:17 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2170.outbound.protection.outlook.com [104.47.56.170]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42hnd9grv8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GUQjzMv1s4/vmMQnZL48Fkk1AGJ4claWIhQbTz60X+EGoFCt6vO/lG4kJul9WLIknuGLWPnim1FAzRGIMWDL0I17QId3IwDYnbtZHwVhQArIjZ3kyVPiENG32pWvSmnkDAYpnzG3DdXqgSvMjTQ67QuYePpDYVdwKLb+Cm0BJmz0AG7bGJjwofwadHH9EAQqn8KGi5z4ZECzesIhNGz4rPaTmTN5K026zp0wxyS8CcO8wVIv8+n/RvC0yxui8NEiYKdAFX/z3yhY1fdrEiGbfumFuFNk59bIVlMx+v74Z3bM48P8Ehu0bk9DiaCSN2t47zDVC0SvAYT/dY5a7O5CEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=2I2nGJCrSNGlix2tK72vpDplalsn6tvrolm7Fdi+J4o=; b=uKsFV7D/+0P6Vu28QgHjbbihGTK8Dy9AdgmZlWlzgUws5vB0Pq6YXpRXIMWqV8LN8ARxh6Ng6P5Y6YHmv4ihegCq2ENYtMPYHeOYmyY3B1yOE/ic4Fz4/0vCJBO484zKF+BCwNiCGcx1N55WJOl+AmOIOmARuaxp1wHKm4/A/l9o3HLbwBI8SLP5FHe3gKRq3Zc2fOQane/dA92SLlXwkmcS32CKMLIN5xr5iBudxgUFxyxNCh8sbdVXAELIJszRR4Vg+JzMLtSDezG9o+7igTwrCUT4WJxaQkeN0h5kRXWoo1/iykSmRBF88kMKpDrq8kLptVtmAUQA+vdA++vocg== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2I2nGJCrSNGlix2tK72vpDplalsn6tvrolm7Fdi+J4o=; b=lkGJpxb7FzxfkDmF9rOssYe1rJqT7TtMCJy2Jy4YR16kdDBfu4pYqLXdS7sl3Flzz+PRK0+RYA02QV2JhmOxGV1JkrJzjeoAmQVcmaGeJXbwqQrLNeH1cQGP0cKYPKSuU7CzmzeQ6sOZfRlbV3F0aRB3J1CknX8/itmVz7/kol8= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by SJ0PR10MB4672.namprd10.prod.outlook.com (2603:10b6:a03:2af::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Wed, 30 Oct 2024 18:32:13 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%4]) with mapi id 15.20.8093.024; Wed, 30 Oct 2024 18:32:13 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, yonghong.song@linux.dev Subject: [PATCH 4/5] btf: generate and output DECL_TAG and TYPE_TAG records Date: Wed, 30 Oct 2024 11:31:54 -0700 Message-ID: <20241030183155.2038501-5-david.faust@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241030183155.2038501-1-david.faust@oracle.com> References: <20241030183155.2038501-1-david.faust@oracle.com> X-ClientProxiedBy: MW2PR16CA0040.namprd16.prod.outlook.com (2603:10b6:907:1::17) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|SJ0PR10MB4672:EE_ X-MS-Office365-Filtering-Correlation-Id: 3341b7cb-bf87-4376-9813-08dcf9112c77 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: f0xWWKyvWE2yIxZ7pvlPYY5vCS4DvbEgzFQQjfH1sHeFbBnjyaLdu7XsUeDspnGP+/3EKGZmlgHkm6c45yYE+sYmSaVe99MWE1WaeaVd285wrS514PVzpjPHYDSluA1/W8lP4HBrOwYvVU8fXCYQJSwN0zrTtlkqaqggsyUYavYWumRyClHsISq1wSshB4r9k4GINVYO8P1xG8GpJImZOPinSM3Wjc07RrMtVE4wOqAeKUs1p1nVh6QJT0XUXx1BuHUvcQqNMib6NCU3dYJ8itWJnIPZxLGmLROojXqpEDK0rcYW0vk6o2mTm001cl8plTStsrE0xC69yLRjVPs0n6p2tRbmA6WUJoQIPEiteOg6HMjSy6REA9tuHn7Dh+1pABgYIZcobTE2hNsQP6fffq2X1+9IvDHFEA/IhR9vE1RCXsU9Nzy8qDWxckAPOibDD2sPGVgYmUBsd2P9VETj9LWafz8J1TMqV58bD3q02qHzoQCs1bCS4Imfh/7z7UPRnFJL7NbTzlKIJOjX7o/Zog7rfrafola+0lkhvaHr9ir6EZF7Kye1niGur2jB/tCQBjJxWITR1e2qe8mBk40edQXWwSl2Ddcjt+PQmVTCR+7yvvGKdQsPjyq/7u5BtRvCzrIlYtC6ZFKguNZzTvpBy9E70Jhh+tAI7H3AVcc9E+3u1pfn/QHpopRcwBWWI50HVsRJb57tAy6U9Y56BSdffefgBTAnbPlXy6hzPdUhtyLqZK1hVRi1kt7Yy2KjUVTONCj/DeUchyAXH4QK5N8StqHRswnNEKU9bP465e/yknRRGqmSU1y9k3YZNayx02Aj6uRxYU4llu4AosNw6yArV18UNsDmW+lFwN4cejtZhw3hU7YQtBYB8E2bxvMdNZXkaxIDnnD72u1YijVCNh/dr75uoKvbRIhMvKG7I9F3p6aut3VDzFJNtXeJxEb9vrZXpvXHA4xtTvXKE6Hn5y/Wf4+P3zh2Ll0iEDKslCg3z0/2MooTuyKy7+0NK7of+RHSdsYsUjJFEWQ2j2Z7hhWfBZiwdsSSmB0I9U7p6kkhpGMZ6qkbrv9q/Yi65NZfyWEZrvF1RIiB7I3pX0o3t9nHNJzHbPiZLpWAC5zlu7KakotnrnTy9MABRS2p502p35m1TuOeHw2zHGKV7pDoR4tfwaoJnEQEXn90S4X02EsWJVJDWKN8JoSchHeN0C+7Ji/CrQwllhL8KnWHOu3b69GQwSWK7kiE2IuvRrPBwphmMPlyURMPAK6l2hIF87xi3fhX/LDIINvCJFApVZOgmaYYAQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR10MB7953.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZdOBjT1uu6ZeeE3ABzc4Agh8XqQbMw8YjMVkbZ/o4hWWcZdlxL1sJlSqcSS6uM8aKc3nNRQmdtgBt0zTqo5t7nWfmYbmjfKTpEASQ3+uEJVZEBKbax4MBayFOjaMDDkZ40xiZCE9lRUiBEWyz7BLRLi5aFGHcqLC4GHmLUX61Mg/jZ8Xs46yrDh9FOk4AKgAXU8D+Pbv9H0AThX1C2HvhffHbQua/kpSo4wZDpYtdaK3aG/KqMr2xUFKiC5vG7ks2FFy32t5UrPtIXVCiW/AxJHcYYSlaJXk4A4lHVooYe52BH+AY4o36qluR+bh+P+QuFwIOUpsCJ+UMNcv9lrtSy04wpqyffD3zDWdTe1ipimM+MBLPbODw66p1LeT0s5MmSTG3clF73IgvGUR6d31Mdnz0D+jWEg1LRdg8jqIoHXU1MW1jTOdfZ/mFfRv4R/0/fRtE3fW/CuoqBIYDPMkJEMPRgQB2f591thp8YR4V6566C13bNwOEFHTkOJurO4XHl4HO+OIYbWS5/yzfMRLoWz9nEEyGwEwFu3aGAcBnLWIlTuNhDity861TY9olBZzUsAjYazPg7u3rGuipZXjPBFbWR8rDxpezs6E/kXAJcpe0/ffO5cpHoSe8OFMD6o1sHwMhYvGbqitLddbsIOBzni+T5W/74RY66OTfOL8U3POfPaEsmWKcFu9ARpZOlyESMejZWSbdqGg+/7EJpGLqof/h50m2lm4tDZFnz1lDUt0wfSFGkZRopX53dkMqBY95w3yo/t+LC7db9C3Mg1GcKOuXoCRAsBhCh0L0MX5TxjWf+7UcZSyxY4SYuq/MbfP4jtH5OZOHwdiz1fPRQe6Fn+PB7/M0lokG9Szlw5xnqa24lqS76XREV6HIRNeHHA6+pfiTd8q/patskFMZsWX5kDXp60QEnF8rmFwXIzfALv7fX4aknJjjpNg9ODxv7ARvLd/yXVGRUTIUgruhDxoZ9T0sPXWXIQUqQj+2ha7sx59nrB1k3ukdyWx7vyBe4obW0lxBMAGaTUfesaoq8dcGBGJNHdloI1pJuqnFkCa1KWQewXKVEoVal2brDWu1EzpTVt9o/crGawVRIKyRjOS1BS9BG0nhawbUYHtjXvN1W9kWFx6JsB6awlbdXDeJWg3uYStW5Vw4GcGdYqsuz8clym59foFDD72Oh+rrdT6WzGm1reAORBnAdx8xkUHf667NDJzpde8HyT3TFy9v5Py9lh3ETvXP/+1xz1VouQ7o2ETrjreA14EkjiDlZuMv+RO5smKnb7QzLFZ7cSXKtOKpQCuLTpVIBpgeGiy5VZSGTbbw+CDUm6qXF/GkD4jJABzdKyoXxJVmy9LriZotI+wuxsf59h9rOfzXL85+zQPnT0cGAgc8Q44FAiO1JMZLDtHXI9XIYAfpWXIjwwui09fJ57dKQeX6IXh2b/CyPOQbGZMeG395+nH6V2XCFvLT3AtT9Wby/h4HnGE6bgh7FU4TweC+zd8gpLv1Cl1nKUFp3iXnTrMMVigVulHYNtvqP65MkSCZYrM90xvR/QvC7JNNfB2nC89vlVZlz1SurYY5kNdBkkrQ6HcgeuuQFshzDoUuZZ4ygKlEVSrND3vgS7bQw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: j6ftK28Mx8WnMulVsrrUdhHXO9Usme7HVbQXzlpYngfX964Gw26OkU3GArqW6yJylaPLHjbZIa7JmLN+nkBBrLIurT1hcB5saWREcIQwsWg8kSvVMvVFGK6tA1Oi0CRGeqCkUoRoaJqZjudrBUEnFDxHKN8w7mtUFcEx+7DeDt8oEqN933CvtbryZ6YUaSouwvurbEgo1xgdCj0dq6uew5YIO7rdHTFAb60+LiERQoe255XwSZRLPLQdwR93Ef1tEtlarOuVnoIPkoTbmX88h5+hKcEw0zorgus6aDYCCPtv1kj1Nt0h2AS9WYEn3uz1JScgd0slDxeQWoNrZTtSUKYtF1DHjnlDUX4Jm33EwZC1sQAs3Cd23zae5pITdIlePHGl/1w9Qpl/cbq+hAyVrM1EazfTMgX50+pGa4FxPiwsc8ZvxKXI8WvLuk4kAcLuVB1ARe07CWgpJpU4hU26KGMXEJ00LnTZ9wS8v+XcRCF1kmd/D1g2wT6wkD3MJp/QVxYF7+lmk0JrXr9pmWEAbVivvvzml60YmdxWUO/q+1ROM7Sw5HN6WkoEyefOFUQJk7pZIffiJhiG981OgwvPPOUXFd+DgLmiNfr+5qCKXoc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3341b7cb-bf87-4376-9813-08dcf9112c77 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 18:32:13.7631 (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: QwRUf8IEVlh0TAi2df4b4Rr0dgQYOnz+6mf1eWFl8+N9jwuB2Q3MmBJY1q4P7pjuqtsgEu5mvaVImoxLrodZkA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4672 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-30_14,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410300145 X-Proofpoint-GUID: _ub0riLvnyLDmjrEKwtYzZyglTObDAwm X-Proofpoint-ORIG-GUID: _ub0riLvnyLDmjrEKwtYzZyglTObDAwm X-Spam-Status: No, score=-13.8 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Support the btf_decl_tag and btf_type_tag attributes in BTF by creating and emitting BTF_KIND_DECL_TAG and BTF_KIND_TYPE_TAG records, respectively, for them. Some care is required when -gprune-btf is in effect to avoid emitting decl or type tags for declarations or types which have been pruned and will not be emitted in BTF. gcc/ * btfout.cc (get_btf_kind): Handle DECL_TAG and TYPE_TAG kinds. (btf_calc_num_vbytes): Likewise. (btf_asm_type): Likewise. (output_asm_btf_vlen_bytes): Likewise. (output_btf_tags): New. (btf_output): Call it here. (btf_add_used_type): Replace with simple wrapper around... (btf_add_used_type_1): ...the implementation. Handle BTF_KIND_DECL_TAG and BTF_KIND_TYPE_TAG. (btf_add_vars): Update btf_add_used_type call. (btf_assign_tag_ids): New. (btf_mark_type_used): Update btf_add_used_type call. (btf_collect_pruned_types): Likewise. Handle type and decl tags. (btf_finish): Call btf_assign_tag_ids. gcc/testsuite/ * gcc.dg/debug/btf/btf-decl-tag-1.c: New test. * gcc.dg/debug/btf/btf-decl-tag-2.c: New test. * gcc.dg/debug/btf/btf-decl-tag-3.c: New test. * gcc.dg/debug/btf/btf-decl-tag-4.c: New test. * gcc.dg/debug/btf/btf-type-tag-1.c: New test. * gcc.dg/debug/btf/btf-type-tag-2.c: New test. * gcc.dg/debug/btf/btf-type-tag-3.c: New test. * gcc.dg/debug/btf/btf-type-tag-4.c: New test. * gcc.dg/debug/btf/btf-type-tag-c2x-1.c: New test. include/ * btf.h (BTF_KIND_DECL_TAG, BTF_KIND_TYPE_TAG) New defines. (struct btf_decl_tag): New. --- gcc/btfout.cc | 176 +++++++++++++++--- .../gcc.dg/debug/btf/btf-decl-tag-1.c | 14 ++ .../gcc.dg/debug/btf/btf-decl-tag-2.c | 22 +++ .../gcc.dg/debug/btf/btf-decl-tag-3.c | 22 +++ .../gcc.dg/debug/btf/btf-decl-tag-4.c | 34 ++++ .../gcc.dg/debug/btf/btf-type-tag-1.c | 27 +++ .../gcc.dg/debug/btf/btf-type-tag-2.c | 17 ++ .../gcc.dg/debug/btf/btf-type-tag-3.c | 21 +++ .../gcc.dg/debug/btf/btf-type-tag-4.c | 25 +++ .../gcc.dg/debug/btf/btf-type-tag-c2x-1.c | 23 +++ include/btf.h | 14 ++ 11 files changed, 371 insertions(+), 24 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-2.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-3.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-4.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-2.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-3.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-4.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-c2x-1.c diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 083ca48d627..e8190f685f9 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -141,6 +141,8 @@ get_btf_kind (uint32_t ctf_kind) case CTF_K_VOLATILE: return BTF_KIND_VOLATILE; case CTF_K_CONST: return BTF_KIND_CONST; case CTF_K_RESTRICT: return BTF_KIND_RESTRICT; + case CTF_K_DECL_TAG: return BTF_KIND_DECL_TAG; + case CTF_K_TYPE_TAG: return BTF_KIND_TYPE_TAG; default:; } return BTF_KIND_UNKN; @@ -217,6 +219,7 @@ btf_calc_num_vbytes (ctf_dtdef_ref dtd) case BTF_KIND_CONST: case BTF_KIND_RESTRICT: case BTF_KIND_FUNC: + case BTF_KIND_TYPE_TAG: /* These kinds have no vlen data. */ break; @@ -256,6 +259,10 @@ btf_calc_num_vbytes (ctf_dtdef_ref dtd) vlen_bytes += vlen * sizeof (struct btf_var_secinfo); break; + case BTF_KIND_DECL_TAG: + vlen_bytes += sizeof (struct btf_decl_tag); + break; + default: break; } @@ -452,6 +459,20 @@ btf_asm_type (ctf_dtdef_ref dtd) and should write 0. */ dw2_asm_output_data (4, 0, "(unused)"); return; + case BTF_KIND_DECL_TAG: + { + if (dtd->ref_type) + break; + else if (dtd->dtd_u.dtu_tag.ref_var) + { + /* ref_type is NULL for decl tag attached to a variable. */ + ctf_dvdef_ref dvd = dtd->dtd_u.dtu_tag.ref_var; + dw2_asm_output_data (4, dvd->dvd_id, + "btt_type: (BTF_KIND_VAR '%s')", + dvd->dvd_name); + return; + } + } default: break; } @@ -801,6 +822,12 @@ output_asm_btf_vlen_bytes (ctf_container_ref ctfc, ctf_dtdef_ref dtd) at this point. */ gcc_unreachable (); + case BTF_KIND_DECL_TAG: + dw2_asm_output_data (4, dtd->dtd_u.dtu_tag.component_idx, + "component_idx=%d", + dtd->dtd_u.dtu_tag.component_idx); + break; + default: /* All other BTF type kinds have no variable length data. */ break; @@ -851,6 +878,20 @@ output_btf_func_types (void) btf_asm_func_type (ref); } +static void +output_btf_tags (ctf_container_ref ctfc) +{ + /* If pruning, tags which are not pruned have already been added to + the used list and output by output_btf_types. */ + if (debug_prune_btf) + return; + + ctf_dtdef_ref dtd; + unsigned i; + FOR_EACH_VEC_ELT (*ctfc->ctfc_tags, i, dtd) + output_asm_btf_type (ctfc, dtd); +} + /* Output all BTF_KIND_DATASEC records. */ static void @@ -869,6 +910,7 @@ btf_output (ctf_container_ref ctfc) output_btf_types (ctfc); output_btf_vars (ctfc); output_btf_func_types (); + output_btf_tags (ctfc); output_btf_datasec_types (); output_btf_strs (ctfc); } @@ -985,7 +1027,8 @@ static vec fixups; is created and emitted. This vector stores them. */ static GTY (()) vec *forwards; -/* Recursively add type DTD and any types it references to the used set. +/* Implementation of btf_add_used_type. + Recursively add type DTD and any types it references to the used set. Return a type that should be used for references to DTD - usually DTD itself, but may be NULL if DTD corresponds to a type which will not be emitted. CHECK_PTR is true if one of the predecessors in recursive calls is a struct @@ -996,8 +1039,8 @@ static GTY (()) vec *forwards; CREATE_FIXUPS is false. */ static ctf_dtdef_ref -btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, - bool check_ptr, bool seen_ptr, bool create_fixups) +btf_add_used_type_1 (ctf_container_ref ctfc, ctf_dtdef_ref dtd, + bool check_ptr, bool seen_ptr, bool create_fixups) { if (dtd == NULL) return NULL; @@ -1029,8 +1072,9 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, fixups.unordered_remove (i); /* Add the concrete base type. */ - dtd->ref_type = btf_add_used_type (ctfc, dtd->ref_type, check_ptr, - seen_ptr, create_fixups); + dtd->ref_type = btf_add_used_type_1 (ctfc, dtd->ref_type, + check_ptr, seen_ptr, + create_fixups); return dtd; } default: @@ -1044,8 +1088,8 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, the reference to the bitfield. The slice type won't be emitted, but we need the information in it when writing out the bitfield encoding. */ - btf_add_used_type (ctfc, dtd->dtd_u.dtu_slice.cts_type, - check_ptr, seen_ptr, create_fixups); + btf_add_used_type_1 (ctfc, dtd->dtd_u.dtu_slice.cts_type, + check_ptr, seen_ptr, create_fixups); return dtd; } @@ -1069,7 +1113,11 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, case BTF_KIND_INT: case BTF_KIND_FLOAT: case BTF_KIND_FWD: - /* Leaf kinds which do not refer to any other types. */ + case BTF_KIND_DECL_TAG: + /* Leaf kinds which do not refer to any other types. + DECL_TAG is a special case: we treat it as though it does not refer + to any other types, since we only want the DECL_TAG to be added if + the type to which it refers has already been added. */ break; case BTF_KIND_FUNC: @@ -1082,6 +1130,7 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, case BTF_KIND_CONST: case BTF_KIND_VOLATILE: case BTF_KIND_RESTRICT: + case BTF_KIND_TYPE_TAG: { /* These type kinds refer to exactly one other type. */ if (check_ptr && !seen_ptr) @@ -1106,18 +1155,18 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, } /* Add the type to which this type refers. */ - dtd->ref_type = btf_add_used_type (ctfc, dtd->ref_type, check_ptr, - seen_ptr, create_fixups); + dtd->ref_type = btf_add_used_type_1 (ctfc, dtd->ref_type, check_ptr, + seen_ptr, create_fixups); break; } case BTF_KIND_ARRAY: { /* Add element and index types. */ ctf_arinfo_t *arr = &(dtd->dtd_u.dtu_arr); - arr->ctr_contents = btf_add_used_type (ctfc, arr->ctr_contents, false, - false, create_fixups); - arr->ctr_index = btf_add_used_type (ctfc, arr->ctr_index, false, false, - create_fixups); + arr->ctr_contents = btf_add_used_type_1 (ctfc, arr->ctr_contents, + false, false, create_fixups); + arr->ctr_index = btf_add_used_type_1 (ctfc, arr->ctr_index, false, + false, create_fixups); break; } case BTF_KIND_STRUCT: @@ -1133,8 +1182,8 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, /* Add member type for struct/union members. For enums, only the enumerator names are needed. */ if (kind == BTF_KIND_STRUCT || kind == BTF_KIND_UNION) - dmd->dmd_type = btf_add_used_type (ctfc, dmd->dmd_type, true, - false, create_fixups); + dmd->dmd_type = btf_add_used_type_1 (ctfc, dmd->dmd_type, true, + false, create_fixups); ctf_add_string (ctfc, dmd->dmd_name, &(dmd->dmd_name_offset), CTF_STRTAB); } @@ -1143,16 +1192,17 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, case BTF_KIND_FUNC_PROTO: { /* Add return type. */ - dtd->ref_type = btf_add_used_type (ctfc, dtd->ref_type, false, false, - create_fixups); + dtd->ref_type = btf_add_used_type_1 (ctfc, dtd->ref_type, false, false, + create_fixups); /* Add arg types. */ ctf_func_arg_t * farg; for (farg = dtd->dtd_u.dtu_argv; farg != NULL; farg = (ctf_func_arg_t *) ctf_farg_list_next (farg)) { - farg->farg_type = btf_add_used_type (ctfc, farg->farg_type, false, - false, create_fixups); + farg->farg_type = btf_add_used_type_1 (ctfc, farg->farg_type, + false, false, + create_fixups); /* Note: argument names are stored in the auxilliary string table, since CTF does not include arg names. That table has not been cleared, so no need to re-add argument names here. */ @@ -1166,6 +1216,16 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, return dtd; } +/* Recursively add type DTD and any types it references to the used set. + Return a type that should be used for references to DTD - usually DTD itself, + but may be NULL if DTD corresponds to a type which will not be emitted. */ + +static ctf_dtdef_ref +btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) +{ + return btf_add_used_type_1 (ctfc, dtd, false, false, true); +} + /* Initial entry point of BTF generation, called at early_finish () after CTF information has possibly been output. Translate all CTF information to BTF, and do any processing that must be done early, such as creating @@ -1402,7 +1462,7 @@ btf_add_vars (ctf_container_ref ctfc) ctf_dmdef_t *dmd; for (dmd = dtd->dtd_u.dtu_members; dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd)) - btf_add_used_type (ctfc, dmd->dmd_type, false, false, true); + btf_add_used_type (ctfc, dmd->dmd_type); } } } @@ -1488,6 +1548,50 @@ btf_assign_var_ids (ctf_container_ref ctfc) } } +/* Assign BTF IDs for type and decl tags and account for their size. */ + +static void +btf_assign_tag_ids (ctf_container_ref ctfc) +{ + /* Both decl and type tags may be pruned if the types/decls to which they + refer are pruned. This is handled in collect_pruned_types, and through + that process they have also been assigned ids already. */ + if (debug_prune_btf) + return; + + size_t num_tags = vec_safe_length (ctfc->ctfc_tags); + if (num_tags == 0) + return; + + unsigned int i; + ctf_dtdef_ref dtd; + FOR_EACH_VEC_ELT (*ctfc->ctfc_tags, i, dtd) + { + /* Assign BTF id. */ + ctf_id_t id = ctfc->ctfc_nextid++; + gcc_assert (id <= BTF_MAX_TYPE); + dtd->dtd_type = id; + + /* Tags on functions will have a ref_type pointing to the + FUNC_PROTO, we want them to point the FUNC record instead. */ + ctf_dtdef_ref *pdtd = NULL; + if (dtd->ref_type && (pdtd = func_map->get (dtd->ref_type)) != NULL) + { + dtd->ref_type = *pdtd; + } + + /* Strings for tags are stored in the auxilliary strtab, which is + concatenated after the regular strtab. ctti_name only accounts + for offset in the auxilliary strtab until this point. */ + dtd->dtd_data.ctti_name += ctfc_get_strtab_len (ctfc, CTF_STRTAB); + + ctfc->ctfc_num_types++; + + if (btf_dtd_kind (dtd) == BTF_KIND_DECL_TAG) + ctfc->ctfc_num_vlen_bytes += sizeof (struct btf_decl_tag); + } +} + /* Assign BTF IDs for datasec records and account for their size. */ static void @@ -1522,7 +1626,7 @@ btf_mark_type_used (tree t) if (!dtd) return; - btf_add_used_type (ctfc, dtd, false, false, true); + btf_add_used_type (ctfc, dtd); } /* Callback used for assembling the only-used-types list. Note that this is @@ -1549,7 +1653,7 @@ btf_collect_pruned_types (ctf_container_ref ctfc) size_t i; FOR_EACH_VEC_ELT (*funcs, i, dtd) { - btf_add_used_type (ctfc, dtd->ref_type, false, false, true); + btf_add_used_type (ctfc, dtd->ref_type); ctf_add_string (ctfc, dtd->dtd_name, &(dtd->dtd_data.ctti_name), CTF_STRTAB); } @@ -1558,10 +1662,33 @@ btf_collect_pruned_types (ctf_container_ref ctfc) for (i = 0; i < ctfc->ctfc_vars_list_count; i++) { ctf_dvdef_ref dvd = ctfc->ctfc_vars_list[i]; - btf_add_used_type (ctfc, dvd->dvd_type, false, false, true); + btf_add_used_type (ctfc, dvd->dvd_type); ctf_add_string (ctfc, dvd->dvd_name, &(dvd->dvd_name_offset), CTF_STRTAB); } + /* Used type tags will be added by recursive btf_add_used_type calls above. + For decl tags, scan the list and only add those decl tags whose referent + types are marked as used. We may have pruned a struct type with members + annotated by a decl tag. */ + FOR_EACH_VEC_ELT (*ctfc->ctfc_tags, i, dtd) + { + /* Only add decl tags whose referent types have not been pruned. + Variables are never pruned, so decl tags on variables are always + used. */ + if (btf_dtd_kind (dtd) == BTF_KIND_DECL_TAG + && ((dtd->ref_type && btf_used_types->contains (dtd->ref_type)) + || (dtd->dtd_u.dtu_tag.ref_var))) + btf_add_used_type (ctfc, dtd); + + /* Tags on functions or function args will have a ref_type pointing to the + FUNC_PROTO, we want them to point the FUNC record instead. */ + ctf_dtdef_ref *pdtd = NULL; + if (dtd->ref_type + && btf_used_types->contains (dtd->ref_type) + && (pdtd = func_map->get (dtd->ref_type)) != NULL) + dtd->ref_type = *pdtd; + } + /* Process fixups. If the base type was never added, create a forward for it and adjust the reference to point to that. If it was added, then nothing needs to change. */ @@ -1634,6 +1761,7 @@ btf_finish (void) btf_assign_var_ids (tu_ctfc); btf_assign_func_ids (tu_ctfc); + btf_assign_tag_ids (tu_ctfc); btf_assign_datasec_ids (tu_ctfc); /* Finally, write out the complete .BTF section. */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-1.c new file mode 100644 index 00000000000..c933d84b497 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-1.c @@ -0,0 +1,14 @@ +/* Test simple BTF decl tag generation for variables. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_decl_tag ("decl1"))) +#define __tag2 __attribute__((btf_decl_tag ("decl2"))) +#define __tag3 __attribute__((btf_decl_tag ("decl3"))) + +int x __tag1 __tag2; +int y __tag1; + +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 'x'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 'x'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 'y'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-2.c b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-2.c new file mode 100644 index 00000000000..c4f09ca839c --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-2.c @@ -0,0 +1,22 @@ +/* Test BTF decl tag generation for structs. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_decl_tag ("decl1"))) +#define __tag2 __attribute__((btf_decl_tag ("decl2"))) +#define __tag3 __attribute__((btf_decl_tag ("decl3"))) + +struct Foo { + int a; + int b __tag3 __tag2; + char *z __tag1; +}; + +struct Foo f __tag1 __tag2; + +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_STRUCT 'Foo'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl3'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_STRUCT 'Foo'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_STRUCT 'Foo'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=2" 1} } */ + +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 'f'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 'f'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-3.c b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-3.c new file mode 100644 index 00000000000..7eb8a93ec12 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-3.c @@ -0,0 +1,22 @@ +/* Test BTF decl tag generation for functions and function args. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_decl_tag ("decl1"))) +#define __tag2 __attribute__((btf_decl_tag ("decl2"))) +#define __tag3 __attribute__((btf_decl_tag ("decl3"))) + +int __tag1 __tag2 func (int arg_a __tag3 __tag1, int arg_b __tag2) +{ + return arg_a * arg_b; +} + +int foo (int x) { + return func (x, x + 1); +} + +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=0" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl3'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=0" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=1" 1} } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-4.c b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-4.c new file mode 100644 index 00000000000..a9022375529 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-4.c @@ -0,0 +1,34 @@ +/* Test BTF decl tag generation with BTF pruning. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -gprune-btf -dA" } */ + +#define __decl1 __attribute__((btf_decl_tag ("decl1"))) +#define __decl2 __attribute__((btf_decl_tag ("decl2"))) +#define __decl3 __attribute__((btf_decl_tag ("decl3"))) + +struct S { + /* This tag on S.v shall not be emitted, because struct S is pruned and + replaced with a FWD, which does not hold any member info. */ + int v __decl3; + int w; +}; + +struct T { + int a; + struct S *s __decl1; + int c __decl2; +}; + +struct T t __decl1; + +int __decl1 func (struct T *t __decl2) +{ + return t->a + t->c; +} + +/* { dg-final { scan-assembler-not " BTF_KIND_DECL_TAG 'decl3'" } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_STRUCT 'T'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_STRUCT 'T'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=2" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 't'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=0" 1} } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-1.c new file mode 100644 index 00000000000..750add9d923 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-1.c @@ -0,0 +1,27 @@ +/* Test simple generation of BTF type tags. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_type_tag("type1"))) +#define __tag2 __attribute__((btf_type_tag("type2"))) +#define __tag3 __attribute__((btf_type_tag("type3"))) + +int __tag1 __tag2 x; +int __tag1 y; + +struct Foo { + char a; + int b; +}; + +struct Foo * __tag1 __tag3 f; + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'x'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type2'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1} } */ + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'y'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1 } } */ +/* { dg-final { scan-assembler " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_INT" } } */ + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'f'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type3'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type3'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_PTR" 1 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-2.c b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-2.c new file mode 100644 index 00000000000..35126fc84ae --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-2.c @@ -0,0 +1,17 @@ +/* Test BTF type tag generation with cv-quals. + BTF format requires that type tags precede cv-quals on a given + type in the type chain. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_type_tag("type1"))) +#define __tag2 __attribute__((btf_type_tag("type2"))) +#define __tag3 __attribute__((btf_type_tag("type3"))) + +/* var (a) -> tag2 -> tag1 -> const -> int */ +const int __tag1 __tag2 a; + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'a'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type2'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_CONST ''\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_CONST ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_INT" 1 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-3.c b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-3.c new file mode 100644 index 00000000000..c6523830f07 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-3.c @@ -0,0 +1,21 @@ +/* Test BTF type tag generation with typedefs. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_type_tag("type1"))) +#define __tag2 __attribute__((btf_type_tag("type2"))) +#define __tag3 __attribute__((btf_type_tag("type3"))) + +typedef const int foo; +typedef int __tag1 bar; + +foo __tag2 x; +const bar y; + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'x'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type2'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPEDEF 'foo'\\)" 1 } } */ + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'y'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_CONST" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_CONST ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPEDEF 'bar'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPEDEF 'bar'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_INT" 1 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-4.c b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-4.c new file mode 100644 index 00000000000..1fb97232242 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-4.c @@ -0,0 +1,25 @@ +/* Test BTF type tag generation with BTF pruning. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -gprune-btf -dA" } */ + +#define __tag1 __attribute__((btf_type_tag("type1"))) +#define __tag2 __attribute__((btf_type_tag("type2"))) +#define __tag3 __attribute__((btf_type_tag("type3"))) + +struct S { + int v ; + /* This tag on S.w shall not be emitted because struct S is pruned. */ + int __tag3 w; +}; + +struct T { + int __tag1 a; + struct S * __tag2 s; + int c; +}; + +struct T t; + +/* { dg-final { scan-assembler-not " BTF_KIND_TYPE_TAG 'type3'" } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_INT" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_PTR" 1} } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-c2x-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-c2x-1.c new file mode 100644 index 00000000000..c6129d6dd56 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-c2x-1.c @@ -0,0 +1,23 @@ +/* Test BTF type tag generation using C2x standard attribute syntax. + Note: in more complicated cases the __attribute__ syntax causes BTF type tags + to "slide around" in defined, but often unexpected ways. */ + +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 [[gnu::btf_type_tag ("type1")]] +#define __tag2 [[gnu::btf_type_tag ("type2")]] +#define __tag3 [[gnu::btf_type_tag ("type3")]] + +/* var (z) -> tag2 -> tag3 -> const -> ptr -> tag2 -> ptr -> tag1 -> volatile -> int */ +volatile int __tag1 * __tag2 * __tag3 __tag2 const z; + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'z'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type2'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type3'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type3'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_CONST" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_CONST ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_PTR" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_PTR ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type2'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_PTR" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_PTR ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VOLATILE ''\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_VOLATILE ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_INT" 1 } } */ diff --git a/include/btf.h b/include/btf.h index 0c3e1a1cf51..ff152362530 100644 --- a/include/btf.h +++ b/include/btf.h @@ -114,6 +114,8 @@ struct btf_type #define BTF_KIND_VAR 14 /* Variable. */ #define BTF_KIND_DATASEC 15 /* Section such as .bss or .data. */ #define BTF_KIND_FLOAT 16 /* Floating point. */ +#define BTF_KIND_DECL_TAG 17 /* Declaration tag. */ +#define BTF_KIND_TYPE_TAG 18 /* Type tag. */ #define BTF_KIND_ENUM64 19 /* Enumeration up to 64 bits. */ #define BTF_KIND_MAX BTF_KIND_ENUM64 #define NR_BTF_KINDS (BTF_KIND_MAX + 1) @@ -227,6 +229,18 @@ struct btf_enum64 uint32_t val_hi32; /* high 32-bit value for a 64-bit value Enumerator */ }; +/* BTF_KIND_DECL_TAG is followed by a single struct btf_decl_tag, which + describes the item to which the tag applies: + - If component_idx == -1, then the tag applies to item referred to by + the type_id. + - Otherwise, the tag applies to the struct or union member, or function + argument of the type referred to by type_id with the 0-based index + given by component_idx. */ +struct btf_decl_tag +{ + int32_t component_idx; +}; + #ifdef __cplusplus } #endif