From patchwork Tue Jun 11 19:01:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1946489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=CaJE72O8; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=fdGktgor; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzJ3l6mBCz20Pb for ; Wed, 12 Jun 2024 05:03:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16FDC385DDE3 for ; Tue, 11 Jun 2024 19:03:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 7FD21385DC1E for ; Tue, 11 Jun 2024 19:02:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FD21385DC1E 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 7FD21385DC1E Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132577; cv=pass; b=ZS7t5s72dmCDgztPhcu2uqF7CJ+Kq/Q+40MRVdTjiypIZ8yeKiAxXX66oy5H/N6P8bNQaA+uT1oK55tlAzn30//ZsKwVtn21eQuK/B2sUQ7+qJCNikh4Ih40/SiQl1lK9dczZ/NQL5+f6Zq3wjEuG6Q1Dp4i14qaeY/bF2qhY4w= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132577; c=relaxed/simple; bh=YSXDzSnwK/AgrZ70wnrmq8weelY4MNxWqNct+gakgtw=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=t5PK1jNYVwAOcLGgEBFqAvJ8PWMeMpkQtizLSu5bblIVw6bMWdPFN6726jSU9Voi+iVHe9t6CyputjVkY2o4em59wVpjuwq84z+NZyv78CfaRXEgicWy0XgI7J3HbkBoyAmmGIb5/4CIgNO0KltrtZZi4EqqL+wSZjhL0Xi9riA= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45BFp4MG008957 for ; Tue, 11 Jun 2024 19:02:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=p5hi/kO5QjsAHuBeyqODFPrDrcCMw0DPUi/BnHrCsMk=; b= CaJE72O8lmWHbnvVdyxwDXqImWV3ooaqA6UcbxKaKvZI3ZatZptF6SzqpLHYfU99 etV/88HoQpKjxeQsInIdLhJXa6c7GWjCCtKcBdSuwZOoMLQqUIjkbRxgGP2/veio SH8LvNMFSPjDwHjcDt/Khhz2Z32X8/nnGwzpain5Iko37ZZeG/QMLSJkEk1gLxqs 34B88a//DUi9ufMbtGoGcQeP3ok0QOmjtnhHYmBYcoCX/NWEdOTB9+xe0E+XyS/Y Ge8rkWrRbCAEz45c1odHdFwLV9o3NmzQjfCZV/ZJ2gz41C0LCpsFCpqXFIQMzOi3 McNiuPBzjxEJ1rn6szaR4Q== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh195jgf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:02:53 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45BIFLA5021545 for ; Tue, 11 Jun 2024 19:02:53 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncauxd38-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:02:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ov4cOo7ns9xd7M9hKfTLgxIdtjxo1CuhBK23Gc3jN3568UfKkQoUd6I8Atp+QZzKd47+j6DBmtDrLB02YyVL83m7160tY9hY8vfqKzxtobcmibzey102ur25W/waKyYLJV8D1UTQok4JBvnQHVeliXETw6WGRsMq+psySAGZxR+9Rz5I0M1Xr+yE5kvJlOAQGjNWAc6bt5E685N6Y+nVvLJhQrLmhWa+bT4V06spd1gLphJIwFedP0xG9qLrULUqJubw4tZkc9LauYgmPyEXTO+H+cbdW3Uas3ah6d1EfCNVrQDixJYfMfUJnWNKqzAJAbB+1DsjvwzKoqup1eLvyw== 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=p5hi/kO5QjsAHuBeyqODFPrDrcCMw0DPUi/BnHrCsMk=; b=BWGKP92vW2FrD19v2Tw6fVW2+DZKp2K1rjjpQmmbiZIrKBisqDLLyHILBBYFxIRmmyrqREXcyD+/91tqrA2bKfgbdeSDjoCFy3eBXX9dzuqe9ffJIlOspfZoiIQJxl4dgnLHC1thwgb3RHKxMGuKyk60Xg28Eysp/7Dh7XS9mr5CpQ0n3f+b0ewCZutcQUI+ujvvLNq/b5AJ1xQDL8KRdQadfpYCsw00cUuhKb1CMl/6XH2RnBhbXaOMsSV0Ls51JgPU7AwfZP01xRezJjpEHhiRJ25SJY+Yf35QF15T8TrURI/6HvOzoh4eDW+NpB1Tg68NLK3UaNCLypxxPAgPGA== 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=p5hi/kO5QjsAHuBeyqODFPrDrcCMw0DPUi/BnHrCsMk=; b=fdGktgorUIpagBrbTF90tSgZnwIyGLQuLknd8AOmTL7clbMa5pD+R7zDDZvZ+tVoFPOHrZxlFehoQ8lVxD1xF8RKhh/S2vyolX0yRqY+dVzpZyL+30mg5Ry941p/oc7zoKJEo2pMRk0HHx82d9XvksiT++55lKtKPwTabIFRSsk= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by CH2PR10MB4134.namprd10.prod.outlook.com (2603:10b6:610:a7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.39; Tue, 11 Jun 2024 19:02:51 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%5]) with mapi id 15.20.7633.036; Tue, 11 Jun 2024 19:02:51 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com, jose.marchesi@oracle.com, cupertino.miranda@oracle.com Subject: [PATCH v4 1/6] ctf, btf: restructure CTF/BTF emission Date: Tue, 11 Jun 2024 12:01:40 -0700 Message-ID: <20240611190145.115887-2-david.faust@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240611190145.115887-1-david.faust@oracle.com> References: <20240611190145.115887-1-david.faust@oracle.com> X-ClientProxiedBy: MW4PR04CA0382.namprd04.prod.outlook.com (2603:10b6:303:81::27) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|CH2PR10MB4134:EE_ X-MS-Office365-Filtering-Correlation-Id: d5519c2e-ed31-43e8-83d1-08dc8a491777 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230032|1800799016|366008|376006; X-Microsoft-Antispam-Message-Info: LvFH91G5zc8KQsHyAWA5lQ55nSamOCHYB+DCm2qFJ8Rf2+Ub0WIXloF5EJvyEMmOkceaN2EsnGkq4cBXhZXK6TV7UzerdWXzzOuy5aZ6aStPYweeGpLp4d2zhZjQi0E1dheqjws0NqL+1y4PVpHzeC32acs0b9xbwqFCIk7K9NuJDXPOyw31ESo709GOUR/R5rOLVGNsJIBSljr9ZRrzVeAnTkQpqfIAKr8Wl9lM8bmDV8oBpHwiXH4FvrC/8UjpSDKAIlBGocAtZnHbSf6g3lwmt1Ja1s00sSg7q3HUX26IOp3mfvxrtICde4Nklt/ob1KXDsEn06uKwOA9pXTn+Yo+7oFMpyHjqHodpYoIPd3dG/kYtt2mHuN2loMG/Mw+BnfLiUTJcBgnIVPcvIaEHVWcfzNPqB/+ndSZqMHE7/jU0R3ozPy18KBlrYk9xsfWnQUfryOcMLLfY/5EeBcGGo8NJz7LhQ1rzc8y9kLCoZRYUOJnhIG+mri4Je5UTB5XB0K07R46OEEzO0m88dqM642G1h1ykP3p990Qt4z0KDolY1Qpyz7CRpcBpqyUQZ+4N1UKize7x0luzwlddv3w7tOvflIy5Pc/l/EQvGcRfkrbISjjFgQn8YNxgPknPY6cNFm2klXb3IBAWD7Nj7VtRvGRb/LuQ0TQRiZFPvH7q3Cud+kPE961Nx1LpZbRBA4Yh/rvNZegopjoXSGuKdU8yJ/uOt7rUBXCBkC9RSbZAPEh97rdzOVOEQaxzJOkf+luBzLR1ZCKGs5qPqlpqwWMFd+3Tk5VWGbbVpAHN+naphSUE66gfJYEycJRgo0UgpkdA1lWBuDGq6Q6Qv4bUqFzRTY49B/J6tmgkgrcvE/3pwknXmZFndlaNW/ObP+Y19jjH2moqWlCnD9CNEtwWV+SB4JiI9vMzdjPfPK4miAhMkSw4+RF6cSeBZyiMmtany9tSBjhKVjj2dk22EHyXj/NVRsvg82EVM3xMkk06iotP/Y738Yl6/4nFpFGvIfjVP8DP0D2WVAJDpi62Vfp5mtvycG31YVyE0UdDzV+Wn4bx57QIbhXziHMu2nE6HccK4Sl+SYmcKGymrjTUbZFNyxs0lzicbrXko+yrIqHzhgqaqN5GAv2kOHebmC3uc9iNT37VP+Ib6wY9rbh07Qm9FWbR0eTDNpeqwKBuDRBYa411ORqzOU5IlmaxeXOe/0zsJAZWDjl26m1EIb3Av5vmWqFzLN7gGO/JRyATh/OxLHQPbLlYM23Q9aPUaEo4LpkPEjF4fGaOKlJDdavlJR1E7VVgZAa4gYk46C8odXaDUN+IUCLVj/wDukBs8yAE8R7zv+Y 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:(13230032)(1800799016)(366008)(376006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QQlLl7V6fGUujSSlUA/axET/hd52dgKe9hhpH2VLkoANU/VjF6tNXFri+AHxBDrJ460CBs6S6RaY0LiWDKuCNHm775Vt4hZyYLgqtYCmPHoAlakb/oTJLssLAeOe6NaHvLLBRfSX64qTIYMW1AI4GjpM0IFEh6zYPvlK/U1vFlnsj828tAThuSeE9YSe10RezszT0jchykD9619vmAP1bxKNANVd9EOv0zuNxcxIy8tiNdN9f5MsbyUwbCX4r8nxpmQOQbYJe+DlG6mK0eE15ZlwnJ/la8XBj55bJ3V1H47EteJgoAeX/KuV3VN369EQVNPOGpgDoJolYJxCocy/GgXdS+w6QnrSYGrxSTbfBjfburjS81ToG/vn07PgexHlvFWIAQUC2fj0aQpuvkT7+I+cnZYbz2IL9HbA68OcMRIY+9j0w8JpItSFXob24HE2lONRkmsYwyEvQtTUaRwL9/r582/gP37/mNn2ST1bGqvuPT71wk4AQbdzGxDAQYQyo360lxTLssmYTjGaAqdF/b02j6D/yskiU2omTRH4SZxcrttYJT5k2FpuQbwy8ZrqalhiMZLNEh7oEcm7X1wBgq8Pf8V8i/UP2DtSts1KuSNppbk+juhZ+mZ18szLTtrTEsULmMyOr6RnRXgzi9XzKdma3Oc0bHPU5gp3JVpHq2RhnkfKBe+GqIe42bvuoCxxG3TbzbnH/x5yJMoBVAJoatcaYlQf/rFuW4wugSY1C2x9kDiz+hkyACaeRJR2OIBR0XpVvNzV6tbtIErXjcidE2KlJaoXiyAJMGfQsWTfWpwonmZazI3Yoplo4SEWJ1jir6o2uoefXiopPHDJQ/n6OK9QRMU6pq/D+KiMRv52gySOTpY/tNiIWKJo5LqpUgHKdgqrtZk0TOHIY/Gnvnm4FgrCh0O8XhqlmcXZNlmsvu6XUVX7QkdR/R2PXjZAfiAiziupkmO10tsxFQOuJJ6jm7CbGn7P5wgDbS9iJ3+7FDFPbxMui9GGmU/F7arstc88l6m7s3WSakWZveFReBo0S8yuIl99OeQpAyOjwJ9IYMmNJGvWasSWJoJ4Y6tIdSjXdXFCj77Ra1KnQ3tAky5bz3XMFIS3pyXsPFj45mKcr8DAggh8DfcvX8plexpcYWiPhxOauFzl5wye8DHbkJ5okX4RUgzIJUe0JVnUJKM69H5JcE3wCjLOduwjdJFb4furxQFMxKrhd++LKJM/FdM3mB9rggY7zQkk+vbP41wVOtGg7Rf8x9dN9/nDk7V94cWlV+Lo9M2iNWWBD3iG/g5ohqIix1sfJpRoEsJbgGTwFb1Ip7UH/LFQbhtCuajLelGiVaj5YdtzsxSJu0eQDXFRc08PpbrmgZlcHytLpCRY6SfLRZqLAJHd7PSVg/D3x87r3+WF11rnKcsetrNPDlQMfsr+4f8lSK8oXRlaI9QKtl8xnN8ad5sVJUBCDZMx2hMwwV0XnUuIkYDkPkLVVqmEe8H1Npdc9mjS3tej3ffuSP5CucULPWz6hcN39tQ54vGIXCBrBpnablV9sW+N3cUr6cd2PvTQ8cERNFcORPFlmcN6juJcqCruJZ3+FfadSDWDr2LY80Y6aDimpWZ1FPQUPA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: gDEaYJEBKEirG0zCTZ1ahVI9BzQfgQdeyBXvr6OVTdURM1fzHR2xaLxdb8LevuKbecCJQERXpoqO+TWT1BRNurPsC8x2vxgAOwBGKNvfiiHhsk3lA/ACiOpW+wAc9fBHnGmCoMl3q7iYl6nUZf8s/AsU4tUYuOeSDO4HB166QQ6YwWZ68thR7b6Ndc8jya5s9GKu5PyB1jAMo4ZeSLxLrYUy1R2mjD0WsK8JKs6dbHdfn7DbP7AeFoLovm+isQYJt1OM0Dg3kS3kvxK0L27Oqt05p7+za8svAJwRAPul6mVkDJh+UR0gJIlAhMirrRUFRapCy3zOqRaL7T/SzIZk36P/WmoYJPwsa0nPFBg0UcmoIK4eR0IYV3tOB2MHHRdxvFzSbbO+W9YhabaUpbU0rKuuIfcLJLoKV8jw2dQN6tPiMPpG/4uesRZynt5ykcxmo0MtBFx1AYO5TyEOYBO3YbG2UUKt4WxG5F6uN3oz4wknqUQrE0XsBP9mNaKPfl0G2MOI/wxhN7MIbAx03HEtzlL9RMI0T3OnMaASPO4KRu2UmpRgHA54tgOVBixbbVCVloGfBb8ZgAq2haoMrWQ+bL8Hf/JUStDLvWvFDgwKkH8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5519c2e-ed31-43e8-83d1-08dc8a491777 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 19:02:51.1908 (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: BSdi5W8wDEg+CEFG87eCoiwnb4gCKPsS+UoEZld+83iULKBS6OLVfj86NB418Levbr3a76yHhPMUlTiOv+We+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4134 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-11_09,2024-06-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406110130 X-Proofpoint-GUID: gbZW-RZDJ4wqPYGSrzuH5VVM0CBdbVfw X-Proofpoint-ORIG-GUID: gbZW-RZDJ4wqPYGSrzuH5VVM0CBdbVfw X-Spam-Status: No, score=-13.7 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This commit makes some structural changes to the CTF/BTF debug info emission. In particular: a) CTF is new always fully generated and emitted before any BTF-related procedures are run. This means that BTF-related functions can change, even irreversibly, the shared in-memory representation used by the two formats without issue. b) BTF generation has fewer entry points, and is cleanly divided into early_finish and finish. c) BTF is now always emitted at finish (called from dwarf2out_finish), for all targets in non-LTO builds, rather than being emitted at early_finish for targets other than BPF CO-RE. In LTO builds, BTF is emitted at early_finish as before. Note that this change alone does not alter the contents of BTF at all, regardless of whether it would have previously been emitted at early_finish or finish, because the calculation of the BTF to be emitted is not moved by this patch, only the write-out. The changes are transparent to both CTF and BTF emission. gcc/ * btfout.cc (btf_init_postprocess): Rename to... (btf_early_finish): ...this. (btf_output): Rename to... (btf_finish): ...this. * ctfc.h: Analogous changes. * dwarf2ctf.cc (ctf_debug_early_finish): Conditionally call btf_early_finish, or ctf_finalize as appropriate. Emit BTF here for LTO builds. (ctf_debug_finish): Always call btf_finish here if generating BTF info in non-LTO builds. (ctf_debug_finalize, ctf_debug_init_postprocess): Delete. * dwarf2out.cc (dwarf2out_early_finish): Remove call to ctf_debug_init_postprocess. --- gcc/btfout.cc | 28 +++++++++++++++++++++ gcc/ctfc.h | 4 +-- gcc/dwarf2ctf.cc | 65 +++++++++++++++--------------------------------- gcc/dwarf2out.cc | 2 -- 4 files changed, 50 insertions(+), 49 deletions(-) diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 07f066a47068..d5e9f3bd43d3 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -1491,6 +1491,34 @@ btf_finalize (void) tu_ctfc = NULL; } +/* 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 + BTF_KIND_FUNC records. */ + +void +btf_early_finish (void) +{ + btf_init_postprocess (); +} + +/* Late entry point for BTF generation, called from dwarf2out_finish (). + Complete and emit BTF information. */ + +void +btf_finish (const char * filename) +{ + btf_output (filename); + + /* If compiling for BPF with CO-RE info, we cannot deallocate until after the + contents of the .BTF.ext section are finalized, which happens very late in + BPF backend. Therefore, the deallocation (i.e. btf_finalize ()) is delayed + until TARGET_ASM_FILE_END for BPF CO-RE. */ + if (!btf_with_core_debuginfo_p ()) + btf_finalize (); +} + + /* Traversal function for all BTF_KIND_FUNC type records. */ bool diff --git a/gcc/ctfc.h b/gcc/ctfc.h index fa188bf2f5a4..e7bd93901cfa 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -384,8 +384,8 @@ extern void ctf_init (void); extern void ctf_output (const char * filename); extern void ctf_finalize (void); -extern void btf_output (const char * filename); -extern void btf_init_postprocess (void); +extern void btf_early_finish (void); +extern void btf_finish (const char * filename); extern void btf_finalize (void); extern ctf_container_ref ctf_get_tu_ctfc (void); diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index dc59569fe560..8f9e2fada9e3 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -933,30 +933,6 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) return type_id; } -/* Prepare for output and write out the CTF debug information. */ - -static void -ctf_debug_finalize (const char *filename, bool btf) -{ - if (btf) - { - btf_output (filename); - /* btf_finalize when compiling BPF applciations gets deallocated by the - BPF target in bpf_file_end. */ - if (btf_debuginfo_p () && !btf_with_core_debuginfo_p ()) - btf_finalize (); - } - - else - { - /* Emit the collected CTF information. */ - ctf_output (filename); - - /* Reset the CTF state. */ - ctf_finalize (); - } -} - bool ctf_do_die (dw_die_ref die) { @@ -996,27 +972,27 @@ ctf_debug_init (void) add_name_attribute (ctf_unknown_die, "unknown"); } -/* Preprocess the CTF debug information after initialization. */ - -void -ctf_debug_init_postprocess (bool btf) -{ - /* Only BTF requires postprocessing right after init. */ - if (btf) - btf_init_postprocess (); -} - /* Early finish CTF/BTF debug info. */ void ctf_debug_early_finish (const char * filename) { - /* Emit CTF debug info early always. */ - if (ctf_debug_info_level > CTFINFO_LEVEL_NONE - /* Emit BTF debug info early if CO-RE relocations are not - required. */ - || (btf_debuginfo_p () && !btf_with_core_debuginfo_p ())) - ctf_debug_finalize (filename, btf_debuginfo_p ()); + /* Emit the collected CTF information. */ + if (ctf_debug_info_level > CTFINFO_LEVEL_NONE) + ctf_output (filename); + + /* If emitting BTF, start translation to BTF. */ + if (btf_debuginfo_p ()) + { + btf_early_finish (); + + /* For LTO builds, also emit BTF now. */ + if (flag_lto && !in_lto_p) + btf_finish (filename); + } + else + /* Otherwise, done with the CTF container. */ + ctf_finalize (); } /* Finish CTF/BTF debug info emission. */ @@ -1024,11 +1000,10 @@ ctf_debug_early_finish (const char * filename) void ctf_debug_finish (const char * filename) { - /* Emit BTF debug info here when CO-RE relocations need to be generated. - BTF with CO-RE relocations needs to be generated when CO-RE is in effect - for the BPF target. */ - if (btf_debuginfo_p () && btf_with_core_debuginfo_p ()) - ctf_debug_finalize (filename, btf_debuginfo_p ()); + /* Emit BTF late, unless this is an LTO build in which case it was + already done early. */ + if (btf_debuginfo_p () && !flag_lto) + btf_finish (filename); } #include "gt-dwarf2ctf.h" diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index f90f7b1cfef2..e00735a37895 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -33242,8 +33242,6 @@ dwarf2out_early_finish (const char *filename) ctf_debug_do_cu (comp_unit_die ()); for (limbo_die_node *node = limbo_die_list; node; node = node->next) ctf_debug_do_cu (node->die); - /* Post process the debug data in the CTF container if necessary. */ - ctf_debug_init_postprocess (btf_debuginfo_p ()); ctf_debug_early_finish (filename); } From patchwork Tue Jun 11 19:01:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1946493 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=Aqt6vQtu; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=VrF33Woh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzJ5M40prz20Pb for ; Wed, 12 Jun 2024 05:04:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A3AE385ED4B for ; Tue, 11 Jun 2024 19:04:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id D4EFE385DDC1 for ; Tue, 11 Jun 2024 19:02:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D4EFE385DDC1 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 D4EFE385DDC1 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132586; cv=pass; b=UN8ZeNbUYKWy6Q+lMiVtPYYGVrFQQ48RzWRmKfvq5R1MorFbIUtZCdeViY4gdEUdtW4bkd7wur2MzsCJ7axG7XIF0i28aKIQcvjyoyr+7fxABNQc9YSZ2gtlD+9f2B7sHDzM4cMnr43ir4ZuEcQce3aFlZeyTtK0T79H5myszgY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132586; c=relaxed/simple; bh=EXcQduL4hvGRZKoZEPDlIGrZbqjK8hCJ3e9i7qdT4Zc=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=bgRPFyvjUXa2+o562Q57JtTjTnlJev2yZE66BnsZsESM4MfT1JTN0QFP5FBoNqNQ6t2mjLGmFctmBtcRRSKoh1GgNjL+Ly441jsDxxt2uXSjYVdoGW7/qBj24pLL/U9vyrjRkfkmEkO43AGaVAMSpQHohQwsommH8uPZ6kUCOgk= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45BG1LDh026881 for ; Tue, 11 Jun 2024 19:02:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=at4RT2eJLtLmq4pnkb83IgPg0WiZiSyIrBHbyhEYwPk=; b= Aqt6vQtuhgPttmd2hpX+4roAIpnblulNw/7dVe9IfoNZRibA2e1adYugRgOJ6D3N nCLGR/COWHld+INvmvpNggVkFlVorahLHHQqDLfJsFEAXz7vFA+icn1kTu7NHwX7 fU5cvobVsr7E4DAiK65WbsOnE7BWBBMCA1TzpjePIUv4vO97vZF+eedoyiv4Tw5S meyM2nFo3t5apxSxlPIB4Xp/WAt4fJFjHaNPNH+2vsiGMzTcw/WzbDw7iXdbmxaZ TRq/7CPJ3eoFd9TL/CVSXSpqmsD0lTC2uhC6x+KTMsFpQTcqWiaSsjuB85Biq+oj KZlJ1EcCU8glbp2MmVEb4g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh1gdmw2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:02:58 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45BIEno1036760 for ; Tue, 11 Jun 2024 19:02:57 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2040.outbound.protection.outlook.com [104.47.73.40]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncdwppep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:02:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DsPmdi4lCs5OBzyQoSwA4FatK/T9ZzOoSpYaXYtNtDHOr7WmF2q2nmcxGn+02OUiD5DKbnfuqrELyqQ+ZSFN3cZ9AUJY/oQSx126i5JPpa6prvAiJM36Vg/9WJo97BEzOLbCiyXXgTZNHxbMh9r6MeYG6wPNrFRb3O5x9gh4jbZMQBlB2dyg4C8vwSFuce/3ncUueoOKmonTnStNY6gKRYRCa2N7Kj65SeK6JqDTRKEa9kvP72W9Z97uruyYcwPZ90TrkVQnEoxoyVcPcq3jn7QUBAVsbtqMLNoKE1AYkXia8KzJTiGIBZ8QnvFd3HGYhOGKUq16+xzVqn7ePR61lA== 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=at4RT2eJLtLmq4pnkb83IgPg0WiZiSyIrBHbyhEYwPk=; b=m2y4N2m33mxlYwbJLBpKD5CNIZtbn1YcFI7FKO9nd3zykS6NggN7uwsMCK41b13LOwU94/DyjrFpw1eiVBhi6fs5PgLhrNt9IkzqTYmZp0efSZnZMJ+JCMEHkvygqV733skm/F3I356aquyE2S5tLdUA2EhEkj+T44q7922+W7dgoy+5K2EVK4Urc7xlSreR80NU8gmPYffeadQNCM52uDhYdJa+izhmc4C2Ugijtsz6h9DELp1LiWAAtKsXhauBi21h+7MlCI3Gz7TS8V8Gn61wy7EpfI6hzjXVhRqNHB87bFAe7WtPjH1rGKA99535ypwdSAzHCFCrNqRFOIKpZw== 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=at4RT2eJLtLmq4pnkb83IgPg0WiZiSyIrBHbyhEYwPk=; b=VrF33WohN5bpPCagEJEadVqvkw5hMxN3fF3tLUhdxi1Vsh51O9EgPrldwZkdloD3X1CnAG8y3bjHzPRLj8uAvgFhGHoacpW3rBMZ/aHiWPHJwr2mikLjV1DZFBUtVyNbgvYij038gpjHlbPI9LvfypU31/YXjyOOLdYHwx6t6lQ= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by CH2PR10MB4134.namprd10.prod.outlook.com (2603:10b6:610:a7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.39; Tue, 11 Jun 2024 19:02:54 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%5]) with mapi id 15.20.7633.036; Tue, 11 Jun 2024 19:02:54 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com, jose.marchesi@oracle.com, cupertino.miranda@oracle.com Subject: [PATCH v4 2/6] ctf: use pointers instead of IDs internally Date: Tue, 11 Jun 2024 12:01:41 -0700 Message-ID: <20240611190145.115887-3-david.faust@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240611190145.115887-1-david.faust@oracle.com> References: <20240611190145.115887-1-david.faust@oracle.com> X-ClientProxiedBy: MW4PR03CA0030.namprd03.prod.outlook.com (2603:10b6:303:8f::35) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|CH2PR10MB4134:EE_ X-MS-Office365-Filtering-Correlation-Id: 597966aa-620e-4743-5bac-08dc8a491925 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230032|1800799016|366008|376006; X-Microsoft-Antispam-Message-Info: iVXVb4N7mgM8PZsdyyh89MFgdpLJb0l5DwzFIGbP8LrfmjtzqoX4QZJUhrM2iRhBUgIo1oucPNS09b4+YqeY1et7iPGaVSWq/RMWLuZkOVIcmhny5DBcya3vwqllxc7wtPhVj9iAjuK7vxHt1ve7swPEQ0YkuWzMwDGahmwSCvtlId9CZbETh4op4m1Fe+bhbWKhIQYHvRIWToP2z0djBFA0NrD1w/uo4vS4jG9iXMYya2AMDtUEphKyOlKehnklpqh0NtaEGxVv2hYdV+3G+dIK2Sb3RmTOFzj6bLhRiEuItyRQGnY/+rX+CA2+axShmO2jz0++cN/v8cQLSqtRkQyRposyo0vQibXqViWYISggXZkIKYFa8eDPaNXF8Isy/px+Li7iDghRRFaQZ6gcsdW3iyF6c/SQGSJR+k29o5jOjC55stxm3HzaS1QPlv8Kb8p/A97USWNct9+umHuj9I2Ses1oE4jNJk99sJUUv8xtW5C1b9o1gJ9wCWYF9+V9YhjElgBqhpyBqc4f+GbukErBxGHdA+IcQafB/vv3wqh5LRAajR8qmTDXak/tXYoVOdPmcoezgR13BshZwKE0MW9/Xb9Ronv/KSI5dTPgxInju2h3RhiPolZ9RCPWkxKFXRJm0bCDY7whQTWVxZ5mp+aLfKxejvkct4xja/gaNQaQ0Q2OeDD9o6JFFSpRhiYluorSjAnhAjne19AaYW1Dn4B8qIeOslnlDgXmQ0wQe0Hfd1ynmtWC+Ygzk+fv4Gohqu1aaUiYaNpw/bOXAIzzGLP7CczI7n2SoJ0fHZ1lUYkgH53b3xmMi/z+Xdka3gp4BWyNsUtaWt7CdAk9Pn1oOCIEsulrEAcHclrhBi2uv2d+PEKC75s/bG7/LZ8eHIPUdTpYoYCtZt1aOSXe21inBQH/XDMd5LLV4Hw3aJcNL7rFSaxLZ2CmUeL1owm/VUOC5crCswrw11qbwHI6JnX7BnpfI3Dgrujj1W4d4qnrdlo2spA3yD3Nc94sJ8eaphAEzl3Rjfv1n6449Cr9TbxL0BJBKEflbKLXqXHcGxRXdz3v8PGwnvDz/WWwp2EpeLy0IN/tqUrhMZcYKshsu++WI/ttItowhzev05VIi2ssATJQRviOu/Unruz0wwuVl9QW/LT2WsTU/rLhtfsQ5yvS+Dad47BfsjiZIP8Gywd+XWY21XqHWKB0w7Q+eyBGs4+joeQNPNz6muBjI27mDWWyuHEDAhSKUVUliePzhcxDcOVdurSnhooKbWLcpKs5a/EmXt+uZakI3x7mKcwdbTVNe4wCgdrE7Od3TmbCuF9uM4DuHJwI8a4RlCmI16EyQtDo 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:(13230032)(1800799016)(366008)(376006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZdBB0tHvAelaAE2hN/A+09m45CmSUWw6MQ4d0sp0PYN6ZYONICRMxcQvEoyiNZ4S4oRlEMDbokTEWNOIpN0FihsmsKfzyZYnZkRcQ6QFbdepOyX0vi1PuH8GE2Nnotnc7PkVsrnfcwu9LFI8gx5lUTH3VTYITbqxVMuLCF9ipJXoLtEWBhwXdqS+iE9rB7+9IROVIpV1rHJKVsLFQo2cU7V30He0nu2scUyf873QrfQKBlU7p9a0eJnRdQVJjOnkLdNKxAZswqgWs2Poo02i+5tpc2KkHoYsO/SydQaep2MWJR//CuHSufVp5imJOFA/dnnnRTk/uve09k+F2Td6zoRdUrlD5JNEYnPC8+zlvAyDSoZ84k2LpK0mMVAp1YV0zVPs44ioXTYXemnxQu3KcY/QwqVrAhqUVAkH5P6BaF6KMLMfIQbxjNMZXhs3ZncxdctaQr+RK8z1jsC9d5xe6zoXjy1mLuOsWYrKo9Z5FaM2rvk4PzfbM8uniBsr5J/ayMfGBzFbS5R/pnH2J8IW3wXKQWEdZC3a1mN4noBkYG1wiucpV8aZtO+LY1oeF+qSjGn6+llsBeV/GVRo1uye9ublv+BeD59Td2V4EJXaJ5IEvi5dKcSLKt3q7LtZL4BhZX62Z3Z2fRFdNylWu71kPmkfor7tNQJAUP7WshsKiGC5k+aR2V4QXHLvBK7CQ6CHhTkjEMAurzzYx866icruc0wc+p0RC+NN2ti/WxUxqCG6fpjCO2w6n0x9KiORqLo7ReiO5/JPZjZ9bgQPxPkhGq4voXvfPVx00gvyC4p/r9HYVsyaMg5J2z74bKrmqrhJOgFlpN9dc7gd3y2aWEmamNbVpNe4pWvo0lr55Y0tOK45P11biECnJOMMshK3ItnHbe7j0FB4CC1ExpubcWEE5XKXF10xTus4V1Rj7FzZDWBJ5eYS48uqGx7GT7qw0mJnxd56qH3VKw93gIL1hpsEN+7EBEmeoHz8M+XGy0K1zpldpo7lcfC9QCmgqB25FyVOtm34nGEMf8jE5HCcGusQxcDG0Jov8AknMwFMtejxen5PcmVPhwTMQPousQhoKa9U/m23KR3gFMvtobQ7h2QNq1EJ3uoCCo5EUXCRSKBbZtaTbm5CV8kJ2WuKH/V7n6qLXpmuLI+hDtC1UUCdQUdgHUDtjetLuzKCZ5OaHul6yYuAYBl3o3C3yyha35xJMD/vW3ccUFLt30zR70FwwZfqvNop2vBut1NNggBGBY9LIYTW+UkE8+cJhKWQR5u3KLoMUyizzsb0yJ3wGFAA8myZUKWJJbjN0Q+2TrD7lNb/ZpdmGk+RGr4+AuCzJJ6A35yIVopbnAg+HZR/jKHvL6oBaaK7nKumujKAYM+iwtXd0GQYmPtaBGD90h6ArWsdZfMlP4R6lrG7M5DBRvkxxz3bMVScQNmV/BSQ20tG6ZNsl1kCsxj/hbyJLNeqTH4n3wOsA8BQfJmFkYAbwve5+Gn94+81gE8b8/q7wPvsoW0EsnHSHFzJJOHGe7eNEZ0NwpfciWzU4n0HPxO7tufDA5hBGVMhwGpb8gLUT+ICJUEMoWPubjrmUttAe9EiLvu8OQdBaGJOEfSYLWfTQDUhC96kIg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: K7+uYzKtjdTeAPoA8azSwZo6UmT+ss+4o1/hKjx2MZcRH05YcufKO/x+eeXj1AAr4ZNn2jAqyDNpbJvPTywHELGwjtPUJY49/PWVLNUIQSDTOjeP73FPzTvc4Tc4S9UmRyDjQq8nvQF1QgP2aSb2Gyzci/A4vbCIhIt9/uIoKFcKBTGSl5JKHrMCIV6zytuE4LXGRs3SB98unN1fd6ARJn6xTBB3dIMx3UmL0Ifob55EVc/SGcj8ZVn2Gx453rq/PVogRLxiQKZmAobGQVgFyqUzvSNkt2bQzx2PBs6uL3p+btxK+8vTBjhJSO40XYRl93NMnyP9aEBpkbPU5Xu0g3hYFbBY36g6TaOJo83ITGoEPxYWMT+ohoXFy307FaXDJoe9JTY9ettNHws0X1YXSbKVvtw0fXR0R/njy2bIuAWeARw9YLmiJ2vGpt1zZVfP2S+KnHjIysaUg03T75AisOOmIokeE8EnfvgSzLOcICJ0mTnLrakk5KL4t5CReftbn5jgBvadn749DFUx9eTEsje6hjG1ikl6Tebefb2PU6U4zqL7FjQWxiJiSLJxSBt2WBPlJXLuTvYWDAmQGOPQUttu7Y1u5yIQCE8QY1UacWc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 597966aa-620e-4743-5bac-08dc8a491925 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 19:02:54.1082 (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: AemJMgsEwa1yRnIyFcCQJ6fkbeywwWjNR0sEKsb0VUH9/mdAbJ3bfYDi7EsULRYRnztYabkcd3zHvM9MP9jqjA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4134 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-11_09,2024-06-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 adultscore=0 mlxscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406110130 X-Proofpoint-ORIG-GUID: rE_USV6AMJEcDWPWiL6Vyw-fK58vjlAd X-Proofpoint-GUID: rE_USV6AMJEcDWPWiL6Vyw-fK58vjlAd X-Spam-Status: No, score=-13.7 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch replaces all inter-type references in the ctfc internal data structures with pointers, rather than the references-by-ID which were used previously. A couple of small updates in the BPF backend are included to make it compatible with the change. This change is only to the in-memory representation of various CTF structures to make them easier to work with in various cases. It is outwardly transparent; there is no change in emitted CTF. gcc/ * btfout.cc (BTF_VOID_TYPEID, BTF_INIT_TYPEID): Move defines to include/btf.h. (btf_dvd_emit_preprocess_cb, btf_emit_preprocess) (btf_dmd_representable_bitfield_p, btf_asm_array, btf_asm_varent) (btf_asm_sou_member, btf_asm_func_arg, btf_init_postprocess): Adapt to structural changes in ctf_* structs. * ctfc.h (struct ctf_dtdef): Add forward declaration. (ctf_dtdef_t, ctf_dtdef_ref): Move typedefs earlier. (struct ctf_arinfo, struct ctf_funcinfo, struct ctf_sliceinfo) (struct ctf_itype, struct ctf_dmdef, struct ctf_func_arg) (struct ctf_dvdef): Use pointers instead of type IDs for references to other types and use typedefs where appropriate. (struct ctf_dtdef): Add ref_type member. (ctf_type_exists): Use pointer instead of type ID. (ctf_add_reftype, ctf_add_enum, ctf_add_slice, ctf_add_float) (ctf_add_integer, ctf_add_unknown, ctf_add_pointer) (ctf_add_array, ctf_add_forward, ctf_add_typedef) (ctf_add_function, ctf_add_sou, ctf_add_enumerator) (ctf_add_variable): Likewise. Return pointer instead of ID. (ctf_lookup_tree_type): Return pointer to type instead of ID. * ctfc.cc: Analogous changes. * ctfout.cc (ctf_asm_type, ctf_asm_slice, ctf_asm_varent) (ctf_asm_sou_lmember, ctf_asm_sou_member, ctf_asm_func_arg) (output_ctf_objt_info): Adapt to changes. * dwarf2ctf.cc (gen_ctf_type, gen_ctf_void_type) (gen_ctf_unknown_type, gen_ctf_base_type, gen_ctf_pointer_type) (gen_ctf_subrange_type, gen_ctf_array_type, gen_ctf_typedef) (gen_ctf_modifier_type, gen_ctf_sou_type, gen_ctf_function_type) (gen_ctf_enumeration_type, gen_ctf_variable, gen_ctf_function) (gen_ctf_type, ctf_do_die): Likewise. * config/bpf/btfext-out.cc (struct btf_ext_core_reloc): Use pointer instead of type ID. (bpf_core_reloc_add, bpf_core_get_sou_member_index) (output_btfext_core_sections): Adapt to above changes. * config/bpf/core-builtins.cc (process_type): Likewise. include/ * btf.h (BTF_VOID_TYPEID, BTF_INIT_TYPEID): Move defines here, from gcc/btfout.cc. --- gcc/btfout.cc | 40 +++-- gcc/config/bpf/btfext-out.cc | 14 +- gcc/config/bpf/core-builtins.cc | 3 +- gcc/ctfc.cc | 151 +++++++++---------- gcc/ctfc.h | 90 +++++------ gcc/ctfout.cc | 22 ++- gcc/dwarf2ctf.cc | 257 +++++++++++++++----------------- include/btf.h | 5 + 8 files changed, 290 insertions(+), 292 deletions(-) diff --git a/gcc/btfout.cc b/gcc/btfout.cc index d5e9f3bd43d3..9d73478ba9a6 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -61,11 +61,6 @@ static char btf_info_section_label[MAX_BTF_LABEL_BYTES]; #define BTF_INFO_SECTION_LABEL "Lbtf" #endif -/* BTF encodes void as type id 0. */ - -#define BTF_VOID_TYPEID 0 -#define BTF_INIT_TYPEID 1 - #define BTF_INVALID_TYPEID 0xFFFFFFFF /* Mapping of CTF variables to the IDs they will be assigned when they are @@ -626,7 +621,8 @@ btf_dvd_emit_preprocess_cb (ctf_dvdef_ref *slot, ctf_container_ref arg_ctfc) return 1; /* Do not add variables which refer to unsupported types. */ - if (!voids.contains (var->dvd_type) && btf_removed_type_p (var->dvd_type)) + if (!voids.contains (var->dvd_type->dtd_type) + && btf_removed_type_p (var->dvd_type->dtd_type)) return 1; arg_ctfc->ctfc_vars_list[num_vars_added] = var; @@ -716,7 +712,7 @@ btf_emit_preprocess (ctf_container_ref ctfc) static bool btf_dmd_representable_bitfield_p (ctf_container_ref ctfc, ctf_dmdef_t *dmd) { - ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type]; + ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type->dtd_type]; if (CTF_V2_INFO_KIND (ref_type->dtd_data.ctti_info) == CTF_K_SLICE) { @@ -913,8 +909,8 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) static void btf_asm_array (ctf_container_ref ctfc, ctf_arinfo_t arr) { - btf_asm_type_ref ("bta_elem_type", ctfc, arr.ctr_contents); - btf_asm_type_ref ("bta_index_type", ctfc, arr.ctr_index); + btf_asm_type_ref ("bta_elem_type", ctfc, arr.ctr_contents->dtd_type); + btf_asm_type_ref ("bta_index_type", ctfc, arr.ctr_index->dtd_type); dw2_asm_output_data (4, arr.ctr_nelems, "bta_nelems"); } @@ -927,7 +923,7 @@ btf_asm_varent (ctf_container_ref ctfc, ctf_dvdef_ref var) (*(btf_var_ids->get (var)) + num_types_added + 1), var->dvd_name); dw2_asm_output_data (4, BTF_TYPE_INFO (BTF_KIND_VAR, 0, 0), "btv_info"); - btf_asm_type_ref ("btv_type", ctfc, var->dvd_type); + btf_asm_type_ref ("btv_type", ctfc, var->dvd_type->dtd_type); dw2_asm_output_data (4, var->dvd_visibility, "btv_linkage"); } @@ -937,8 +933,8 @@ btf_asm_varent (ctf_container_ref ctfc, ctf_dvdef_ref var) static void btf_asm_sou_member (ctf_container_ref ctfc, ctf_dmdef_t * dmd, unsigned int idx) { - ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type]; - ctf_id_t base_type = dmd->dmd_type; + ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type->dtd_type]; + ctf_id_t base_type = dmd->dmd_type->dtd_type; uint64_t sou_offset = dmd->dmd_offset; dw2_asm_output_data (4, dmd->dmd_name_offset, @@ -959,7 +955,7 @@ btf_asm_sou_member (ctf_container_ref ctfc, ctf_dmdef_t * dmd, unsigned int idx) sou_offset |= ((bits & 0xff) << 24); /* Refer to the base type of the slice. */ - base_type = ref_type->dtd_u.dtu_slice.cts_type; + base_type = ref_type->dtd_u.dtu_slice.cts_type->dtd_type; } else { @@ -1003,9 +999,11 @@ btf_asm_func_arg (ctf_container_ref ctfc, ctf_func_arg_t * farg, else dw2_asm_output_data (4, 0, "farg_name"); - btf_asm_type_ref ("farg_type", ctfc, (btf_removed_type_p (farg->farg_type) - ? BTF_VOID_TYPEID - : farg->farg_type)); + ctf_id_t ref_id = BTF_VOID_TYPEID; + if (farg->farg_type && !btf_removed_type_p (farg->farg_type->dtd_type)) + ref_id = farg->farg_type->dtd_type; + + btf_asm_type_ref ("farg_type", ctfc, ref_id); } /* Asm'out a BTF_KIND_FUNC type. */ @@ -1381,7 +1379,7 @@ btf_init_postprocess (void) to create the const modifier type (if needed) now, before making the types list. So we can't avoid iterating with FOR_EACH_VARIABLE here, and then again when creating the DATASEC entries. */ - ctf_id_t constvoid_id = CTF_NULL_TYPEID; + ctf_dtdef_ref constvoid_dtd = NULL; varpool_node *var; FOR_EACH_VARIABLE (var) { @@ -1400,10 +1398,10 @@ btf_init_postprocess (void) continue; /* Create the 'const' modifier type for void. */ - if (constvoid_id == CTF_NULL_TYPEID) - constvoid_id = ctf_add_reftype (tu_ctfc, CTF_ADD_ROOT, - dvd->dvd_type, CTF_K_CONST, NULL); - dvd->dvd_type = constvoid_id; + if (constvoid_dtd == NULL) + constvoid_dtd = ctf_add_reftype (tu_ctfc, CTF_ADD_ROOT, + dvd->dvd_type, CTF_K_CONST, NULL); + dvd->dvd_type = constvoid_dtd; } } diff --git a/gcc/config/bpf/btfext-out.cc b/gcc/config/bpf/btfext-out.cc index 7ec438fd1d10..b3df7b555d5f 100644 --- a/gcc/config/bpf/btfext-out.cc +++ b/gcc/config/bpf/btfext-out.cc @@ -134,7 +134,7 @@ struct GTY ((chain_next ("%h.next"))) btf_ext_lineinfo /* Internal representation of a BPF CO-RE relocation record. */ struct GTY ((chain_next ("%h.next"))) btf_ext_core_reloc { - unsigned int bpfcr_type; /* BTF type ID of container. */ + ctf_dtdef_ref bpfcr_type; /* BTF type involved in relocation. */ unsigned int bpfcr_astr_off; /* Offset of access string in .BTF string table. */ rtx_code_label * bpfcr_insn_label; /* RTX label attached to instruction @@ -296,13 +296,14 @@ bpf_core_reloc_add (const tree type, const char * section_name, struct btf_ext_core_reloc *bpfcr = bpf_create_core_reloc (section_name, &sec); ctf_container_ref ctfc = ctf_get_tu_ctfc (); + ctf_dtdef_ref dtd = ctf_lookup_tree_type (ctfc, type); /* Buffer the access string in the auxiliary strtab. */ bpfcr->bpfcr_astr_off = 0; gcc_assert (accessor != NULL); bpfcr->bpfcr_astr_off = btf_ext_add_string (accessor); - bpfcr->bpfcr_type = get_btf_id (ctf_lookup_tree_type (ctfc, type)); + bpfcr->bpfcr_type = dtd; bpfcr->bpfcr_insn_label = label; bpfcr->bpfcr_kind = kind; @@ -341,7 +342,8 @@ bpf_core_get_sou_member_index (ctf_container_ref ctfc, const tree node) for (dmd = dtd->dtd_u.dtu_members; dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd)) { - bool field_has_btf = get_btf_id (dmd->dmd_type) <= BTF_MAX_TYPE; + bool field_has_btf = (dmd->dmd_type + && dmd->dmd_type->dtd_type <= BTF_MAX_TYPE); if (field == node) return field_has_btf ? i : -1; @@ -574,8 +576,10 @@ output_btfext_core_sections (void) false); char *str = xstrdup (pp_formatted_text (&pp)); - dw2_asm_output_data (4, bpfcr->bpfcr_type, "bpfcr_type (%s)", - str); + uint32_t type_id = bpfcr->bpfcr_type + ? bpfcr->bpfcr_type->dtd_type + : BTF_VOID_TYPEID; + dw2_asm_output_data (4, type_id, "bpfcr_type (%s)", str); dw2_asm_output_data (4, bpfcr->bpfcr_astr_off + str_aux_off, "bpfcr_astr_off (\"%s\")", bpfcr->info.accessor_str); diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc index 829acea98f79..232bebcadbd5 100644 --- a/gcc/config/bpf/core-builtins.cc +++ b/gcc/config/bpf/core-builtins.cc @@ -1021,7 +1021,8 @@ process_type (struct cr_builtins *data) && data->default_value != NULL) { ctf_container_ref ctfc = ctf_get_tu_ctfc (); - unsigned int btf_id = get_btf_id (ctf_lookup_tree_type (ctfc, ret.type)); + ctf_dtdef_ref dtd = ctf_lookup_tree_type (ctfc, ret.type); + unsigned int btf_id = dtd ? dtd->dtd_type : BTF_VOID_TYPEID; data->rtx_default_value = expand_normal (build_int_cst (integer_type_node, btf_id)); } diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc index 67711606ab85..8da37f260458 100644 --- a/gcc/ctfc.cc +++ b/gcc/ctfc.cc @@ -373,9 +373,9 @@ ctf_add_cuname (ctf_container_ref ctfc, const char * filename) ctf_dvd_lookup, as applicable, to ascertain that the CTF type or the CTF variable respectively does not already exist, and then add it. */ -static ctf_id_t +static ctf_dtdef_ref ctf_add_generic (ctf_container_ref ctfc, uint32_t flag, const char * name, - ctf_dtdef_ref * rp, dw_die_ref die) + dw_die_ref die) { ctf_dtdef_ref dtd; ctf_id_t type; @@ -397,18 +397,16 @@ ctf_add_generic (ctf_container_ref ctfc, uint32_t flag, const char * name, ctf_dtd_insert (ctfc, dtd); - *rp = dtd; - return type; + return dtd; } -static ctf_id_t +static ctf_dtdef_ref ctf_add_encoded (ctf_container_ref ctfc, uint32_t flag, const char * name, const ctf_encoding_t * ep, uint32_t kind, dw_die_ref die) { ctf_dtdef_ref dtd; - ctf_id_t type; - type = ctf_add_generic (ctfc, flag, name, &dtd, die); + dtd = ctf_add_generic (ctfc, flag, name, die); dtd->dtd_data.ctti_info = CTF_TYPE_INFO (kind, flag, 0); @@ -424,83 +422,79 @@ ctf_add_encoded (ctf_container_ref ctfc, uint32_t flag, const char * name, ctfc->ctfc_num_stypes++; - return type; + return dtd; } -ctf_id_t -ctf_add_reftype (ctf_container_ref ctfc, uint32_t flag, ctf_id_t ref, +ctf_dtdef_ref +ctf_add_reftype (ctf_container_ref ctfc, uint32_t flag, ctf_dtdef_ref ref, uint32_t kind, dw_die_ref die) { ctf_dtdef_ref dtd; - ctf_id_t type; - gcc_assert (ref <= CTF_MAX_TYPE); + gcc_assert (ref != NULL); - type = ctf_add_generic (ctfc, flag, NULL, &dtd, die); + dtd = ctf_add_generic (ctfc, flag, NULL, die); dtd->dtd_data.ctti_info = CTF_TYPE_INFO (kind, flag, 0); /* Caller of this API must guarantee that a CTF type with id = ref already exists. This will also be validated for us at link-time. */ - dtd->dtd_data.ctti_type = (uint32_t) ref; + dtd->dtd_data.ctti_type = (uint32_t) ref->dtd_type; + dtd->ref_type = ref; ctfc->ctfc_num_stypes++; - return type; + return dtd; } -ctf_id_t +ctf_dtdef_ref ctf_add_forward (ctf_container_ref ctfc, uint32_t flag, const char * name, uint32_t kind, dw_die_ref die) { ctf_dtdef_ref dtd; - ctf_id_t type = 0; - type = ctf_add_generic (ctfc, flag, name, &dtd, die); + dtd = ctf_add_generic (ctfc, flag, name, die); dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_FORWARD, flag, 0); dtd->dtd_data.ctti_type = kind; ctfc->ctfc_num_stypes++; - return type; + return dtd; } -ctf_id_t +ctf_dtdef_ref ctf_add_typedef (ctf_container_ref ctfc, uint32_t flag, const char * name, - ctf_id_t ref, dw_die_ref die) + ctf_dtdef_ref ref, dw_die_ref die) { ctf_dtdef_ref dtd; - ctf_id_t type; - gcc_assert (ref <= CTF_MAX_TYPE); + gcc_assert (ref != NULL); /* Nameless Typedefs are not expected. */ gcc_assert ((name != NULL) && strcmp (name, "")); - type = ctf_add_generic (ctfc, flag, name, &dtd, die); + dtd = ctf_add_generic (ctfc, flag, name, die); dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_TYPEDEF, flag, 0); - /* Caller of this API must guarantee that a CTF type with id = ref already - exists. This will also be validated for us at link-time. */ - dtd->dtd_data.ctti_type = (uint32_t) ref; + dtd->dtd_data.ctti_type = (uint32_t) ref->dtd_type; + dtd->ref_type = ref; gcc_assert (dtd->dtd_type != dtd->dtd_data.ctti_type); ctfc->ctfc_num_stypes++; - return type; + return dtd; } -ctf_id_t -ctf_add_slice (ctf_container_ref ctfc, uint32_t flag, ctf_id_t ref, +ctf_dtdef_ref +ctf_add_slice (ctf_container_ref ctfc, uint32_t flag, ctf_dtdef_ref ref, uint32_t bit_offset, uint32_t bit_size, dw_die_ref die) { ctf_dtdef_ref dtd; - ctf_id_t type; uint32_t roundup_nbytes; gcc_assert ((bit_size <= 255) && (bit_offset <= 255)); - gcc_assert (ref <= CTF_MAX_TYPE); + gcc_assert (ref != NULL); - type = ctf_add_generic (ctfc, flag, NULL, &dtd, die); + dtd = ctf_add_generic (ctfc, flag, NULL, die); dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_SLICE, flag, 0); @@ -512,51 +506,48 @@ ctf_add_slice (ctf_container_ref ctfc, uint32_t flag, ctf_id_t ref, dtd->dtd_data.ctti_size = roundup_nbytes ? (1 << ceil_log2 (roundup_nbytes)) : 0; - /* Caller of this API must guarantee that a CTF type with id = ref already - exists. This will also be validated for us at link-time. */ - dtd->dtd_u.dtu_slice.cts_type = (uint32_t) ref; + dtd->dtd_u.dtu_slice.cts_type = ref; dtd->dtd_u.dtu_slice.cts_bits = bit_size; dtd->dtd_u.dtu_slice.cts_offset = bit_offset; ctfc->ctfc_num_stypes++; - return type; + return dtd; } -ctf_id_t +ctf_dtdef_ref ctf_add_float (ctf_container_ref ctfc, uint32_t flag, const char * name, const ctf_encoding_t * ep, dw_die_ref die) { return (ctf_add_encoded (ctfc, flag, name, ep, CTF_K_FLOAT, die)); } -ctf_id_t +ctf_dtdef_ref ctf_add_integer (ctf_container_ref ctfc, uint32_t flag, const char * name, const ctf_encoding_t * ep, dw_die_ref die) { return (ctf_add_encoded (ctfc, flag, name, ep, CTF_K_INTEGER, die)); } -ctf_id_t +ctf_dtdef_ref ctf_add_unknown (ctf_container_ref ctfc, uint32_t flag, const char * name, const ctf_encoding_t * ep, dw_die_ref die) { return (ctf_add_encoded (ctfc, flag, name, ep, CTF_K_UNKNOWN, die)); } -ctf_id_t -ctf_add_pointer (ctf_container_ref ctfc, uint32_t flag, ctf_id_t ref, +ctf_dtdef_ref +ctf_add_pointer (ctf_container_ref ctfc, uint32_t flag, ctf_dtdef_ref ref, dw_die_ref die) { return (ctf_add_reftype (ctfc, flag, ref, CTF_K_POINTER, die)); } -ctf_id_t +ctf_dtdef_ref ctf_add_array (ctf_container_ref ctfc, uint32_t flag, const ctf_arinfo_t * arp, dw_die_ref die) { ctf_dtdef_ref dtd; - ctf_id_t type; gcc_assert (arp); @@ -564,7 +555,7 @@ ctf_add_array (ctf_container_ref ctfc, uint32_t flag, const ctf_arinfo_t * arp, arp->ctr_index are already added. This will also be validated for us at link-time. */ - type = ctf_add_generic (ctfc, flag, NULL, &dtd, die); + dtd = ctf_add_generic (ctfc, flag, NULL, die); dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_ARRAY, flag, 0); dtd->dtd_data.ctti_size = 0; @@ -572,15 +563,14 @@ ctf_add_array (ctf_container_ref ctfc, uint32_t flag, const ctf_arinfo_t * arp, ctfc->ctfc_num_stypes++; - return type; + return dtd; } -ctf_id_t +ctf_dtdef_ref ctf_add_enum (ctf_container_ref ctfc, uint32_t flag, const char * name, HOST_WIDE_INT size, bool eunsigned, dw_die_ref die) { ctf_dtdef_ref dtd; - ctf_id_t type; /* In the compiler, no need to handle the case of promoting forwards to enums. This comment is simply to note a divergence from libctf. */ @@ -595,7 +585,7 @@ ctf_add_enum (ctf_container_ref ctfc, uint32_t flag, const char * name, = CTF_TYPE_INFO (CTF_K_FORWARD, CTF_ADD_NONROOT, 0); } - type = ctf_add_generic (ctfc, flag, name, &dtd, die); + dtd = ctf_add_generic (ctfc, flag, name, die); dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_ENUM, flag, 0); @@ -608,21 +598,21 @@ ctf_add_enum (ctf_container_ref ctfc, uint32_t flag, const char * name, ctfc->ctfc_num_stypes++; - return type; + return dtd; } int -ctf_add_enumerator (ctf_container_ref ctfc, ctf_id_t enid, const char * name, - HOST_WIDE_INT value, dw_die_ref die) +ctf_add_enumerator (ctf_container_ref ctfc, ctf_dtdef_ref enum_dtd, + const char * name, HOST_WIDE_INT value, dw_die_ref die) { ctf_dmdef_t * dmd; uint32_t kind, vlen, root; - /* Callers of this API must make sure that CTF_K_ENUM with enid has been - addded. This will also be validated for us at link-time. */ + /* The associated CTF type of kind CTF_K_ENUM must already exist. + This will also be validated for us at link-time. */ ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, die); gcc_assert (dtd); - gcc_assert (dtd->dtd_type == enid); + gcc_assert (dtd == enum_dtd); gcc_assert (name); kind = CTF_V2_INFO_KIND (dtd->dtd_data.ctti_info); @@ -646,7 +636,7 @@ ctf_add_enumerator (ctf_container_ref ctfc, ctf_id_t enid, const char * name, /* Buffer the strings in the CTF string table. */ dmd->dmd_name = ctf_add_string (ctfc, name, &(dmd->dmd_name_offset)); - dmd->dmd_type = CTF_NULL_TYPEID; + dmd->dmd_type = NULL; dmd->dmd_offset = 0; dmd->dmd_value = value; @@ -662,7 +652,7 @@ ctf_add_enumerator (ctf_container_ref ctfc, ctf_id_t enid, const char * name, int ctf_add_member_offset (ctf_container_ref ctfc, dw_die_ref sou, - const char * name, ctf_id_t type, + const char * name, ctf_dtdef_ref type, uint64_t bit_offset) { ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, sou); @@ -702,7 +692,7 @@ ctf_add_member_offset (ctf_container_ref ctfc, dw_die_ref sou, } int -ctf_add_variable (ctf_container_ref ctfc, const char * name, ctf_id_t 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) { @@ -747,16 +737,16 @@ ctf_add_variable (ctf_container_ref ctfc, const char * name, ctf_id_t ref, int ctf_add_function_arg (ctf_container_ref ctfc, dw_die_ref func, - const char * name, ctf_id_t type) + const char * name, ctf_dtdef_ref arg_dtd) { - ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, func); + ctf_dtdef_ref func_dtd = ctf_dtd_lookup (ctfc, func); ctf_func_arg_t * farg; uint32_t vlen; /* The function to which argument is being added must already exist. */ - gcc_assert (dtd); + gcc_assert (func_dtd); /* The number of args must have been non-zero. */ - vlen = CTF_V2_INFO_VLEN (dtd->dtd_data.ctti_info); + vlen = CTF_V2_INFO_VLEN (func_dtd->dtd_data.ctti_info); gcc_assert (vlen); farg = ggc_cleared_alloc (); @@ -766,9 +756,9 @@ ctf_add_function_arg (ctf_container_ref ctfc, dw_die_ref func, these strings to avoid unnecessary bloat in CTF section in CTF V3. */ farg->farg_name = ctf_add_string (ctfc, name, &(farg->farg_name_offset), CTF_AUX_STRTAB); - farg->farg_type = type; + farg->farg_type = arg_dtd; - ctf_farg_list_append (&dtd->dtd_u.dtu_argv, farg); + ctf_farg_list_append (&func_dtd->dtd_u.dtu_argv, farg); /* For aux_str, keep ctfc_aux_strlen updated for debugging. */ if ((name != NULL) && strcmp (name, "")) @@ -777,13 +767,12 @@ ctf_add_function_arg (ctf_container_ref ctfc, dw_die_ref func, return 0; } -ctf_id_t +ctf_dtdef_ref ctf_add_function (ctf_container_ref ctfc, uint32_t flag, const char * name, const ctf_funcinfo_t * ctc, dw_die_ref die, bool from_global_func, int linkage) { ctf_dtdef_ref dtd; - ctf_id_t type; uint32_t vlen; gcc_assert (ctc); @@ -791,27 +780,27 @@ ctf_add_function (ctf_container_ref ctfc, uint32_t flag, const char * name, vlen = ctc->ctc_argc; gcc_assert (vlen <= CTF_MAX_VLEN); - type = ctf_add_generic (ctfc, flag, name, &dtd, die); + dtd = ctf_add_generic (ctfc, flag, name, die); dtd->from_global_func = from_global_func; dtd->linkage = linkage; dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_FUNCTION, flag, vlen); + dtd->ref_type = ctc->ctc_return; /* Caller must make sure CTF types for ctc->ctc_return are already added. */ - dtd->dtd_data.ctti_type = (uint32_t) ctc->ctc_return; + dtd->dtd_data.ctti_type = (uint32_t) ctc->ctc_return->dtd_type; /* Caller must make sure CTF types for function arguments are already added via ctf_add_function_arg () API. */ ctfc->ctfc_num_stypes++; - return type; + return dtd; } -ctf_id_t +ctf_dtdef_ref ctf_add_sou (ctf_container_ref ctfc, uint32_t flag, const char * name, uint32_t kind, size_t size, dw_die_ref die) { ctf_dtdef_ref dtd; - ctf_id_t type = 0; gcc_assert ((kind == CTF_K_STRUCT) || (kind == CTF_K_UNION)); @@ -828,7 +817,7 @@ ctf_add_sou (ctf_container_ref ctfc, uint32_t flag, const char * name, = CTF_TYPE_INFO (CTF_K_FORWARD, CTF_ADD_NONROOT, 0); } - type = ctf_add_generic (ctfc, flag, name, &dtd, die); + dtd = ctf_add_generic (ctfc, flag, name, die); dtd->dtd_data.ctti_info = CTF_TYPE_INFO (kind, flag, 0); @@ -845,32 +834,32 @@ ctf_add_sou (ctf_container_ref ctfc, uint32_t flag, const char * name, ctfc->ctfc_num_stypes++; } - return type; + return dtd; } -/* Given a TREE_TYPE node, return the CTF type ID for that type. */ +/* Given a TREE_TYPE node, return the CTF type object for that type. */ -ctf_id_t +ctf_dtdef_ref ctf_lookup_tree_type (ctf_container_ref ctfc, const tree type) { dw_die_ref die = lookup_type_die (type); if (die == NULL) - return CTF_NULL_TYPEID; + return NULL; ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, die); if (dtd == NULL) - return CTF_NULL_TYPEID; + return NULL; - return dtd->dtd_type; + return dtd; } /* Check if CTF for TYPE has already been generated. Mainstay for de-duplication. If CTF type already exists, returns TRUE and updates - the TYPE_ID for the caller. */ + the CTF type object DTD for the caller. */ bool ctf_type_exists (ctf_container_ref ctfc, dw_die_ref type, - ctf_id_t * type_id) + ctf_dtdef_ref * dtd) { bool exists = false; ctf_dtdef_ref ctf_type_seen = ctf_dtd_lookup (ctfc, type); @@ -879,7 +868,7 @@ ctf_type_exists (ctf_container_ref ctfc, dw_die_ref type, { exists = true; /* CTF type for this type exists. */ - *type_id = ctf_type_seen->dtd_type; + *dtd = ctf_type_seen; } return exists; diff --git a/gcc/ctfc.h b/gcc/ctfc.h index e7bd93901cfa..b2060eaf7e9b 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -48,6 +48,10 @@ along with GCC; see the file COPYING3. If not see typedef uint64_t ctf_id_t; +struct ctf_dtdef; +typedef struct ctf_dtdef ctf_dtdef_t; +typedef ctf_dtdef_t * ctf_dtdef_ref; + /* CTF string table element (list node). */ typedef struct GTY ((chain_next ("%h.cts_next"))) ctf_string @@ -81,8 +85,8 @@ typedef struct GTY (()) ctf_encoding typedef struct GTY (()) ctf_arinfo { - ctf_id_t ctr_contents; /* Type of array contents. */ - ctf_id_t ctr_index; /* Type of array index. */ + ctf_dtdef_ref ctr_contents; /* Type of array contents. */ + ctf_dtdef_ref ctr_index; /* Type of array index. */ unsigned int ctr_nelems; /* Number of elements. */ } ctf_arinfo_t; @@ -90,14 +94,14 @@ typedef struct GTY (()) ctf_arinfo typedef struct GTY (()) ctf_funcinfo { - ctf_id_t ctc_return; /* Function return type. */ - unsigned int ctc_argc; /* Number of typed arguments to function. */ - unsigned int ctc_flags; /* Function attributes (see below). */ + ctf_dtdef_ref ctc_return; /* Function return type. */ + unsigned int ctc_argc; /* Number of typed arguments to function. */ + unsigned int ctc_flags; /* Function attributes (see below). */ } ctf_funcinfo_t; typedef struct GTY (()) ctf_sliceinfo { - unsigned int cts_type; /* Reference CTF type. */ + ctf_dtdef_ref cts_type; /* Reference CTF type. */ unsigned short cts_offset; /* Offset in bits of the first bit. */ unsigned short cts_bits; /* Size in bits. */ } ctf_sliceinfo_t; @@ -130,7 +134,7 @@ typedef struct GTY (()) ctf_itype typedef struct GTY ((chain_next ("%h.dmd_next"))) ctf_dmdef { const char * dmd_name; /* Name of this member. */ - ctf_id_t dmd_type; /* Type of this member (for sou). */ + ctf_dtdef_ref dmd_type; /* Type of this member (for sou). */ uint32_t dmd_name_offset; /* Offset of the name in str table. */ uint64_t dmd_offset; /* Offset of this member in bits (for sou). */ HOST_WIDE_INT dmd_value; /* Value of this member (for enum). */ @@ -143,7 +147,7 @@ typedef struct GTY ((chain_next ("%h.dmd_next"))) ctf_dmdef typedef struct GTY (()) ctf_func_arg { - ctf_id_t farg_type; /* Type identifier of the argument. */ + ctf_dtdef_ref farg_type; /* Type of the argument. */ const char * farg_name; /* Name of the argument. */ uint32_t farg_name_offset; /* Offset of the name in str table. */ struct ctf_func_arg * farg_next;/* A list node. */ @@ -158,6 +162,7 @@ struct GTY ((for_user)) ctf_dtdef dw_die_ref dtd_key; /* Type key for hashing. */ const char * dtd_name; /* Name associated with definition (if any). */ ctf_id_t dtd_type; /* Type identifier for this definition. */ + ctf_dtdef_ref ref_type; /* Type referred to by this type (if any). */ ctf_itype_t dtd_data; /* Type node. */ bool from_global_func; /* Whether this type was added from a global function. */ @@ -178,7 +183,7 @@ struct GTY ((for_user)) ctf_dtdef } dtd_u; }; -typedef struct ctf_dtdef ctf_dtdef_t; +#define ctf_type_id(dtd) ((uint32_t) dtd->dtd_type) /* Variable definition for CTF generation. */ @@ -188,13 +193,11 @@ struct GTY ((for_user)) ctf_dvdef const char * dvd_name; /* Name associated with variable. */ uint32_t dvd_name_offset; /* Offset of the name in str table. */ unsigned int dvd_visibility; /* External visibility. 0=static,1=global. */ - ctf_id_t dvd_type; /* Type of variable. */ + ctf_dtdef_ref dvd_type; /* Type of variable. */ }; typedef struct ctf_dvdef ctf_dvdef_t; - typedef ctf_dvdef_t * ctf_dvdef_ref; -typedef ctf_dtdef_t * ctf_dtdef_ref; /* Location information for CTF Types and CTF Variables. */ @@ -390,7 +393,7 @@ extern void btf_finalize (void); extern ctf_container_ref ctf_get_tu_ctfc (void); -extern bool ctf_type_exists (ctf_container_ref, dw_die_ref, ctf_id_t *); +extern bool ctf_type_exists (ctf_container_ref, dw_die_ref, ctf_dtdef_ref *); extern void ctf_add_cuname (ctf_container_ref, const char *); @@ -404,41 +407,42 @@ extern bool ctf_dvd_ignore_lookup (const ctf_container_ref ctfc, extern const char * ctf_add_string (ctf_container_ref, const char *, uint32_t *, int); -extern ctf_id_t ctf_add_reftype (ctf_container_ref, uint32_t, ctf_id_t, - uint32_t, dw_die_ref); -extern ctf_id_t ctf_add_enum (ctf_container_ref, uint32_t, const char *, - HOST_WIDE_INT, bool, dw_die_ref); -extern ctf_id_t ctf_add_slice (ctf_container_ref, uint32_t, ctf_id_t, - uint32_t, uint32_t, dw_die_ref); -extern ctf_id_t ctf_add_float (ctf_container_ref, uint32_t, const char *, - const ctf_encoding_t *, dw_die_ref); -extern ctf_id_t ctf_add_integer (ctf_container_ref, uint32_t, const char *, - const ctf_encoding_t *, dw_die_ref); -extern ctf_id_t ctf_add_unknown (ctf_container_ref, uint32_t, const char *, - const ctf_encoding_t *, dw_die_ref); -extern ctf_id_t ctf_add_pointer (ctf_container_ref, uint32_t, ctf_id_t, - dw_die_ref); -extern ctf_id_t ctf_add_array (ctf_container_ref, uint32_t, - const ctf_arinfo_t *, dw_die_ref); -extern ctf_id_t ctf_add_forward (ctf_container_ref, uint32_t, const char *, - uint32_t, dw_die_ref); -extern ctf_id_t ctf_add_typedef (ctf_container_ref, uint32_t, const char *, - ctf_id_t, dw_die_ref); -extern ctf_id_t ctf_add_function (ctf_container_ref, uint32_t, const char *, - const ctf_funcinfo_t *, dw_die_ref, bool, int); -extern ctf_id_t ctf_add_sou (ctf_container_ref, uint32_t, const char *, - uint32_t, size_t, dw_die_ref); - -extern int ctf_add_enumerator (ctf_container_ref, ctf_id_t, const char *, +extern ctf_dtdef_ref ctf_add_reftype (ctf_container_ref, uint32_t, + ctf_dtdef_ref, uint32_t, dw_die_ref); +extern ctf_dtdef_ref ctf_add_enum (ctf_container_ref, uint32_t, const char *, + HOST_WIDE_INT, bool, dw_die_ref); +extern ctf_dtdef_ref ctf_add_slice (ctf_container_ref, uint32_t, ctf_dtdef_ref, + uint32_t, uint32_t, dw_die_ref); +extern ctf_dtdef_ref ctf_add_float (ctf_container_ref, uint32_t, const char *, + const ctf_encoding_t *, dw_die_ref); +extern ctf_dtdef_ref ctf_add_integer (ctf_container_ref, uint32_t, const char *, + const ctf_encoding_t *, dw_die_ref); +extern ctf_dtdef_ref ctf_add_unknown (ctf_container_ref, uint32_t, const char *, + const ctf_encoding_t *, dw_die_ref); +extern ctf_dtdef_ref ctf_add_pointer (ctf_container_ref, uint32_t, + ctf_dtdef_ref, dw_die_ref); +extern ctf_dtdef_ref ctf_add_array (ctf_container_ref, uint32_t, + const ctf_arinfo_t *, dw_die_ref); +extern ctf_dtdef_ref ctf_add_forward (ctf_container_ref, uint32_t, const char *, + uint32_t, dw_die_ref); +extern ctf_dtdef_ref ctf_add_typedef (ctf_container_ref, uint32_t, const char *, + ctf_dtdef_ref, dw_die_ref); +extern ctf_dtdef_ref ctf_add_function (ctf_container_ref, uint32_t, + const char *, const ctf_funcinfo_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 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_id_t, uint64_t); + ctf_dtdef_ref, uint64_t); extern int ctf_add_function_arg (ctf_container_ref, dw_die_ref, - const char *, ctf_id_t); -extern int ctf_add_variable (ctf_container_ref, const char *, ctf_id_t, + 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_id_t ctf_lookup_tree_type (ctf_container_ref, const tree); +extern ctf_dtdef_ref ctf_lookup_tree_type (ctf_container_ref, const tree); extern ctf_id_t get_btf_id (ctf_id_t); typedef bool (*funcs_traverse_callback) (ctf_dtdef_ref, void *); diff --git a/gcc/ctfout.cc b/gcc/ctfout.cc index ee082b5fd016..157afbac4f48 100644 --- a/gcc/ctfout.cc +++ b/gcc/ctfout.cc @@ -380,7 +380,8 @@ ctf_asm_type (ctf_dtdef_ref type) static void ctf_asm_slice (ctf_dtdef_ref type) { - dw2_asm_output_data (4, type->dtd_u.dtu_slice.cts_type, "cts_type"); + dw2_asm_output_data (4, ctf_type_id (type->dtd_u.dtu_slice.cts_type), + "cts_type"); dw2_asm_output_data (2, type->dtd_u.dtu_slice.cts_offset, "cts_offset"); dw2_asm_output_data (2, type->dtd_u.dtu_slice.cts_bits, "cts_bits"); } @@ -390,8 +391,10 @@ ctf_asm_slice (ctf_dtdef_ref type) static void ctf_asm_array (ctf_dtdef_ref dtd) { - dw2_asm_output_data (4, dtd->dtd_u.dtu_arr.ctr_contents, "cta_contents"); - dw2_asm_output_data (4, dtd->dtd_u.dtu_arr.ctr_index, "cta_index"); + dw2_asm_output_data (4, ctf_type_id (dtd->dtd_u.dtu_arr.ctr_contents), + "cta_contents"); + dw2_asm_output_data (4, ctf_type_id (dtd->dtd_u.dtu_arr.ctr_index), + "cta_index"); dw2_asm_output_data (4, dtd->dtd_u.dtu_arr.ctr_nelems, "cta_nelems"); } @@ -403,7 +406,7 @@ ctf_asm_varent (ctf_dvdef_ref var) /* Output the reference to the name in the string table. */ dw2_asm_output_data (4, var->dvd_name_offset, "ctv_name"); /* Output the type index. */ - dw2_asm_output_data (4, var->dvd_type, "ctv_typeidx"); + dw2_asm_output_data (4, ctf_type_id (var->dvd_type), "ctv_typeidx"); } /* Asm'out a member of CTF struct or union, represented by ctf_lmember_t. */ @@ -414,7 +417,7 @@ ctf_asm_sou_lmember (ctf_dmdef_t * dmd) dw2_asm_output_data (4, dmd->dmd_name_offset, "ctlm_name"); dw2_asm_output_data (4, CTF_OFFSET_TO_LMEMHI (dmd->dmd_offset), "ctlm_offsethi"); - dw2_asm_output_data (4, dmd->dmd_type, "ctlm_type"); + dw2_asm_output_data (4, ctf_type_id (dmd->dmd_type), "ctlm_type"); dw2_asm_output_data (4, CTF_OFFSET_TO_LMEMLO (dmd->dmd_offset), "ctlm_offsetlo"); } @@ -426,7 +429,7 @@ ctf_asm_sou_member (ctf_dmdef_t * dmd) { dw2_asm_output_data (4, dmd->dmd_name_offset, "ctm_name"); dw2_asm_output_data (4, dmd->dmd_offset, "ctm_offset"); - dw2_asm_output_data (4, dmd->dmd_type, "ctm_type"); + dw2_asm_output_data (4, ctf_type_id (dmd->dmd_type), "ctm_type"); } /* Asm'out an enumerator constant. */ @@ -443,7 +446,10 @@ ctf_asm_enum_const (ctf_dmdef_t * dmd) static void ctf_asm_func_arg (ctf_func_arg_t * farg) { - dw2_asm_output_data (4, farg->farg_type, "dtu_argv"); + /* farg_type may be NULL, indicating varargs. */ + dw2_asm_output_data (4, farg->farg_type + ? ctf_type_id (farg->farg_type) + : 0, "dtu_argv"); } /* CTF writeout to asm file. */ @@ -537,7 +543,7 @@ output_ctf_obj_info (ctf_container_ref ctfc) var = ctfc->ctfc_gobjts_list[i]; /* CTF type ID corresponding to the type of the variable. */ - dw2_asm_output_data (4, var->dvd_type, "objtinfo_var_type"); + dw2_asm_output_data (4, ctf_type_id (var->dvd_type), "objtinfo_var_type"); } } diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index 8f9e2fada9e3..00b876e2fe2c 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -29,7 +29,7 @@ along with GCC; see the file COPYING3. If not see /* Forward declarations for some routines defined in this file. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_type (ctf_container_ref, dw_die_ref); /* All the DIE structures we handle come from the DWARF information @@ -156,7 +156,7 @@ ctf_get_die_loc_col (dw_die_ref die) /* Generate CTF for the void type. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_void_type (ctf_container_ref ctfc) { ctf_encoding_t ctf_encoding = {0, 0, 0}; @@ -174,10 +174,10 @@ gen_ctf_void_type (ctf_container_ref ctfc) /* Generate CTF type of unknown kind. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_unknown_type (ctf_container_ref ctfc) { - ctf_id_t unknown_type_id; + ctf_dtdef_ref dtd; /* In CTF, the unknown type is encoded as a 0 byte sized type with kind CTF_K_UNKNOWN. Create an encoding object merely to reuse the underlying @@ -187,11 +187,11 @@ gen_ctf_unknown_type (ctf_container_ref ctfc) gcc_assert (ctf_unknown_die != NULL); /* Type de-duplication. */ - if (!ctf_type_exists (ctfc, ctf_unknown_die, &unknown_type_id)) - unknown_type_id = ctf_add_unknown (ctfc, CTF_ADD_ROOT, "unknown", - &ctf_encoding, ctf_unknown_die); + if (!ctf_type_exists (ctfc, ctf_unknown_die, &dtd)) + dtd = ctf_add_unknown (ctfc, CTF_ADD_ROOT, "unknown", + &ctf_encoding, ctf_unknown_die); - return unknown_type_id; + return dtd; } /* Sizes of entities can be given in bytes or bits. This function @@ -217,10 +217,10 @@ ctf_die_bitsize (dw_die_ref die) Important: the caller of this API must make sure that duplicate types are not added. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_base_type (ctf_container_ref ctfc, dw_die_ref type) { - ctf_id_t type_id = CTF_NULL_TYPEID; + ctf_dtdef_ref dtd = NULL; ctf_encoding_t ctf_encoding = {0, 0, 0}; @@ -236,8 +236,8 @@ gen_ctf_base_type (ctf_container_ref ctfc, dw_die_ref type) ctf_encoding.cte_bits = 0; gcc_assert (name_string); - type_id = ctf_add_integer (ctfc, CTF_ADD_ROOT, name_string, - &ctf_encoding, type); + dtd = ctf_add_integer (ctfc, CTF_ADD_ROOT, name_string, + &ctf_encoding, type); break; case DW_ATE_boolean: @@ -246,8 +246,8 @@ gen_ctf_base_type (ctf_container_ref ctfc, dw_die_ref type) ctf_encoding.cte_bits = bit_size; gcc_assert (name_string); - type_id = ctf_add_integer (ctfc, CTF_ADD_ROOT, name_string, - &ctf_encoding, type); + dtd = ctf_add_integer (ctfc, CTF_ADD_ROOT, name_string, + &ctf_encoding, type); break; case DW_ATE_float: { @@ -269,7 +269,7 @@ gen_ctf_base_type (ctf_container_ref ctfc, dw_die_ref type) break; ctf_encoding.cte_bits = bit_size; - type_id = ctf_add_float (ctfc, CTF_ADD_ROOT, name_string, + dtd = ctf_add_float (ctfc, CTF_ADD_ROOT, name_string, &ctf_encoding, type); break; @@ -291,7 +291,7 @@ gen_ctf_base_type (ctf_container_ref ctfc, dw_die_ref type) ctf_encoding.cte_format |= CTF_INT_SIGNED; ctf_encoding.cte_bits = bit_size; - type_id = ctf_add_integer (ctfc, CTF_ADD_ROOT, name_string, + dtd = ctf_add_integer (ctfc, CTF_ADD_ROOT, name_string, &ctf_encoding, type); break; @@ -315,7 +315,7 @@ gen_ctf_base_type (ctf_container_ref ctfc, dw_die_ref type) break; ctf_encoding.cte_bits = bit_size; - type_id = ctf_add_float (ctfc, CTF_ADD_ROOT, name_string, + dtd = ctf_add_float (ctfc, CTF_ADD_ROOT, name_string, &ctf_encoding, type); break; } @@ -324,41 +324,40 @@ gen_ctf_base_type (ctf_container_ref ctfc, dw_die_ref type) break; } - return type_id; + return dtd; } /* Generate CTF for a pointer type. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_pointer_type (ctf_container_ref ctfc, dw_die_ref ptr_type) { - ctf_id_t type_id = CTF_NULL_TYPEID; - ctf_id_t ptr_type_id = CTF_NULL_TYPEID; + ctf_dtdef_ref pointed_dtd, pointer_dtd; dw_die_ref pointed_type_die = ctf_get_AT_type (ptr_type); - type_id = gen_ctf_type (ctfc, pointed_type_die); + pointed_dtd = gen_ctf_type (ctfc, pointed_type_die); /* Type de-duplication. Consult the ctfc_types hash again before adding the CTF pointer type because there can be cases where a pointer type may have been added by the gen_ctf_type call above. */ - if (ctf_type_exists (ctfc, ptr_type, &ptr_type_id)) - return ptr_type_id; + if (!ctf_type_exists (ctfc, ptr_type, &pointer_dtd)) + pointer_dtd = ctf_add_pointer (ctfc, CTF_ADD_ROOT, pointed_dtd, ptr_type); - ptr_type_id = ctf_add_pointer (ctfc, CTF_ADD_ROOT, type_id, ptr_type); - return ptr_type_id; + return pointer_dtd; } /* Recursively generate CTF for array dimensions starting at DIE C (of type DW_TAG_subrange_type) until DIE LAST (of type DW_TAG_subrange_type) is - reached. ARRAY_ELEMS_TYPE_ID is base type for the array. */ + reached. ARRAY_ELEMS_TYPE is the CTF type object for the type of the + array elements. */ -static ctf_id_t -gen_ctf_subrange_type (ctf_container_ref ctfc, ctf_id_t array_elems_type_id, +static ctf_dtdef_ref +gen_ctf_subrange_type (ctf_container_ref ctfc, ctf_dtdef_ref array_elems_type, dw_die_ref c, dw_die_ref last) { ctf_arinfo_t arinfo; - ctf_id_t array_node_type_id = CTF_NULL_TYPEID; + ctf_dtdef_ref array_dtd; dw_attr_node *upper_bound_at; dw_die_ref array_index_type; @@ -398,30 +397,29 @@ gen_ctf_subrange_type (ctf_container_ref ctfc, ctf_id_t array_elems_type_id, arinfo.ctr_index = gen_ctf_type (ctfc, array_index_type); if (c == last) - arinfo.ctr_contents = array_elems_type_id; + arinfo.ctr_contents = array_elems_type; else - arinfo.ctr_contents = gen_ctf_subrange_type (ctfc, array_elems_type_id, + arinfo.ctr_contents = gen_ctf_subrange_type (ctfc, array_elems_type, dw_get_die_sib (c), last); - if (!ctf_type_exists (ctfc, c, &array_node_type_id)) - array_node_type_id = ctf_add_array (ctfc, CTF_ADD_ROOT, &arinfo, c); + if (!ctf_type_exists (ctfc, c, &array_dtd)) + array_dtd = ctf_add_array (ctfc, CTF_ADD_ROOT, &arinfo, c); - return array_node_type_id; + return array_dtd; } /* Generate CTF for an ARRAY_TYPE. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_array_type (ctf_container_ref ctfc, dw_die_ref array_type) { dw_die_ref first, last, array_elems_type; - ctf_id_t array_elems_type_id = CTF_NULL_TYPEID; - ctf_id_t array_type_id = CTF_NULL_TYPEID; + ctf_dtdef_ref array_dtd, elem_dtd; int vector_type_p = get_AT_flag (array_type, DW_AT_GNU_vector); if (vector_type_p) - return array_elems_type_id; + return NULL; /* Find the first and last array dimension DIEs. */ last = dw_get_die_child (array_type); @@ -429,41 +427,36 @@ gen_ctf_array_type (ctf_container_ref ctfc, /* Type de-duplication. Consult the ctfc_types before adding CTF type for the first dimension. */ - if (!ctf_type_exists (ctfc, first, &array_type_id)) + if (!ctf_type_exists (ctfc, first, &array_dtd)) { array_elems_type = ctf_get_AT_type (array_type); /* First, register the type of the array elements if needed. */ - array_elems_type_id = gen_ctf_type (ctfc, array_elems_type); + elem_dtd = gen_ctf_type (ctfc, array_elems_type); - array_type_id = gen_ctf_subrange_type (ctfc, array_elems_type_id, first, - last); + array_dtd = gen_ctf_subrange_type (ctfc, elem_dtd, first, last); } - return array_type_id; + return array_dtd; } /* Generate CTF for a typedef. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_typedef (ctf_container_ref ctfc, dw_die_ref tdef) { - ctf_id_t tdef_type_id, tid; + ctf_dtdef_ref tdef_dtd, dtd; const char *tdef_name = get_AT_string (tdef, DW_AT_name); dw_die_ref tdef_type = ctf_get_AT_type (tdef); - tid = gen_ctf_type (ctfc, tdef_type); + dtd = gen_ctf_type (ctfc, tdef_type); /* Type de-duplication. This is necessary because the ctf for the typedef may have been already added due to the gen_ctf_type call above. */ - if (!ctf_type_exists (ctfc, tdef, &tdef_type_id)) - { - tdef_type_id = ctf_add_typedef (ctfc, CTF_ADD_ROOT, - tdef_name, - tid, - tdef); - } - return tdef_type_id; + if (!ctf_type_exists (ctfc, tdef, &tdef_dtd)) + tdef_dtd = ctf_add_typedef (ctfc, CTF_ADD_ROOT, tdef_name, dtd, tdef); + + return tdef_dtd; } /* Generate CTF for a type modifier. @@ -472,14 +465,16 @@ gen_ctf_typedef (ctf_container_ref ctfc, dw_die_ref tdef) supported by CTF, then this function skips the modifier die and continues with the underlying type. - For all other cases, this function returns a CTF_NULL_TYPEID; -*/ + If the modifier is supported by CTF, then this function constructs and + returns an appropate CTF type representing the modifier. + + For all other cases, this function returns NULL. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_modifier_type (ctf_container_ref ctfc, dw_die_ref modifier) { uint32_t kind = CTF_K_MAX; - ctf_id_t modifier_type_id, qual_type_id; + ctf_dtdef_ref dtd, modifier_dtd; dw_die_ref qual_type = ctf_get_AT_type (modifier); switch (dw_get_die_tag (modifier)) @@ -489,37 +484,35 @@ gen_ctf_modifier_type (ctf_container_ref ctfc, dw_die_ref modifier) case DW_TAG_restrict_type: kind = CTF_K_RESTRICT; break; case DW_TAG_atomic_type: break; default: - return CTF_NULL_TYPEID; + return NULL; } /* Register the type for which this modifier applies. */ - qual_type_id = gen_ctf_type (ctfc, qual_type); + dtd = gen_ctf_type (ctfc, qual_type); /* Skip generating a CTF modifier record for _Atomic as there is no representation for it. */ if (dw_get_die_tag (modifier) == DW_TAG_atomic_type) - return qual_type_id; + return dtd; gcc_assert (kind != CTF_K_MAX); /* Now register the modifier itself. */ - if (!ctf_type_exists (ctfc, modifier, &modifier_type_id)) - modifier_type_id = ctf_add_reftype (ctfc, CTF_ADD_ROOT, - qual_type_id, kind, - modifier); + if (!ctf_type_exists (ctfc, modifier, &modifier_dtd)) + modifier_dtd = ctf_add_reftype (ctfc, CTF_ADD_ROOT, dtd, kind, modifier); - return modifier_type_id; + return modifier_dtd; } /* Generate CTF for a struct type. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) { uint32_t bit_size = ctf_die_bitsize (sou); int declaration_p = get_AT_flag (sou, DW_AT_declaration); const char *sou_name = get_AT_string (sou, DW_AT_name); - ctf_id_t sou_type_id; + ctf_dtdef_ref sou_dtd; /* An incomplete structure or union type is represented in DWARF by a structure or union DIE that does not have a size attribute and @@ -531,10 +524,10 @@ gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) /* This is a complete struct or union type. Generate a CTF type for it if it doesn't exist already. */ - if (!ctf_type_exists (ctfc, sou, &sou_type_id)) - sou_type_id = ctf_add_sou (ctfc, CTF_ADD_ROOT, - sou_name, kind, bit_size / 8, - sou); + if (!ctf_type_exists (ctfc, sou, &sou_dtd)) + sou_dtd = ctf_add_sou (ctfc, CTF_ADD_ROOT, + sou_name, kind, bit_size / 8, + sou); /* Now process the struct members. */ { @@ -547,7 +540,7 @@ gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) const char *field_name; dw_die_ref field_type; HOST_WIDE_INT field_location; - ctf_id_t field_type_id; + ctf_dtdef_ref field_dtd; c = dw_get_die_sib (c); @@ -556,7 +549,7 @@ gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) field_location = ctf_get_AT_data_member_location (c); /* Generate the field type. */ - field_type_id = gen_ctf_type (ctfc, field_type); + field_dtd = gen_ctf_type (ctfc, field_type); /* If this is a bit-field, then wrap the field type generated above with a CTF slice. */ @@ -610,29 +603,29 @@ gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) surely something to look at for the next format version bump for CTF. */ if (bitsize <= 255 && (bitpos - field_location) <= 255) - field_type_id = ctf_add_slice (ctfc, CTF_ADD_NONROOT, - field_type_id, + field_dtd = ctf_add_slice (ctfc, CTF_ADD_NONROOT, + field_dtd, bitpos - field_location, bitsize, c); else - field_type_id = gen_ctf_unknown_type (ctfc); + field_dtd = gen_ctf_unknown_type (ctfc); } /* Add the field type to the struct or union type. */ ctf_add_member_offset (ctfc, sou, field_name, - field_type_id, + field_dtd, field_location); } while (c != dw_get_die_child (sou)); } - return sou_type_id; + return sou_dtd; } /* Generate CTF for a function type. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, bool from_global_func) { @@ -643,17 +636,16 @@ gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, uint32_t num_args = 0; int linkage = get_AT_flag (function, DW_AT_external); - ctf_id_t return_type_id; - ctf_id_t function_type_id; + ctf_dtdef_ref return_dtd, function_dtd; /* First, add the return type. */ - return_type_id = gen_ctf_type (ctfc, return_type); - func_info.ctc_return = return_type_id; + return_dtd = gen_ctf_type (ctfc, return_type); + func_info.ctc_return = return_dtd; /* Type de-duplication. Consult the ctfc_types hash before adding the CTF function type. */ - if (ctf_type_exists (ctfc, function, &function_type_id)) - return function_type_id; + if (ctf_type_exists (ctfc, function, &function_dtd)) + return function_dtd; /* Do a first pass on the formals to determine the number of arguments, and whether the function type gets a varargs. */ @@ -681,12 +673,12 @@ gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, func_info.ctc_argc = num_args; /* Type de-duplication has already been performed by now. */ - function_type_id = ctf_add_function (ctfc, CTF_ADD_ROOT, - function_name, - (const ctf_funcinfo_t *)&func_info, - function, - from_global_func, - linkage); + function_dtd = ctf_add_function (ctfc, CTF_ADD_ROOT, + function_name, + (const ctf_funcinfo_t *)&func_info, + function, + from_global_func, + linkage); /* Second pass on formals: generate the CTF types corresponding to them and add them as CTF function args. */ @@ -694,7 +686,7 @@ gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, dw_die_ref c; unsigned int i = 0; const char *arg_name; - ctf_id_t arg_type; + ctf_dtdef_ref arg_type; c = dw_get_die_child (function); if (c) @@ -706,7 +698,7 @@ 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, "", 0); + ctf_add_function_arg (ctfc, function, "", NULL); } else if (dw_get_die_tag (c) == DW_TAG_formal_parameter) { @@ -723,12 +715,12 @@ gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, while (c != dw_get_die_child (function)); } - return function_type_id; + return function_dtd; } /* Generate CTF for an enumeration type. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_enumeration_type (ctf_container_ref ctfc, dw_die_ref enumeration) { const char *enum_name = get_AT_string (enumeration, DW_AT_name); @@ -736,7 +728,7 @@ gen_ctf_enumeration_type (ctf_container_ref ctfc, dw_die_ref enumeration) unsigned int signedness = get_AT_unsigned (enumeration, DW_AT_encoding); int declaration_p = get_AT_flag (enumeration, DW_AT_declaration); - ctf_id_t enumeration_type_id; + ctf_dtdef_ref enum_dtd; /* If this is an incomplete enum, generate a CTF forward for it and be done. */ @@ -756,10 +748,10 @@ gen_ctf_enumeration_type (ctf_container_ref ctfc, dw_die_ref enumeration) } /* Generate a CTF type for the enumeration. */ - enumeration_type_id = ctf_add_enum (ctfc, CTF_ADD_ROOT, - enum_name, bit_size / 8, - (signedness == DW_ATE_unsigned), - enumeration); + enum_dtd = ctf_add_enum (ctfc, CTF_ADD_ROOT, + enum_name, bit_size / 8, + (signedness == DW_ATE_unsigned), + enumeration); /* Process the enumerators. */ { @@ -787,13 +779,13 @@ gen_ctf_enumeration_type (ctf_container_ref ctfc, dw_die_ref enumeration) else value_wide_int = AT_int (enumerator_value); - ctf_add_enumerator (ctfc, enumeration_type_id, + ctf_add_enumerator (ctfc, enum_dtd, enumerator_name, value_wide_int, enumeration); } while (c != dw_get_die_child (enumeration)); } - return enumeration_type_id; + return enum_dtd; } /* Add a CTF variable record for the given input DWARF DIE. */ @@ -804,7 +796,7 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die) const char *var_name = get_AT_string (die, DW_AT_name); dw_die_ref var_type = ctf_get_AT_type (die); unsigned int external_vis = get_AT_flag (die, DW_AT_external); - ctf_id_t var_type_id; + ctf_dtdef_ref var_dtd; /* Avoid duplicates. */ if (ctf_dvd_lookup (ctfc, die)) @@ -822,11 +814,10 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die) dw_die_ref decl = get_AT_ref (die, DW_AT_specification); /* Add the type of the variable. */ - var_type_id = gen_ctf_type (ctfc, var_type); + 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_type_id, die, external_vis, - decl); + (void) 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]. */ @@ -837,10 +828,10 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die) static void gen_ctf_function (ctf_container_ref ctfc, dw_die_ref die) { - ctf_id_t function_type_id; + ctf_dtdef_ref function_dtd; /* Type de-duplication. Consult the ctfc_types hash before adding the CTF function type. */ - if (ctf_type_exists (ctfc, die, &function_type_id)) + if (ctf_type_exists (ctfc, die, &function_dtd)) return; /* Add the type of the function and update the global functions @@ -857,43 +848,43 @@ gen_ctf_function (ctf_container_ref ctfc, dw_die_ref die) this function returns the type id of the existing type. If the given DIE is not recognized as a type, then this function - returns CTF_NULL_TYPEID. */ + returns NULL. */ -static ctf_id_t +static ctf_dtdef_ref gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) { - ctf_id_t type_id; + ctf_dtdef_ref dtd = NULL; int unrecog_die = false; - if (ctf_type_exists (ctfc, die, &type_id)) - return type_id; + if (ctf_type_exists (ctfc, die, &dtd)) + return dtd; switch (dw_get_die_tag (die)) { case DW_TAG_base_type: - type_id = gen_ctf_base_type (ctfc, die); + dtd = gen_ctf_base_type (ctfc, die); break; case DW_TAG_pointer_type: - type_id = gen_ctf_pointer_type (ctfc, die); + dtd = gen_ctf_pointer_type (ctfc, die); break; case DW_TAG_typedef: - type_id = gen_ctf_typedef (ctfc, die); + dtd = gen_ctf_typedef (ctfc, die); break; case DW_TAG_array_type: - type_id = gen_ctf_array_type (ctfc, die); + dtd = gen_ctf_array_type (ctfc, die); break; case DW_TAG_structure_type: - type_id = gen_ctf_sou_type (ctfc, die, CTF_K_STRUCT); + dtd = gen_ctf_sou_type (ctfc, die, CTF_K_STRUCT); break; case DW_TAG_union_type: - type_id = gen_ctf_sou_type (ctfc, die, CTF_K_UNION); + dtd = gen_ctf_sou_type (ctfc, die, CTF_K_UNION); break; case DW_TAG_subroutine_type: - type_id = gen_ctf_function_type (ctfc, die, - false /* from_global_func */); + dtd = gen_ctf_function_type (ctfc, die, + false /* from_global_func */); break; case DW_TAG_enumeration_type: - type_id = gen_ctf_enumeration_type (ctfc, die); + dtd = gen_ctf_enumeration_type (ctfc, die); break; case DW_TAG_atomic_type: /* FALLTHROUGH */ @@ -902,35 +893,35 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) case DW_TAG_restrict_type: /* FALLTHROUGH */ case DW_TAG_volatile_type: - type_id = gen_ctf_modifier_type (ctfc, die); + dtd = gen_ctf_modifier_type (ctfc, die); break; case DW_TAG_unspecified_type: { const char *name = get_AT_string (die, DW_AT_name); if (name && strcmp (name, "void") == 0) - type_id = gen_ctf_void_type (ctfc); + dtd = gen_ctf_void_type (ctfc); else - type_id = CTF_NULL_TYPEID; + dtd = NULL; break; } case DW_TAG_reference_type: - type_id = CTF_NULL_TYPEID; + dtd = NULL; break; default: /* Unrecognized DIE. */ unrecog_die = true; - type_id = CTF_NULL_TYPEID; + dtd = NULL; break; } /* For all types unrepresented in CTF, use an explicit CTF type of kind CTF_K_UNKNOWN. */ - if ((type_id == CTF_NULL_TYPEID) && (!unrecog_die)) - type_id = gen_ctf_unknown_type (ctfc); + if ((dtd == NULL) && (!unrecog_die)) + dtd = gen_ctf_unknown_type (ctfc); - return type_id; + return dtd; } bool @@ -951,7 +942,7 @@ ctf_do_die (dw_die_ref die) return false; } else - return gen_ctf_type (tu_ctfc, die) == CTF_NULL_TYPEID; + return (gen_ctf_type (tu_ctfc, die) == NULL); } /* Initialize CTF subsystem for CTF debug info generation. */ diff --git a/include/btf.h b/include/btf.h index 24b38bace178..3f45ffb0b6bb 100644 --- a/include/btf.h +++ b/include/btf.h @@ -56,6 +56,11 @@ struct btf_header /* Maximum number of struct, union, enum members or func args. */ #define BTF_MAX_VLEN 0xffff +/* Type ID 0 represents the void type. */ +#define BTF_VOID_TYPEID 0 +/* Initial type ID for regular types. */ +#define BTF_INIT_TYPEID 1 + struct btf_type { uint32_t name_off; /* Offset in string section of type name. */ From patchwork Tue Jun 11 19:01:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1946492 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=incjlSXR; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=opQai1OR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzJ4B2k5wz20Pb for ; Wed, 12 Jun 2024 05:03:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7FFCE3861835 for ; Tue, 11 Jun 2024 19:03:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 88552385E45A for ; Tue, 11 Jun 2024 19:03:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88552385E45A 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 88552385E45A Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132591; cv=pass; b=hcmU8l5n+0Vvp2j261N457hokYK+Aix4phnCILhUkw9g+JnnsJENMubM3xHVeyXoiieX/+6Fa4UjLcnpKt9zJC23tUhuHjLBXt27rX7caxQHTe+c0cZAgGninyHv/KKtmw8HPWDDlzoCTDINrC8fPzskaZsqEgTMzcoQgMiAtWU= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132591; c=relaxed/simple; bh=IT4RPkntNN2FjhUCT4EGqMt0EmmYSYU6cujrcpjXy4c=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=SzAsefdulVWlGXRg6IilZW6SZdJDhcq7CUzfPVqw4v/WTgxASFKOrrRIuw3NLSCubRZ3vr3ffInURqiiZRd/C0YBvGKILdt/Sq5SxAJTrHIzp5n4D+Kl1iyIX9mzIJ003E1ZNu0MtwZ5GF9SZrkKtnrQp5lBRYzCfO0mJv+nCgg= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45BFoHQM009030 for ; Tue, 11 Jun 2024 19:03:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=QSpoBlj8Nr5THWcjebRXoEecv4ltSFWZVvOBD/j+bGE=; b= incjlSXRDyoqO/zDmUSx4+gdVS79zwwcBpHIsySQloNLdmjyEUVYAQmdLMD1uAg/ t03wKFWiW9eo2V9VP7oohh18QokiUX4qyQLb2jzQ/hczGWOZOzMM9L2gyX1d6gZ/ hLJMkBuNmjT3mTiZboOxIP6RF/dLoAPHqENuseRNkuubuFK5X5fXcVCTooP6qE3H A4dt2FTl16u9EBM6+TFZ2qsUdHysON3sdFSXjyYg8DEI3PyOquc+3Q5qyeOb2h48 8dtUHLqA3j78QNkTBlN8cNQtmPe7iypKvDN6yuwGAu8sZ869STNa2KB171rrFEkf Dvnq3Dl4mVUNpSbXCezYVA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh195jh8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:03:01 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45BHquCO027086 for ; Tue, 11 Jun 2024 19:03:00 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2040.outbound.protection.outlook.com [104.47.73.40]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncdtpavg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:03:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V/25yyLhBo/8bLnx4oCkhpybc+9ap94vQwD9I0LvkGmW1fgGauvzoV3jsu2MHh+LaeyAVfsjdNpcf4+mbolJBxOuT2qbREa5715yVcztdJaY8KUPUZe5epHYZ/EZMVzetXdWH70LItI5w8uAHZ38opmgctD4OaWoiXb2SPyvwJG5kkEelPcZPdwxIZRn6nZvPwi9hhfFrf1tU6dSKzzF6A2wBgMEi8QbMkCJSGf/r3sJcYvg5jhWuuXdjbdGnNpQR/2x5+zGymqTEchSeZ+tsy4wd5su7GPgYbuk1Bid4Vmq8WgTZB5AegaCUty4zWM+NZeoOiuFZhrZwiRHxk45KA== 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=QSpoBlj8Nr5THWcjebRXoEecv4ltSFWZVvOBD/j+bGE=; b=oR2FRR3JyVqNVSf8nB59p+Agur9Z24r3y+b/PpdwEUrIq1w3Q8bTp/FwP8/flNGbBPsppuA825bkrLSq5+1Uih7YjAEyfslJcOFxOM0KJHxdGqjwrjmoP5N9Uu1PGshIMAI74dTIPoGcfb+Q7YuP9L39dR96do0IJ4mD/rZXKy5ez2FL/VpeMaQOxf7xaHcOmBe7+xBjG/G6qzbmGzba7ZggLolpbM96wPYtbbrzgsxfFkLhIF/pMwAe1/KU507zRRzHGFkWxnWY+4EVX8p9gxOyTReWq4Xr4KHTJRSIenNBZQKB9WYW0W237d6kZaazXOuwx8duXULgcEB69B1Qlg== 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=QSpoBlj8Nr5THWcjebRXoEecv4ltSFWZVvOBD/j+bGE=; b=opQai1ORhh7b5U8BS0IyK5NgdEAPFimP852iBRPwXqzAm/4BgyGSMXA//9JSNwA4DtznbT77Ths164B4scgzsTA6iYnzo6nzBhZsxiVLk4ffVqBHMmwe7VOxJDBL+XSZtenNBbjMGNYhV3SN4hf+F13Eu3arUUXjqH7eYp3PnoE= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by CH2PR10MB4134.namprd10.prod.outlook.com (2603:10b6:610:a7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.39; Tue, 11 Jun 2024 19:02:57 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%5]) with mapi id 15.20.7633.036; Tue, 11 Jun 2024 19:02:57 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com, jose.marchesi@oracle.com, cupertino.miranda@oracle.com Subject: [PATCH v4 3/6] btf: refactor and simplify implementation Date: Tue, 11 Jun 2024 12:01:42 -0700 Message-ID: <20240611190145.115887-4-david.faust@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240611190145.115887-1-david.faust@oracle.com> References: <20240611190145.115887-1-david.faust@oracle.com> X-ClientProxiedBy: MW4PR03CA0114.namprd03.prod.outlook.com (2603:10b6:303:b7::29) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|CH2PR10MB4134:EE_ X-MS-Office365-Filtering-Correlation-Id: 15803eef-a35e-4df4-0bd8-08dc8a491ae3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230032|1800799016|366008|376006; X-Microsoft-Antispam-Message-Info: g5mAweVVMM5nbIKvS7RAfUsq3LDYvcqoPB19t+u/Xtq9bnlo2YmePjwD5G6maZLWQOk7QAADTc1PoxgFpYX+GrapWB9gK6je3VjpqRKqf0hG9fpDd7Ey/7M2uCNdZ8Avh7oR4zpSF61H/vHD9S75HcRe4x6V4let/hP2kyOCOSGgE710E20XR1AUHFN+8ptJBzU0pqkR9LYVGuM7DH1xOqBGB+XyPYD6YHkbB5x2nhCS3JT3U5kB63xyM/r78n9yAMwmX3MxxPRRyf5BJkIr/pkCW6r9o1v4gADz640t3DLAGYUtNTCLRwku2QHz4wvglWsJra/eTCW+kJkqrr/tc0VREKXskRNxCRMCH5NBkMrETXQTa3RmaDPUHnxv4kVk0hC6Fz1ooXgLROIGZxCgCvSrVYWHSrvGv0wl2sapmnVEQ7Kdwe9dM03+mVoQZ6d9GWSG6To2lhirLaFKbqkGHLVRdhbBMHxwH9ORQiCbTOjxs8F6HLj4cc5AYPnIbUrttzhou4cNy26HMPRXjx51SzKAIOhI7ThgvIsrSMcOv7zqZ3gunTjAbysDXgzI090l955TKpUKxmtMbYcrd9edSxup1POMpo5r3h6MIq3rDtrDQYZSIouUa5aXbLXfTpi/jhQ5qZzA+m4487OVbNwkHgOT6YKcW23jwSj4g11z/Ao8z4C5yvdcjSSqQN0EkQ/7pek+pBalET3ThCLAZouBVkVTaXosGMfp92Ck2PnBf4uQFbyxK1Hia+M0X15rnDxJxoKyNj6kGTGGohac1cEBKa450i+LCQvKsAvksV9gL60oNlJG7Qd3mG8IeRq0MHklTlItTee32l7nVbTbkb/wC3Gzv13TYAjK9LkIdc7I7acif2u4Bw7YGLaQR421poCZ1gvh9VQwRDchrvPauMZHgBVqsKibg1nj6D2bW3zfk9RDUfP6cOxTyDUWt4vgZhgWqzgZSKtz5vfRlmh6gl8cd9nJCLRtBTMRShDizYNSG9FxYwYxPeLpRGiXk3zWTQqTQO8P+dfTZqsMdahcjqP6kEuT5xPd6Gtm2OJZ8QuqjUNetjrU6LqNDfr9MaAywIbwatLgFMo4fqsSvg2D5ck1IwO5/hCYQrBrt875JljwqXptfvDt/q4KbCzxtBWFlVfUqR+ej0QVU7xaT6NM+arOa1lHqrFbGlKr/yAke7pDv2gS7Ghl0tpkHnlBijjLcpdKD1yCufDYY4y6wvrKT1k+njfPNSU0afDMdpKin11g6DjSOHxEg6komA8QXCqzX9oUBG1uiwF5P8SdO9eZ/BcHEY4TNKH8eqsJ6Obu1ePfrIJ4y/krf/Bkfn7E+5zMYCBu 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:(13230032)(1800799016)(366008)(376006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FSubuR2Ukcu6yHW5I7ju9cIpBsyk01HkwEr/D+xp/z2nOjy7SKf9fxEa/5WZ0s9rAyajOPNkuR2KjxueaUrs2MGlFUSN9ceX3tqv28gBXoK80ZBP56taVQtGqwHO4BbaIYz3TlgKcvZiTgnWGKknm7WUskJIik/W199wA9lqP6K5ueWpKR0C8+Yp+M0k9npFr55NGoUpZHNTq5deXk03fAeJMcNa+Gk+6agz8bs/Bj9bO9EuiQ/ayZFL7IbxmPgVuZU+6KrbOIveG+62395eBZJFp2IBunmQCXtTbsKSuH3SkvFRdLcNoMyXV+l6ASD+Ikgjlj2kF77ngoOsdRLMOMzwwQOv2VK4yiKKdfT8WWOaBmYJDXM1GzM+FcgbbaJKTaU0oRdg1vEcRfaRCGz76GXRtta0vwXJU6w1ubFmnM+n8gmcetxdEMBJN4JqgKKicEZ0Zf1YdvK+bNvBd+kAIR62Y3sW5B9V6NmMV0vKENGLFSHcNPxf+xWvBk5qy6QmcrbwhR/Mp7lZ+Kwe5tHbP9iF+UAJpB0qfTRmxoSWoHaM/0PI22O6I0+BoszBLL5fm6O4AfOmCcl8YD7GtFV0fWtqb2KJ/p3F4DBPVUwtnZTQkqiSOfQ425OHsxCfSppCVoEh/ezpB+qoBhyiDCQL/RA5qVADZ7bv4WWnMN+mGZi5KfzgkwQvOwG6LEgcvW2/cq8uFB0SsttMiNaCcoW9csjoS+RQ9wdXQ+IidV92vB4sM2guwo4cwLW27IMpPyU5CIVdHmqzcYkRlRmYtnp8DoSP4IYKFCSmQJ2NHYGU5bU8gN/gIIG5AYYAKLsH4Qh5hL851hcX4O9J+tuvu+oLLsJOOv9d219AeHpwBWWxJXPXMAQfqmk+2JPrgIrsz7Y7JUdr0TJ99VbDDiO8G6EsmZooNqb8LkAuOqclAFn/8nVLtCzleRZmioYEVg2bpPZNlYTsBpvIVSE/XyMMHtsdoant8RgGoDKp/R4TwifW0mCvONmGVQU5ixPzqu9WcQh3LfZi/D0FxRLcin5Mztxz5S9fxvp2wt7hhioiSiraivDVYjzFYcWjK6MVLp/fInEMJVg4wUYhMQjNMwjVoh1Aa1FBsDWseIkd/tMHn6uEAL7qedrqot7YSS0LCAyXO6X/3L41pDiM4hy8o5/SWxAtdv5FLedAoKAHN+rp4t965/WlhDu67Qo0iHBlW8XytbH7InZqSrfTZuzWIlvFh7Oej0FURZFM/8XpZMGuuS6f0HCs80+zSxPVaxOZO8OyrGOpxEDycULn9DH0lLLcabshG+Ll22WkZdDRu6GRtwMeQ00/TClGiMtkKzkJOb67fW6E9c/713Qyan5Lca3jPhaSLvODS5CuXLc1297srHW8BjT+rizVzUDFmzGpqM87+yq7w2ayZwEh8YFNLOqdAUUYvnGApmApfUM6yB65fYykDODTZLqv+vURO1Nxe639XGweo6t+h3Tlq8DonfYgfXmEHEMls14ge1DVzvMUVAen8LKETLeJX6faocm0QpGXnUqsO04AlIntq+cN9+PudajnGF9WR9hW/9eGSj6jrEiVvaaLawuEtUwr213+NstE5SSob/S/Vw0UpOHr/tQ9SNpshQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: j0DWeCJM/HsJLyhfIAoP02OxsA2Dsaf53VpBlI5gSKHPxYHV3Fl2HWUE3MTicKS8qi0h5g7RJTAaa9/92h8srgEF1QP50jdS6CROtx4q3mShPF5kIw1OlGlW7IJx3NkPesYs4AReWFD2kJkCHZAtdQ39jFqj/hLpylIP8vhqu/SiQQ0P6gcBM8JMLp0yV6IVf2FHgPwQJvybNYx50zxhJZamZG86dvtNShNjIcw8Swm9nfXk33+rAYt7puj1TZ4R4BBBOUyxhHQN0JjB4itRNHnSFl8oFKmSojjkQyWMl10RL325/ssIPAxEpl+NGI+12MYtt44Ms1WNyd8/mrDAsQZaRCeOVGm4UNj5wqB3LqYmlf9ZbfMgVDxGSMAN+unNmVMxfVRbtpXb6sS/rlZzKcwTCMr4fegqKlkVCkPXrynm59qc7otye4rIIzwz6ND+5mmiSVlQpek71x9+FxvTrjqrjiJhnJ7sm8kBR530jVBiWI2qwOE0uvp73tBwwtk/G8VxjaVnYbGwe01P5YJxzwTouvf9GgfYU1TmaCZdYD97i3LCyJItTy3xqpi9Jk9nirEy/5z9P+rknAb+Nardc5EibiONK+q74zEcaL12eEs= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15803eef-a35e-4df4-0bd8-08dc8a491ae3 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 19:02:56.9927 (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: a60EV2ahnOSmx/uMrXep1OSVu2P3DgOXF0v7hMUnoVcguzIAB/sm1fvB5L/rnefm7MeUqnWAA8NEJJeEwvk4iA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4134 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-11_09,2024-06-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406110130 X-Proofpoint-GUID: jles3Hl4f8_7H93AwCUei8tBLRvNj-Cj X-Proofpoint-ORIG-GUID: jles3Hl4f8_7H93AwCUei8tBLRvNj-Cj X-Spam-Status: No, score=-13.7 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TVD_PH_BODY_ACCOUNTS_PRE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch heavily refactors btfout.cc to take advantage of the structural changes in the prior commits. Now that inter-type references are internally stored as simply pointers, all the painful, brittle, confusing infrastructure that was used in the process of converting CTF type IDs to BTF type IDs can be thrown out. This greatly simplifies the entire process of converting from CTF to BTF, making the code cleaner, easier to read, and easier to maintain. In addition, we no longer need to worry about destructive changes in internal data structures used commonly by CTF and BTF, which allows deleting several ancillary data structures previously used in btfout.cc. This is nearly transparent, but a few improvements have also been made: 1) BTF_KIND_FUNC records are now _always_ constructed at early_finish, allowing us to construct records even for functions which are later inlined by optimizations. DATASEC entries for functions are only constructed at late_finish, to avoid incorrectly generating entries for functions which get inlined. 2) BTF_KIND_VAR records and DATASEC entries for them are now always constructed at (late) finish, which avoids cases where we could incorrectly create records for variables which were completely optimized away. This fixes PR debug/113566 for non-LTO builds. In LTO builds, BTF must be emitted at early_finish, so some VAR records may be emitted for variables which are later optimized away. 3) Some additional assembler comments have been added with more information for debugging. gcc/ * btfout.cc (struct btf_datasec_entry): New. (struct btf_datasec): Add `id' member. Change `entries' to use new struct btf_datasec_entry. (func_map): New hash_map. (max_translated_id): New. (btf_var_ids, btf_id_map, holes, voids, num_vars_added) (num_types_added, num_types_created): Delete. (btf_absolute_var_id, btf_relative_var_id, btf_absolute_func_id) (btf_relative_func_id, btf_absolute_datasec_id, init_btf_id_map) (get_btf_id, set_btf_id, btf_emit_id_p): Delete. (btf_removed_type_p): Delete. (btf_dtd_kind, btf_emit_type_p): New helpers. (btf_fwd_to_enum_p, btf_calc_num_vbytes): Use them. (btf_collect_datasec): Delete. (btf_dtd_postprocess_cb, btf_dvd_emit_preprocess_cb) (btf_dtd_emit_preprocess_cb, btf_emit_preprocess): Delete. (btf_dmd_representable_bitfield_p): Adapt to type reference changes and delete now-unused ctfc argument. (btf_asm_datasec_type_ref): Delete. (btf_asm_type_ref): Adapt to type reference changes, simplify. (btf_asm_type): Likewise. Mark struct/union types with bitfield members. (btf_asm_array): Adapt to data structure changes. (btf_asm_varent): Likewise. (btf_asm_sou_member): Likewise. Ensure non-bitfield members are correctly re-encoded if struct or union contains any bitfield. (btf_asm_func_arg, btf_asm_func_type, btf_asm_datasec_entry) (btf_asm_datasec_type): Adapt to data structure changes. (output_btf_header): Adapt to other changes, simplify type length calculation, add info to assembler comments. (output_btf_vars): Adapt to other changes. (output_btf_strs): Fix overlong lines. (output_asm_btf_sou_fields, output_asm_btf_enum_list) (output_asm_btf_func_args_list, output_asm_btf_vlen_bytes) (output_asm_btf_type, output_btf_types, output_btf_func_types) (output_btf_datasec_types): Adapt to other changes. (btf_init_postprocess): Delete. (btf_output): Change to only perform output. (btf_add_const_void, btf_add_func_records): New. (btf_early_finish): Use them here. New. (btf_datasec_push_entry): Adapt to data structure changes. (btf_datasec_add_func, btf_datasec_add_var): New. (btf_add_func_datasec_entries): New. (btf_emit_variable_p): New helper. (btf_add_vars): Use it here. New. (btf_type_list_cb, btf_collect_translated_types): New. (btf_assign_func_ids, btf_late_assign_var_ids) (btf_assign_datasec_ids): New. (btf_finish): Remove unused argument. Call new btf_late* functions and btf_output. (btf_finalize): Adapt to data structure changes. * ctfc.h (struct ctf_dtdef): Convert existing boolean flags to BOOL_BITFIELD and reorder. (struct ctf_dvdef): Add dvd_id member. (btf_finish): Remove argument from prototype. (get_btf_id): Delete prototype. (funcs_traverse_callback, traverse_btf_func_types): Add an explanatory comment. * dwarf2ctf.cc (ctf_debug_finish): Remove unused argument. * dwarf2ctf.h: Analogous change. * dwarf2out.cc: Likewise. --- gcc/btfout.cc | 1257 +++++++++++++++++++--------------------------- gcc/ctfc.h | 17 +- gcc/dwarf2ctf.cc | 6 +- gcc/dwarf2ctf.h | 2 +- gcc/dwarf2out.cc | 2 +- 5 files changed, 542 insertions(+), 742 deletions(-) diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 9d73478ba9a6..89f148de9650 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -63,53 +63,44 @@ static char btf_info_section_label[MAX_BTF_LABEL_BYTES]; #define BTF_INVALID_TYPEID 0xFFFFFFFF -/* Mapping of CTF variables to the IDs they will be assigned when they are - converted to BTF_KIND_VAR type records. Strictly accounts for the index - from the start of the variable type entries, does not include the number - of types emitted prior to the variable records. */ -static GTY (()) hash_map *btf_var_ids; - -/* Mapping of type IDs from original CTF ID to BTF ID. Types do not map - 1-to-1 from CTF to BTF. To avoid polluting the CTF container when updating - type references-by-ID, we use this map instead. */ -static ctf_id_t * btf_id_map = NULL; - -/* Information for creating the BTF_KIND_DATASEC records. */ +/* Internal representation of an entry in a BTF_KIND_DATASEC record. */ +struct btf_datasec_entry +{ + union { + ctf_dvdef_ref dvd; /* Reference to the underlying variable represented. */ + ctf_dtdef_ref dtd; /* Reference to the underlying type represented. */ + }; + bool is_var; /* True iff this entry represents a variable. */ + uint32_t size; /* Size of variable or function, in bytes. + For functions, always zero at compile time. */ +}; + +/* Internal representation of a BTF_KIND_DATASEC record. */ typedef struct btf_datasec { - const char *name; /* Section name, e.g. ".bss". */ - uint32_t name_offset; /* Offset to name in string table. */ - vec entries; /* Variable entries in this section. */ + ctf_id_t id; /* BTF type ID of this record. */ + const char *name; /* Section name, e.g. ".bss". */ + uint32_t name_offset; /* Offset to name in string table. */ + vec entries; /* Entries in this section. */ } btf_datasec_t; /* One BTF_KIND_DATASEC record is created for each output data section which will hold at least one variable. */ static vec datasecs; -/* Holes occur for types which are present in the CTF container, but are either - non-representable or redundant in BTF. */ -static vec holes; - -/* CTF definition(s) of void. Only one definition of void should be generated. - We should not encounter more than one definition of void, but use a vector - to be safe. */ -static vec voids; - /* Functions in BTF have two separate type records - one for the prototype (BTF_KIND_FUNC_PROTO), as well as a BTF_KIND_FUNC. CTF_K_FUNCTION types map closely to BTF_KIND_FUNC_PROTO, but the BTF_KIND_FUNC records must be created. This vector holds them. */ static GTY (()) vec *funcs; -/* The number of BTF variables added to the TU CTF container. */ -static unsigned int num_vars_added = 0; - -/* The number of BTF types added to the TU CTF container. */ -static unsigned int num_types_added = 0; +/* Maps BTF_KIND_FUNC_PROTO to the BTF_KIND_FUNC record for it. Used when + creating DATASEC entries. */ +static GTY (()) hash_map *func_map; -/* The number of types synthesized for BTF that do not correspond to - CTF types. */ -static unsigned int num_types_created = 0; +/* Highest BTF ID assigned to any regular type translated from CTF. + Does not include BTF_KIND_{VAR,FUNC,DATASEC} types. */ +static ctf_id_t max_translated_id = 0; /* Name strings for BTF kinds. Note: the indices here must match the type defines in btf.h. */ @@ -155,6 +146,16 @@ get_btf_kind (uint32_t ctf_kind) return BTF_KIND_UNKN; } +/* Convenience wrapper around get_btf_kind for the common case. */ + +static uint32_t +btf_dtd_kind (ctf_dtdef_ref dtd) +{ + if (!dtd) + return BTF_KIND_UNKN; + return get_btf_kind (CTF_V2_INFO_KIND (dtd->dtd_data.ctti_info)); +} + /* Some BTF types, like BTF_KIND_FUNC_PROTO, are anonymous. The machinery in btfout to emit BTF, may reset dtd_data->ctti_name, but does not update the name in the ctf_dtdef_ref type object (deliberate choice). This @@ -168,101 +169,20 @@ get_btf_type_name (ctf_dtdef_ref dtd) return (dtd->dtd_data.ctti_name) ? dtd->dtd_name : anon; } -/* Helper routines to map between 'relative' and 'absolute' IDs. - - In BTF all records (including variables) are output in one long list, and all - inter-type references are via index into that list. But internally since we - a) translate from CTF, which separates variable records from regular types - and b) create some additional types after the fact, things like VAR and FUNC - records are stored in separate vectors with their own indices. These - functions map between the 'relative' IDs (i.e. indices in their respective - containers) and 'absolute' IDs (i.e. indices in the final contiguous - output list), which goes in order: - all normal type records translated from CTF - all BTF_KIND_VAR records - all BTF_KIND_FUNC records (synthesized split function records) - all BTF_KIND_DATASEC records (synthesized) - - The extra '+ 1's below are to account for the implicit "void" record, which - has index 0 but isn't actually contained in the type list. */ - -/* Return the final BTF ID of the variable at relative index REL. */ - -static ctf_id_t -btf_absolute_var_id (ctf_id_t rel) -{ - return rel + (num_types_added + 1); -} - -/* Return the relative index of the variable with final BTF ID ABS. */ - -static ctf_id_t -btf_relative_var_id (ctf_id_t abs) -{ - return abs - (num_types_added + 1); -} - -/* Return the final BTF ID of the func record at relative index REL. */ - -static ctf_id_t -btf_absolute_func_id (ctf_id_t rel) -{ - return rel + (num_types_added + 1) + num_vars_added; -} - -/* Return the relative index of the func record with final BTF ID ABS. */ - -static ctf_id_t -btf_relative_func_id (ctf_id_t abs) -{ - return abs - ((num_types_added + 1) + num_vars_added); -} - -/* Return the final BTF ID of the datasec record at relative index REL. */ - -static ctf_id_t -btf_absolute_datasec_id (ctf_id_t rel) -{ - return rel + (num_types_added + 1) + num_vars_added + funcs->length (); -} - - -/* Allocate the btf_id_map, and initialize elements to BTF_INVALID_TYPEID. */ - -static void -init_btf_id_map (size_t len) +static bool +btf_emit_type_p (ctf_dtdef_ref dtd) { - btf_id_map = XNEWVEC (ctf_id_t, len); + uint32_t kind = btf_dtd_kind (dtd); - btf_id_map[0] = BTF_VOID_TYPEID; - for (size_t i = 1; i < len; i++) - btf_id_map[i] = BTF_INVALID_TYPEID; -} + if (kind == BTF_KIND_UNKN) + /* This type is not representable in BTF. */ + return false; -/* Return the BTF type ID of CTF type ID KEY, or BTF_INVALID_TYPEID if the CTF - type with ID KEY does not map to a BTF type. */ + if (kind == BTF_KIND_INT && dtd->dtd_data.ctti_size == 0) + /* This is a (redundant) definition of void. */ + return false; -ctf_id_t -get_btf_id (ctf_id_t key) -{ - return btf_id_map[key]; -} - -/* Set the CTF type ID KEY to map to BTF type ID VAL. */ - -static inline void -set_btf_id (ctf_id_t key, ctf_id_t val) -{ - btf_id_map[key] = val; -} - -/* Return TRUE iff the given CTF type ID maps to a BTF type which will - be emitted. */ -static inline bool -btf_emit_id_p (ctf_id_t id) -{ - return ((btf_id_map[id] != BTF_VOID_TYPEID) - && (btf_id_map[id] <= BTF_MAX_TYPE)); + return true; } /* Return true if DTD is a forward-declared enum. The BTF representation @@ -271,9 +191,8 @@ btf_emit_id_p (ctf_id_t id) static bool btf_fwd_to_enum_p (ctf_dtdef_ref dtd) { - uint32_t btf_kind = get_btf_kind (CTF_V2_INFO_KIND (dtd->dtd_data.ctti_info)); - - return (btf_kind == BTF_KIND_FWD && dtd->dtd_data.ctti_type == CTF_K_ENUM); + uint32_t kind = btf_dtd_kind (dtd); + return (kind == BTF_KIND_FWD && dtd->dtd_data.ctti_type == CTF_K_ENUM); } /* Each BTF type can be followed additional, variable-length information @@ -285,7 +204,7 @@ btf_calc_num_vbytes (ctf_dtdef_ref dtd) { uint64_t vlen_bytes = 0; - uint32_t kind = get_btf_kind (CTF_V2_INFO_KIND (dtd->dtd_data.ctti_info)); + uint32_t kind = btf_dtd_kind (dtd); uint32_t vlen = CTF_V2_INFO_VLEN (dtd->dtd_data.ctti_info); switch (kind) @@ -355,41 +274,6 @@ init_btf_sections (void) BTF_INFO_SECTION_LABEL, btf_label_num++); } -/* Push a BTF datasec variable entry INFO into the datasec named SECNAME, - creating the datasec if it does not already exist. */ - -static void -btf_datasec_push_entry (ctf_container_ref ctfc, const char *secname, - struct btf_var_secinfo info) -{ - if (secname == NULL) - return; - - for (size_t i = 0; i < datasecs.length (); i++) - if (strcmp (datasecs[i].name, secname) == 0) - { - datasecs[i].entries.safe_push (info); - return; - } - - /* If we don't already have a datasec record for secname, make one. */ - - uint32_t str_off; - ctf_add_string (ctfc, secname, &str_off, CTF_AUX_STRTAB); - if (strcmp (secname, "")) - ctfc->ctfc_aux_strlen += strlen (secname) + 1; - - btf_datasec_t ds; - ds.name = secname; - ds.name_offset = str_off; - - ds.entries.create (0); - ds.entries.safe_push (info); - - datasecs.safe_push (ds); -} - - /* Return the section name, as of interest to btf_collect_datasec, for the given symtab node. Note that this deliberately returns NULL for objects which do not go in a section btf_collect_datasec cares about. */ @@ -418,301 +302,15 @@ get_section_name (symtab_node *node) return section_name; } -/* Construct all BTF_KIND_DATASEC records for CTFC. One such record is created - for each non-empty data-containing section in the output. Each record is - followed by a variable number of entries describing the variables stored - in that section. */ - -static void -btf_collect_datasec (ctf_container_ref ctfc) -{ - cgraph_node *func; - FOR_EACH_FUNCTION (func) - { - dw_die_ref die = lookup_decl_die (func->decl); - if (die == NULL) - continue; - - ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, die); - if (dtd == NULL) - continue; - - if (DECL_EXTERNAL (func->decl) - && (lookup_attribute ("kernel_helper", - DECL_ATTRIBUTES (func->decl))) != NULL_TREE) - continue; - - /* Functions actually get two types: a BTF_KIND_FUNC_PROTO, and - also a BTF_KIND_FUNC. But the CTF container only allocates one - type per function, which matches closely with BTF_KIND_FUNC_PROTO. - For each such function, also allocate a BTF_KIND_FUNC entry. - These will be output later. */ - ctf_dtdef_ref func_dtd = ggc_cleared_alloc (); - func_dtd->dtd_data = dtd->dtd_data; - func_dtd->dtd_data.ctti_type = dtd->dtd_type; - func_dtd->linkage = dtd->linkage; - func_dtd->dtd_name = dtd->dtd_name; - /* +1 for the sentinel type not in the types map. */ - func_dtd->dtd_type = num_types_added + num_types_created + 1; - - /* Only the BTF_KIND_FUNC type actually references the name. The - BTF_KIND_FUNC_PROTO is always anonymous. */ - dtd->dtd_data.ctti_name = 0; - - vec_safe_push (funcs, func_dtd); - num_types_created++; - - /* Mark any 'extern' funcs and add DATASEC entries for them. */ - if (DECL_EXTERNAL (func->decl)) - { - func_dtd->linkage = BTF_FUNC_EXTERN; - - const char *section_name = get_section_name (func); - /* Note: get_section_name () returns NULL for functions in text - section. This is intentional, since we do not want to generate - DATASEC entries for them. */ - if (section_name == NULL) - continue; - - struct btf_var_secinfo info; - - info.type = func_dtd->dtd_type; - - /* Both zero at compile time. */ - info.size = 0; - info.offset = 0; - - btf_datasec_push_entry (ctfc, section_name, info); - } - } - - varpool_node *node; - FOR_EACH_VARIABLE (node) - { - dw_die_ref die = lookup_decl_die (node->decl); - if (die == NULL) - continue; - - ctf_dvdef_ref dvd = ctf_dvd_lookup (ctfc, die); - if (dvd == NULL) - continue; - - /* Mark extern variables. */ - if (DECL_EXTERNAL (node->decl)) - { - dvd->dvd_visibility = BTF_VAR_GLOBAL_EXTERN; - - /* PR112849: avoid assuming a section for extern decls without - an explicit section, which would result in incorrectly - emitting a BTF_KIND_DATASEC entry for them. */ - if (node->get_section () == NULL) - continue; - } - - const char *section_name = get_section_name (node); - if (section_name == NULL) - continue; - - struct btf_var_secinfo info; - - info.type = 0; - unsigned int *var_id = btf_var_ids->get (dvd); - if (var_id) - info.type = btf_absolute_var_id (*var_id); - else - continue; - - info.size = 0; - tree size = DECL_SIZE_UNIT (node->decl); - if (tree_fits_uhwi_p (size)) - info.size = tree_to_uhwi (size); - else if (VOID_TYPE_P (TREE_TYPE (node->decl))) - info.size = 1; - - /* Offset is left as 0 at compile time, to be filled in by loaders such - as libbpf. */ - info.offset = 0; - - btf_datasec_push_entry (ctfc, section_name, info); - } - - num_types_created += datasecs.length (); -} - -/* Return true if the type ID is that of a type which will not be emitted (for - example, if it is not representable in BTF). */ - -static bool -btf_removed_type_p (ctf_id_t id) -{ - return holes.contains (id); -} - -/* Adjust the given type ID to account for holes and duplicate definitions of - void. */ - -static ctf_id_t -btf_adjust_type_id (ctf_id_t id) -{ - size_t n; - ctf_id_t i = 0; - - /* Do not adjust invalid type markers. */ - if (id == BTF_INVALID_TYPEID) - return id; - - for (n = 0; n < voids.length (); n++) - if (id == voids[n]) - return BTF_VOID_TYPEID; - - for (n = 0; n < holes.length (); n++) - { - if (holes[n] < id) - i++; - else if (holes[n] == id) - return BTF_VOID_TYPEID; - } - - return id - i; -} - -/* Postprocessing callback routine for types. */ - -int -btf_dtd_postprocess_cb (ctf_dtdef_ref *slot, ctf_container_ref arg_ctfc) -{ - ctf_dtdef_ref ctftype = (ctf_dtdef_ref) * slot; - - size_t index = ctftype->dtd_type; - gcc_assert (index <= arg_ctfc->ctfc_types->elements ()); - - uint32_t ctf_kind, btf_kind; - - ctf_kind = CTF_V2_INFO_KIND (ctftype->dtd_data.ctti_info); - btf_kind = get_btf_kind (ctf_kind); - - if (btf_kind == BTF_KIND_UNKN) - /* This type is not representable in BTF. Create a hole. */ - holes.safe_push (ctftype->dtd_type); - - else if (btf_kind == BTF_KIND_INT && ctftype->dtd_data.ctti_size == 0) - { - /* This is a (redundant) definition of void. */ - voids.safe_push (ctftype->dtd_type); - holes.safe_push (ctftype->dtd_type); - } - - arg_ctfc->ctfc_types_list[index] = ctftype; - - return 1; -} - -/* Preprocessing callback routine for variables. */ - -int -btf_dvd_emit_preprocess_cb (ctf_dvdef_ref *slot, ctf_container_ref arg_ctfc) -{ - ctf_dvdef_ref var = (ctf_dvdef_ref) * slot; - - /* If this is an extern variable declaration with a defining declaration - later, skip it so that only the defining declaration is emitted. - This is the same case, fix and reasoning as in CTF; see PR105089. */ - if (ctf_dvd_ignore_lookup (arg_ctfc, var->dvd_key)) - return 1; - - /* Do not add variables which refer to unsupported types. */ - if (!voids.contains (var->dvd_type->dtd_type) - && btf_removed_type_p (var->dvd_type->dtd_type)) - return 1; - - arg_ctfc->ctfc_vars_list[num_vars_added] = var; - btf_var_ids->put (var, num_vars_added); - - num_vars_added++; - num_types_created++; - - return 1; -} - -/* Preprocessing callback routine for types. */ - -static void -btf_dtd_emit_preprocess_cb (ctf_container_ref ctfc, ctf_dtdef_ref dtd) -{ - if (!btf_emit_id_p (dtd->dtd_type)) - return; - - ctfc->ctfc_num_vlen_bytes += btf_calc_num_vbytes (dtd); -} - -/* Preprocess the CTF information to prepare for BTF output. BTF is almost a - subset of CTF, with many small differences in encoding, and lacking support - for some types (notably floating point formats). - - During the preprocessing pass: - - Ascertain that the sorted list of types has been prepared. For the BTF - generation process, this is taken care of by the btf_init_postprocess (). - - - BTF_KIND_FUNC and BTF_KIND_DATASEC records are constructed. These types do - not have analogues in CTF (the analogous type to CTF_K_FUNCTION is - BTF_KIND_FUNC_PROTO), but can be relatively easily deduced from CTF - information. - - - Construct BTF_KIND_VAR records, representing variables. - - - Calculate the total size in bytes of variable-length information following - BTF type records. This is used for outputting the BTF header. - - After preprocessing, all BTF information is ready to be output: - - ctfc->ctfc_types_list holdstypes converted from CTF types. This does not - include KIND_VAR, KIND_FUNC, nor KIND_DATASEC types. These types have been - re-encoded to the appropriate representation in BTF. - - ctfc->ctfc_vars_list holds all variables which should be output. - Variables of unsupported types are not present in this list. - - Vector 'funcs' holds all BTF_KIND_FUNC types, one to match each - BTF_KIND_FUNC_PROTO. - - Vector 'datasecs' holds all BTF_KIND_DATASEC types. */ - -static void -btf_emit_preprocess (ctf_container_ref ctfc) -{ - size_t num_ctf_types = ctfc->ctfc_types->elements (); - size_t num_ctf_vars = ctfc->ctfc_vars->elements (); - size_t i; - - if (num_ctf_types) - { - gcc_assert (ctfc->ctfc_types_list); - /* Preprocess the types. */ - for (i = 1; i <= num_ctf_types; i++) - btf_dtd_emit_preprocess_cb (ctfc, ctfc->ctfc_types_list[i]); - } - - btf_var_ids = hash_map::create_ggc (100); - - if (num_ctf_vars) - { - /* Allocate and construct the list of variables. While BTF variables are - not distinct from types (in that variables are simply types with - BTF_KIND_VAR), it is simpler to maintain a separate list of variables - and append them to the types list during output. */ - ctfc->ctfc_vars_list = ggc_vec_alloc(num_ctf_vars); - ctfc->ctfc_vars->traverse - (ctfc); - - ctfc->ctfc_num_vlen_bytes += (num_vars_added * sizeof (struct btf_var)); - } - - btf_collect_datasec (ctfc); -} - /* Return true iff DMD is a member description of a bit-field which can be validly represented in BTF. */ static bool -btf_dmd_representable_bitfield_p (ctf_container_ref ctfc, ctf_dmdef_t *dmd) +btf_dmd_representable_bitfield_p (ctf_dmdef_t *dmd) { - ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type->dtd_type]; + ctf_dtdef_ref ref_type = dmd->dmd_type; + if (!ref_type) + return false; if (CTF_V2_INFO_KIND (ref_type->dtd_data.ctti_info) == CTF_K_SLICE) { @@ -734,76 +332,34 @@ btf_dmd_representable_bitfield_p (ctf_container_ref ctfc, ctf_dmdef_t *dmd) /* Asm'out a reference to another BTF type. */ static void -btf_asm_type_ref (const char *prefix, ctf_container_ref ctfc, ctf_id_t ctf_id) +btf_asm_type_ref (const char *prefix, ctf_dtdef_ref dtd) { - ctf_id_t btf_id = get_btf_id (ctf_id); - if (btf_id == BTF_VOID_TYPEID || btf_id == BTF_INVALID_TYPEID) - { - /* There is no explicit void type. - Also handle any invalid refs that made it this far, just in case. */ - dw2_asm_output_data (4, btf_id, "%s: void", prefix); - } + if (!dtd || !btf_emit_type_p (dtd)) + dw2_asm_output_data (4, BTF_VOID_TYPEID, "%s: void", prefix); else { - gcc_assert (btf_id <= num_types_added); - - /* Ref to a standard type in the types list. Note: take care that we - must index the type list by the original CTF id, not the BTF id. */ - ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[ctf_id]; - uint32_t ref_kind - = get_btf_kind (CTF_V2_INFO_KIND (ref_type->dtd_data.ctti_info)); - - const char *kind_name = btf_fwd_to_enum_p (ref_type) - ? btf_kind_name (BTF_KIND_ENUM) - : btf_kind_name (ref_kind); - - dw2_asm_output_data (4, btf_id, "%s: (BTF_KIND_%s '%s')", - prefix, kind_name, - get_btf_type_name (ref_type)); - } -} - -/* Asm'out a reference to a BTF_KIND_VAR or BTF_KIND_FUNC type. These type - kinds are BTF-specific, and should only be referred to by entries in - BTF_KIND_DATASEC records. */ - -static void -btf_asm_datasec_type_ref (const char *prefix, ctf_container_ref ctfc, - ctf_id_t btf_id) -{ - if (btf_id >= num_types_added + 1 - && btf_id < num_types_added + num_vars_added + 1) - { - /* Ref to a variable. Should only appear in DATASEC entries. */ - ctf_id_t var_id = btf_relative_var_id (btf_id); - ctf_dvdef_ref dvd = ctfc->ctfc_vars_list[var_id]; - dw2_asm_output_data (4, btf_id, "%s: (BTF_KIND_VAR '%s')", - prefix, dvd->dvd_name); - - } - else if (btf_id >= num_types_added + num_vars_added + 1) - { - /* Ref to a FUNC record. */ - size_t func_id = btf_relative_func_id (btf_id); - ctf_dtdef_ref ref_type = (*funcs)[func_id]; - dw2_asm_output_data (4, btf_id, "%s: (BTF_KIND_FUNC '%s')", - prefix, get_btf_type_name (ref_type)); + uint32_t kind = btf_dtd_kind (dtd); + if (btf_fwd_to_enum_p (dtd)) + kind = BTF_KIND_ENUM; + else if (kind == BTF_KIND_FUNC_PROTO && dtd->dtd_type > max_translated_id) + kind = BTF_KIND_FUNC; + + dw2_asm_output_data (4, dtd->dtd_type, "%s: (BTF_KIND_%s '%s')", + prefix, btf_kind_name (kind), + get_btf_type_name (dtd)); } - else - /* The caller should not be calling this. */ - gcc_unreachable (); } /* Asm'out a BTF type. This routine is responsible for the bulk of the task of converting CTF types to their BTF representation. */ static void -btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) +btf_asm_type (ctf_dtdef_ref dtd) { uint32_t btf_kind, btf_kflag, btf_vlen, btf_size; uint32_t ctf_info = dtd->dtd_data.ctti_info; - btf_kind = get_btf_kind (CTF_V2_INFO_KIND (ctf_info)); + btf_kind = btf_dtd_kind (dtd); btf_size = dtd->dtd_data.ctti_size; btf_vlen = CTF_V2_INFO_VLEN (ctf_info); @@ -822,17 +378,17 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) if (btf_kind == BTF_KIND_STRUCT || btf_kind == BTF_KIND_UNION) { - /* If a struct/union has ANY bitfield members, set kflag=1. - Note that we must also change the encoding of every member to encode - both member bitfield size (stealing most-significant 8 bits) and bit - offset (LS 24 bits). This is done during preprocessing. */ + /* If a struct/union has ANY bitfield members, set kflag=1. */ ctf_dmdef_t *dmd; for (dmd = dtd->dtd_u.dtu_members; dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd)) { /* Set kflag if this member is a representable bitfield. */ - if (btf_dmd_representable_bitfield_p (ctfc, dmd)) - btf_kflag = 1; + if (btf_dmd_representable_bitfield_p (dmd)) + { + btf_kflag = 1; + break; + } } } @@ -866,7 +422,7 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) : BTF_KF_ENUM_SIGNED; if (dtd->dtd_data.ctti_size == 0x8) btf_kind = BTF_KIND_ENUM64; - } + } /* PR debug/112656. BTF_KIND_FUNC_PROTO is always anonymous. */ else if (btf_kind == BTF_KIND_FUNC_PROTO) @@ -874,7 +430,7 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) dw2_asm_output_data (4, dtd->dtd_data.ctti_name, "TYPE %" PRIu64 " BTF_KIND_%s '%s'", - get_btf_id (dtd->dtd_type), btf_kind_name (btf_kind), + dtd->dtd_type, btf_kind_name (btf_kind), get_btf_type_name (dtd)); dw2_asm_output_data (4, BTF_TYPE_INFO (btf_kind, btf_kflag, btf_vlen), "btt_info: kind=%u, kflag=%u, vlen=%u", @@ -900,30 +456,29 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) break; } - ctf_id_t ref_id = dtd->dtd_data.ctti_type; - btf_asm_type_ref ("btt_type", ctfc, ref_id); + btf_asm_type_ref ("btt_type", dtd->ref_type); } /* Asm'out the variable information following a BTF_KIND_ARRAY. */ static void -btf_asm_array (ctf_container_ref ctfc, ctf_arinfo_t arr) +btf_asm_array (ctf_arinfo_t arr) { - btf_asm_type_ref ("bta_elem_type", ctfc, arr.ctr_contents->dtd_type); - btf_asm_type_ref ("bta_index_type", ctfc, arr.ctr_index->dtd_type); + btf_asm_type_ref ("bta_elem_type", arr.ctr_contents); + btf_asm_type_ref ("bta_index_type", arr.ctr_index); dw2_asm_output_data (4, arr.ctr_nelems, "bta_nelems"); } /* Asm'out a BTF_KIND_VAR. */ static void -btf_asm_varent (ctf_container_ref ctfc, ctf_dvdef_ref var) +btf_asm_varent (ctf_dvdef_ref var) { - dw2_asm_output_data (4, var->dvd_name_offset, "TYPE %u BTF_KIND_VAR '%s'", - (*(btf_var_ids->get (var)) + num_types_added + 1), - var->dvd_name); + dw2_asm_output_data (4, var->dvd_name_offset, + "TYPE %" PRIu64 " BTF_KIND_VAR '%s'", + var->dvd_id, var->dvd_name); dw2_asm_output_data (4, BTF_TYPE_INFO (BTF_KIND_VAR, 0, 0), "btv_info"); - btf_asm_type_ref ("btv_type", ctfc, var->dvd_type->dtd_type); + btf_asm_type_ref ("btv_type", var->dvd_type); dw2_asm_output_data (4, var->dvd_visibility, "btv_linkage"); } @@ -931,23 +486,22 @@ btf_asm_varent (ctf_container_ref ctfc, ctf_dvdef_ref var) BTF_KIND_UNION. */ static void -btf_asm_sou_member (ctf_container_ref ctfc, ctf_dmdef_t * dmd, unsigned int idx) +btf_asm_sou_member (ctf_dmdef_t * dmd, unsigned int idx) { - ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type->dtd_type]; - ctf_id_t base_type = dmd->dmd_type->dtd_type; + ctf_dtdef_ref base_type = dmd->dmd_type; uint64_t sou_offset = dmd->dmd_offset; dw2_asm_output_data (4, dmd->dmd_name_offset, "MEMBER '%s' idx=%u", dmd->dmd_name, idx); - /* Re-encode bitfields to BTF representation. */ - if (CTF_V2_INFO_KIND (ref_type->dtd_data.ctti_info) == CTF_K_SLICE) + if (base_type + && CTF_V2_INFO_KIND (base_type->dtd_data.ctti_info) == CTF_K_SLICE) { - if (btf_dmd_representable_bitfield_p (ctfc, dmd)) + if (btf_dmd_representable_bitfield_p (dmd)) { - unsigned short word_offset = ref_type->dtd_u.dtu_slice.cts_offset; - unsigned short bits = ref_type->dtd_u.dtu_slice.cts_bits; + unsigned short word_offset = base_type->dtd_u.dtu_slice.cts_offset; + unsigned short bits = base_type->dtd_u.dtu_slice.cts_bits; /* Pack the bit offset and bitfield size together. */ sou_offset += word_offset; @@ -955,17 +509,17 @@ btf_asm_sou_member (ctf_container_ref ctfc, ctf_dmdef_t * dmd, unsigned int idx) sou_offset |= ((bits & 0xff) << 24); /* Refer to the base type of the slice. */ - base_type = ref_type->dtd_u.dtu_slice.cts_type->dtd_type; + base_type = base_type->dtd_u.dtu_slice.cts_type; } else { /* Bitfield cannot be represented in BTF. Emit the member as having 'void' type. */ - base_type = BTF_VOID_TYPEID; + base_type = NULL; } } - btf_asm_type_ref ("btm_type", ctfc, base_type); + btf_asm_type_ref ("btm_type", base_type); dw2_asm_output_data (4, sou_offset, "btm_offset"); } @@ -988,86 +542,68 @@ btf_asm_enum_const (unsigned int size, ctf_dmdef_t * dmd, unsigned int idx) /* Asm'out a function parameter description following a BTF_KIND_FUNC_PROTO. */ static void -btf_asm_func_arg (ctf_container_ref ctfc, ctf_func_arg_t * farg, - size_t stroffset) +btf_asm_func_arg (ctf_func_arg_t * farg, size_t stroffset) { /* If the function arg does not have a name, refer to the null string at the start of the string table. This ensures correct encoding for varargs '...' arguments. */ if ((farg->farg_name != NULL) && strcmp (farg->farg_name, "")) - dw2_asm_output_data (4, farg->farg_name_offset + stroffset, "farg_name"); + dw2_asm_output_data (4, farg->farg_name_offset + stroffset, + "farg_name '%s'", farg->farg_name); else - dw2_asm_output_data (4, 0, "farg_name"); - - ctf_id_t ref_id = BTF_VOID_TYPEID; - if (farg->farg_type && !btf_removed_type_p (farg->farg_type->dtd_type)) - ref_id = farg->farg_type->dtd_type; + dw2_asm_output_data (4, 0, "farg_name ''"); - btf_asm_type_ref ("farg_type", ctfc, ref_id); + btf_asm_type_ref ("farg_type", farg->farg_type); } /* Asm'out a BTF_KIND_FUNC type. */ static void -btf_asm_func_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, ctf_id_t id) +btf_asm_func_type (ctf_dtdef_ref dtd) { - ctf_id_t ref_id = dtd->dtd_data.ctti_type; dw2_asm_output_data (4, dtd->dtd_data.ctti_name, "TYPE %" PRIu64 " BTF_KIND_FUNC '%s'", - btf_absolute_func_id (id), get_btf_type_name (dtd)); + dtd->dtd_type, get_btf_type_name (dtd)); dw2_asm_output_data (4, BTF_TYPE_INFO (BTF_KIND_FUNC, 0, dtd->linkage), "btt_info: kind=%u, kflag=%u, linkage=%u", BTF_KIND_FUNC, 0, dtd->linkage); - btf_asm_type_ref ("btt_type", ctfc, ref_id); + btf_asm_type_ref ("btt_type", dtd->ref_type); } -/* Collect the name for the DATASEC reference required to be output as a - symbol. */ +/* Asm'out a variable entry following a BTF_KIND_DATASEC. */ -static const char * -get_name_for_datasec_entry (ctf_container_ref ctfc, ctf_id_t ref_id) +static void +btf_asm_datasec_entry (struct btf_datasec_entry entry) { - if (ref_id >= num_types_added + 1 - && ref_id < num_types_added + num_vars_added + 1) + const char *symbol_name = NULL; + if (entry.is_var) { - /* Ref to a variable. Should only appear in DATASEC entries. */ - ctf_id_t var_id = btf_relative_var_id (ref_id); - ctf_dvdef_ref dvd = ctfc->ctfc_vars_list[var_id]; - return dvd->dvd_name; + symbol_name = entry.dvd->dvd_name; + dw2_asm_output_data (4, entry.dvd->dvd_id, + "bts_type: (BTF_KIND_VAR '%s')", symbol_name); } - else if (ref_id >= num_types_added + num_vars_added + 1) + else { - /* Ref to a FUNC record. */ - size_t func_id = btf_relative_func_id (ref_id); - ctf_dtdef_ref ref_type = (*funcs)[func_id]; - return get_btf_type_name (ref_type); + symbol_name = entry.dtd->dtd_name; + btf_asm_type_ref ("bts_type", entry.dtd); } - return NULL; -} - -/* Asm'out a variable entry following a BTF_KIND_DATASEC. */ -static void -btf_asm_datasec_entry (ctf_container_ref ctfc, struct btf_var_secinfo info) -{ - const char *symbol_name = get_name_for_datasec_entry (ctfc, info.type); - btf_asm_datasec_type_ref ("bts_type", ctfc, info.type); if (!btf_with_core_debuginfo_p () || symbol_name == NULL) - dw2_asm_output_data (4, info.offset, "bts_offset"); + dw2_asm_output_data (4, 0, "bts_offset"); else dw2_asm_output_offset (4, symbol_name, NULL, "bts_offset"); - dw2_asm_output_data (4, info.size, "bts_size"); + + dw2_asm_output_data (4, entry.size, "bts_size"); } /* Asm'out a whole BTF_KIND_DATASEC, including its variable entries. */ static void -btf_asm_datasec_type (ctf_container_ref ctfc, btf_datasec_t ds, ctf_id_t id, - size_t stroffset) +btf_asm_datasec_type (btf_datasec_t ds) { - dw2_asm_output_data (4, ds.name_offset + stroffset, + dw2_asm_output_data (4, ds.name_offset, "TYPE %" PRIu64 " BTF_KIND_DATASEC '%s'", - btf_absolute_datasec_id (id), ds.name); + ds.id, ds.name); dw2_asm_output_data (4, BTF_TYPE_INFO (BTF_KIND_DATASEC, 0, ds.entries.length ()), "btt_info: n_entries=%u", ds.entries.length ()); @@ -1075,7 +611,7 @@ btf_asm_datasec_type (ctf_container_ref ctfc, btf_datasec_t ds, ctf_id_t id, loaders such as libbpf. */ dw2_asm_output_data (4, 0, "btt_size"); for (size_t i = 0; i < ds.entries.length (); i++) - btf_asm_datasec_entry (ctfc, ds.entries[i]); + btf_asm_datasec_entry (ds.entries[i]); } /* Compute and output the header information for a .BTF section. */ @@ -1094,20 +630,11 @@ output_btf_header (ctf_container_ref ctfc) uint32_t type_off = 0, type_len = 0; uint32_t str_off = 0, str_len = 0; - uint32_t datasec_vlen_bytes = 0; if (!ctfc_is_empty_container (ctfc)) { - for (size_t i = 0; i < datasecs.length (); i++) - { - datasec_vlen_bytes += ((datasecs[i].entries.length ()) - * sizeof (struct btf_var_secinfo)); - } - /* Total length (bytes) of the types section. */ - type_len = (num_types_added * sizeof (struct btf_type)) - + (num_types_created * sizeof (struct btf_type)) - + datasec_vlen_bytes + type_len = ctfc->ctfc_num_types * sizeof (struct btf_type) + ctfc->ctfc_num_vlen_bytes; str_off = type_off + type_len; @@ -1119,7 +646,9 @@ output_btf_header (ctf_container_ref ctfc) /* Offset of type section. */ dw2_asm_output_data (4, type_off, "type_off"); /* Length of type section in bytes. */ - dw2_asm_output_data (4, type_len, "type_len"); + dw2_asm_output_data (4, type_len, "type_len: ntypes=%u, vlen=%u", + (uint32_t) ctfc->ctfc_num_types, + (uint32_t) ctfc->ctfc_num_vlen_bytes); /* Offset of string section. */ dw2_asm_output_data (4, str_off, "str_off"); /* Length of string section in bytes. */ @@ -1132,11 +661,11 @@ static void output_btf_vars (ctf_container_ref ctfc) { size_t i; - size_t num_ctf_vars = num_vars_added; + size_t num_ctf_vars = ctfc->ctfc_vars_list_count; if (num_ctf_vars) { for (i = 0; i < num_ctf_vars; i++) - btf_asm_varent (ctfc, ctfc->ctfc_vars_list[i]); + btf_asm_varent (ctfc->ctfc_vars_list[i]); } } @@ -1151,7 +680,8 @@ output_btf_strs (ctf_container_ref ctfc) while (ctf_string) { - dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_string, str_pos = 0x%x", str_pos); + dw2_asm_output_nstring (ctf_string->cts_str, -1, + "btf_string, str_pos = 0x%x", str_pos); str_pos += strlen(ctf_string->cts_str) + 1; ctf_string = ctf_string->cts_next; } @@ -1159,7 +689,8 @@ output_btf_strs (ctf_container_ref ctfc) ctf_string = ctfc->ctfc_aux_strtable.ctstab_head; while (ctf_string) { - dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_aux_string, str_pos = 0x%x", str_pos); + dw2_asm_output_nstring (ctf_string->cts_str, -1, + "btf_aux_string, str_pos = 0x%x", str_pos); str_pos += strlen(ctf_string->cts_str) + 1; ctf_string = ctf_string->cts_next; } @@ -1169,7 +700,7 @@ output_btf_strs (ctf_container_ref ctfc) BTF_KIND_UNION type. */ static void -output_asm_btf_sou_fields (ctf_container_ref ctfc, ctf_dtdef_ref dtd) +output_asm_btf_sou_fields (ctf_dtdef_ref dtd) { ctf_dmdef_t * dmd; @@ -1177,7 +708,7 @@ output_asm_btf_sou_fields (ctf_container_ref ctfc, ctf_dtdef_ref dtd) for (dmd = dtd->dtd_u.dtu_members; dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd)) { - btf_asm_sou_member (ctfc, dmd, idx); + btf_asm_sou_member (dmd, idx); idx++; } } @@ -1185,8 +716,7 @@ output_asm_btf_sou_fields (ctf_container_ref ctfc, ctf_dtdef_ref dtd) /* Output all enumerator constants following a BTF_KIND_ENUM{,64}. */ static void -output_asm_btf_enum_list (ctf_container_ref ARG_UNUSED (ctfc), - ctf_dtdef_ref dtd) +output_asm_btf_enum_list (ctf_dtdef_ref dtd) { ctf_dmdef_t * dmd; @@ -1209,7 +739,7 @@ output_asm_btf_func_args_list (ctf_container_ref ctfc, ctf_func_arg_t * farg; for (farg = dtd->dtd_u.dtu_argv; farg != NULL; farg = (ctf_func_arg_t *) ctf_farg_list_next (farg)) - btf_asm_func_arg (ctfc, farg, farg_name_offset); + btf_asm_func_arg (farg, farg_name_offset); } /* Output the variable portion of a BTF type record. The information depends @@ -1220,7 +750,7 @@ output_asm_btf_vlen_bytes (ctf_container_ref ctfc, ctf_dtdef_ref dtd) { uint32_t btf_kind, encoding; - btf_kind = get_btf_kind (CTF_V2_INFO_KIND (dtd->dtd_data.ctti_info)); + btf_kind = btf_dtd_kind (dtd); if (btf_kind == BTF_KIND_UNKN) return; @@ -1233,8 +763,7 @@ output_asm_btf_vlen_bytes (ctf_container_ref ctfc, ctf_dtdef_ref dtd) if (dtd->dtd_data.ctti_size < 1) break; - /* In BTF the CHAR `encoding' seems to not be used, so clear it - here. */ + /* In BTF the CHAR `encoding' seems to not be used, so clear it here. */ dtd->dtd_u.dtu_enc.cte_format &= ~BTF_INT_CHAR; encoding = BTF_INT_DATA (dtd->dtd_u.dtu_enc.cte_format, @@ -1245,16 +774,16 @@ output_asm_btf_vlen_bytes (ctf_container_ref ctfc, ctf_dtdef_ref dtd) break; case BTF_KIND_ARRAY: - btf_asm_array (ctfc, dtd->dtd_u.dtu_arr); + btf_asm_array (dtd->dtd_u.dtu_arr); break; case BTF_KIND_STRUCT: case BTF_KIND_UNION: - output_asm_btf_sou_fields (ctfc, dtd); + output_asm_btf_sou_fields (dtd); break; case BTF_KIND_ENUM: - output_asm_btf_enum_list (ctfc, dtd); + output_asm_btf_enum_list (dtd); break; case BTF_KIND_FUNC_PROTO: @@ -1284,9 +813,9 @@ output_asm_btf_vlen_bytes (ctf_container_ref ctfc, ctf_dtdef_ref dtd) static void output_asm_btf_type (ctf_container_ref ctfc, ctf_dtdef_ref type) { - if (btf_emit_id_p (type->dtd_type)) + if (btf_emit_type_p (type)) { - btf_asm_type (ctfc, type); + btf_asm_type (type); output_asm_btf_vlen_bytes (ctfc, type); } } @@ -1298,7 +827,9 @@ static void output_btf_types (ctf_container_ref ctfc) { size_t i; - size_t num_types = ctfc->ctfc_types->elements (); + size_t num_types; + num_types = ctfc->ctfc_types->elements (); + if (num_types) { for (i = 1; i <= num_types; i++) @@ -1309,76 +840,45 @@ output_btf_types (ctf_container_ref ctfc) /* Output all BTF_KIND_FUNC type records. */ static void -output_btf_func_types (ctf_container_ref ctfc) +output_btf_func_types (void) { ctf_dtdef_ref ref; unsigned i; FOR_EACH_VEC_ELT (*funcs, i, ref) - btf_asm_func_type (ctfc, ref, i); + btf_asm_func_type (ref); } /* Output all BTF_KIND_DATASEC records. */ static void -output_btf_datasec_types (ctf_container_ref ctfc) +output_btf_datasec_types (void) { - size_t name_offset = ctfc_get_strtab_len (ctfc, CTF_STRTAB); - - for (size_t i = 0; i < datasecs.length(); i++) - btf_asm_datasec_type (ctfc, datasecs[i], i, name_offset); + for (size_t i = 0; i < datasecs.length (); i++) + btf_asm_datasec_type (datasecs[i]); } -/* Postprocess the CTF debug data post initialization. - - During the postprocess pass: - - - Prepare the sorted list of BTF types. - - The sorted list of BTF types is, firstly, used for lookup (during the BTF - generation process) of CTF/BTF types given a typeID. - - Secondly, in the emitted BTF section, BTF Types need to be in the sorted - order of their type IDs. The BTF types section is viewed as an array, - with type IDs used to index into that array. It is essential that every - type be placed at the exact index corresponding to its ID, or else - references to that type from other types will no longer be correct. - - - References to void types are converted to reference BTF_VOID_TYPEID. In - CTF, a distinct type is used to encode void. - - - Bitfield struct/union members are converted to BTF encoding. CTF uses - slices to encode bitfields, but BTF does not have slices and encodes - bitfield information directly in the variable-length btf_member - descriptions following the struct or union type. - - - Unrepresentable types are removed. We cannot have any invalid BTF types - appearing in the output so they must be removed, and type ids of other - types and references adjust accordingly. This also involves ensuring that - BTF descriptions of struct members referring to unrepresentable types are - not emitted, as they would be nonsensical. - - - Adjust inner- and inter-type references-by-ID to account for removed - types, and construct the types list. */ +/* Write out all BTF debug info. */ void -btf_init_postprocess (void) +btf_output (ctf_container_ref ctfc) { - ctf_container_ref tu_ctfc = ctf_get_tu_ctfc (); - - holes.create (0); - voids.create (0); + output_btf_header (ctfc); + output_btf_types (ctfc); + output_btf_vars (ctfc); + output_btf_func_types (); + output_btf_datasec_types (); + output_btf_strs (ctfc); +} - num_types_added = 0; - num_types_created = 0; +/* Workaround for 'const void' variables. These variables are sometimes used + in eBPF programs to address kernel symbols. DWARF does not generate const + qualifier on void type, so we would incorrectly emit these variables + without the const qualifier. Find any such variables, and update them to + refer to a new 'const' modifier type for void. */ - /* Workaround for 'const void' variables. These variables are sometimes used - in eBPF programs to address kernel symbols. DWARF does not generate const - qualifier on void type, so we would incorrectly emit these variables - without the const qualifier. - Unfortunately we need the TREE node to know it was const, and we need - to create the const modifier type (if needed) now, before making the types - list. So we can't avoid iterating with FOR_EACH_VARIABLE here, and then - again when creating the DATASEC entries. */ +static void +btf_add_const_void (ctf_container_ref ctfc) +{ ctf_dtdef_ref constvoid_dtd = NULL; varpool_node *var; FOR_EACH_VARIABLE (var) @@ -1393,120 +893,392 @@ btf_init_postprocess (void) if (die == NULL) continue; - ctf_dvdef_ref dvd = ctf_dvd_lookup (tu_ctfc, die); + ctf_dvdef_ref dvd = ctf_dvd_lookup (ctfc, die); if (dvd == NULL) continue; /* Create the 'const' modifier type for void. */ if (constvoid_dtd == NULL) - constvoid_dtd = ctf_add_reftype (tu_ctfc, CTF_ADD_ROOT, + constvoid_dtd = ctf_add_reftype (ctfc, CTF_ADD_ROOT, dvd->dvd_type, CTF_K_CONST, NULL); dvd->dvd_type = constvoid_dtd; } } +} - size_t i; - size_t num_ctf_types = tu_ctfc->ctfc_types->elements (); +/* Functions actually get two type records: a BTF_KIND_FUNC_PROTO, and also a + BTF_KIND_FUNC. But the CTF container only allocates one type per function, + which matches closely with BTF_KIND_FUNC_PROTO. For each such function, + construct a BTF_KIND_FUNC entry. This is done early, because we want FUNC + records even for functions which are later inlined by optimizations. */ - if (num_ctf_types) +static void +btf_add_func_records (ctf_container_ref ctfc) +{ + cgraph_node *func; + FOR_EACH_FUNCTION (func) { - init_btf_id_map (num_ctf_types + 1); - - /* Allocate the types list and traverse all types, placing each type - at the index according to its ID. Add 1 because type ID 0 always - represents VOID. */ - tu_ctfc->ctfc_types_list - = ggc_vec_alloc(num_ctf_types + 1); - tu_ctfc->ctfc_types->traverse - (tu_ctfc); - - /* Build mapping of CTF type ID -> BTF type ID, and count total number - of valid BTF types added. */ - for (i = 1; i <= num_ctf_types; i++) - { - ctf_dtdef_ref dtd = tu_ctfc->ctfc_types_list[i]; - ctf_id_t btfid = btf_adjust_type_id (dtd->dtd_type); - set_btf_id (dtd->dtd_type, btfid); - if (btfid < BTF_MAX_TYPE && (btfid != BTF_VOID_TYPEID)) - num_types_added ++; - } + dw_die_ref die = lookup_decl_die (func->decl); + if (die == NULL) + continue; + + ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, die); + if (dtd == NULL) + continue; + + /* Do not add FUNC records for kernel helpers. */ + if (DECL_EXTERNAL (func->decl) + && (lookup_attribute ("kernel_helper", + DECL_ATTRIBUTES (func->decl))) != NULL_TREE) + continue; + + ctf_dtdef_ref func_dtd = ggc_cleared_alloc (); + func_dtd->dtd_data = dtd->dtd_data; + func_dtd->dtd_data.ctti_type = dtd->dtd_type; + func_dtd->ref_type = dtd; + func_dtd->linkage = dtd->linkage; + func_dtd->dtd_name = dtd->dtd_name; + /* Type ID will be assigned just before output. */ + + /* Only the BTF_KIND_FUNC type actually references the name. + The BTF_KIND_FUNC_PROTO is always anonymous. */ + dtd->dtd_data.ctti_name = 0; + + /* Mark 'extern' funcs. */ + if (DECL_EXTERNAL (func->decl)) + func_dtd->linkage = BTF_FUNC_EXTERN; + + /* Buffer newly created FUNC records. We cannot simply insert them + into the types map, because types are keyed by their DWARF DIE, + and we have no unique DIE to use as a key since the FUNC_PROTOs + are already present in the map. */ + vec_safe_push (funcs, func_dtd); + func_map->put (dtd, func_dtd); } } -/* Process and output all BTF data. Entry point of btfout. */ +/* 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 + BTF_KIND_FUNC records. */ void -btf_output (const char * filename) +btf_early_finish (void) { ctf_container_ref tu_ctfc = ctf_get_tu_ctfc (); - init_btf_sections (); - - datasecs.create (0); vec_alloc (funcs, 16); + func_map = hash_map::create_ggc (16); - ctf_add_cuname (tu_ctfc, filename); + /* Note: from this point on, destructive changes are made to the TU CTFC to + translate CTF to BTF. If CTF debug info has also been requested, it must + be emitted before starting the translation to BTF. */ + btf_add_const_void (tu_ctfc); + btf_add_func_records (tu_ctfc); +} - btf_emit_preprocess (tu_ctfc); +/* Push a BTF datasec entry ENTRY into the datasec named SECNAME, + creating the datasec record if it does not already exist. */ - output_btf_header (tu_ctfc); - output_btf_types (tu_ctfc); - output_btf_vars (tu_ctfc); - output_btf_func_types (tu_ctfc); - output_btf_datasec_types (tu_ctfc); - output_btf_strs (tu_ctfc); +static void +btf_datasec_push_entry (ctf_container_ref ctfc, const char *secname, + struct btf_datasec_entry entry) +{ + if (secname == NULL) + return; + + /* If we already have a datasec record for the appropriate section, + append the new entry to it. */ + for (size_t i = 0; i < datasecs.length (); i++) + if (strcmp (datasecs[i].name, secname) == 0) + { + datasecs[i].entries.safe_push (entry); + return; + } + + /* If we don't already have a datasec record for secname, make one. */ + uint32_t str_off; + ctf_add_string (ctfc, secname, &str_off, CTF_AUX_STRTAB); + if (strcmp (secname, "")) + ctfc->ctfc_aux_strlen += strlen (secname) + 1; + + /* Note: ID will be assigned just before output. */ + btf_datasec_t ds; + ds.name = secname; + ds.name_offset = str_off; + + /* Insert the entry into the new datasec record. */ + ds.entries.create (1); + ds.entries.quick_push (entry); + + /* Insert the datasec record itself. */ + datasecs.safe_push (ds); } -/* Reset all state for BTF generation so that we can rerun the compiler within - the same process. */ +/* Create a datasec entry for a function, and insert it into the datasec + record for the appropriate section. Create the record if it does not + yet exist. */ -void -btf_finalize (void) +static void +btf_datasec_add_func (ctf_container_ref ctfc, cgraph_node *func, + ctf_dtdef_ref func_dtd) { - btf_info_section = NULL; + const char *section_name = get_section_name (func); - /* Clear preprocessing state. */ - num_vars_added = 0; - num_types_added = 0; - num_types_created = 0; + /* Note: get_section_name () returns NULL for functions in text + section. This is intentional, since we do not want to generate + DATASEC entries for them. */ + if (section_name == NULL) + return; - holes.release (); - voids.release (); - for (size_t i = 0; i < datasecs.length (); i++) - datasecs[i].entries.release (); - datasecs.release (); + struct btf_datasec_entry entry; + gcc_assert (func_dtd); + entry.dtd = func_dtd; + entry.is_var = false; - funcs = NULL; + /* Size is left as zero at compile time, to be filled in by loaders + such as libbpf. */ + entry.size = 0; - btf_var_ids->empty (); - btf_var_ids = NULL; + btf_datasec_push_entry (ctfc, section_name, entry); +} - free (btf_id_map); - btf_id_map = NULL; +/* Create a datasec entry for a variable, and insert it into the datasec + record for the appropriate section. Create the record if it does not + yet exist. */ - ctf_container_ref tu_ctfc = ctf_get_tu_ctfc (); - ctfc_delete_container (tu_ctfc); - tu_ctfc = NULL; +static void +btf_datasec_add_var (ctf_container_ref ctfc, varpool_node *var, + ctf_dvdef_ref dvd) +{ + /* PR112849: avoid assuming a section for extern decls without + an explicit section, which would result in incorrectly + emitting a BTF_KIND_DATASEC entry for them. */ + if (DECL_EXTERNAL (var->decl) && var->get_section () == NULL) + return; + + const char *section_name = get_section_name (var); + if (section_name == NULL) + return; + + gcc_assert (dvd); + struct btf_datasec_entry entry; + entry.dvd = dvd; + entry.is_var = true; + entry.size = 0; + + tree size = DECL_SIZE_UNIT (var->decl); + if (tree_fits_uhwi_p (size)) + entry.size = tree_to_uhwi (size); + else if (VOID_TYPE_P (TREE_TYPE (var->decl))) + entry.size = 1; + + btf_datasec_push_entry (ctfc, section_name, entry); } -/* 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 - BTF_KIND_FUNC records. */ +/* Add datasec entries for functions to CTFC. */ -void -btf_early_finish (void) +static void +btf_add_func_datasec_entries (ctf_container_ref ctfc) +{ + /* We need to create FUNC records at early_finish, so that we have them + even for functions which are later inlined by optimization passes. + But on the other hand, we do not want datasec entries for such functions, + so only create the datasec entries for them late. This loop will not + hit functions which have already been inlined. */ + cgraph_node *func; + FOR_EACH_FUNCTION (func) + { + dw_die_ref die = lookup_decl_die (func->decl); + if (die == NULL) + continue; + + ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, die); + if (dtd == NULL) + continue; + + ctf_dtdef_ref *pdtd = func_map->get (dtd); + if (pdtd && DECL_EXTERNAL (func->decl)) + btf_datasec_add_func (ctfc, func, *pdtd); + } +} + +/* Helper function used to determine whether or not a BTF_KIND_VAR record + for the variable VAR shall be emitted. */ + +static bool +btf_emit_variable_p (ctf_container_ref ctfc, varpool_node *var, + ctf_dvdef_ref *pdvd) +{ + dw_die_ref die = lookup_decl_die (var->decl); + if (die == NULL) + return false; + + ctf_dvdef_ref dvd = ctf_dvd_lookup (ctfc, die); + if (dvd == NULL) + return false; + + /* If this is an extern variable declaration with a defining declaration + later, skip it so that only the defining declaration is emitted. + This is the same case, fix and reasoning as in CTF; see PR105089. */ + if (ctf_dvd_ignore_lookup (ctfc, dvd->dvd_key)) + return false; + + /* Skip variables with unrepresentable types. */ + if (!btf_emit_type_p (dvd->dvd_type)) + return false; + + *pdvd = dvd; + return true; +} + +/* Add BTF_KIND_VAR records for variables. */ + +static void +btf_add_vars (ctf_container_ref ctfc) { - btf_init_postprocess (); + size_t num_ctf_vars = ctfc->ctfc_vars->elements (); + + ctfc->ctfc_vars_list = ggc_vec_alloc(num_ctf_vars); + + varpool_node *var; + ctf_dvdef_ref dvd; + FOR_EACH_VARIABLE (var) + { + if (!btf_emit_variable_p (ctfc, var, &dvd)) + continue; + + /* Mark 'extern' variables. */ + if (DECL_EXTERNAL (var->decl)) + dvd->dvd_visibility = BTF_VAR_GLOBAL_EXTERN; + + /* Add the variable to the vars list. */ + ctfc->ctfc_vars_list[ctfc->ctfc_vars_list_count++] = dvd; + + /* Add a BTF_KIND_DATASEC entry for the variable. */ + btf_datasec_add_var (ctfc, var, dvd); + } +} + +/* Callback used by btf_assign_type_ids to insert types into their initial + positions in the type list. */ + +static int +btf_type_list_cb (ctf_dtdef_ref *slot, ctf_container_ref ctfc) +{ + ctf_dtdef_ref dtd = *slot; + ctfc->ctfc_types_list[dtd->dtd_type] = dtd; + return 1; +} + +/* Construct the initial type list and assign BTF IDs for all types translated + from CTF. */ + +static void +btf_collect_translated_types (ctf_container_ref ctfc) +{ + size_t num_ctf_types = ctfc->ctfc_types->elements (); + + /* First, place each type at its CTF-assigned index in the list. + The '+1' here and below is to account for the implicit void type with + ID 0. There is no real type at index 0 in the list. */ + ctfc->ctfc_types_list = ggc_vec_alloc(num_ctf_types + 1); + ctfc->ctfc_types->traverse (ctfc); + + /* Now, pass through the list and adjust IDs to account for types which will + not be emitted. This results in each type that will be emitted in BTF + being assigned an appropriate ID. Note that types which will not be + emitted remain in the list; they are skipped at output time. */ + unsigned int skip = 0; + for (size_t i = 1; i <= num_ctf_types; i++) + { + ctf_dtdef_ref dtd = ctfc->ctfc_types_list[i]; + if (!btf_emit_type_p (dtd)) + { + dtd->dtd_type = BTF_INVALID_TYPEID; + skip += 1; + continue; + } + + dtd->dtd_type -= skip; + ctfc->ctfc_num_types++; + ctfc->ctfc_num_vlen_bytes += btf_calc_num_vbytes (dtd); + } + + max_translated_id = ctfc->ctfc_num_types; + ctfc->ctfc_nextid = ctfc->ctfc_num_types + 1; +} + +/* Assign BTF IDs for FUNC records and account for their size. */ + +static void +btf_assign_func_ids (ctf_container_ref ctfc) +{ + ctf_dtdef_ref dtd; + unsigned int i; + FOR_EACH_VEC_ELT (*funcs, i, dtd) + { + dtd->dtd_type = ctfc->ctfc_nextid++; + ctfc->ctfc_num_types++; + } +} + +/* Assign BTF IDs for variables and account for their size. */ + +static void +btf_assign_var_ids (ctf_container_ref ctfc) +{ + for (size_t i = 0; i < ctfc->ctfc_vars_list_count; i++) + { + ctf_dvdef_ref dvd = ctfc->ctfc_vars_list[i]; + ctf_id_t id = ctfc->ctfc_nextid++; + gcc_assert (id <= BTF_MAX_TYPE); + dvd->dvd_id = id; + + ctfc->ctfc_num_types++; + ctfc->ctfc_num_vlen_bytes += sizeof (struct btf_var); + } +} + +/* Assign BTF IDs for datasec records and account for their size. */ + +static void +btf_assign_datasec_ids (ctf_container_ref ctfc) +{ + for (size_t i = 0; i < datasecs.length (); i++) + { + datasecs[i].id = ctfc->ctfc_nextid++; + datasecs[i].name_offset += ctfc_get_strtab_len (ctfc, CTF_STRTAB); + ctfc->ctfc_num_types++; + ctfc->ctfc_num_vlen_bytes += (datasecs[i].entries.length () + * sizeof (struct btf_var_secinfo)); + } } /* Late entry point for BTF generation, called from dwarf2out_finish (). Complete and emit BTF information. */ void -btf_finish (const char * filename) +btf_finish (void) { - btf_output (filename); + ctf_container_ref tu_ctfc = ctf_get_tu_ctfc (); + init_btf_sections (); + + datasecs.create (0); + + tu_ctfc->ctfc_num_types = 0; + tu_ctfc->ctfc_num_vlen_bytes = 0; + tu_ctfc->ctfc_vars_list_count = 0; + + btf_add_vars (tu_ctfc); + btf_collect_translated_types (tu_ctfc); + btf_add_func_datasec_entries (tu_ctfc); + btf_assign_var_ids (tu_ctfc); + btf_assign_func_ids (tu_ctfc); + btf_assign_datasec_ids (tu_ctfc); + + /* Finally, write out the complete .BTF section. */ + btf_output (tu_ctfc); /* If compiling for BPF with CO-RE info, we cannot deallocate until after the contents of the .BTF.ext section are finalized, which happens very late in @@ -1516,6 +1288,27 @@ btf_finish (const char * filename) btf_finalize (); } +/* Reset all state for BTF generation so that we can rerun the compiler within + the same process. */ + +void +btf_finalize (void) +{ + btf_info_section = NULL; + max_translated_id = 0; + + for (size_t i = 0; i < datasecs.length (); i++) + datasecs[i].entries.release (); + datasecs.release (); + + funcs = NULL; + func_map->empty (); + func_map = NULL; + + ctf_container_ref tu_ctfc = ctf_get_tu_ctfc (); + ctfc_delete_container (tu_ctfc); + tu_ctfc = NULL; +} /* Traversal function for all BTF_KIND_FUNC type records. */ diff --git a/gcc/ctfc.h b/gcc/ctfc.h index b2060eaf7e9b..d0b724817a7f 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -164,10 +164,14 @@ struct GTY ((for_user)) ctf_dtdef ctf_id_t dtd_type; /* Type identifier for this definition. */ ctf_dtdef_ref ref_type; /* Type referred to by this type (if any). */ ctf_itype_t dtd_data; /* Type node. */ - bool from_global_func; /* Whether this type was added from a global - function. */ uint32_t linkage; /* Used in function types. 0=local, 1=global. */ - bool dtd_enum_unsigned; /* Enum signedness. */ + + /* Whether this type was added from a global function. */ + BOOL_BITFIELD from_global_func : 1; + /* Enum signedness. */ + BOOL_BITFIELD dtd_enum_unsigned : 1; + /* Lots of spare bits. */ + union GTY ((desc ("ctf_dtu_d_union_selector (&%1)"))) { /* struct, union, or enum. */ @@ -194,6 +198,7 @@ struct GTY ((for_user)) ctf_dvdef uint32_t dvd_name_offset; /* Offset of the name in str table. */ unsigned int dvd_visibility; /* External visibility. 0=static,1=global. */ ctf_dtdef_ref dvd_type; /* Type of variable. */ + ctf_id_t dvd_id; /* ID of this variable. Only used for BTF. */ }; typedef struct ctf_dvdef ctf_dvdef_t; @@ -388,7 +393,7 @@ extern void ctf_output (const char * filename); extern void ctf_finalize (void); extern void btf_early_finish (void); -extern void btf_finish (const char * filename); +extern void btf_finish (void); extern void btf_finalize (void); extern ctf_container_ref ctf_get_tu_ctfc (void); @@ -443,7 +448,9 @@ extern int 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); -extern ctf_id_t get_btf_id (ctf_id_t); + +/* Callback and traversal function for BTF_KIND_FUNC records. Used by BPF + target for BPF CO-RE implementation. */ typedef bool (*funcs_traverse_callback) (ctf_dtdef_ref, void *); bool traverse_btf_func_types (funcs_traverse_callback, void *); diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index 00b876e2fe2c..d948c4da0f4a 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -979,7 +979,7 @@ ctf_debug_early_finish (const char * filename) /* For LTO builds, also emit BTF now. */ if (flag_lto && !in_lto_p) - btf_finish (filename); + btf_finish (); } else /* Otherwise, done with the CTF container. */ @@ -989,12 +989,12 @@ ctf_debug_early_finish (const char * filename) /* Finish CTF/BTF debug info emission. */ void -ctf_debug_finish (const char * filename) +ctf_debug_finish () { /* Emit BTF late, unless this is an LTO build in which case it was already done early. */ if (btf_debuginfo_p () && !flag_lto) - btf_finish (filename); + btf_finish (); } #include "gt-dwarf2ctf.h" diff --git a/gcc/dwarf2ctf.h b/gcc/dwarf2ctf.h index 46184325bae6..f8a181a97625 100644 --- a/gcc/dwarf2ctf.h +++ b/gcc/dwarf2ctf.h @@ -32,7 +32,7 @@ extern void ctf_debug_init (void); extern void ctf_debug_init_postprocess (bool); extern bool ctf_do_die (dw_die_ref); extern void ctf_debug_early_finish (const char *); -extern void ctf_debug_finish (const char *); +extern void ctf_debug_finish (void); /* Wrappers for CTF/BTF to fetch information from GCC DWARF DIE. Used in ctfc.cc. diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index e00735a37895..52d528ebf138 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -32345,7 +32345,7 @@ dwarf2out_finish (const char *filename) /* Generate CTF/BTF debug info. */ if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE || btf_debuginfo_p ()) && lang_GNU_C ()) - ctf_debug_finish (filename); + ctf_debug_finish (); #ifdef CODEVIEW_DEBUGGING_INFO if (codeview_debuginfo_p ()) From patchwork Tue Jun 11 19:01:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1946491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=Tn76LUuM; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=kMsTMlwu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzJ482mrrz20Pb for ; Wed, 12 Jun 2024 05:03:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A0F08386183D for ; Tue, 11 Jun 2024 19:03:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 48290385DDFE for ; Tue, 11 Jun 2024 19:03:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 48290385DDFE 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 48290385DDFE Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132591; cv=pass; b=UggQ0hdd2+21J4ddFFWxiaSV6q01RSvkbPfvvT9rIsxFQ7+Gwv8huDzUR74DfWFBLRkGKIuqMyVGqmpqx2oJFdDaj9cGXWhtk9kvbM6JHfamo6Z/qvWkaQPHFQwHE8jBy/B60Fe7LjCV2z8rwMSQxUNqwkAxGHcSerTQ0tD6GcI= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132591; c=relaxed/simple; bh=xCmjfNqRispBY/heOgAqqZKBerg0Gh9B9WC54TC9LPs=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=h1DS6L8TMXkCthGTxmeF2HoVXy50Ff7MsQRKku/9plt86BxSYxoGxKyZyOa3/PuWzn2h3x+mL33J6S5NTyR6yT772HAShvGQjgqwxOnS1yglEfgT6O16Axdzm9Y/Ed+u00fWvrKaXRFsA/eRe5Czvam4vkqpd+CFznF1NstK/Zo= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45BFpeN4006136 for ; Tue, 11 Jun 2024 19:03:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=EzVuz5QMIEbTp7fh+bIcmlUonroTitR3QKTGK8Ya24U=; b= Tn76LUuMQB4RS1irOK0gBGQFusSfHHqiBaI1xgeKq2dplBV1G2V2sm/3sfrqfsvw jv415KpLkw0b5kZtqgVn2XOPDnj0Kn3p+yFE7NwhoiGliP8MPHzKykkknJFYTbI3 9k2hXoSedwnUSCacQL9HiMjMCVN1ENpMjX2VO8RZs/6T03x85F1rgYvf9gsrDNdp WQhzJpnvJPMxaE82gciiNe11gkb9FUkoUIuZzAsFSUSOsIdftsaiE56NX9ifdW8C 5oE6C0bWA/idigLCMxHT0UV4ur7YBuSNZTJgWyqcJk0U9/BvX4R51nGDBGROdIf2 3zBc/hZ9NZY3fL97iiPJvQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh3p5j1y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:03:03 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45BHj77s027353 for ; Tue, 11 Jun 2024 19:03:02 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2040.outbound.protection.outlook.com [104.47.73.40]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncdtpawn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:03:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BxmDy6TITTMbvzTijf4v3wOda1pQ9HUTDJJGbySPx21h71bdNMnDTPjuW8zYiRPqBaHaTJmYDzE8QUho28iPUZ7rTDPFUiI3gZancV0ePyew4Lne/Gcwys0YGj3qGBCQaGn0MaHphpZuYMYVUoLzfWV6V+1W6obYFsVaqCfZaBDVoMGq6yStz8MjBAwjwFoQ6++S2/0yspYcjwEfFL01qWcnnOHI3yY43JwNV758m53vc/KCjMl9F3keb4CMdhK9v84HYE9OLbZQBmoJ1WetV2iEY7p4YUes3q7pONrgLDB32QcC1YBqd9ZXzTjfIa8dPxAHOucwkcceEP2h90kNeQ== 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=EzVuz5QMIEbTp7fh+bIcmlUonroTitR3QKTGK8Ya24U=; b=OLrzmpEmli/FMBAvXbqEXxzRoiFIopYFKmt1mP70NpHs5IgkYv2zir5pxEWewdSRhPN5htWCmRz+sg4a8KBvIHJlvubwsENmw32zBLO0KyzYVkyhP5xnnDI9hsD0u0VwabkvcNbp1tTui/nnNebyKXEUS0fuRqWTN9hUSa6EW+XQN889dTl4jSo33ATN5pBNByWitmjIRhFUFxdxrONK/++IXxCIyJ5v8oB7KH3A4DaqQa/SsQGC6XrwHjRUnTGzQnQdYxzRwZiQwLkbUyHSDcDRepyFkhZA7N3bg0Fwe+43iPgIU+qutXmkF91r9badL2PV6qDugL0cIIy854KXEg== 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=EzVuz5QMIEbTp7fh+bIcmlUonroTitR3QKTGK8Ya24U=; b=kMsTMlwujH1Gy6nYEHXRLyaXrO9k1yjOVO3W4g7PfdSYT5XkXgqBXYsbOWekUNgyiKlpA+ty/iYYgLOq3w7i1q+daNfqoAZTxltNEy84SDXvRfLJglLLCbbk2pZppyd3mVYuujNyy6ZnmoHJBZgooKKRlvPJcCmnDO7QpY4dJvU= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by CH2PR10MB4134.namprd10.prod.outlook.com (2603:10b6:610:a7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.39; Tue, 11 Jun 2024 19:02:59 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%5]) with mapi id 15.20.7633.036; Tue, 11 Jun 2024 19:02:59 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com, jose.marchesi@oracle.com, cupertino.miranda@oracle.com Subject: [PATCH v4 4/6] btf: add -gprune-btf option Date: Tue, 11 Jun 2024 12:01:43 -0700 Message-ID: <20240611190145.115887-5-david.faust@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240611190145.115887-1-david.faust@oracle.com> References: <20240611190145.115887-1-david.faust@oracle.com> X-ClientProxiedBy: MW4PR03CA0025.namprd03.prod.outlook.com (2603:10b6:303:8f::30) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|CH2PR10MB4134:EE_ X-MS-Office365-Filtering-Correlation-Id: e5bcdcc8-3697-4467-5fae-08dc8a491c6c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230032|1800799016|366008|376006; X-Microsoft-Antispam-Message-Info: 9SamRZtTcJ/NBsxqXwjfvZOWVjOpOekrTPE3uNw3QQ8fBIMLQTbGDMPWFiHy0xrFZedkT4TpCp+n38NLyn9RFo1YkvkdBCLEmIIOkOi+T35uSkhbWjG/M5zOi58ShxpT6Oo2cE4l/bHqrgwWHYFQhJ/cegxi5lTqMOf0W3HLzLNKg23oj11IpBtVCsROKJO1PuZPa7HOqPFjs6Agy/8SbKrKTnivivjhO8BgoueHGZ6HlfJTYCDC/CAhsgDCtULLrIZ2WfiLCHwA32HsqvvIameYWOMVHiNZNBUxmU+9BUYyB+HZhcTq7eQ3wQuIZmT6pzbUMgGDLArkb0JoGbiz5cSYTT05PED80IOJF7yvBGaXHSmQTi1yVp8L/yWbzUgzcvBPDmG1YCPEYksPT1SRGVncvV8NFHNpl86rVCdEzL8q0Q+S8pGAMzg5KR38+9Xe6RSmsjfu49xQD5NikPBFWJ72YTKhx9t5Cawv7FNarNwvnUFajobp2107ra0jcziEYAnXyNXTy7MGPwaGIe8phqJErgyDFHLfbEHZ41r6j+PkXNdrMoypJ757cIOijHy8swH7yTc+hyPQnpvcaWu4U9QF5kpU8t4ZUgHxEwlfa3JSwXrAyn6ICzxXtn175oZzMR2ATtD5Q1Fa/k4d76bWPo7ywe/apyXeSH27kiPSkDGAIwI8UaA1l+dnCpYMlSFeUu303ri6fPxGujs1W5wCTyBzwxzmYTkhTisqVQp0UK3YoaVNePbXbUXLJ6E5OCswdTZzsFkZ+V4aNvQyzv07DPS32NpcYyaW+iKtd+4Nkv+dlzGi9WJH1suxHL2vo8DVWl8WLJJ0+AY8XFm5ICNM1wtdjYMcDsWOdbrOA4iEWHuPAMh0gfi2wvepZuCLSE3Yotn1TCHXHEPOJSoSxcu2JU/t6kxNgWCHI2lbfRMZ/ibCXGmJxZn7fdWcUNfYEVa6OWSBPgVlat2Ss6hK9e9lZ89TuV9wg8TOu8bMs6c5OErWkRpeESwoqHxrM9+r/3GS9Q3zKU65gokaNZdO84fldHf5rwjfQrtyzkrCgYgA+n7ER0FDgblxQTy0QQN8hmuyECmc/SgJ+ErLTsXvj2/L1ckMC2zbqgSDKpDtBLN11jqq7r9G0ysCsl5mEL8RJSbG5CTz2npiaM2vAiW0q/HERTBySHhDoT5rpQ5hGp186wUrqn0JFSe1Xzc98/6zj/uuWslvWYmUtK0fibRHfWt8SnUCv1vzav9kl3Ksfc8uWGo6Hi8nBFkYn3jCYDTEeNjOl8ERkW0TghmoQgi/4v7LfQ== 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:(13230032)(1800799016)(366008)(376006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4FHBfwxLVKz6O1J0Q4i5nY++r7OSOaaeF9fU1GdnIqDeOMvJwGRmma5AHjPDNIi3E3tK1SGMdE/X1MEYfoKvGNB2vlpTgzehOaHw11t39k7FeG51knatMHwdXFr/41XVAN2066InVUBxlf8paeqKIuea3koqlv5Jt7FgVWNRhZxJTGyaOzMDX3MFFtlihRdmfvK9wBkNg+a7zF8jcJAP4CA3gWuHMX9+TdGWxU1x6TrzplElYAMmFqhPDuIOfnMrU6LZV+nUWcqOXYvUXCcOFYVOMxmNYAlo6+c9VvnHIiOGLbEAE1P9ykcJLfGGftUzhL2jLOrX7VVLrQ9LZ48CWNjBq8jh4BsJOO2jegZ6UD4yztPUcYL0vTLULj36IcS3RK7nc9UMicDIyji6An1+6MTYOgmU+/14RnlN8Z2SLwWCg7OcgiSG1u1u+i+cfwRdySqSoyQUYjWri5RuhCHG5P0fYuyI8Vw8RIw8x4C0g5p5CU5vEW5JqtnRdb17r7PVSzB6DcaGriVirtRJO5oQfSSzFmMxdDnQo8AZ/Ep/zgBJKQ3E2WZ7/RhhleZ8LDMJVJ33bcvUgJJtR2pNTBwP7E+ZV4UGoyLdh5/4dY0ujMb16s0reQE23d8dvr2+iJ43TpkJziMIj9GNk+WYX3xmPQOC+EvDkwzISlU3Cz93qdFtUBK5jsk2UHtKzR+a/Sa8W3tr3XwTQ8IMYGfEOMiBzuVvhaYYa26Xpz60Qabba5pzGRSPfEoX5jLphqaVcH4qgEcs7gOOvRh9sCumcOidERWUej/505QB1osfJP+PuamlWVvanQAvOY+PYGL8PNU9653F3Fb58hSUg1/XuO27jSzgAHClWkuECf9jeiGXPNTAxK9mOVnR+/vlSMoEKrqaqoUKEU5nQNQWtZjI8JDf7PhY+sqADZIE8I+kDxpp0AUcNBGbtYYH6mXdAjQiSvreL8X/wjuXAuuJUO5yk1OakXHtb/k/H8BAM+NPCE5b0uEyhyNc0e7PdOnY+BIc2j/w0mJUYNEuzMfz9LyfiJ58d1F3cAg5ycEM5mhpegGftwmS44rKhGVxjrNeAtSWFdfIUC9TkL2TiCNwxvzk4VL9F6njqYISdsJxA0N8e7NBtU0ZVui7WG8CL5AQ7THwIw8CZ/lcfBPCtojf3zSbLSiZxxRf5oOAucjWlf0a42gNvnL3HoSOG3s+J1t3U0s+AIZS5nUobD+hHq+mYFro5t4CxL1OrvM/sc15+paIIt0wt1i1pdVhtwg4mdZlVn9uvl7oBtwJ1VGf1jqFdb8a/EjqULhcGFOhNNoTUd5/oENbzaTtajI6ZZ5xjvOaLGeqCm8xQe3x5LfcZ4eCo2loah8HEnAFvZMQS4y/DyuCgZG7vZvx+1gTc6PzCGdfIISfxZWTNAW1gWGxwRfVHMpj7VJCa9avrzNrLvuNiBvKGFZ1PYI+pKi0cGLOGQyX9/yMxW1ByQS+22DX4LjgpJjJTSIIbbp1fo+ZFwN0fe/PlpcdOi91jHs6hpNb29/20ggRXNLEYruv2TsIE21Qu1HeIN3irYoJpWXkaHJBIKNy2dZ7R/ethSQEw9u8h+KcYhFaaVse4uH8bZN0GOHKaUOj21ONiw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: AH68FvPFzwY+tlHrTfnGM3sRGsdjDKfapJqc1uSi+E8OgRdYaCEpe9Yw2Bdd+urEfa1tvYXUVqR58vsXRAVEp/zaJVw6ASCRzVh++HiRcDSL6iKlWj5vlJmcPNm7Xz4BF5TyaIPOHhf4r9oj2i1mV/53MXXjQvLJ55Mt/mrZE5zGNb2RoX4NbZi3wgBpl3hznBBLpt7yu4O0l9FYeadkuPaF0fzvfxtGnI1eZku9atFgWCZ+mQiErliboXgqxkkgztqVp+6OINqVtmVhid08dOOp0VxjxDft9WHHyE9q8ojEuTJGNqJkQLmAdaNLdkXgIJVUJc8+dXQDrdW4+p6jPKG/D6wRMLQFuJF8V66T38XCptNro6xiYPptfdDep50CCyKdli8zZRdihOZpy3+F1ygwYPuKVDG9odCICNlBq828gsqAajTJkR3IW8gVV9a6jR4pvA4p4jtrqOv9cAF5cA15w9PCe/Ru6ZQLf7EUkfT50BEjIczMVTD+w7LdHCbnblmaxTPA8cgJW1f10Gr9ra8qQaZsWmwCE5Fp/qxiRuEe52Kfb1rXt6oN/qQe2cwcPMow4m3/5y0UfcFn5bRSSAJpt2aU6o4tju0ybi+jCoY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5bcdcc8-3697-4467-5fae-08dc8a491c6c X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 19:02:59.5365 (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: cbdY2yv9OFJglvjC1sXXcnx3lqOzV2kLrQkoZw/0lfkHKRLD+hlWwaSKkTAHXNYtYYP6r7rOW8LfF4KoOEndgA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4134 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-11_09,2024-06-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406110130 X-Proofpoint-GUID: 5h8CxRK8AylYPmJh9mLh1LsvJcOWO4RU X-Proofpoint-ORIG-GUID: 5h8CxRK8AylYPmJh9mLh1LsvJcOWO4RU X-Spam-Status: No, score=-13.7 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch adds a new option, -gprune-btf, to control BTF debug info generation. As the name implies, this option enables a kind of "pruning" of the BTF information before it is emitted. When enabled, rather than emitting all type information translated from DWARF, only information for types directly used in the source program is emitted. The primary purpose of this pruning is to reduce the amount of unnecessary BTF information emitted, especially for BPF programs. It is very common for BPF programs to include Linux kernel internal headers in order to have access to kernel data structures. However, doing so often has the side effect of also adding type definitions for a large number of types which are not actually used by nor relevant to the program. In these cases, -gprune-btf commonly reduces the size of the resulting BTF information by 10x or more, as seen on average when compiling Linux kernel BPF selftests. This both slims down the size of the resulting object and reduces the time required by the BPF loader to verify the program and its BTF information. Note that the pruning implemented in this patch follows the same rules as the BTF pruning performed unconditionally by LLVM's BPF backend when generating BTF. In particular, the main sources of pruning are: 1) Only generate BTF for types used by variables and functions at the file scope. Note that which variables are known to be "used" may differ slightly between LTO and non-LTO builds due to optimizations. For non-LTO builds (and always for the BPF target), variables which are optimized away during compilation are considered to be unused, and they (along with their types) are pruned. For LTO builds, such variables are not known to be optimized away by the time pruning occurs, so VAR records for them and information for their types may be present in the emitted BTF information. This is a missed optimization that may be fixed in the future. 2) Avoid emitting full BTF for struct and union types which are only pointed-to by members of other struct/union types. In these cases, the full BTF_KIND_STRUCT or BTF_KIND_UNION which would normally be emitted is replaced with a BTF_KIND_FWD, as though the underlying type was a forward-declared struct or union type. gcc/ * btfout.cc (btf_used_types): New hash set. (struct btf_fixup): New. (fixups, forwards): New vecs. (btf_output): Calculate num_types depending on debug_prune_btf. (btf_early_finsih): New initialization for debug_prune_btf. (btf_add_used_type): New function. (btf_used_type_list_cb): Likewise. (btf_collect_pruned_types): Likewise. (btf_add_vars): Handle special case for variables in ".maps" section when generating BTF for BPF CO-RE target. (btf_late_finish): Use btf_collect_pruned_types when debug_prune_btf is in effect. Move some initialization to btf_early_finish. (btf_finalize): Additional deallocation for debug_prune_btf. * common.opt (gprune-btf): New flag. * ctfc.cc (init_ctf_strtable): Make non-static. * ctfc.h (init_ctf_strtable, ctfc_delete_strtab): Make extern. * doc/invoke.texi (Debugging Options): Document -gprune-btf. gcc/testsuite/ * gcc.dg/debug/btf/btf-prune-1.c: New test. * gcc.dg/debug/btf/btf-prune-2.c: Likewise. * gcc.dg/debug/btf/btf-prune-3.c: Likewise. * gcc.dg/debug/btf/btf-prune-maps.c: Likewise. --- gcc/btfout.cc | 358 +++++++++++++++++- gcc/common.opt | 4 + gcc/ctfc.cc | 2 +- gcc/ctfc.h | 3 + gcc/doc/invoke.texi | 20 + gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c | 25 ++ gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c | 33 ++ gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c | 35 ++ .../gcc.dg/debug/btf/btf-prune-maps.c | 20 + 9 files changed, 493 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-maps.c diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 89f148de9650..34d8cec0a2e3 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -828,7 +828,10 @@ output_btf_types (ctf_container_ref ctfc) { size_t i; size_t num_types; - num_types = ctfc->ctfc_types->elements (); + if (debug_prune_btf) + num_types = max_translated_id; + else + num_types = ctfc->ctfc_types->elements (); if (num_types) { @@ -957,6 +960,212 @@ btf_add_func_records (ctf_container_ref ctfc) } } +/* The set of types used directly in the source program, and any types manually + marked as used. This is the set of types which will be emitted when + flag_prune_btf is set. */ +static GTY (()) hash_set *btf_used_types; + +/* Fixup used to avoid unnecessary pointer chasing for types. A fixup is + created when a structure or union member is a pointer to another struct + or union type. In such cases, avoid emitting full type information for + the pointee struct or union type (which may be quite large), unless that + type is used directly elsewhere. */ +struct btf_fixup +{ + ctf_dtdef_ref pointer_dtd; /* Type node to which the fixup is applied. */ + ctf_dtdef_ref pointee_dtd; /* Original type node referred to by pointer_dtd. + If this concrete type is not otherwise used, + then a forward is created. */ +}; + +/* Stores fixups while processing types. */ +static vec fixups; + +/* For fixups where the underlying type is not used in the end, a BTF_KIND_FWD + 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. + 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 + or union member. SEEN_PTR is true if CHECK_PTR is true AND one of the + predecessors was a pointer type. These two flags are used to avoid chasing + pointers to struct/union only used from pointer members. For such types, we + will emit a forward instead of the full type information, unless + 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) +{ + if (dtd == NULL) + return NULL; + + uint32_t ctf_kind = CTF_V2_INFO_KIND (dtd->dtd_data.ctti_info); + uint32_t kind = get_btf_kind (ctf_kind); + + /* Check whether the type has already been added. */ + if (btf_used_types->contains (dtd)) + { + /* It's possible the type was already added as a fixup, but that we now + have a concrete use of it. */ + switch (kind) + { + case BTF_KIND_PTR: + case BTF_KIND_TYPEDEF: + case BTF_KIND_CONST: + case BTF_KIND_VOLATILE: + case BTF_KIND_RESTRICT: + if (check_ptr) + /* Type was previously added as a fixup, and that's OK. */ + return dtd; + else + { + /* The type was previously added as a fixup, but now we have + a concrete use of it. Remove the fixup. */ + for (size_t i = 0; i < fixups.length (); i++) + if (fixups[i].pointer_dtd == 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); + return dtd; + } + default: + return dtd; + } + } + + if (ctf_kind == CTF_K_SLICE) + { + /* Bitfield. Add the underlying type to the used set, but leave + 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); + return dtd; + } + + /* Skip redundant definitions of void and types with no BTF encoding. */ + if ((kind == BTF_KIND_INT && dtd->dtd_data.ctti_size == 0) + || (kind == BTF_KIND_UNKN)) + return NULL; + + /* Add the type itself, and assign its id. + Do this before recursing to handle things like linked list structures. */ + gcc_assert (ctfc->ctfc_nextid <= BTF_MAX_TYPE); + dtd->dtd_type = ctfc->ctfc_nextid++; + btf_used_types->add (dtd); + ctf_add_string (ctfc, dtd->dtd_name, &(dtd->dtd_data.ctti_name), CTF_STRTAB); + ctfc->ctfc_num_types++; + ctfc->ctfc_num_vlen_bytes += btf_calc_num_vbytes (dtd); + + /* Recursively add types referenced by this type. */ + switch (kind) + { + case BTF_KIND_INT: + case BTF_KIND_FLOAT: + case BTF_KIND_FWD: + /* Leaf kinds which do not refer to any other types. */ + break; + + case BTF_KIND_FUNC: + case BTF_KIND_VAR: + /* Root kinds; no type we are visiting may refer to these. */ + gcc_unreachable (); + + case BTF_KIND_PTR: + case BTF_KIND_TYPEDEF: + case BTF_KIND_CONST: + case BTF_KIND_VOLATILE: + case BTF_KIND_RESTRICT: + { + /* These type kinds refer to exactly one other type. */ + if (check_ptr && !seen_ptr) + seen_ptr = (kind == BTF_KIND_PTR); + + /* Try to avoid chasing pointers to struct/union types if the + underlying type isn't used. */ + if (check_ptr && seen_ptr && create_fixups) + { + ctf_dtdef_ref ref = dtd->ref_type; + uint32_t ref_kind = btf_dtd_kind (ref); + + if ((ref_kind == BTF_KIND_STRUCT || ref_kind == BTF_KIND_UNION) + && !btf_used_types->contains (ref)) + { + struct btf_fixup fixup; + fixup.pointer_dtd = dtd; + fixup.pointee_dtd = ref; + fixups.safe_push (fixup); + break; + } + } + + /* 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); + 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); + break; + } + case BTF_KIND_STRUCT: + case BTF_KIND_UNION: + case BTF_KIND_ENUM: + case BTF_KIND_ENUM64: + { + /* Add members. */ + ctf_dmdef_t *dmd; + for (dmd = dtd->dtd_u.dtu_members; + dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd)) + { + /* 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); + ctf_add_string (ctfc, dmd->dmd_name, &(dmd->dmd_name_offset), + CTF_STRTAB); + } + break; + } + case BTF_KIND_FUNC_PROTO: + { + /* Add return type. */ + dtd->ref_type = btf_add_used_type (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); + /* 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. */ + } + break; + } + default: + return NULL; + } + + return dtd; +} + /* 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 @@ -975,6 +1184,26 @@ btf_early_finish (void) be emitted before starting the translation to BTF. */ btf_add_const_void (tu_ctfc); btf_add_func_records (tu_ctfc); + + /* These fields are reset to count BTF types etc. */ + tu_ctfc->ctfc_num_types = 0; + tu_ctfc->ctfc_num_vlen_bytes = 0; + tu_ctfc->ctfc_vars_list_count = 0; + + if (debug_prune_btf) + { + btf_used_types + = hash_set::create_ggc (tu_ctfc->ctfc_types->elements ()); + tu_ctfc->ctfc_nextid = 1; + fixups.create (1); + + /* Empty the string table, which was already populated with strings for + all types translated from DWARF. We may only need a very small subset + of these strings; those will be re-added below. */ + ctfc_delete_strtab (&tu_ctfc->ctfc_strtable); + init_ctf_strtable (&tu_ctfc->ctfc_strtable); + tu_ctfc->ctfc_strlen++; + } } /* Push a BTF datasec entry ENTRY into the datasec named SECNAME, @@ -1157,6 +1386,25 @@ btf_add_vars (ctf_container_ref ctfc) /* Add a BTF_KIND_DATASEC entry for the variable. */ btf_datasec_add_var (ctfc, var, dvd); + + const char *section = var->get_section (); + if (section && (strcmp (section, ".maps") == 0) && debug_prune_btf) + { + /* The .maps section has special meaning in BTF: it is used for BPF + map definitions. These definitions should be structs. We must + collect pointee types used in map members as though they are used + directly, effectively ignoring (from the pruning perspective) that + they are struct members. */ + ctf_dtdef_ref dtd = dvd->dvd_type; + uint32_t kind = btf_dtd_kind (dvd->dvd_type); + if (kind == BTF_KIND_STRUCT) + { + 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); + } + } } } @@ -1255,6 +1503,86 @@ btf_assign_datasec_ids (ctf_container_ref ctfc) } } +/* Callback used for assembling the only-used-types list. Note that this is + the same as btf_type_list_cb above, but the hash_set traverse requires a + different function signature. */ + +static bool +btf_used_type_list_cb (const ctf_dtdef_ref& dtd, ctf_container_ref ctfc) +{ + ctfc->ctfc_types_list[dtd->dtd_type] = dtd; + return true; +} + +/* Collect the set of types reachable from global variables and functions. + This is the minimal set of types, used when generating pruned BTF. */ + +static void +btf_collect_pruned_types (ctf_container_ref ctfc) +{ + vec_alloc (forwards, 1); + + /* Add types used from functions. */ + ctf_dtdef_ref dtd; + size_t i; + FOR_EACH_VEC_ELT (*funcs, i, dtd) + { + btf_add_used_type (ctfc, dtd->ref_type, false, false, true); + ctf_add_string (ctfc, dtd->dtd_name, &(dtd->dtd_data.ctti_name), + CTF_STRTAB); + } + + /* Add types used from global variables. */ + 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); + ctf_add_string (ctfc, dvd->dvd_name, &(dvd->dvd_name_offset), CTF_STRTAB); + } + + /* 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. */ + for (i = 0; i < fixups.length (); i++) + { + struct btf_fixup *fx = &fixups[i]; + if (!btf_used_types->contains (fx->pointee_dtd)) + { + /* The underlying type is not used. Create a forward. */ + ctf_dtdef_ref fwd = ggc_cleared_alloc (); + ctf_id_t id = ctfc->ctfc_nextid++; + gcc_assert (id <= BTF_MAX_TYPE); + + bool union_p = (btf_dtd_kind (fx->pointee_dtd) == BTF_KIND_UNION); + + fwd->dtd_name = fx->pointee_dtd->dtd_name; + fwd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_FORWARD, union_p, 0); + fwd->dtd_type = id; + ctfc->ctfc_num_types++; + ctfc->ctfc_num_vlen_bytes += btf_calc_num_vbytes (fwd); + ctf_add_string (ctfc, fwd->dtd_name, &(fwd->dtd_data.ctti_name), + CTF_STRTAB); + + /* Update the pointer to point to the forward. */ + fx->pointer_dtd->ref_type = fwd; + vec_safe_push (forwards, fwd); + } + } + + /* Construct the resulting pruned type list. */ + ctfc->ctfc_types_list + = ggc_vec_alloc (btf_used_types->elements () + 1 + + vec_safe_length (forwards)); + + btf_used_types->traverse (ctfc); + + /* Insert the newly created forwards into the regular types list too. */ + FOR_EACH_VEC_ELT (*forwards, i, dtd) + ctfc->ctfc_types_list[dtd->dtd_type] = dtd; + + max_translated_id = btf_used_types->elements () + vec_safe_length (forwards); +} + /* Late entry point for BTF generation, called from dwarf2out_finish (). Complete and emit BTF information. */ @@ -1266,13 +1594,22 @@ btf_finish (void) datasecs.create (0); - tu_ctfc->ctfc_num_types = 0; - tu_ctfc->ctfc_num_vlen_bytes = 0; - tu_ctfc->ctfc_vars_list_count = 0; - btf_add_vars (tu_ctfc); - btf_collect_translated_types (tu_ctfc); + if (debug_prune_btf) + { + /* Collect pruned set of BTF types and prepare for emission. + This includes only types directly used in file-scope variables and + function return/argument types. */ + btf_collect_pruned_types (tu_ctfc); + } + else + { + /* Collect all BTF types and prepare for emission. + This includes all types translated from DWARF. */ + btf_collect_translated_types (tu_ctfc); + } btf_add_func_datasec_entries (tu_ctfc); + btf_assign_var_ids (tu_ctfc); btf_assign_func_ids (tu_ctfc); btf_assign_datasec_ids (tu_ctfc); @@ -1305,6 +1642,15 @@ btf_finalize (void) func_map->empty (); func_map = NULL; + if (debug_prune_btf) + { + btf_used_types->empty (); + btf_used_types = NULL; + + fixups.release (); + forwards = NULL; + } + ctf_container_ref tu_ctfc = ctf_get_tu_ctfc (); ctfc_delete_container (tu_ctfc); tu_ctfc = NULL; diff --git a/gcc/common.opt b/gcc/common.opt index f2bc47fdc5e6..849f6456ff85 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -3534,6 +3534,10 @@ gbtf Common Driver RejectNegative JoinedOrMissing Generate BTF debug information at default level. +gprune-btf +Common Driver Var(debug_prune_btf) Init(0) +Generate pruned BTF when emitting BTF info. + gdwarf Common Driver JoinedOrMissing RejectNegative Generate debug information in default version of DWARF format. diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc index 8da37f260458..8f531ffebf88 100644 --- a/gcc/ctfc.cc +++ b/gcc/ctfc.cc @@ -909,7 +909,7 @@ ctfc_get_dvd_srcloc (ctf_dvdef_ref dvd, ctf_srcloc_ref loc) /* Initialize the CTF string table. The first entry in the CTF string table (empty string) is added. */ -static void +void init_ctf_strtable (ctf_strtable_t * strtab) { strtab->ctstab_head = NULL; diff --git a/gcc/ctfc.h b/gcc/ctfc.h index d0b724817a7f..29267dc036d1 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -369,6 +369,9 @@ extern unsigned int ctfc_get_num_ctf_vars (ctf_container_ref); extern ctf_strtable_t * ctfc_get_strtab (ctf_container_ref, int); +extern void init_ctf_strtable (ctf_strtable_t *); +extern void ctfc_delete_strtab (ctf_strtable_t *); + /* Get the length of the specified string table in the CTF container. */ extern size_t ctfc_get_strtab_len (ctf_container_ref, int); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index a0b375646468..8479fd5cf2b8 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -522,6 +522,7 @@ Objective-C and Objective-C++ Dialects}. @xref{Debugging Options,,Options for Debugging Your Program}. @gccoptlist{-g -g@var{level} -gdwarf -gdwarf-@var{version} -gbtf -gctf -gctf@var{level} +-gprune-btf -gno-prune-btf -ggdb -grecord-gcc-switches -gno-record-gcc-switches -gstrict-dwarf -gno-strict-dwarf -gas-loc-support -gno-as-loc-support @@ -12003,6 +12004,25 @@ eBPF target. On other targets, like x86, BTF debug information can be generated along with DWARF debug information when both of the debug formats are enabled explicitly via their respective command line options. +@opindex gprune-btf +@opindex gno-prune-btf +@item -gprune-btf +@itemx -gno-prune-btf +Prune BTF information before emission. When pruning, only type +information for types used by global variables and file-scope functions +will be emitted. If compiling for the BPF target with BPF CO-RE +enabled, type information will also be emitted for types used in BPF +CO-RE relocations. In addition, struct and union types which are only +referred to via pointers from members of other struct or union types +shall be pruned and replaced with BTF_KIND_FWD, as though those types +were only present in the input as forward declarations. + +This option substantially reduces the size of produced BTF information, +but at significant loss in the amount of detailed type information. +It is primarily useful when compiling for the BPF target, to minimize +the size of the resulting object, and to eliminate BTF information +which is not immediately relevant to the BPF program loading process. + @opindex gctf @item -gctf @itemx -gctf@var{level} diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c new file mode 100644 index 000000000000..7115d074bd58 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c @@ -0,0 +1,25 @@ +/* Simple test of -gprune-btf option operation. + Since 'struct foo' is not used, no BTF shall be emitted for it. */ + +/* { dg-do compile } */ +/* { dg-options "-gbtf -gprune-btf -dA" } */ + +/* No BTF info for 'struct foo' nor types used only by it. */ +/* { dg-final { scan-assembler-not "BTF_KIND_STRUCT 'foo'" } } */ +/* { dg-final { scan-assembler-not "BTF_KIND_INT 'char'" } } */ + +/* We should get BTF info for 'struct bar' since it is used. */ +/* { dg-final { scan-assembler "BTF_KIND_STRUCT 'bar'"} } */ + +struct foo { + int a; + char c; +}; + +struct bar { + int x; + long z[4]; +}; + +struct bar a_bar; + diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c new file mode 100644 index 000000000000..e6b4a1946f1b --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c @@ -0,0 +1,33 @@ +/* Test that -gprune-btf does not chase pointer-to-struct members. */ + +/* { dg-do compile } */ +/* { dg-options "-gbtf -gprune-btf -dA" } */ + +/* Only use of B is via a pointer member of C. + Full BTF for B is replaced with a forward. */ +/* { dg-final { scan-assembler-not "BTF_KIND_STRUCT 'B'" } } */ +/* { dg-final { scan-assembler-times "TYPE \[0-9\]+ BTF_KIND_FWD 'B'" 1 } } */ + +/* Detailed info for B is omitted, and A is otherwise unused. */ +/* { dg-final { scan-assembler-not "BTF_KIND_\[A-Z\]+ 'A'" } } */ + +/* { dg-final { scan-assembler "BTF_KIND_STRUCT 'C'" } } */ + +struct A; + +struct B { + int x; + int (*do_A_thing) (int, int); + struct A *other; +}; + +struct C { + unsigned int x; + struct B * a; +}; + +int +foo (struct C *c) +{ + return c->x; +} diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c new file mode 100644 index 000000000000..16f8110fc781 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c @@ -0,0 +1,35 @@ +/* Test that -gprune-btf does not prune through array members. */ + +/* { dg-do compile } */ +/* { dg-options "-gbtf -gprune-btf -dA" } */ + +/* We expect full BTF information each struct. */ +/* { dg-final { scan-assembler "TYPE \[0-9\]+ BTF_KIND_FWD 'file'" } } */ +/* { dg-final { scan-assembler "TYPE \[0-9\]+ BTF_KIND_STRUCT 'A'" } } */ +/* { dg-final { scan-assembler "TYPE \[0-9\]+ BTF_KIND_STRUCT 'B'" } } */ +/* { dg-final { scan-assembler "TYPE \[0-9\]+ BTF_KIND_STRUCT 'C'" } } */ + +struct file; + +struct A { + void *private; + long (*read)(struct file *, char *, unsigned long); + long (*write)(struct file *, const char *, unsigned long); +}; + +struct B { + unsigned int x; + struct A **as; +}; + +struct C { + struct A *arr_a[4]; + struct A *lone_a; + unsigned int z; +}; + +unsigned int +foo (struct B *b, struct C *c) +{ + return b->x + c->z; +} diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-prune-maps.c b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-maps.c new file mode 100644 index 000000000000..f3d870ac59ec --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-maps.c @@ -0,0 +1,20 @@ +/* Test special meaning of .maps section for BTF when pruning. For global + variables of struct type placed in this section, we must treat members as + though they are used directly, always collecting pointee types. + Therefore, full type information for struct keep_me should be emitted. */ + +/* { dg-do compile } */ +/* { dg-options "-gbtf -gprune-btf -dA" } */ + +/* { dg-final { scan-assembler-not "BTF_KIND_FWD 'keep_me'" } } */ +/* { dg-final { scan-assembler "BTF_KIND_STRUCT 'keep_me'" } } */ + +struct keep_me { + int a; + char c; +}; + +struct { + int *key; + struct keep_me *value; +} my_map __attribute__((section (".maps"))); From patchwork Tue Jun 11 19:01:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1946490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=osYMBOkX; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=AkYFa/Jm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzJ4146hkz20Pb for ; Wed, 12 Jun 2024 05:03:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8443A385ED72 for ; Tue, 11 Jun 2024 19:03:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 3B3AF385E45C for ; Tue, 11 Jun 2024 19:03:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B3AF385E45C 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 3B3AF385E45C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132590; cv=pass; b=OhiaPVI83CC+muN/lqNafgDwfSgt16xJM32tLwZkCi/mpnBaQVJG01nR7h7/mmGM8MvTHNfmVCE5MHZwP+2xg3qWN5EylwydFTK32Ge++PBhmaOZkmkDdOW2+rbjrf8zLCqp0MHu3b3kTFBorO5nSIMtmyS7nDYqEmtHu+uIwNM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132590; c=relaxed/simple; bh=fzpROpME1gmSvvvRXT5pXX79p5GtZx3Prf28yAAgGbU=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=XNEijB/W/vV8dk6u691+nKdKzeZWo0mx1R/OIkF05eLG7BjdBtQrradDUu1ZBKSYCE4y9jXQtqMNxM8tMU7Kvnxcnl7OPU+0tIKHouxj0rLzKOmYkSR/vwEPCGkwRGSTI96f40oqHmb4b1QcVb9AyDS8XNq0tFBHGreab5LegOU= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45BFxBnT026893 for ; Tue, 11 Jun 2024 19:03:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=87N8nwXH6w0o9I+RVBuxQd1jUwdrvqXvM8+kLYF63pk=; b= osYMBOkX9wTcTUzkKEGHlP8SydgIiLh7p3YPS2sl5e3Xiq7mSUAGokGxgtLO45gc F6iJCRIYUv9PeqgII4Cez0dn5dsfTyH5AHf5HdIR7gsyldaN6udIXBsf+y0Yq2lN zA1eiKmREiKYu6CM7Y+io0mW0cGHCdsuE/E/3DVQC9ijL0xKFoiyN6Iz11xBC2mX wux4vYclCaY+U29dhnZLo6lRmWFGGTVZ0lSIdQCAqEZArnqwjVGivnTbJbLdq23F 7p3230sUurvkaRz+FnHgZFdTMApn98XTKVD95bkaeDPJTos5hymnmY8DAEe0rQS2 LPWGMEXAvWBanbv6CD8JTA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh1gdmwn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:03:05 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45BIk50b012608 for ; Tue, 11 Jun 2024 19:03:04 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2041.outbound.protection.outlook.com [104.47.73.41]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ync9xaqh2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:03:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GL1BGpsoxBFl+sqDpuGiOfFXg1gzi2b7Gae2z2MbvA4EoQS00fUuz8NiOfienVluSul6EpDW0cO6sx7XS9AqOgsZM33hM+IlQuhIQ0H5K2K/W3tGKTUDXjYgV03acaFrdEkyArf+g/no3g6YiKgkiiaQrW6Kafs6TMU0hmS+kck0VNmR8uNm4KKGBRj0gbPHMl+JBEofxSaPH7yB2H6+MKtOZFwVuwCl+69l4rvNeFupj9Meb1Qf+1ciUYwDLGk+TMLGTbFW4mpSBc9iuXfJgFYov0hbzEGdk6WXCvLDmSxKqyYsiokSuStBYQvDETBiXWNc43H8juJ3tFa2PKcC8w== 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=87N8nwXH6w0o9I+RVBuxQd1jUwdrvqXvM8+kLYF63pk=; b=nQ2X466TlqTS+kGoX9T3Sn6R6wXMMczjPr9F/yxoiYy0BMBeOKRxyNL+JnFZSG4XV3+cRwFjxFhfL9kUvRF5Op4n1vG4/IqqjdNeZkHN+T9RUzdFSj8Z7bCAL8qTGCSWmab0xvLsCwIv1kiPjIaFZQBsp2YW0yDE+4gWj3CENYAaKpyJri3X8Z+kBRTygKbnFd5fnVBoPLWgx5GganVkkTZVos32ZRzBgJ0pwQzlD3GE+1VfYcdQme3TDiSW5YkvE2OrlNHdJUL2YrxEhJukKLYK5VNjyeVDo3NOUMdhXCb6qZ/MNwpCypyLdGeYD4HDbPZKA536JupM1SE9kSM5MQ== 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=87N8nwXH6w0o9I+RVBuxQd1jUwdrvqXvM8+kLYF63pk=; b=AkYFa/Jmlk+8B5IFvo2IlD+EW0nJu4ywgRK2EI3wfyDOIOZ71liwFfq2H769fsNS2BoJM9sET4rdVSEveJUn2iZMTcnWrkIQA0OK+raqJJ0Mg4nPAE9Y6pYQ8TcWUXRN1yZTk6h3G+rfvtEKsgoMok4uZuE3k5aJ/hI5lGx82ls= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by CH2PR10MB4134.namprd10.prod.outlook.com (2603:10b6:610:a7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.39; Tue, 11 Jun 2024 19:03:02 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%5]) with mapi id 15.20.7633.036; Tue, 11 Jun 2024 19:03:02 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com, jose.marchesi@oracle.com, cupertino.miranda@oracle.com Subject: [PATCH v4 5/6] bpf,btf: enable BTF pruning by default for BPF Date: Tue, 11 Jun 2024 12:01:44 -0700 Message-ID: <20240611190145.115887-6-david.faust@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240611190145.115887-1-david.faust@oracle.com> References: <20240611190145.115887-1-david.faust@oracle.com> X-ClientProxiedBy: MW4PR04CA0056.namprd04.prod.outlook.com (2603:10b6:303:6a::31) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|CH2PR10MB4134:EE_ X-MS-Office365-Filtering-Correlation-Id: 8ba4e342-2c3a-4aca-3706-08dc8a491e0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230032|1800799016|366008|376006; X-Microsoft-Antispam-Message-Info: wYA8ecObkWuqcpkZHDVMBLDQKBCqgbtB3gtX84gCJ1x+ZLaW5O50ap1zRT1v69LgDe8zzLDGkwpeV7C6o+Kcahy+JU2hqSFsVT45H1MGf32XiTTz13X0dT5D1Drzqu6WbDBGeRunnyHHzvaaHkd66ZdDj/BG3H09fziYCU/Au3/rP+oK44AmfIjzrJmySw0gwy1FPlaaOvdAXZBzzk4UvadKFTvyZByVrAVKMJViF8RwiwduLaHU9oKoXdxDHumD/vGDilaPWQFrDrr4fedyxlhTZ3D9PGRds/9xQxwguxQ9H+C6+cZxc6wQg625v2p9eZ9USb4ZFb2CEFl3fcw0H4HrM8U2WMxG1Qi/ydiSNm9Zmegyy/6xy2XYMpyfi52eNYSWGsV+5hOIblsJYug3D8HzbVXjd64cq468vBSCqVMj9/rXSuyN5Fhq4K+wIi3Oe2jtI+/pFj0bG/uWQtBC9fgLDsslsqxwi5v7MkKfIgwuhynFfnjiFZuEbSfEvptnVryZSXiZ3gpW5zfd/IFcA76ZzBn6AcHJaC82UvSFHCTRcNJVfiYmYR0JjdONcVRT4FMCshASln6mV1DbkljHX00/a20w+1HojCyRg+WYrz+ZDKvesHARDEu7Rz5DbtUG1LeRlvEIT5OEznv9kI98YsmyGXok303V52YuVT5dZ0CBfiReZx/egYtU+BCiQe/W53CkL14z5VCwARWFM/PZAoOK7i1WsAaPoWyFFVYi88yzL3ygUS2++PEnh2EaTNtFIgYVoSIqrb8ywrACIJd3J1fPXgepvl2M25vDHsaE3HK6NwjYvSGxztsCu2tyRuglG0V95QhPGTAdcRAs7/Vm8irPwSf+zb6cx8WeM372LDmTBrQooBY7n54FVlN+Vx8q+o6KTbaHAQgdE06WLny4X/T1ktB6a4MER+Y765eFqWd8/j0J3btj2de3FPnb6nwhRbDzf8xsm7n/JrkMc+WnZyRfkFY+zD6LkRgfSyWs68CnmlWEqTPNcmV0hP2pIICp18iSodxqhKMFRi9/RWZpOaiQhJy4+JAMdOLVs6BOumZRrZWAuXnzv9vOQrGSUIgC+hCbomxj+104DN7dPGuntkmAm8DIPftIa7tYoEz3n40ur7A/ssUJS9PAmoO1yHCm21gh5d3kcJ8neDlsW3qK0KGoFZDEo2ekjR49mJLkWM85MjBgKlzfhW27RpzUmkNEYMhq2VMA5a7l2/vi01OTyAGLCgV534CMgjUvety8FrbZSt92JRzoN/A9Wj3uCsHR 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:(13230032)(1800799016)(366008)(376006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PDGvEBK9bhF71WVqAqCMtNt/d0hfrSvkyC4lL9JbAn5CjRKVzI3V/TxE7TNs24TUPn50H/GxFcQ2hSF2rU5S9ktXVtSiLsF+mRh9mL4ep9032uotoBXi/e5JrhoLFAfPv/FBQwBkV1UAnL7mTlHfv6DTels1H9ThE+teZ9aNkgEeRzFZUmkS8MrU2C2oeCgjHAd3kVk+q+inU0nGiIiywmasYov1YTH2NRF/rIrmZbTw7+boxO2TI9zcEj67h/Vb8WhfcAMCrElpxgYk8JiX3F4TyuJl63ZA+SBRaRiGlH/HGU5FOb4vaPXW4tw3YnP034NH+OgmJ65XS1jwweb/tSP8jtNoII8KFbBaNEonN1P5mIhVKCSCu9UoRIrfLSpv5zmqaDo16gt5iNU/yvUSSHqstoepVv3Hv1A+TZpqa+RVPWVvbtQ7PQWoGU4uQyYUEU7X82tuygBZt5Bqp7aP54lbl90kVGD9VilLIeG7ZmnKQSeOhr2mI1xkaI2rSDlpSua62DRCySgyeUrGJOiU06nH+Tnz4Q0bLUHm7/wMjUEQy9EgSy2Jhj0OKEtMgH5C+mEk/xLniMtp5FuxKZBVWt+tVxEexaitzPZy6ho8Egi2/0B6+PAF4u4f1707h10DSMTcGpwJ3Rxo7r1JWBXVae798oic5Ypaejir7z7/nEbUN1ZSBz+OuveHwZ3k70FO5J3HfJrf7JwpMjdDQ6tC6ok/X2IMb8u8q80bTW44k6LQbVx+i33PFMzjn7+AUAK6V0V86acC7nqqSnmSCQ44U++9tT7mHpBdqP+/esDkU1fhAbsFsz30Bfwo6wPYvInKBa7NdvRFoDG1yp7XExQhQF/XFPWCjdefbXFxJAfy4J/Io9ejxYaFBqfyWhx8X64/ibLAveSF4uH6l+iYxiWj8CD9f/HtwhrSZjC0PsQW4JlKVaBr/mfOYj9s8e/b6fxFbK3G/rRYvg8Uadrbedq5781bBgPnhCo7MPmo9SLJNYMByhTHsuG+QRDJQCokyxeO1k8rc22tePUaS10H4XoG1xMF8xNLVvw8TK/2RAC6mFEUurRm0Bp2WM/XjHRpj5vmuoPbLTR2IyKRHu4VAQkB6AkrvvEUSbbnTEz29zDpz9ZQOoVwTmDQa4gXcGDMKpxRkoEMNPuKgxVq5APCnIZIf2r4eL91ayJUpP+/j2A4iRXCxX/zqYnIKoAoeQKU6MsS27Crt1pBF8VK9dxoc1fnpcS/QLxViYvL1U25HSyiZ3Vd3oIDK0NB2hCoXfTNQJfdFdYTbd7GNK6BDAeebbb4QzdfmHmY/1cUy3HfKJD12CxBumn51Qbc/B5eVCVWdizdeg+DMsYJf4H6rNhQYU1Ehwi85vVv4LAXmBzDg8apdm0tOzJMZ9lWwB0qeC1fvnrycbJE7xqtpLBwIgIONbXyN7uyL1yirCZgRLI5zf9AaW8izBoC4pLFOhMLvQYncfMx/xEjLcqcA4f5Q34gVm60nFIhG4PplH0M9i+UIDPwvQZJRrOO5e6i9xwcIb0+1UwSE6t35eyIxDvS+qekzkuG0xlSQn072PMh0uxiS1n43ZyPgbRTtRiTRWgbw2Po9RwJnTr45qeONrDqJ30cuQd/qQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: rV7RoZ0Fa+qtDyEqWoVZ2Pm+Ym6zJ+WdLn9rvq3++6zGF2RSDu0+GGg26KHEHiOaRurT9v2yAp+1zE3/IIomuNlPN6eP34SQw1qiC1yKKQw+qDdf1DfRkqMBj3PwVbWqQmKjRFbcpMq6KkcIGdowgnXUp41zn11p3o4h9lzitKWxBZF26ncFj4zOY/+Md9jARTGR0nCBNOV9WsH1X3vZsWf3Ff8N3MQ8BVxz2Kstp4JpGaZQyapJqOqs6i+Ilae+5BfPQE5ga5Wc5brOY50NLtgJkyumxSbBag2ab2F/eVTfqTLnrgq43hnhl6Th8/gXgiTtujTkkps1NWtWaJJppehkD4trfBdLPC/Dwf2CgjKAUYihokB0ggUBvlEkR40fVNh4zhleRALzaCfevatFGhpWunozzWmHlBJsLHTFxC77deiLU6x7DrHcgv8d237avyeY96PstxzYe3GuQmKWCDBqoFyyXdQZB8r3T0nUsr7RSgyL++020zndsWgeEP5ncqalOGGQWTHGIW+UJATJQlpWjw/dPIslpjZQw0lSV0mbFB4d3czKvHseathF6iiEQcyKlENi3N4wJ8OMfcLlCMPH3+9GIrfK2PmsVNPkdmo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ba4e342-2c3a-4aca-3706-08dc8a491e0f X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 19:03:02.2505 (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: v121RkDuPulXRe4I3qvP4cj2CLYgx0lyD5m2Xdt1Z9v5NmF6oSKo8FQVTPBXfpipBAuv6cq3jQymbhZcxnuuJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4134 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-11_09,2024-06-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406110130 X-Proofpoint-ORIG-GUID: 2F7gETvaCeKtJ2NwSBQOUSgtVdCY1K9a X-Proofpoint-GUID: 2F7gETvaCeKtJ2NwSBQOUSgtVdCY1K9a X-Spam-Status: No, score=-13.7 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch enables -gprune-btf by default in the BPF backend when generating BTF information, and fixes BPF CO-RE generation when using -gprune-btf. When generating BPF CO-RE information, we must ensure that types used in CO-RE relocations always have sufficient BTF information emited so that the CO-RE relocations can be processed by a BPF loader. The BTF pruning algorithm on its own does not have sufficient information to determine which types are used in a BPF CO-RE relocation, so this information must be supplied by the BPF backend, using a new btf_mark_type_used function. Co-authored-by: Cupertino Miranda gcc/ * btfout.cc (btf_mark_type_used): New. * ctfc.h (btf_mark_type_used): Declare it here. * config/bpf/bpf.cc (bpf_option_override): Enable -gprune-btf by default if -gbtf is enabled. * config/bpf/core-builtins.cc (extra_fn): New typedef. (compute_field_expr): Add callback parameter, and call it if supplied. Fix computation for MEM_REF. (mark_component_type_as_used): New. (bpf_mark_types_as_used): Likewise. (bpf_expand_core_builtin): Call here. * doc/invoke.texi (Debugging Options): Note that -gprune-btf is enabled by default for BPF target when generating BTF. gcc/testsuite/ * gcc.dg/debug/btf/btf-variables-5.c: Adjust one test for bpf-*-* target. --- gcc/btfout.cc | 22 ++++++ gcc/config/bpf/bpf.cc | 5 ++ gcc/config/bpf/core-builtins.cc | 71 +++++++++++++++++-- gcc/ctfc.h | 1 + gcc/doc/invoke.texi | 3 + .../gcc.dg/debug/btf/btf-variables-5.c | 6 +- 6 files changed, 100 insertions(+), 8 deletions(-) diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 34d8cec0a2e3..083ca48d6279 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -1503,6 +1503,28 @@ btf_assign_datasec_ids (ctf_container_ref ctfc) } } + +/* Manually mark that type T is used to ensure it will not be pruned. + Used by the BPF backend when generating BPF CO-RE to mark types used + in CO-RE relocations. */ + +void +btf_mark_type_used (tree t) +{ + /* If we are not going to prune anyway, this is a no-op. */ + if (!debug_prune_btf) + return; + + gcc_assert (TYPE_P (t)); + ctf_container_ref ctfc = ctf_get_tu_ctfc (); + ctf_dtdef_ref dtd = ctf_lookup_tree_type (ctfc, t); + + if (!dtd) + return; + + btf_add_used_type (ctfc, dtd, false, false, true); +} + /* Callback used for assembling the only-used-types list. Note that this is the same as btf_type_list_cb above, but the hash_set traverse requires a different function signature. */ diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index dd1bfe38d29b..c62af7a6efa7 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -221,6 +221,11 @@ bpf_option_override (void) && !(target_flags_explicit & MASK_BPF_CORE)) target_flags |= MASK_BPF_CORE; + /* -gbtf implies -gprune-btf for BPF target. */ + if (btf_debuginfo_p ()) + SET_OPTION_IF_UNSET (&global_options, &global_options_set, + debug_prune_btf, true); + /* Determine available features from ISA setting (-mcpu=). */ if (bpf_has_jmpext == -1) bpf_has_jmpext = (bpf_isa >= ISA_V2); diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc index 232bebcadbd5..86e2e9d6e39f 100644 --- a/gcc/config/bpf/core-builtins.cc +++ b/gcc/config/bpf/core-builtins.cc @@ -624,13 +624,20 @@ bpf_core_get_index (const tree node, bool *valid) ALLOW_ENTRY_CAST is an input arguments and specifies if the function should consider as valid expressions in which NODE entry is a cast expression (or - tree code nop_expr). */ + tree code nop_expr). + + EXTRA_FN is a callback function to allow extra functionality with this + function traversal. Currently used for marking used type during expand + pass. */ + +typedef void (*extra_fn) (tree); static unsigned char compute_field_expr (tree node, unsigned int *accessors, bool *valid, tree *access_node, - bool allow_entry_cast = true) + bool allow_entry_cast = true, + extra_fn callback = NULL) { unsigned char n = 0; unsigned int fake_accessors[MAX_NR_ACCESSORS]; @@ -647,6 +654,9 @@ compute_field_expr (tree node, unsigned int *accessors, *access_node = node; + if (callback != NULL) + callback (node); + switch (TREE_CODE (node)) { case INDIRECT_REF: @@ -664,17 +674,19 @@ compute_field_expr (tree node, unsigned int *accessors, case COMPONENT_REF: n = compute_field_expr (TREE_OPERAND (node, 0), accessors, valid, - access_node, false); + access_node, false, callback); accessors[n] = bpf_core_get_index (TREE_OPERAND (node, 1), valid); return n + 1; case ARRAY_REF: case ARRAY_RANGE_REF: - case MEM_REF: n = compute_field_expr (TREE_OPERAND (node, 0), accessors, valid, - access_node, false); + access_node, false, callback); accessors[n++] = bpf_core_get_index (node, valid); return n; + case MEM_REF: + accessors[0] = bpf_core_get_index (node, valid); + return 1; case NOP_EXPR: if (allow_entry_cast == true) { @@ -683,7 +695,7 @@ compute_field_expr (tree node, unsigned int *accessors, } n = compute_field_expr (TREE_OPERAND (node, 0), accessors, valid, - access_node, false); + access_node, false, callback); return n; case ADDR_EXPR: @@ -1549,6 +1561,51 @@ bpf_resolve_overloaded_core_builtin (location_t loc, tree fndecl, return construct_builtin_core_reloc (loc, fndecl, args, argsvec->length ()); } +/* Callback function for bpf_mark_field_expr_types_as_used. */ + +static void +mark_component_type_as_used (tree node) +{ + if (TREE_CODE (node) == COMPONENT_REF) + btf_mark_type_used (TREE_TYPE (TREE_OPERAND (node, 0))); +} + +/* Mark types needed for BPF CO-RE relocations as used. Doing so ensures that + these types do not get pruned from the BTF information. */ + +static void +bpf_mark_types_as_used (struct cr_builtins *data) +{ + tree expr = data->expr; + switch (data->kind) + { + case BPF_RELO_FIELD_BYTE_OFFSET: + case BPF_RELO_FIELD_BYTE_SIZE: + case BPF_RELO_FIELD_EXISTS: + case BPF_RELO_FIELD_SIGNED: + case BPF_RELO_FIELD_LSHIFT_U64: + case BPF_RELO_FIELD_RSHIFT_U64: + if (TREE_CODE (expr) == ADDR_EXPR) + expr = TREE_OPERAND (expr, 0); + + expr = root_for_core_field_info (expr); + compute_field_expr (data->expr, NULL, NULL, NULL, false, + mark_component_type_as_used); + break; + case BPF_RELO_TYPE_ID_LOCAL: + case BPF_RELO_TYPE_ID_TARGET: + case BPF_RELO_TYPE_EXISTS: + case BPF_RELO_TYPE_SIZE: + case BPF_RELO_ENUMVAL_EXISTS: + case BPF_RELO_ENUMVAL_VALUE: + case BPF_RELO_TYPE_MATCHES: + btf_mark_type_used (data->type); + break; + default: + gcc_unreachable (); + } +} + /* Used in bpf_expand_builtin. This function is called in RTL expand stage to convert the internal __builtin_core_reloc in unspec:UNSPEC_CORE_RELOC RTL, which will contain a third argument that is the index in the vec collected @@ -1567,6 +1624,8 @@ bpf_expand_core_builtin (tree exp, enum bpf_builtins code) tree index = CALL_EXPR_ARG (exp, 0); struct cr_builtins *data = get_builtin_data (TREE_INT_CST_LOW (index)); + bpf_mark_types_as_used (data); + rtx v = expand_normal (data->default_value); rtx i = expand_normal (index); return gen_rtx_UNSPEC (DImode, diff --git a/gcc/ctfc.h b/gcc/ctfc.h index 29267dc036d1..41e1169f271d 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -457,6 +457,7 @@ extern ctf_dtdef_ref ctf_lookup_tree_type (ctf_container_ref, const tree); typedef bool (*funcs_traverse_callback) (ctf_dtdef_ref, void *); bool traverse_btf_func_types (funcs_traverse_callback, void *); +extern void btf_mark_type_used (tree); /* CTF section does not emit location information; at this time, location information is needed for BTF CO-RE use-cases. */ diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 8479fd5cf2b8..0afd686733d0 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -12023,6 +12023,9 @@ It is primarily useful when compiling for the BPF target, to minimize the size of the resulting object, and to eliminate BTF information which is not immediately relevant to the BPF program loading process. +This option is enabled by default for the BPF target when generating +BTF information. + @opindex gctf @item -gctf @itemx -gctf@var{level} diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c b/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c index 8aae76cacabd..a08130cfc072 100644 --- a/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c @@ -11,9 +11,11 @@ /* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t \]+\[^\n\]*btv_info" 1 } } */ /* { dg-final { scan-assembler-times "\[\t \]0x1\[\t \]+\[^\n\]*btv_linkage" 1 } } */ -/* Expect 2 array types, one of which is unsized. */ +/* Expect 2 array types, one of which is unsized. For BPF target, -gprune-btf + is the default and will remove the unsized array type. */ /* { dg-final { scan-assembler-times "\[\t \]0x4\[\t \]+\[^\n\]*bta_nelems" 1 } } */ -/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*bta_nelems" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*bta_nelems" 1 { target { !bpf-*-* } } } } */ +/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*bta_nelems" 0 { target { bpf-*-* } } } } */ extern const char FOO[]; const char FOO[] = "foo"; From patchwork Tue Jun 11 19:01:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1946494 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=GkWlCPWV; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=S7upyntj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzJ5d07Hkz20Py for ; Wed, 12 Jun 2024 05:05:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B8663861034 for ; Tue, 11 Jun 2024 19:05:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 0D8DB385ED4C for ; Tue, 11 Jun 2024 19:03:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D8DB385ED4C 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 0D8DB385ED4C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132594; cv=pass; b=f4p0vmSteu9gtIxlBxAZ7LL3nWQRADcQT1lq42pz2QZhIvQmXGR3HY451IvX02iG8S7Nz8XvNcii5Jm2zFFmzoj0Aa0FileN8HGKPHqQO0p9vWip+IQS4L0P1kr2UaqbPdw5GiLnUbTmql9PHg/n847rAThIg4lQ2SLu+8BLolM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132594; c=relaxed/simple; bh=wVtLyUMx+pDoYSaM5Ra4Uo+7bBzBWxogdq2DM2cqOSQ=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=kEVLBg0hqOgJxItDKXgkH1M57cdgLqpz7icFvTZCeN9j/EyYDWM6AsHbxlTQVOinxmqRAcqX9Y2s6zFeVBlXDu4ddsfKwIwtrX/XKEvplySmtvUYXMbhsB2AEvErtbZOSISFoXkZlqNbirCHf+5fskPDAC8lcCvtXLtHKxeF2ys= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45BFn4Jw028034 for ; Tue, 11 Jun 2024 19:03:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=F2sfyswTKb4q2LbxbRTiC+Jo+e9airrfnbj4ehU3v7w=; b= GkWlCPWVqt3FSJCn5jdZ35Iv8LkFaAnpQiRBAwbMCANp+0/UfMGmjn09PhFSS35L n0nz1G69AEfgaCIxNza9laOltRA+56U9B2TV4G+MeKLj5949knEnXzj//8fFSas+ AUvn0QhLriC19PuqE86OzLTSqk1zlWt5Clp0Vi8XYIfNqyLz4KHs3bX0yDv6qffg LJvlKdOeATdXjrcEumopuHNvkLCLZ2NOYBujJZxRJqivsGf/Yv9rxH9xSY8uDAfn IwZQafh6XuXESoOiAW5PbU3cebzDteaDigvfSZrI8QLsljxTdXwCLEVsg0fbznqN WNf0yXdisLz9Rl45yJPwtQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh1mdknd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:03:12 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45BIRgHe019928 for ; Tue, 11 Jun 2024 19:03:11 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2040.outbound.protection.outlook.com [104.47.73.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ync8xn7gu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:03:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oUM7ye9BnrAkHEWEEtTvdmqQwXUYfjL49qQ5SaL2epTwsCXERhdfE4nhYe+ygXO0vJER8//R5LcLISJasSV+AdHpsP+Xi58VhyGfmKt8qmcJ8i3CulkjWTrSYTc9czDbag5WBcaxPpXIHiFSSi7A0+ToXJ8j3+OZvBAz5fGQ+xagA1nHSzT2cRkhgAU3UaWg9SowKdinSFQpDB5IdqoR9bWsn6YYQCAnR71yZ0k4nWzwGoUUhIV17DYWOfET+WzJOlkCRdH2QFbHCMDQv6u7VpDFa3kRDzj3UflA0JvuezScBvWMM97IJrLL/yzK1rOV0KAeaLp0EnMp4XISE6ZU4w== 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=F2sfyswTKb4q2LbxbRTiC+Jo+e9airrfnbj4ehU3v7w=; b=GSdyclQBmmNEc8D/7pgZ5lNjiEIrNlBnpFOSt7sydVLc+LtZncfJa+dyqiFn1BxySGE6XxgGxPz6RhRX5iixOqKT/Yhl1vNnPjI8McX2bnQCJCMZFSe3jbJ8s4OhQYE89FdeTxIYwikksVcc4yWdjV7mWgdW/qbp2xUC+OsZMz55O8t3Lp7vJtv1KhtSyg6r4Vs/1wbcl5B5PzFX+sdD30TB2lxdwvI7NDmlSYSollHsuJ4fMSAIPKC+1OfwCXcWvZgq+EkbcEMsGkverboNqhGoxQUbY5pG0Yj6N6mV5GcdocIwGK/BsEgnUhGut/YAwJacpgyLdWbttit+0/vf8Q== 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=F2sfyswTKb4q2LbxbRTiC+Jo+e9airrfnbj4ehU3v7w=; b=S7upyntjUmpdHP4+k5bug6jsar3BRAnCStqqSjiQfy+EvtGAgEfuM0Jp8RRSzJw2+ByBBVybDZRy8Qg52dXkStbUnYi+sobhT6wnAqXvz/6NeY3q4DzduK/N52XtNX+nmwfvSYOFWGLaIacBcv82iMykwQHcHiW0LSsLVvkyQCw= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by CH2PR10MB4134.namprd10.prod.outlook.com (2603:10b6:610:a7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.39; Tue, 11 Jun 2024 19:03:08 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%5]) with mapi id 15.20.7633.036; Tue, 11 Jun 2024 19:03:05 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com, jose.marchesi@oracle.com, cupertino.miranda@oracle.com Subject: [PATCH v4 6/6] opts: allow any combination of DWARF, CTF, BTF Date: Tue, 11 Jun 2024 12:01:45 -0700 Message-ID: <20240611190145.115887-7-david.faust@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240611190145.115887-1-david.faust@oracle.com> References: <20240611190145.115887-1-david.faust@oracle.com> X-ClientProxiedBy: MW4PR04CA0146.namprd04.prod.outlook.com (2603:10b6:303:84::31) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|CH2PR10MB4134:EE_ X-MS-Office365-Filtering-Correlation-Id: 70ad6107-4734-48f6-be9d-08dc8a491fb5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230032|1800799016|366008|376006; X-Microsoft-Antispam-Message-Info: eKWVPtGOj09z2ePpYAT2Ftc8VZKwf5j/c/bkHlTvvXDLl3bCZ5Ew71VCo8y+pMfMhtRzQz6Y42memae4XUhJ6NXIqQr8pY/2wvK/PNfOX8uM5YwtSVhikYl6v/yD2/R0gXE4Ujfm+Uf20Viz1FRtTJI3nLOXQbSejRY4FNcfXzwpMrjIQ38lsuJYJVCeH2PdU7eF8KtMGXzClA/KFcXcrC6M8S/AMEHzRQTpYiPy5rBeQZ3pL6wdU6d63gRemmpAod2NwxD11jaPJVw2LZdvhNdPVLmk5QLtX2Ly/Ypioz9cMLzk/9KBs6+nwS9oAUdI8Xw8OvZTYzixk48Fu+me4FfnbGj6GwvDAjxvHaQCfgZBixm1W9DqR9Eio1GcQNQgnJvy0hwNivmeZsfexojtBLs/AUg52C4n9JWxGNoUI+2amF7QXOWedxfvz5gKnfZVGqcpKo4Bya4gbDVMhOmGncaFyRGoUIpTSux8P5obN7Fed85EA2cJ2NgVmtbFny8usB9gd/vA7h0HdMWFqVDF4+VsmDZp6+6cb2ws6PWkhzRBOZbxE6otlLTSQcrNTR9OKvXDqbawA/I5bbpE8M3Fp6xzuMx5tnnvsozpL9x7iQFe97ph+SOaxjy22wbOfNtOt2I9n5WPnYyWtl+y6KnVbgi0JDxnQzV30FISBoScJHVbskf8knue/BEywS1zqtzPmgmHim8vxbtJM1b1RqY1VJA8f/t6HzWSQuGAdtZ/SrV0VBcpNpPjye8DphDerV1ibTrsP1QVRaic/89w6bY7fM/PKLiuv6VuoWtAwqPgxDCTyFpVcCudorSVcYBTpgHa9a+gPN+cCpQbItzoVxUd0QVQL+oQdyjwdEvdmH6TG4wQAbRhD7IzU6Up8rwhTP9qSukktD7kbH/DPxx6A/GsauPJGxZjF4CHquQWrzMB0nVG8j5Gu7lr5DZvSdK+VS+QmFqmrnPwLMc3qp+yF/Wtk4Fh4Xbn1Xg/22cdCvIrzPGkffNaLX+NImNjpZNmGd9ePSl0mS1rMLHR3uUGkk03ByG8KcYog5YCpS6i6iGQAXPuzER75tQ5z6m2aJHa3VNFC+zOy/reooJBDF2erxoQlF/m491lqNW17yN0EcpDSDt31RcLAc1usfq6VMrsPnBSudTrUYgjO/TJ+q8iWxdqZutUgoDEtBW3anQFnzgPpThvnd0xbmwIYMXguG1zcfdcG/c7BmoJ/kxoYUJqwmmFjFjQWMKY/e61zBle6ch7PfG6vALjLAdLbUzwyaWWjjfMj3m1T4FrBMwTvmgW8rqEcA== 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:(13230032)(1800799016)(366008)(376006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TlCIpUmT1+Vr9j6vMK/cAfo4pyaqvA8xt9BPREBArFH5zliYXmxrNb0diPmNAYY4PRWoP53rNLFr7+pB+NVXNUZO3x31PlEIv6bDZfd5PKJf3EUjMvpyNmSW/TgZLDeWpNkIp3760FQpqtvaAgcciO3OBGIl4d9hj/eEU6j3ukiVPHYeUKIJLQmMC+9px4wJwZ+4ID18AzGtjhiYLGqAKLfrGaToP7bszvLPP6P4UtxavfiFLxQVPvTP8QK3FqVkZ9WcNXMt41lCFmQX1K0t0u3WJyXgVFAh8x75RV8rhlVZIYdWWU612fl0aW74ytfzw0Nro2aIbV1qmL/4BdApCTannNDD9Lh0pS8ElYLZKy9QT0dY29iuc3xXVP/TFtA/0Lbs3pBUsufBAVD6rFpaH53Uz+PIhM+TJaFsIiwbpFOVfVKO2nkJf43yllxR7vG0sZPhMhUFKrG98NIO6bQeCT/sws8zbUc5nxP469CwUbOuFVMDh0MF0pZ4fj/sIBDWmk500WL58Jff5ygRFFh9/dDkM0RizvtsOCx7vPVr1kyK5bV2QpfLrTf5t3I1LpI4bMEVlJ1d47e/FCdWa4+7QQNo/cSb8aOBVFZCHEDrfQQpx6klA0J1++uLcrfF7Lork0hrOglYOyWjfBmKOYpezNJcEWGGqqrjNVKvRWFeu3Az28bw0l8+FvJXn3lHWTk8tePwZWRzQqTdbhCp3CAZ+yho5/UTDMk2+ok3XKXv5GWumT6/cnaQKAdOM32pu83dKiHmow2R/x/CSSEeIgqgSL5R7n/paWBd40qzzvJ8c0LVa7FS6xHy1lzce41w3JQwaJ3arehK8fU1OQrzFhM/9rWlHzEThN2B+FamZIHICxGDII86Wl3RkftOYBKOLCWET6L/brYbnpsoG8jU/3Uj094FGHQJln3TaLgDnJOh1BtuhvK9J1Pt83KEsvy3CWrlptCaa1ZSowTHutMzMX/dBwGnZ/VZsjCy6ufihvStwV+8MxLKiY5v9ZuKmkssFRj1FMb5pfu3sd5IVYPvxGdh5f5NS4j+JAizz7U1vTlAqy/vg1ZLRMEQTr2Sjfw9vXjotYiiGHgQ+mk/O6+ensNQY4WcqFVhV75g3wLIptcqAQiYqZvcyc3KMz5TxrRYD5JweJy61z+h29iaQ8Q/o7twfXFPnKqlDyT4CodRJZsyi2IG6INXmehz+pwmT/AqZmxDb5Zc49BYmpRE09SGsIcexFvv+K6SoP6YlCZM3jucYWVdnfEVqe8BDonho/yV75JzQm92VnudnzWWPALyxdwHKUtZpMMo0VlnS/zqopDxwv1XKSANm3t8tTrGnOiXJTkiMFWP5lPbXF29feGiUGYAlxcOnurPEbJnAKiofZX2sKuhQZBEAToeCvyuy8/XEgjGQcWCimHogU6FimU5BWotNEAJxd2hrQ3QKzjZ+CwmxohmMW20vZCh0L7IpcwCkH9R7RsIFDNHYA+Ks/JCF9oQyLVA0ZjwYrHJCTaJMuTs5migsuFO8cM9z859ez0pQY3mpzMmIbiSjkRT5eV0rT1v2MT/eHEr9Ik0iggyS/9/UyBzvAa0UrHrhMnbhOLCjBRLuMIhWcrH2gr4lVS1BGuP8A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Bd2J8DVtcxU5DChQElMJyTjbJqcplnkZxIJfDxgh7MISqaGMuubSqSc2+t6yziUkN/qnsDn47SZfUPwyABdMvg6Gr/UGyfwrpuy+9TFIVarZd5Buk3BgHnlbPuj3lt+nRzJittEDUAvywDL6SqykNNadswk7Kjx31EF9b8mC0jDZ7hNuB/JGOmM8ZKgnsq24jyUZ50gx0L+Cd4Q7O6g2ARcdYxvAQ7GuPpCNItqX29VNRMkqQpNCuVPmLMcyQj7wD31CnBo71n2PIp0rdDS0mXCAfKL6RMCHG46kAF2wzLjH2mzTzxE2XibBF+eYcXdrp28Zb8PbVVaBEQO/uYMc6KzzZm22dKWoc8tmdnAjiI93US/RG6upyoz3fpR3ovpXqbfDZtSXiD3L9gdFfRl6WTrUJLBDLGazrvluJbcMdXlSY/v0UjHi/nQqsVF3rZHXCBxpA4K4PXMcHpvGXiLuWClhhPp717z4urkgR653I7HZP7vATf+hveOBAvnabno+pqLDdFV98GChT5gd95Q8TMyVzsakaxcZAGCmuDOvHSsP7DbtXRh7g3FFqLSmTeQpUGqSc77Z5GXzMdh88IXAk/dzIipeQkL5vVSCNm0/SPI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 70ad6107-4734-48f6-be9d-08dc8a491fb5 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 19:03:05.0581 (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: f4PEtGC1nO9XZZeKIjrUYMff+EHfeYGOVjX3nFxJmNgDBXPIEhDBtZjKgk7j4gJdaxFZqX9O5KQluEAtwYOvcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4134 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-11_09,2024-06-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=934 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406110130 X-Proofpoint-ORIG-GUID: vixXUBwkKEzCfJgNWkcTxnEfa_qbEg1h X-Proofpoint-GUID: vixXUBwkKEzCfJgNWkcTxnEfa_qbEg1h X-Spam-Status: No, score=-13.7 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Previously it was not supported to generate both CTF and BTF debug info in the same compiler run, as both formats made incompatible changes to the same internal data structures. With the structural change in the prior patches, in particular the guarantee that CTF will always be fully emitted before any BTF translation occurs, there is no longer anything preventing generation of both CTF and BTF at the same time. This patch changes option parsing to allow any combination of -gdwarf, -gctf, and -gbtf at the same time. gcc/ * opts.cc (set_debug_level): Allow any combination of -gdwarf, -gctf and -gbtf to be enabled at the same time. gcc/testsuite/ * gcc.dg/debug/btf/btf-3.c: New test. * gcc.dg/debug/btf/btf-4.c: Likewise. * gcc.dg/debug/btf/btf-5.c: Likewise. --- gcc/opts.cc | 20 +++++--------------- gcc/testsuite/gcc.dg/debug/btf/btf-3.c | 8 ++++++++ gcc/testsuite/gcc.dg/debug/btf/btf-4.c | 8 ++++++++ gcc/testsuite/gcc.dg/debug/btf/btf-5.c | 9 +++++++++ 4 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-3.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-4.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-5.c diff --git a/gcc/opts.cc b/gcc/opts.cc index 1b1b46455af6..7e9f2d91172b 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -3506,21 +3506,11 @@ set_debug_level (uint32_t dinfo, int extended, const char *arg, } else { - /* Make and retain the choice if both CTF and DWARF debug info are to - be generated. */ - if (((dinfo == DWARF2_DEBUG) || (dinfo == CTF_DEBUG)) - && ((opts->x_write_symbols == (DWARF2_DEBUG|CTF_DEBUG)) - || (opts->x_write_symbols == DWARF2_DEBUG) - || (opts->x_write_symbols == CTF_DEBUG))) - { - opts->x_write_symbols |= dinfo; - opts_set->x_write_symbols |= dinfo; - } - /* However, CTF and BTF are not allowed together at this time. */ - else if (((dinfo == DWARF2_DEBUG) || (dinfo == BTF_DEBUG)) - && ((opts->x_write_symbols == (DWARF2_DEBUG|BTF_DEBUG)) - || (opts->x_write_symbols == DWARF2_DEBUG) - || (opts->x_write_symbols == BTF_DEBUG))) + /* Any combination of DWARF, CTF and BTF is allowed. */ + if (((dinfo == DWARF2_DEBUG) || (dinfo == CTF_DEBUG) + || (dinfo == BTF_DEBUG)) + && ((opts->x_write_symbols | (DWARF2_DEBUG | CTF_DEBUG | BTF_DEBUG)) + == (DWARF2_DEBUG | CTF_DEBUG | BTF_DEBUG))) { opts->x_write_symbols |= dinfo; opts_set->x_write_symbols |= dinfo; diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-3.c b/gcc/testsuite/gcc.dg/debug/btf/btf-3.c new file mode 100644 index 000000000000..93c8164a2a54 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-3.c @@ -0,0 +1,8 @@ +/* Verify that BTF debug info can co-exist with DWARF. */ +/* { dg-do compile } */ +/* { dg-options "-gdwarf -gbtf -dA" } */ +/* { dg-final { scan-assembler "0xeb9f.*btf_magic" } } */ +/* { dg-final { scan-assembler "DWARF version number" } } */ + +void func (void) +{ } diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-4.c b/gcc/testsuite/gcc.dg/debug/btf/btf-4.c new file mode 100644 index 000000000000..b087917188bb --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-4.c @@ -0,0 +1,8 @@ +/* Verify that BTF debug info can co-exist with CTF. */ +/* { dg-do compile } */ +/* { dg-options "-gctf -gbtf -dA" } */ +/* { dg-final { scan-assembler "0xeb9f.*btf_magic" } } */ +/* { dg-final { scan-assembler "0xdff2.*CTF preamble magic number" } } */ + +void func (void) +{ } diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-5.c b/gcc/testsuite/gcc.dg/debug/btf/btf-5.c new file mode 100644 index 000000000000..45267b5fc422 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-5.c @@ -0,0 +1,9 @@ +/* Verify that BTF, CTF and DWARF can all co-exist happily. */ +/* { dg-do compile } */ +/* { dg-options "-gctf -gbtf -gdwarf -dA" } */ +/* { dg-final { scan-assembler "0xeb9f.*btf_magic" } } */ +/* { dg-final { scan-assembler "0xdff2.*CTF preamble magic number" } } */ +/* { dg-final { scan-assembler "DWARF version number" } } */ + +void func (void) +{ }