From patchwork Wed Oct 30 18:31:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 99838 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 4E2C93857737 for ; Wed, 30 Oct 2024 18:33:12 +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 5BDA73857C6D for ; Wed, 30 Oct 2024 18:32:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BDA73857C6D 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 5BDA73857C6D 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=1730313141; cv=pass; b=pol0XF1sO/iPIvLda0HVNr+fCDiJs9P9oYx3yNEU+kdbc8yObzCC2yKLLjICfkJ9PEftd4hz+UgktpUYEuHFKzj9piKKS/jqEtYeBG1ZWq2NuNuJVjomi6Qm+m6d/0v/WPxM+e3F7wVHAAYW+L1IKDq0RCLaAjwb6q1bsxIu7ao= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313141; c=relaxed/simple; bh=/g6sYqVhdSWcBn2Kcy71W/+gSldHkrddaOcAsihGEFY=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=tLmtbA7beeu0KHtDklpCNmnY+cenrGshe1CEFsbyTkOQoFDgc3rkO6WB8KhcQ1d8PREmoxdm3qp4C7GjJyjq9blCEW5y8yS8qr9uBR5BcuBTXbmm8sgosg+c+Hbp6cZoKpJl2jyGP4j6YXQrQhqBc81Ynqg6V+ra0rfiJ35FgaM= 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 49UGXZ6u017446; Wed, 30 Oct 2024 18:32:14 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=7u1EAHFlQGVqWiYgXIuVDs5iod4HdjzW27O9NZhAKc8=; b= jIjf0jnPw5sjcBGpZ5wKhQARKVeyu62n4fDS3WLqrswFcAAbNp8lUSY3B6M8WK0/ DFZwEU28xNUAnuGgFL2diNwJftE0pl5QociRTj9LY/hrW0yrs7G/NbvJQK3216FA rWXBWt//BMyk5ErdCUFYkXgsMebXAEdV/LZmcLr+fgFDdjIayhx4E5mHQNl2nDmA /w4oac2REnyNMjNMFV7moqBLkHfhCE9EUw1jehPoLpn6TuljIBDKIQDOVeDyhf75 b/3M+v9bsQ+g0Kpx0Vxg0wFXIBd5JrcFmML/2pyNiwylQ+1SNCO86fmhn4yqe/Pt XX1192cJX6yA9o/Fqg/+2Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdxrr3p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:14 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49UHsren040543; Wed, 30 Oct 2024 18:32:13 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2174.outbound.protection.outlook.com [104.47.56.174]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42hnaqxyya-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZK8FHwrv3nxqNS+GyYr4G1Bc4zkCRPVMBaA73QMDCpWypmGjc14nODvTDBNM6fPmH8fJvA/emma4RZ0H3ZuQRAOz2EBk4xhuSWfyCPqTDVeEBHLkvbDWOJZOeOmkx9CdW3EcTL7LJu6eYcUQoScUwI3IvVbnKj7Cxg+8xYXK7v3SaCMk8UvOjq4yOZsiAy0e7icG5WHkA5wlUqjhYVQ76QjldNQQYHz+7+4WxuAIEamXN+UM9fzsfDTITTTWDKTh2UIpSnMbR7XY13eDsKIXwSwyMkt1dvvUUrpmPIXrPvvOT8hIvcnvgphX7AzzvnZw2y6VOpH6EPmxfzV5OXJt6A== 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=7u1EAHFlQGVqWiYgXIuVDs5iod4HdjzW27O9NZhAKc8=; b=sTyuWR7ww7Tgz5bz7UUudL1J7/6+LSQrjXejuTpi3p8C3Px/0A6ytxL6v7jhqcCA7QYjxshWWvXN+zuHB1a3KTwQxjEKWeKMpVDDXwkxzuYYNRM3DJAxtBesl47aN68Rr39IBnuIpCphMze4YJsLxr5bGqd6uFQ2HTi99XtYk2tNyrkDfUs+2UJ6dE+FBZ6Iki2k1hTkta5w3mjU2JqCI/w861DKRq8lpeMkSHankq8U2kDrtt8R7/5nGjAzXQSQYdGYe2RX5f51OLwfQ3wjFzzqpS9iC4A70YEZxYBQfCGzoyiEhl8E7UDh7ERXics+5nHCsLgoJ7RCY0xHUjC+7A== 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=7u1EAHFlQGVqWiYgXIuVDs5iod4HdjzW27O9NZhAKc8=; b=VELyic2jVt5kpY050tx6G8HkrPP820hE5UM7Llg8CEFbDP0yXbqubBjZRvS0+yXvf+m7nzXMCFQ0cyj3IxelzFdsBSPnUbkUAZG2KeHW6OrX2+4M6mJ3Nn1EbIGKDLBd21iJCxUgM9itSD3dXPOv0pq9N5BW3ThgoUNX9qhIUGA= 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:10 +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:10 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, yonghong.song@linux.dev Subject: [PATCH 3/5] ctf: translate annotation DIEs to internal ctf Date: Wed, 30 Oct 2024 11:31:53 -0700 Message-ID: <20241030183155.2038501-4-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: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) 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: 1c5b100c-b6b2-4b99-77e2-08dcf9112ac2 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: 3G0JU0721IMebPMQuyum2lcGFQ3LUlp0zy6+cl/uJ+PC+bHS2ODKadgoKumGpUQAK+IJlCk1dPUud80Z/FCMqFXnlb4nWPqq4NbQSIa3Epfv3PsT8w9eg0PiddKt9f8daEW3dIWQ4cTH3tcRDasYePeoqh7yMAPXM2UvlsccyGUZw1g5DGLQM255A7VPeaGzBEvJHbG+wAArOC+pBhMtyT6CGs4hJBYRcpYP/vG6szP4SuqVbQsWG0NmQB0GhhyBVC6hUdnlUVjHgJ6lqJ4kNiScB0N7frORdRcl/xbbS/7BAb7BN8boP4iJpN3vHGudiEeXIZhXMNPIrrLzxZnhb4ISuG0fkj+8PcnCMp3le5jKSQtOAWjsonbU6Tt+Zhyr/5Re4ztEMuAEiaDA9n580PIGFWDREO+XiiNmPZgkP8ECgO17aw6VDDL4maq2Rn58oNxw70XcbOSV/vTqOIr9zPukG0geDdTo0AckmqJoelqXR1ExPCUUKBBANBqKfM8pAkpcOe4H/ESmCmOiKCufvwmZeAnLObY5BaVpXF6lTZEQouBcBVSokEJLkgpLTQVPAnnh27SB0bnhH/vjKteVQvhbWfx1WsFx1y/Q5Bf2xwGE/4RHXrRSWinQ2Yg6VsUoqnF+QjODHQP55URgCbFILvG0f4G88uKdY8bb/VHHgXHbeN7FhqRYF5IJJ9QS0TLMR5IVAGIiGL07TQ1AO4vuUVcgWPyXMkOfXV6ji1c54W77g4uJ0WbHx9WwjwFxnkCtNmR45gxr7rYjsTpY5+QYpooKbTj5Kr/roXrXvia1M7vnVMlL1ODVs/BWDOLg6psWmz0NHtMVug/I17QtsYDE1Ufd0+jWYi6WKPjH9fsFOA6cj95Yaw1DQxsZJekT95kcTNMe/YRBIuIUY0edO39tjxzdG8Ibbmafv+sDGk6Gig/U+5KfeuCygOn2Co6ovlODUamlT8ghJTKRCX18rDjmTzsbBmbPIJ8+cIELXJljdkfq3tFzsC9pkJK8V0B7/SlOrG5BPjvNz7CB5vENc3hR8Q/yvEEqZKFUGNX5jM6+JADe2dZC4QMYxcN+r45iymW2XU/bTgmOwxM29Gm7C6/ozqOgU+7k1zWVkAbYdZklL8BhIuFzcRphPGKqy8KqtC+BlEL8klpdBL8Fdcs7LmhHtE6EWPXz5wQ7QGsqWC/rElddXNDUSHCe6qnCIJU1I11C0hqm0FhP+SyIoA9WlR/oWjuLtlhXQ0HBOZXx+CPIliWBn+wgCuuuBqrDVdlPBpJTW+ySiM8mR104vc4rtDMzudnhqmglMCZJlObyLHBBNFACLxnmEj55mKMe7qKX8frV 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: hevYwhbe2h46UqAAmr0+ao/J+awZGxBdI+12Gcn220bvGPdxzO/EfdVd3lQ3bMiBbka6hxz+1F6akaKG5JMybVo/jXBGLj8hldtCciwG+jz0umqtE85/l8sQZ7ZGGTL1OUM5SHY/kojCFqjdyqp7b9naxTMnHoZwa21RYgOd7yqolRblXaTt/tgUO5HVzJ3VYdey6WQicqfN/ol5FA1oPU3xIQWY53fkVqp50W0QXPkvq66SrjETsXr1bDg/A2Pas/GiHAEsQFn8cJgCuF6/CZ+8TzeJL48A5bpikUHhv1TZizR8gJ3Bsq0Bv6DZMEBVzkyycSulKw4gBaFejPBlJb5StVlZv9mgwgmCeTEEktet9WvqkZu2z6LFwJ2wwBKPbihibF3T9qdlrRDXy3cmwp/UAznBpeVCfrhoeQ1MAaXum/TqahY8oNWvAwgbA7l9Ilbn/utDHk2qe7CvtbDjEtqDAIze10I53xUvy2A/GNwmjQbTZDXfnTLsPBT5Xv1LtIg9fKrSXBNo2ntaYhRDBFolOu4kvyWssSBYw4WqrMubBgFNgqYM0sow+2XO/5rQ91SpIW2q7vo0mXicucu2yEAyCKdoVj9CaDhiAisgQ59Ts0uyvcIoktS7Y3gPsdqyOdpUTJnK/FkTYhU364UXO7w7Y2ng4vxHF2H8uWcfoDuJvNq6VyZTzne6OJwFfdnlT05qH521ZciprLmq/XOT3s9Yy8JOTtANMslTGSXXIoK/e1Mb2eSEFVdG+b5UGj+I7J9EhsODW/IukluwNapZEaGr1Ey0hiURjtGcf9PFPOhKqmlIEIRQVdY/+AZr6CiMO7TFeoIkCgfXN+8x1uxjQPPL+hEeSLJtlZcjl+PWUh5byb4qDbrUETPFvKKJRyvE+hfjOpWHwyXLuKsbMcwkZjyFF8QEDs/Pqh2BRdzpoiWSg3KpQmaiQinJnnVqcmvGn09nQyl0BKx8YVYw3R3/SjqjWsEidW9BnUi1cAV4rf2Oe6r1ub6HTSoKf4xq6VLqw3QLhFlYBscov9XBQX4h0CB/VO3gaV7c81SuBqPjuBJwXiJ9AmM43MzH7/kQA4uncK/w1uOE50Qk0li6TpaJndlguSZ7uSQVexGrHriQEZgo4vbsodKsv686Bd0BOhuav0RnXNEFL1JXIvZ/dEuUGmZhc+w+LwpNlIBB9tviWUvqtywGN8tmM+qvXUGODL1AuWWg8QX8iKbt02oWkXHCHifvGhcJBKSilDkMJhmg2SBdwhZqraLrhNUOGbpWwkAVC2IpMWhsZdlNbxmxV0hZhCcYYupTVSzB6rRQBnhHhD3naU0YRK7RBxqNRI7kE0R9G0eK7/qAZtE0L5wSA2bGfnLK7KAHeWSmfm4LD8RdJxL1in+d02v+jlF663D/HcbaIPjPLqjn9nJt26iXpUTiOKc/X119GC0YjKlqx6A0Kxm4U4wO5+5hfqkUMvzv5q6O2cf9Aa5qdSrTn7wHUTh/UibucrXmlcjqSYCuFp6bFkREvLjCM1WaXyOwc3YLSGGRCZU8HAo2GbEsxupx0toftTV67jRiWVRXRv01sAaUVUBGudz74ibwIUn5m0K4Oq917fxHv94Iu8s6lGVCLzjbpQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: dMnqGlL47nc6OEbyZUMbd714njfhQiEmbDkf61xIvLy3Y7auWncOR7OYbjIJpvbWog+8PtOIvXTF0mBPdg7BQb08AMGdSPXYM/kIrjGRCW3XbGLdDceHeg8NwZep8eZ1GXdAN5ESV6JIUe38JvZ3/ocDVuKPzKRAUIMobchIyzzoHreA1LckiEHxmghvWFZJEzJCHNvrJ9+v15jmpuuJk3w7OjfAhE6eLcbaYqOifVxkOdhvCzzAAzdrwY0Ovwx682nbW7o4/sjlUMB4N2yynRR1eJc/MI5G7EUen7kJHN5ImAeZvfRAAItuuK2NLzcOPja/1SD1rkeImfRmTYO/NeYRHymInRTQ8qqzjeF35xtjmpquYVkPYBid87jf+2umBRuM3yVBFgXCqnuQ/yJD4T+ytlmYk5xu/rLawnR5x7s5Y6Jmwc4KSoyRptXdPO5eND8OE5TUSXOC4Q7PoE+G0fyT22oqM1rxrOGCRCeTMoJCy9lY90uXt5BaQL7yVSWgKEqMP2lrTY/zNYWVVUIz18ZblX8x2JVNTd7oKXfF8imSa8lL7rpLQbJgxRmHlrtUcL99c6OSHIVnrigMGXIM3G0MEyOC7YhEneWWPwPDgts= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c5b100c-b6b2-4b99-77e2-08dcf9112ac2 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:10.8628 (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: 3UKPrK6XxgwreScwfbYjTMc3zOMZ0wxQsNDIAWxeOp23pYie+71imVUhSDt1nSc5wRzwSs+V639etNRe2mh6OA== 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 suspectscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410300145 X-Proofpoint-GUID: Qwxqi_LV_Lsh7BuLPVx6TlMLzloFEBUj X-Proofpoint-ORIG-GUID: Qwxqi_LV_Lsh7BuLPVx6TlMLzloFEBUj 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 Translate DW_TAG_GNU_annotation DIEs created for C attributes btf_decl_tag and btf_type_tag into an in-memory representation in the CTF/BTF container. They will be output in BTF as BTF_KIND_DECL_TAG and BTF_KIND_TYPE_TAG records. The new CTF kinds used to represent these annotations, CTF_K_DECL_TAG and CTF_K_TYPE_TAG, are expected to be formalized in the next version of the CTF specification. For now they only exist in memory as a translation step to BTF, and are not emitted when generating CTF information. gcc/ * ctfc.cc (ctf_dtu_d_union_selector): Handle CTF_K_DECL_TAG and CTF_K_TYPE_TAG. (ctf_add_type_tag, ctf_add_decl_tag): New. (ctf_add_variable): Return the new ctf_dvdef_ref rather than zero. (new_ctf_container): Initialize new members. (ctfc_delete_container): Deallocate new members. * ctfc.h (ctf_dvdef, ctf_dvdef_t, ctf_dvdef_ref): Move forward declarations earlier in file. (ctf_tag_t): New typedef. (ctf_dtdef): Add ctf_tag_t member to dtd_u union. (ctf_dtu_d_union_enum): Add new CTF_DTU_D_TAG enumerator. (ctf_container): Add ctfc_tags vector and ctfc_tags_map hash_map members. (ctf_add_type_tag, ctf_add_decl_tag): New function protos. (ctf_add_variable): Change prototype return type to ctf_dvdef_ref. * dwarf2ctf.cc (gen_ctf_type_tags, gen_ctf_decl_tags) (gen_ctf_decl_tags_for_var): New static functions. (gen_ctf_modifier_type): Handle type tags on types with cv-quals. (gen_ctf_sou_type): Handle decl tags. (gen_ctf_function_type): Likewise. (gen_ctf_variable): Likewise. (gen_ctf_function): Likewise. (is_cvr_die): New helper function. (gen_ctf_type): Handle type tags. include/ * ctf.h (CTF_K_DECL_TAG, CTF_K_TYPE_TAG): New defines. --- gcc/ctfc.cc | 66 ++++++++++++++++- gcc/ctfc.h | 41 +++++++++-- gcc/dwarf2ctf.cc | 180 +++++++++++++++++++++++++++++++++++++++++++++-- include/ctf.h | 4 ++ 4 files changed, 277 insertions(+), 14 deletions(-) diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc index 8f531ffebf8..8fca36caa1e 100644 --- a/gcc/ctfc.cc +++ b/gcc/ctfc.cc @@ -107,6 +107,9 @@ ctf_dtu_d_union_selector (ctf_dtdef_ref ctftype) return CTF_DTU_D_ARGUMENTS; case CTF_K_SLICE: return CTF_DTU_D_SLICE; + case CTF_K_DECL_TAG: + case CTF_K_TYPE_TAG: + return CTF_DTU_D_TAG; default: /* The largest member as default. */ return CTF_DTU_D_ARRAY; @@ -445,6 +448,54 @@ ctf_add_reftype (ctf_container_ref ctfc, uint32_t flag, ctf_dtdef_ref ref, return dtd; } +ctf_dtdef_ref +ctf_add_type_tag (ctf_container_ref ctfc, uint32_t flag, const char *value, + ctf_dtdef_ref ref_dtd) +{ + ctf_dtdef_ref dtd; + /* Create a DTD for the tag, but do not place it in the regular types list; + ctf format does not (yet) encode tags. */ + dtd = ggc_cleared_alloc (); + + dtd->dtd_name = ctf_add_string (ctfc, value, &(dtd->dtd_data.ctti_name), + CTF_AUX_STRTAB); + /* Tags uniquely have a one-to-many relationship where one die may translate + to many ctf types. Therefore we cannot key the tags by die. */ + dtd->dtd_key = NULL; + dtd->ref_type = ref_dtd; + dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_TYPE_TAG, flag, 0); + dtd->dtd_u.dtu_tag.ref_var = NULL; /* Not used for type tags. */ + dtd->dtd_u.dtu_tag.component_idx = -1U; /* Not used for type tags. */ + + /* Insert tag directly into the tag list. Type ID will be assigned later. */ + vec_safe_push (ctfc->ctfc_tags, dtd); + return dtd; +} + +ctf_dtdef_ref +ctf_add_decl_tag (ctf_container_ref ctfc, uint32_t flag, const char *value, + ctf_dtdef_ref ref_dtd, uint32_t comp_idx) +{ + ctf_dtdef_ref dtd; + /* Create a DTD for the tag, but do not place it in the regular types list; + ctf format does not (yet) encode tags. */ + dtd = ggc_cleared_alloc (); + + dtd->dtd_name = ctf_add_string (ctfc, value, &(dtd->dtd_data.ctti_name), + CTF_AUX_STRTAB); + /* Tags uniquely have a one-to-many relationship where one die may translate + to many ctf types. Therefore we cannot key the tags by die. */ + dtd->dtd_key = NULL; + dtd->ref_type = ref_dtd; + dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_DECL_TAG, flag, 0); + dtd->dtd_u.dtu_tag.ref_var = NULL; + dtd->dtd_u.dtu_tag.component_idx = comp_idx; + + /* Insert tag directly into the tag list. Type ID will be assigned later. */ + vec_safe_push (ctfc->ctfc_tags, dtd); + return dtd; +} + ctf_dtdef_ref ctf_add_forward (ctf_container_ref ctfc, uint32_t flag, const char * name, uint32_t kind, dw_die_ref die) @@ -691,12 +742,12 @@ ctf_add_member_offset (ctf_container_ref ctfc, dw_die_ref sou, return 0; } -int +ctf_dvdef_ref ctf_add_variable (ctf_container_ref ctfc, const char * name, ctf_dtdef_ref ref, dw_die_ref die, unsigned int external_vis, dw_die_ref die_var_decl) { - ctf_dvdef_ref dvd, dvd_ignore; + ctf_dvdef_ref dvd = NULL, dvd_ignore; gcc_assert (name); @@ -732,7 +783,7 @@ ctf_add_variable (ctf_container_ref ctfc, const char * name, ctf_dtdef_ref ref, ctfc->ctfc_strlen += strlen (name) + 1; } - return 0; + return dvd; } int @@ -949,6 +1000,10 @@ new_ctf_container (void) tu_ctfc->ctfc_ignore_vars = hash_table::create_ggc (10); + vec_alloc (tu_ctfc->ctfc_tags, 100); + tu_ctfc->ctfc_tags_map + = hash_map::create_ggc (100); + return tu_ctfc; } @@ -1003,6 +1058,11 @@ ctfc_delete_container (ctf_container_ref ctfc) ctfc->ctfc_ignore_vars->empty (); ctfc->ctfc_ignore_vars = NULL; + ctfc->ctfc_tags = NULL; + + ctfc->ctfc_tags_map->empty (); + ctfc->ctfc_tags_map = NULL; + ctfc_delete_strtab (&ctfc->ctfc_strtable); ctfc_delete_strtab (&ctfc->ctfc_aux_strtable); if (ctfc->ctfc_vars_list) diff --git a/gcc/ctfc.h b/gcc/ctfc.h index 41e1169f271..cf73a566c3d 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -52,6 +52,10 @@ struct ctf_dtdef; typedef struct ctf_dtdef ctf_dtdef_t; typedef ctf_dtdef_t * ctf_dtdef_ref; +struct ctf_dvdef; +typedef struct ctf_dvdef ctf_dvdef_t; +typedef ctf_dvdef_t * ctf_dvdef_ref; + /* CTF string table element (list node). */ typedef struct GTY ((chain_next ("%h.cts_next"))) ctf_string @@ -155,6 +159,14 @@ typedef struct GTY (()) ctf_func_arg #define ctf_farg_list_next(elem) ((ctf_func_arg_t *)((elem)->farg_next)) +/* Declaration Tag. */ + +typedef struct GTY (()) ctf_tag +{ + uint32_t component_idx; /* Index of component to which tag applies. */ + ctf_dvdef_ref ref_var; /* Non-null iff this tag applies to a variable. */ +} ctf_tag_t; + /* Type definition for CTF generation. */ struct GTY ((for_user)) ctf_dtdef @@ -184,6 +196,8 @@ struct GTY ((for_user)) ctf_dtdef ctf_func_arg_t * GTY ((tag ("CTF_DTU_D_ARGUMENTS"))) dtu_argv; /* slice. */ ctf_sliceinfo_t GTY ((tag ("CTF_DTU_D_SLICE"))) dtu_slice; + /* tag. */ + ctf_tag_t GTY ((tag ("CTF_DTU_D_TAG"))) dtu_tag; } dtd_u; }; @@ -201,9 +215,6 @@ struct GTY ((for_user)) ctf_dvdef ctf_id_t dvd_id; /* ID of this variable. Only used for BTF. */ }; -typedef struct ctf_dvdef ctf_dvdef_t; -typedef ctf_dvdef_t * ctf_dvdef_ref; - /* Location information for CTF Types and CTF Variables. */ typedef struct GTY (()) ctf_srcloc @@ -222,7 +233,8 @@ enum ctf_dtu_d_union_enum { CTF_DTU_D_ARRAY, CTF_DTU_D_ENCODING, CTF_DTU_D_ARGUMENTS, - CTF_DTU_D_SLICE + CTF_DTU_D_SLICE, + CTF_DTU_D_TAG, }; enum ctf_dtu_d_union_enum @@ -287,6 +299,17 @@ typedef struct GTY (()) ctf_container /* CTF variables to be ignored. */ hash_table * GTY (()) ctfc_ignore_vars; + /* BTF type and decl tags. Not yet represented in CTF. These tags also + uniquely have a one-to-many relation with DIEs, meaning a single DIE + may translate to multiple tags. For both of these reasons, they cannot + be stored in the regular types table. */ + vec * GTY (()) ctfc_tags; + /* Type tags logically form part of the type chain similar to cv-quals. + Therefore references to types need to know if the referred-to type has + any type tags, and if so to refer to the outermost type tag. This map + maps a type to the outermost type tag created for it, if any. */ + hash_map * GTY (()) ctfc_tags_map; + /* CTF string table. */ ctf_strtable_t ctfc_strtable; /* Auxilliary string table. At this time, used for keeping func arg names @@ -440,15 +463,19 @@ extern ctf_dtdef_ref ctf_add_function (ctf_container_ref, uint32_t, dw_die_ref, bool, int); extern ctf_dtdef_ref ctf_add_sou (ctf_container_ref, uint32_t, const char *, uint32_t, size_t, dw_die_ref); - +extern ctf_dtdef_ref ctf_add_type_tag (ctf_container_ref, uint32_t, + const char *, ctf_dtdef_ref); +extern ctf_dtdef_ref ctf_add_decl_tag (ctf_container_ref, uint32_t, + const char *, ctf_dtdef_ref, uint32_t); extern int ctf_add_enumerator (ctf_container_ref, ctf_dtdef_ref, const char *, HOST_WIDE_INT, dw_die_ref); extern int ctf_add_member_offset (ctf_container_ref, dw_die_ref, const char *, ctf_dtdef_ref, uint64_t); extern int ctf_add_function_arg (ctf_container_ref, dw_die_ref, const char *, ctf_dtdef_ref); -extern int ctf_add_variable (ctf_container_ref, const char *, ctf_dtdef_ref, - dw_die_ref, unsigned int, dw_die_ref); +extern ctf_dvdef_ref ctf_add_variable (ctf_container_ref, const char *, + ctf_dtdef_ref, dw_die_ref, unsigned int, + dw_die_ref); extern ctf_dtdef_ref ctf_lookup_tree_type (ctf_container_ref, const tree); diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index d948c4da0f4..d7a3073395c 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -32,6 +32,15 @@ along with GCC; see the file COPYING3. If not see static ctf_dtdef_ref gen_ctf_type (ctf_container_ref, dw_die_ref); +static ctf_dtdef_ref +gen_ctf_type_tags (ctf_container_ref, dw_die_ref, ctf_dtdef_ref); + +static void +gen_ctf_decl_tags (ctf_container_ref, dw_die_ref, ctf_dtdef_ref, uint32_t); + +static void +gen_ctf_decl_tags_for_var (ctf_container_ref, dw_die_ref, ctf_dvdef_ref); + /* 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 @@ -500,6 +509,34 @@ gen_ctf_modifier_type (ctf_container_ref ctfc, dw_die_ref modifier) if (!ctf_type_exists (ctfc, modifier, &modifier_dtd)) modifier_dtd = ctf_add_reftype (ctfc, CTF_ADD_ROOT, dtd, kind, modifier); + /* If the qual_type has any type tag(s), then the dtd we get above is for + the outermost type tag. BTF requires that if a type has both cv-quals and + type tags, the type tags are always "outermost" in the type chain. + e.g. [tag1 -> const -> int] rather than [const -> tag1 -> int] + Fix the order of modifiers by making modifier_dtd point to the underlying + qualified type, and making the innermost type tag refer to the + modifier_dtd. */ + if (CTF_V2_INFO_KIND (dtd->dtd_data.ctti_info) == CTF_K_TYPE_TAG) + { + ctf_dtdef_ref inner = dtd, root = dtd; + while (CTF_V2_INFO_KIND (root->dtd_data.ctti_info) == CTF_K_TYPE_TAG) + { + inner = root; + root = root->ref_type; + } + + /* Fix the modifier order: + 1: Innermost type tag points to (outermost) cv-qual. */ + inner->ref_type = modifier_dtd; + inner->dtd_data.ctti_type = (uint32_t) modifier_dtd->dtd_type; + /* 2: cv-qual points to the base type. */ + modifier_dtd->ref_type = root; + modifier_dtd->dtd_data.ctti_type = (uint32_t) root->dtd_type; + + /* Return the outermost type tag with the now-fixed modifier chain. */ + return dtd; + } + return modifier_dtd; } @@ -532,6 +569,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) @@ -616,6 +654,9 @@ gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) field_name, field_dtd, field_location); + + gen_ctf_decl_tags (ctfc, c, sou_dtd, idx); + idx++; } while (c != dw_get_die_child (sou)); } @@ -699,14 +740,18 @@ gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, gcc_assert (i == num_args - 1); /* Add an argument with type 0 and no name. */ ctf_add_function_arg (ctfc, function, "", NULL); + /* Handle any declaration tags on the argument. */ + gen_ctf_decl_tags (ctfc, c, function_dtd, i); } else if (dw_get_die_tag (c) == DW_TAG_formal_parameter) { - i++; arg_name = get_AT_string (c, DW_AT_name); 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); + /* Handle any declaration tags on the argument. */ + gen_ctf_decl_tags (ctfc, c, function_dtd, i); + i++; } else /* This is a local variable. Ignore. */ @@ -797,6 +842,7 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die) dw_die_ref var_type = ctf_get_AT_type (die); unsigned int external_vis = get_AT_flag (die, DW_AT_external); ctf_dtdef_ref var_dtd; + ctf_dvdef_ref dvd; /* Avoid duplicates. */ if (ctf_dvd_lookup (ctfc, die)) @@ -817,10 +863,13 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die) var_dtd = gen_ctf_type (ctfc, var_type); /* Generate the new CTF variable and update global counter. */ - (void) ctf_add_variable (ctfc, var_name, var_dtd, die, external_vis, decl); + dvd = ctf_add_variable (ctfc, var_name, var_dtd, die, external_vis, decl); /* 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 declaration tags on the variable. */ + gen_ctf_decl_tags_for_var (ctfc, die, dvd); } /* Add a CTF function record for the given input DWARF DIE. */ @@ -838,8 +887,119 @@ 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_dtd = gen_ctf_function_type (ctfc, die, true /* from_global_func */); ctfc->ctfc_num_global_funcs += 1; + + /* Handle declaration tags on the function. */ + gen_ctf_decl_tags (ctfc, die, function_dtd, -1U); +} + +/* Handle any DW_AT_GNU_annotation on type DIE by constructing a CTF_K_TYPE_TAG + type for the DW_TAG_GNU_annotation DIE to which it points, if this has not + previously been constructed. There may be multiple annotations chained + together by further occurances of DW_AT_GNU_annotation in the annotation + DIEs themselves, in which case a corresponding chain of CTF_K_TYPE_TAG + records is created. The final TYPE_TAG in the chain refers to the dtd for + the annotated type, which should be supplied in REF_DTD. + + Return the ctf_dtdef_t for the outermost TYPE_TAG created, since anything + referring to this type should refer to it via the chain of type tags. */ + +static ctf_dtdef_ref +gen_ctf_type_tags (ctf_container_ref ctfc, dw_die_ref die, + ctf_dtdef_ref ref_dtd) +{ + if (!btf_debuginfo_p ()) + return ref_dtd; + if (!die || !ref_dtd) + return NULL; + + ctf_dtdef_ref *existing = ctfc->ctfc_tags_map->get (ref_dtd); + if (existing) + return *existing; + + dw_die_ref annot_die = get_AT_ref (die, DW_AT_GNU_annotation); + ctf_dtdef_ref tag_dtd = ref_dtd; + + /* Recurse first; build the chain from back to front. */ + if (annot_die) + tag_dtd = gen_ctf_type_tags (ctfc, annot_die, ref_dtd); + + /* If this is an annotation die, make the tag. */ + if (dw_get_die_tag (die) == DW_TAG_GNU_annotation) + { + const char *name = get_AT_string (die, DW_AT_name); + const char *value = get_AT_string (die, DW_AT_const_value); + if (strcmp (name, "btf_type_tag") == 0) + { + tag_dtd = ctf_add_type_tag (ctfc, CTF_ADD_ROOT, value, tag_dtd); + ctfc->ctfc_tags_map->put (ref_dtd, tag_dtd); + } + } + + return tag_dtd; +} + +/* Handle any DW_AT_GNU_annotation on decl DIE by constructing a CTF_K_DECL_TAG + type for the DW_TAG_GNU_annotation DIE to which it points, if this has not + been previously constructed. There may be multiple annotations chained + together by further occurances of DW_AT_GNU_annotation in the annoation DIEs + themselves, in which case a corresponding CTF_K_DECL_TAG type is created for + each. Unlike TYPE_TAGs, which form a chain, each DECL_TAG individually + refers directly to the annotated decl, which should be supplied in REF_DTD. + IDX is the zero-based component index indicating to which function parameter + or struct or union member the DECL_TAG refers, or (uint32_t) -1 if it refers + to a function decl itself. */ + +static void +gen_ctf_decl_tags (ctf_container_ref ctfc, dw_die_ref die, + ctf_dtdef_ref ref_dtd, uint32_t idx) +{ + if (!btf_debuginfo_p () || !die || !ref_dtd) + return; + + dw_die_ref annot_die = get_AT_ref (die, DW_AT_GNU_annotation); + while (annot_die) + { + const char *name = get_AT_string (annot_die, DW_AT_name); + const char *value = get_AT_string (annot_die, DW_AT_const_value); + + if (strcmp (name, "btf_decl_tag") == 0) + (void) ctf_add_decl_tag (ctfc, CTF_ADD_ROOT, value, ref_dtd, idx); + + annot_die = get_AT_ref (annot_die, DW_AT_GNU_annotation); + } +} + +/* Like gen_ctf_decl_tags above, but specifically for variables. Declaration + tags may appear on variables or other declarations like functions, but due + to the distinction in CTF between variables and types the processing in + each case is slightly different. REF_DVD is the CTF record for the variable + which is annotated. */ + +static void +gen_ctf_decl_tags_for_var (ctf_container_ref ctfc, dw_die_ref die, + ctf_dvdef_ref ref_dvd) +{ + if (!die || !ref_dvd) + return; + + ctf_dtdef_ref tag_dtd = NULL; + + dw_die_ref annot_die = get_AT_ref (die, DW_AT_GNU_annotation); + while (annot_die) + { + const char *name = get_AT_string (annot_die, DW_AT_name); + const char *value = get_AT_string (annot_die, DW_AT_const_value); + + if (strcmp (name, "btf_decl_tag") == 0) + { + tag_dtd = ctf_add_decl_tag (ctfc, CTF_ADD_ROOT, value, NULL, -1U); + tag_dtd->dtd_u.dtu_tag.ref_var = ref_dvd; + } + + annot_die = get_AT_ref (annot_die, DW_AT_GNU_annotation); + } } /* Add CTF type record(s) for the given input DWARF DIE and return its type id. @@ -857,7 +1017,12 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) int unrecog_die = false; if (ctf_type_exists (ctfc, die, &dtd)) - return dtd; + { + if (btf_debuginfo_p ()) + return gen_ctf_type_tags (ctfc, die, dtd); + else + return dtd; + } switch (dw_get_die_tag (die)) { @@ -906,6 +1071,10 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) break; } + case DW_TAG_GNU_annotation: + dtd = NULL; + unrecog_die = true; + break; case DW_TAG_reference_type: dtd = NULL; break; @@ -916,6 +1085,9 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) break; } + if (dtd) + dtd = gen_ctf_type_tags (ctfc, die, dtd); + /* For all types unrepresented in CTF, use an explicit CTF type of kind CTF_K_UNKNOWN. */ if ((dtd == NULL) && (!unrecog_die)) diff --git a/include/ctf.h b/include/ctf.h index f188202d120..d1873556644 100644 --- a/include/ctf.h +++ b/include/ctf.h @@ -423,6 +423,10 @@ union #define CTF_K_CONST 12 /* ctt_type is base type. */ #define CTF_K_RESTRICT 13 /* ctt_type is base type. */ #define CTF_K_SLICE 14 /* Variant data is a ctf_slice_t. */ +#define CTF_K_DECL_TAG 15 /* Declaration tag. Internal use only. + Not valid externally until CTF V4. */ +#define CTF_K_TYPE_TAG 16 /* Type tag. Internal use only. + Not valid externally until CTF V4. */ #define CTF_K_MAX 63 /* Maximum possible (V2) CTF_K_* value. */