From patchwork Wed Oct 30 18:31:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 99837 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 765423857B94 for ; Wed, 30 Oct 2024 18:32:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 7065C385841E for ; Wed, 30 Oct 2024 18:32:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7065C385841E 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 7065C385841E Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313133; cv=pass; b=gRNBM15yvuYeQaGq2nZJOgCHvvfKugODoICLobsHScJO6FW44UNXgl01+JimMJj82BK6SuoFstu49WU77kyYijhp4mi/z6oz0PgKr04odg3glW/pRPwiYGcUA27uvAUp918FGy/Zezao8jKD4gQBZELdl5An/6fLvzTqOIaCuZA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313133; c=relaxed/simple; bh=7RwnuR4MSWEEeoTBOlsHsuU/+6m/DucwNqSJkI4u5Bg=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=QQxY7L4FDQYQlfniGi4bdcJ0xPeJn4QTmybc2tmqhItBcrLNAD23WuFHeNFiirTICTQ0AAi2fUkSnQSZ3YTzQu19RRUldEocVvP/NKVeLxdJ1MORnR52Wi8D0TbqQydyW+6QR0F5SMxJt0I1UrbkfVV8UFDcbyXZBpLnSfspBak= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49UGXZa2017453; Wed, 30 Oct 2024 18:32:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=Z8fmpbIUaoAzJ0b7JOYoxqQkOyM6PAdXZyG9hnDpuCA=; b= e3XwoxZ/jMox4uWH+Mdx3fy0HYBeCJlPVwsmi7ojWpo1Z+VezeGbZWlH+3VmwLUY FLEr9/ejU6fvt3tU2lew718Z7U4Co/B2C26TKnvXh0g7j3XBju5CYMBZNbNh+SDV D4sioqtQkEc7ZDhJro7YuO2JnVLZH38zpP/zEqt1gVLllCZmkdr/QwpKk0KMzaLe 7M8ruXeJrFt91AbRNhXllsMeYJxrYODemME8mP7fAMuRf/XqCb96otkTbh/ovGA4 vPu/II73MpOYRwMwoWiH+oepICXM0802+Sm76OO1uGXCa2be0oIEtRhR3Svt96r7 OhWscZleA6NA8mAX6IApeQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdxrr3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:09 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49UGuvgj040314; Wed, 30 Oct 2024 18:32:08 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42hnaqxyw2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PCfR6AvRwY2a7Rqbrl7Qubv0WxqbvD8ME4jf3F2qLRAjV6aCNGoOkaFPuGIa8RKm+/u1iS7gA2bJavGPt17omOjcKWxn/Uq27n/KNAjqCE5hip10iLMkJhWwnvohrWRrszxkAYVBDYnwY8Ni2JO3JDhJVIzMNjD6A+eNolO1ro2NBhUcaM6q/9R2OaslNzExSsGVhFq8aNDCd4JCaszonJCh4ejhh7hC+JOyTHIUvq5LlvA2xwE6GKrNbMx4PtmalmAV1eLQYWmEUKhb1MOUnMfy15fdeYv3oEp5Od03JLe/eRbmJvThUwrmWwpD92jX3JpJEpcp5DaUW/r9HMEnCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z8fmpbIUaoAzJ0b7JOYoxqQkOyM6PAdXZyG9hnDpuCA=; b=jeHtQS6IS+Vw06nnBG3gVjLlEUtSZsLgRoW4lV6P1Ul16xwPzXzsZxKcGh7Ea8kcAl0A8DuvMtV9rrK3tlnlF9Ndkn1kGOg7yLdj7BcRI/V83FbZ7+1NMTDw54ycjoz1hZm1/vE8BkTEE1TgsRTy8eGG8rITTAIIIdS9gnC4kEgHRbJNvwxO9bdYVmKXUN67eMHO7lJOiloOQvzEm3N8D8n057c2DPJ8zx6NOnSfTo3DsNG3WZK3xpYtQ3at8vQlgXUmbvVT/Y5HdXbitq4o7OtGrCPQjvwXbOV+ZgTcqp2ufUzSNQHVPHKKNEkvs2hmJCrMncC1V+Cy7jAY+vBtSg== 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=Z8fmpbIUaoAzJ0b7JOYoxqQkOyM6PAdXZyG9hnDpuCA=; b=RvjkEKCiDhvzuIqKBVWy/9j21SM90+//yorCZF2svfCZgEGjNvobhqm7tQqoFG4aMnlXlmWcWQnOfQGEOuDNHTlCdB+IlK1Sz+5ti7n05ZxqfqYuZP9/dhP3hP9BfVRhuZYyDg/yonaPJWx+M80VYVTEnU2QSuK7GieumDaYFIU= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by DM4PR10MB5990.namprd10.prod.outlook.com (2603:10b6:8:b2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Wed, 30 Oct 2024 18:32:05 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%4]) with mapi id 15.20.8093.024; Wed, 30 Oct 2024 18:32:05 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, yonghong.song@linux.dev Subject: [PATCH 1/5] c-family: add btf_type_tag and btf_decl_tag attributes Date: Wed, 30 Oct 2024 11:31:51 -0700 Message-ID: <20241030183155.2038501-2-david.faust@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241030183155.2038501-1-david.faust@oracle.com> References: <20241030183155.2038501-1-david.faust@oracle.com> X-ClientProxiedBy: MW4PR04CA0251.namprd04.prod.outlook.com (2603:10b6:303:88::16) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|DM4PR10MB5990:EE_ X-MS-Office365-Filtering-Correlation-Id: edc2a2bc-909b-4935-d783-08dcf9112757 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: 9dLt2zY1lyCbvpgc8c8t83fvPwwL7DGxUd1fXuXWnEAUUxprSexI7Hk0uNHimy/aOs00tF7qzjoPhEnX8Nj2igdU43U8FgkB9qjnZskCR9HVZBeTK5foAGlbRa7wv0wRfPz61yOvqN5i6Co+cUdl4yjZTtn3AJ8Z5Q7d2/rbHEu4Ntkr0DeBcXm25gSdqQDNZDtjqZorBThR3VNVRmK63pbHNeqDwE9H1Ge67P+IzvTyj4MKBsKflM9rm7+I31Dog9hBZ8BQBL/U/hCScX33cc4lIYFYG+qNTpNiaEGYC7ghRWQ/bRXTMfooSU4qfi81gZEYhNqKYtafIGRPWBtDxYepKgrdkCyZNHJphmcbID3uoBkuTpQYRNTJLCQVl/OXRzFFFlqykZ2tx3yAj2ibbt2EsF0MbYMNnt8wQDNnDEX3bXb8ugG/ryPkz8ps6cnFVkFltFKesjT1MmlRlTXBnXBlEq5IJew34K54HSVxPL1yuABktB8cTaPzk3ITYE1zB9oJmn5CzgAdnDJHRztpM+XoDFWD1Q4Y67fpz3ryFtswUuBOvpe6VP8Zsi5BnysuTu8varFgLPh2MH24QUzYQS5JJKBFJAspU0YVUZy7xKAIR0DFu5DpBJyseute0YbfzNaL1fCIl0naQGMV27Kf39yD9kDekrbCW8xKJmnYnzd1vMO1Jgg9XxEyRJgjIfS5NuYmsCJ3IxwaFCu1+xMU1dYvHHOzzx9dOdSV7jENzr33Uk1mWEWKgLYsFPxdk9Joemwda9vTgnFVtZ4RL7odJXnb+xpfduh91VIbqN1fCUbgkgaj2Vy+qSWE2mV4BcC9YcJyzCLA4IBkXqrgB9s+5CE0uooZyO67cKBWdpejFBm0t8ndfw2dQiHpX4TT3zq5Q8WwqAst0RgTGSp01B2955Oo+Tin5wJShc+De3GZo3rAJ05c4idHBIXhwGfaJgTOrJap87KjPUsmuhgxLRR8EMgZb+b4BSpys4gG603K5SS5sFMK/Ju1Tuf3gpJdA9ZmkGHC5+MQmzqslKB7Gg/L9PH0x57bOxmjy2Mh8BtsK1pMDjLo7Q4fftxti2ude9gPP7JNGKsJCt28XV3RwKnevk4tPBQB2Sb2I6SX+YV4+UMJIEF+bsHD/rLFt1zuyuMLd3X/Kj6k4Kpf5OQWxnOI2aDxBbnaN7/XqjihuSiNYwHtCPG5QpF/bM0ZpCRJicWZPxA7Dh6DeXVe+ZMdatBgOwF30/SMi/ECpjj18AOHWOdmUDC2cHegggt4PaTPcO9g+JkPmHLbY5kOEX6eLJ2X2kqbdFD0O+ckTKyj92VSWXzmOC0n1gExoUd+0p3HmBQg X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR10MB7953.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(366016)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 81+BVX2pWPkhzmK7J3bLcwat627tChiQim3bvJfBhNTzG+EV+cVaFnp73+vH6wvw3r/KQLz18tjKUaA39+eXeVdFs9BUrqp97k8cwqoT5mgZocAfMEfNiiddxwUUsGvMOrmaTCmPA4WJXHuNdVvvla92V0vTfVKPedyFzAZfzwqDerKAN5ljOV4nOSIQWw91XD+mYnwU0SQGIsAblXW3+aVlfY5NYZOBib5rOJ/07E3xL97V93fFIgTIuQjLa196t6IXenoF6oTWOFGjL/VlKaAIOBBh+vGZcgP5Bl23HR328lxIDJSKv2E29cW1N5257g7BYe/gFO85+MoROD5NPUFrOaN9y0P9nJlKW1Fh70CLhr1MbjRNlqERHDa/W9bqKAVKkWO7xmO6FSbyucWrR52ETqwuN50Im5PsoSEnjAEfwTFSxwwCeF5sehMaHF1+8helKDQ43huy6HFtaYzKGs/jNL3RUMUnt7aMsTnQja9APlWSuV+E9NhPjihDRXG08ek3y8o0f1T8FtskI1WMP7E3i6r+Pqka0WRcHez53p9MKhbRjpmO4y6+RTuPufh+4O4nN5SCNgNYl/F++hShPEFCoqsv5brna5d1F+ApHU/qfn2M19IzqQJPdWtaCVy1xT7e0gum/WAMrmwXaRauEStt5UcamY/H77Lt5sdlKBy0+jAMAmDY8DaaR5rs5Tf0U6aREZK/ZxX+HeSPjhIy1rtQTcXTpbUADW7Y6kEj2Jxcxrs/m62w8F/y7Mpt8GIANIrXAQ0CJFcVcBZomDnC5if7/hispn4DGK5VV+9tQ23/3Ao5Dttd1gzK/BBhJH5TW3+PxD+JzKuQjVKXIT5QQiPjxbFXo/llFiYyo+a7WwrxohRpHzDxbNs85wdUaAhLh8XUAhFi7+NU9iEYWVNCcV4JEPwauIK6SsT1OOeAzL3H1+H/AyZvI95yEaZ8PvRp9fPPXX2SXU7zC7tMWUmhr0657grGRq8/Znyo6lG1iPR31YY8z4YboxwETqAdxPLQ9y8pTof4tc9ptlKUZ5UiWXAG87A3adcy9eT/44RERdYWcgoZrlHrNUqTc3FT4DijJpz1BclE06fYgdPpXCzm3edh3vR9Hi8cp6NWHZUQQImLCJ2CPk+vTrfAq6LEi+SwGfw3vs8JV107jP+RhqPLjFolI8d4E8W4bdqH6zHalmmgjZCW+argZwzvln9o19x3pUaCUL1zPkl3CHBrXlp5e3No1vuWDIg8DL8CgsS4LwYBxvYgzMxHEhASvnW8wG+z+W3YTXyAONE7ULYKjr9GdA+HgjLeoCkTIeu27mnZXZ/7/mke5YdkUzrU/G+DRqtd81g9m+lKqSwPJv4YhtI3aiH+Wj3eHqVQlAgHqiGbjGDEkibosAljLyLLGjiCbgxeRSZM5jwDoh8BmHjJRNhx+YdUwF2LTeDrA4q0ceK5GCD3ztdO8KXwXHAUIVyn2+QUaW97oULNkHO14B1NpIE8WjkLr+uMoF3y4X7hd/9RC2MAJzzCk7C2nbRrN3E48oY8PxzD8v9zcYVr8dNmcgLhuoMuozixsqiqU33yvg67rVyOxUfV9FBB1uKIlJrdr5kn/aX6SXRKTqYJJB/56/YDig== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: WMyeCBecUHFoz8b5tDdg8/pDK8gnMxvr9wKgFf8DeommN8rbw0eTLLiMIMTX23cMafvmbvi3uaCAhFcTlnmh0txVKSBfEg5UzJDTyCb+589YYXU+mqdz2bobv8M8CePs7/Ld8M+yurWzm9kQjsgPlcyvDoteJgl/s3znnWEIWJRgTNE7hJNw+CQKYsE9a4alsDc6LvIUPYBu/vws1QspgMOo/Cmb7dkpg7U4NISTF3ihKAr3apzRoX3E4wQauBv5k88JTS5sYImsfL1z0XKsx7MX8S54Gmed9E7zg2Pxk/lZedqXxwKsRnMd23MP7K/LA0PzCCHvMNplLsbndiS0D0sTnPSTbWC6+Spj1BGss03I0DjbFv9J0EmCFX3qfr7vQaJ6vH4pRac98k03vRGwlbbOR4E7JG6piaLpMNBUDjuuUfJjvuZz5QAjxnOaaI9gF408XuFTJ32DEvxG+w0gL+tMwTXsLSK3M2ssGkkM6M97m6q/1MLJXDjzNf85JwM8Ks/IO84/ffcSmDApGrR+JHxLJeN5upXybgOpMvFegjhPOZe9ZUJK4h4E5h+dVeTnoWOg71R9gvDixu9aDugwNEdN0ysBLxCeWb1W0mmGHnU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: edc2a2bc-909b-4935-d783-08dcf9112757 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 18:32:05.1629 (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: OC6FS/dNgEQtXa+Euc3EnwAGddtrVoqPJMSR4yUuTAP/uTm5ox/Wr+mUH+ipMbunqIzDNYXl9k2IEnj2IYm7Dw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB5990 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-30_14,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 adultscore=0 mlxlogscore=951 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410300145 X-Proofpoint-GUID: KUIeDq8bRbbEHUpPDuAx8PCR357HnL8t X-Proofpoint-ORIG-GUID: KUIeDq8bRbbEHUpPDuAx8PCR357HnL8t X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Add two new c-family attributes, "btf_decl_tag" and "btf_type_tag" along with a simple shared handler for them. gcc/c-family/ * c-attribs.cc (c_common_attribute_table): Add btf_decl_tag and btf_type_tag attributes. (handle_btf_tag_attribute): New handler for both new attributes. --- gcc/c-family/c-attribs.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 4dd2eecbea5..76374413f9e 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -187,6 +187,8 @@ static tree handle_fd_arg_attribute (tree *, tree, tree, int, bool *); static tree handle_flag_enum_attribute (tree *, tree, tree, int, bool *); static tree handle_null_terminated_string_arg_attribute (tree *, tree, tree, int, bool *); +static tree handle_btf_tag_attribute (tree *, tree, tree, int, bool *); + /* Helper to define attribute exclusions. */ #define ATTR_EXCL(name, function, type, variable) \ { name, function, type, variable } @@ -635,7 +637,11 @@ const struct attribute_spec c_common_gnu_attributes[] = { "flag_enum", 0, 0, false, true, false, false, handle_flag_enum_attribute, NULL }, { "null_terminated_string_arg", 1, 1, false, true, true, false, - handle_null_terminated_string_arg_attribute, NULL} + handle_null_terminated_string_arg_attribute, NULL}, + { "btf_type_tag", 1, 1, false, true, false, false, + handle_btf_tag_attribute, NULL}, + { "btf_decl_tag", 1, 1, true, false, false, false, + handle_btf_tag_attribute, NULL} }; const struct scoped_attribute_specs c_common_gnu_attribute_table = @@ -5069,6 +5075,23 @@ handle_null_terminated_string_arg_attribute (tree *node, tree name, tree args, return NULL_TREE; } +/* Handle the "btf_decl_tag" and "btf_type_tag" attributes. */ + +static tree +handle_btf_tag_attribute (tree * ARG_UNUSED (node), tree name, tree args, + int ARG_UNUSED (flags), bool *no_add_attrs) +{ + if (!args) + *no_add_attrs = true; + else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST) + { + error ("%qE attribute requires a string", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* Handle the "nonstring" variable attribute. */ static tree From patchwork Wed Oct 30 18:31:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 99840 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C86F53857B84 for ; Wed, 30 Oct 2024 18:33:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 2A8C43857C5F for ; Wed, 30 Oct 2024 18:32:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A8C43857C5F 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 2A8C43857C5F Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313140; cv=pass; b=afWWC2c2VE1R7Ml2CLvUWyM3/3zEWtiIZUNNDETfsaVlq9Q71cAR14rk1hY5i2craGKMnTS4WeGpb+Q09UXl+HWuCDG12MeUMBIEmOokQTaMPjAKqsDwsaxJc33qtA2HZMk+zKAv3S8ZGUzPrwiAWRQ3Pr4t111yaOUqbPSXVvA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313140; c=relaxed/simple; bh=5HQSkIAJ8B+M9UYvEU7nukkSx9c4uJf4CVeDrXv0Ayw=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=Zpsye0snjLZV0PDgp6vnash+S1DM0nzw2Q7GX1d44yYtKs357As+n5gwTB7npQSbIrfp/4/dWdPsQ7UC9DaqmCEx/OIP5kXn0Q/3ws66J2OfZ9Nw3HqldZSZPqoo0/1yD9CJQZKa1M+z4dJJZWbch+iW+NNDCCXXgSArK7RUsrE= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49UGXbUf029420; Wed, 30 Oct 2024 18:32:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=Gn+Q5wb29vTk28TasyNBUbGx6LaFnTurT0Ve+4iQ+MA=; b= cK8OzUHg4F0dhdcNcKJf0t1R7jJmv8L+1lSR5Xh4AMKu9t7T5NsGFzwbkJ5LmIj8 cmmE64Y7BHGXKItry9z6w/b2LGt8EyARy1ChII3Cn7FbJ1HGj98/zZThOreGW0Ah jphTOaDQuyavm1Rne/S0PPOPc53DNlrdLfXoMI8KCeiFTt3PLUSUt7gNz4IuTkij 5aJagc0TdmtjlGOqvoZwyWCjzD4gp+E1r/3bKX53jplenzDtfiIK+rIHhtzO6M54 qwqCVM9/VLQeQQK4m5DEAiqiXH6GFmRE1OtyHyU+xX/FcFNsp2xjnVhxsj9R2MFu ocnwpeIAq5TKa+zNKZ4NEw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grc90r1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:13 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49UHsrem040543; Wed, 30 Oct 2024 18:32:13 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2174.outbound.protection.outlook.com [104.47.56.174]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42hnaqxyya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PgdSyPgUK+36CMXH5tIaUUWfHgm4yO4cWqdAWB7NQJD4dtXII+nlKTYJN1VqjFPIzJWpJ9Cm4G+gVyM3bkUaWX5woYH2pf+JdOp/hj85+F0JW4SK6N8BF++83vGB+LU2ED06gKqERO4wLdJ1StTlDPHsxvqpPcek+Zoh+9cnC0XF3W+FKe4C3/OEJeVwccdVYb0NBOfCUOWWClATvdLbwxeYnJN6CY8MpTUbVW9QUA0qYlC0XlnyVFuLr63wT9354ftzKFx6V2icFyJVlMMqggimMuMt4R13yjRcJDtJy/ByUY5xMWUKp5/3UGPB0fGESd3wLIkQ4pgNN0Wgpd5PdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Gn+Q5wb29vTk28TasyNBUbGx6LaFnTurT0Ve+4iQ+MA=; b=UQfgdqSPPCjZ3VpfiHBvvnac36jbtV7ojJWLc7PA10Hm1Oa4G+zsaoVeQjhxSCUXjs2/YQkgiD6i4sIWR6ntNPyW0v7nU2rPG0bIQBPd/nvEUL0eefypstJe4MhZuYRtw8TIym6iS0qGyEPkr1azAgYu1oPOlUtHZk4PKQGXuVlSTzvuD17nuEw2Xwu5nJ60QOh/8oVvV0NqwimYKcR7iqTew5iG03t7RJWNK02B6L4wN+k0NuS6wQMvlTj4KqGXKbBpgP64dEka8B9jvtLJnaumi5lrlIUafZpP1rXdXvtWaxesKBvT8aV3T3b0mDwQKUk18oc+xCqY0Gdg1jq4bg== 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=Gn+Q5wb29vTk28TasyNBUbGx6LaFnTurT0Ve+4iQ+MA=; b=tzn56ZAQxln+JwOru/Pte0yDY5mgrlE/9mWO14Y08IT0Xetb3t/XjHz1jbcqd9ZAYEYNUWBJf/AvCv9J2hplFygdtd3zmjGgOvKV30ymDeGUeaBQ/NVKkxv66PurmkdTdzSa8mblghiw3qKRoOYPGTl0S5+iL3SeQ209+lH8ZzI= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by SJ0PR10MB4672.namprd10.prod.outlook.com (2603:10b6:a03:2af::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Wed, 30 Oct 2024 18:32:09 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%4]) with mapi id 15.20.8093.024; Wed, 30 Oct 2024 18:32:08 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, yonghong.song@linux.dev Subject: [PATCH 2/5] dwarf: create annotation DIEs for btf tags Date: Wed, 30 Oct 2024 11:31:52 -0700 Message-ID: <20241030183155.2038501-3-david.faust@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241030183155.2038501-1-david.faust@oracle.com> References: <20241030183155.2038501-1-david.faust@oracle.com> X-ClientProxiedBy: MW2PR2101CA0030.namprd21.prod.outlook.com (2603:10b6:302:1::43) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|SJ0PR10MB4672:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f3449af-eafa-477f-2a91-08dcf911291d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: yXsW1+ti7rY8FEnUgWVkFFrzCn8kzZ5vSSC7/2QX7Na7ruVvDZ22Pnu4IdVb+2B8MW0dag0HNTUTVvBSP7HwaUiIsf1xQ5g+LC0DZJvdW8OB1TL/MLcbQCgqwCsE2n1aLfTIa/FNRyWUG1VHItHG8zROEcDQChxnhWTzkS3pYarBRL7F8vDz+N3fvPtRCmbulPOXBUlWcI6sXTGS2uUAvkP/9UWamcD/xi8WKiebygimwKGGUz0F1M9GhuFXpDaIqMz9vNaZ5Nhu8aPFVbSGrmy/5JwScQq6S3Tv8Kn4d/+vldnSoBoGxL6n6WBKaLiGwCRbjrzEcY75X94a+alDl9yaIlmojOsBLuJxDmcHdhrUk6RecXnMmUvz8tYbLv/uABkJYAWBiuKWw1pdrKP3OvxObtq5klmOcQdWT/dqR6gbOWplMlp8qZR51/pnNfoW0soyvhNcUEo7h5QlAnEiSc2LF9TwkvelWWXnpCiw8t16Tj8AbTD+U+W0MtPSuwRTV89olR600V/uPViuN79vb4A1xuny8AQauTSdWc63gFV/p0lGmStRP9G8KYdyJvmpSUH1FhKZPqcVvd7Lb88muon1a2g9PFqMj4IYVhWaIefEhIlZ7PDflZhcMN0nR1eAGjT4cqJY2vvpFUe89QKbQLsl37DxiTEtoA6oC95n3rcqQ9nXihOIsglXnT4GGiotD9RMZ92Zv3sAanuHMCN5pffdm5PZProfV8SgSQ8JZQ3hbf6kTRH+ttyrN9I8CB5yEaqRWrRyfeVmufsbL9Ylg1MFrmWauMEGVpALDeFv4q10+gQ/oZ81LHzexBcHdPInJuwfcX319cZJ363iP9mzIN+zs8M7qGBGabtJsP34prwimB3jHXiHiSn4yrTg1KJT962NoOaSY2jCpJPm0BEgC5wImB1wVbkdpzVC/D5nDsBJbsYWQWyX1LoQ9WON8qkuP3D2aoa+ZVIKu5L9VplHqz53V6webI8tZkImJd+o39TLpqbVQdR0/XXT/RfXQKNnuobTbCUuETC6Yp35MLfyqchQRGCtsCtg8Wk3KXzIRO6frBXfEKeAIiuIetFXFQ+pDw70fcj3jFhy9e7q3peUn+si4zi03jksp1nSKB2+YFa56eTxTvOu5X6o9ru2uqAMB7xs0P/rJyRwBh+bRDGehCXnJxDdlYEGfO6/jchISRQc33NHAHOn2XLjPUV+DRigS50+gYuAZB7rXY8aX06Hl4WZmgwjS2xOIk4na5y7D8SC/4CB1guS16lw9IJ2a9/aFSlnoMGNdN4Q7XlcmBfjoA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR10MB7953.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CHGUdu+KJ2HXQcpuGo6crGf7fEmkLWHqpHTKyI3TPZBkKv4Yy43dO/sMCJi3dbGNYNRfWs2BEtpMr6OkCAGUWBAw9afyvUV+KVnGSh78rRj/vQ4JqMkk/mihoq8NB+OCds4d5oDD2rIqIm8nNgrB4ecAciH7Wcyuigi8aHteqKeB8ieNbgA9WF733oxivPSv/XJ+CrF1c8KA/+Sfi7B1nBmrT5oYuwen6GaN59oRU8uLDwUFkcqpVUX/KdigF+fxUsq0ZA4uTQmTz14K8+bsoJDXGpKHIQiyWzIkH0h8w9pA0v+BaxOHqwwIf5UXsO1VWNPolxKo8RRerZX8AUVQ6uOsfM8/cjQS6EWeCvqPTcy49cFfq2CIljb4w6EzPjdeFfRmAShtb8asnmq5zJsn3OdTUWI/1OdBGRGA6M5pq4uObzCmh0gvgnPouaZnosSxKsvjz4m/rvqjnX+xYI6d96qhyGDL1n5QC3Knkumn39e31qkuRSLCMSS1mY+1lH5Wb8F2wbH153OoQnO59zEooa02+3NHRWcojb6Djvh4k7yUVUO0O0RdNplGE6TurBgzXbP3R437CHy7hKeuq2drG0xeMPqHg/L0P9+v2aVF9VN2V3vmN7NCFnjd/z7L8sp7Y2mKK9a4K2hYjZxPdhl/c+otsWPCzBkfuuiFLm2HhyKfV2/4mYyWWtc3RTOy7rpYe8T2Jq7qhQ3MrKq8LEJOIGXiGQVIYsKLJq+/XDW/3Y8zUnE/OxS0G0aHMEJ3MGez/S5/ydpSZn/mIHRmxtsfDj6hcPkpgh/YQrvtrtNXKqZABVbx3ConEadIz7raraXs23h/2XEbbKoZlvcGX191uemHUL4HcmrpgJzt27yeDupC7uCC+FAY2+PAFrgOP8K8QNx6amnGsrRlA4fLJGFLU6srJvgwDmlGYCg7C2N517LK82mfjZMDPPtoUouhQAPMJZW+Frzcif730t+c3j9wfceNsysbyCRkF5OkxwpNNA+UVCNNsjIYKAPxHPRDp6Kmt6jfAqPdzBjzrNt2vDJ11WbqG6hlnCLo3g9aBYNDpkYqoAmyT+Z0iYzfq/fIdRFGWs798mpju8fvOCe3y6K4Pvw3aPiTTdbaYP1sp2nwgV2KPH1U4NBj42/HhmX+KmYeByt+cJZ5ngBuGexPboPr8l5chrsS+QlgJTMVcRWbONxdFQycYObLBQqdIXLflaxQCCSUBbu1c1xkltmmY3kjR26y6aK2sInjIQKx6HYZ9CXB/yWIT28qretgxUKTBLNBmfwgioaB7q2wv4Y3jWub7MPJ9mv8xqQYmzhxrmOT0h79nTUyvUjXU+sccbDgmYBBmCD5GlAY+G4Ry51AtuQ1Bz4cchqWLPn98RTTMsjACYCwRqdgZogu67KTkEER8W7RFHGNTxzh+Bf+5zNiozu66UqXlrwJn1Tno6zAqXG5ew/Py7Lo8XKj0ThzNnyHICywB37PkF8Vi+1zc1eaBrakCRbNIiu9PWZCydCzV1fk+u2yQi73uiaWxXAbP/GlgrCR+acnWgaqWU/xTdB3FOAkK3KGyOShYeuPLdKwZtEsdU8gQWEbCVjuFXadRBo15qG+72elaK0YxCnV0tF9as7x+A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: bF1VRwsLGhAAK10IOorvCHFEGPp85uszC8WMAH9XIQw42Dl8h+Z7LRn8u9pvsatxM8xRPIQ318Ze++b/U5CEb0Fgq4gQssuTDckoTlnpepUXky9K46GhdxzZKWnnC1/IFxr2jwLAMwngqM7QpjvbZZvnzJ1qTM6BGMBHa3UQZTdx9c7DFWRs9YGNzqA+5gGwhPao5X1LdepRtOzxIitzySkeFjbDNDJLN2uwC0OEVC5ULvSofFbaBHECkZmMYpPs0caGuJNnmGOSjmgm/uMqHEQziryn3fsbbH6dsZXFbd0Y/J/hDH/PjGbtM5meMsFkKkJLXuZSTozB2puXKF5rRYXcm2oT5dGyHAaScUpcTLjNm5qpXGNTrpo8bJ3icHwQZAg4rCYAtP0RNBG7Iz8aRJx3RKzWOGanOPHyscrz4Pf+v0MdVCiQNFwJiAO3N5qH11wTqQmljhUEz4Mf5VbShoZgehpEAtCbIYeeh0YNQL6EN/tlso6dzcJdzYsKgHnnnbsyKv+bTi/Xj7U96BrkxOCAqr1pe50h2f+Pz3d8jjzrRtLCMADW2/QPL96241dQxwoFDvzdw9EkVylJx2OGWz9cnmOCyY9DZdM6C8GD9WQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f3449af-eafa-477f-2a91-08dcf911291d X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 18:32:08.1532 (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: N8b94zpNnmRhnKjTXvxGwUK1RD7vyO1ZIEo7WBgKh84jBHVRhKuvjlC0P5s3Tx2fuEngt3W7OnMa812dfk3vMg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4672 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-30_14,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410300145 X-Proofpoint-GUID: 3nEHNpY-ZYbp30xzgcNiLqoH8Jn3g2F9 X-Proofpoint-ORIG-GUID: 3nEHNpY-ZYbp30xzgcNiLqoH8Jn3g2F9 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org The btf_decl_tag and btf_type_tag attributes provide a means to annotate declarations and types respectively with arbitrary user provided strings. These strings are recorded in debug information for post-compilation uses, and despite the name they are meant to be recorded in DWARF as well as BTF. New DWARF extensions DW_TAG_GNU_annotation and DW_AT_GNU_annotation are used to represent these user annotations in DWARF. This patch introduces the new DWARF extension DIE and attribute, and generates them as necessary to represent user annotations from btf_decl_tag and btf_type_tag. The format of the new DIE is as follows: DW_TAG_GNU_annotation DW_AT_name: "btf_decl_tag" or "btf_type_tag" DW_AT_const_value: DW_AT_GNU_annotation: DW_AT_GNU_annotation is a new attribute extension used to refer to these new annotation DIEs. If non-null in any given declaration or type DIE, it is a reference to a DW_TAG_GNU_annotation DIE holding an annotation for that declaration or type. In addition, the DW_TAG_GNU_annotation DIEs may also have a non-null DW_AT_GNU_annotation, referring to another annotation DIE. This allows chains of annotation DIEs to be formed, such as in the case where a single declaration has multiple instances of btf_decl_tag with different string annotations. gcc/ * dwarf2out.cc (struct annotation_node, struct annotation_node_hasher) (btf_tag_htab): New ancillary structures and hash table. (annotation_node_hasher::hash, annotation_node_hasher::equal): New. (hash_btf_tag, gen_btf_tag_dies, gen_btf_type_tag_dies) (gen_btf_decl_tag_dies): New functions. (modified_type_die): Handle btf_type_tag attribute. (gen_formal_parameter_die): Call gen_btf_decl_tags for the parameter. (gen_decl_die): Call gen_btf_decl_tags for the decl. (dwarf2out_early_finish): Empty btf_tag_htab hash table. (dwarf2out_cc_finalize): Delete btf_tag_htab hash table. include/ * dwarf2.def (DW_TAG_GNU_annotation): New DWARF extension. (DW_AT_GNU_annotation): Likewise. gcc/testsuite/ * gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-1.c: New test. * gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-2.c: New test. * gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-3.c: New test. * gcc.dg/debug/dwarf2/dwarf-btf-type-tag-1.c: New test. * gcc.dg/debug/dwarf2/dwarf-btf-type-tag-2.c: New test. * gcc.dg/debug/dwarf2/dwarf-btf-type-tag-3.c: New test. --- gcc/dwarf2out.cc | 253 +++++++++++++++++- .../debug/dwarf2/dwarf-btf-decl-tag-1.c | 11 + .../debug/dwarf2/dwarf-btf-decl-tag-2.c | 25 ++ .../debug/dwarf2/dwarf-btf-decl-tag-3.c | 21 ++ .../debug/dwarf2/dwarf-btf-type-tag-1.c | 10 + .../debug/dwarf2/dwarf-btf-type-tag-2.c | 31 +++ .../debug/dwarf2/dwarf-btf-type-tag-3.c | 15 ++ include/dwarf2.def | 4 + 8 files changed, 366 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-2.c create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-3.c create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-2.c create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-3.c diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 38aedb64470..9f95539062c 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -3696,6 +3696,32 @@ static bool frame_pointer_fb_offset_valid; static vec base_types; +/* A cached btf_type_tag or btf_decl_tag user annotation. */ +struct GTY ((for_user)) annotation_node +{ + const char *name; + const char *value; + hashval_t hash; + dw_die_ref die; + struct annotation_node *next; +}; + +struct annotation_node_hasher : ggc_ptr_hash +{ + typedef const struct annotation_node *compare_type; + + static hashval_t hash (struct annotation_node *); + static bool equal (const struct annotation_node *, + const struct annotation_node *); +}; + +/* A hash table of tag annotation nodes for btf_type_tag and btf_decl_tag C + attributes. DIEs for these user annotations may be reused if they are + structurally equivalent; this hash table is used to ensure the DIEs are + reused wherever possible. */ +static GTY (()) hash_table *btf_tag_htab; + + /* Flags to represent a set of attribute classes for attributes that represent a scalar value (bounds, pointers, ...). */ enum dw_scalar_form @@ -13649,6 +13675,168 @@ long_double_as_float128 (tree type) return NULL_TREE; } + +hashval_t +annotation_node_hasher::hash (struct annotation_node *node) +{ + return node->hash; +} + +bool +annotation_node_hasher::equal (const struct annotation_node *node1, + const struct annotation_node *node2) +{ + return (node1->hash == node2->hash); +} + +/* Return an appropriate entry in the btf tag hash table for a given btf tag. + If a structurally equivalent tag (one with the same name, value, and + subsequent chain of further tags) has already been processed, then the + existing entry for that tag is returned and should be reused. + Otherwise, a new entry is added to the hash table and returned. */ + +static struct annotation_node * +hash_btf_tag (tree attr) +{ + if (attr == NULL_TREE || TREE_CODE (attr) != TREE_LIST) + return NULL; + + if (!btf_tag_htab) + btf_tag_htab = hash_table::create_ggc (10); + + const char * name = IDENTIFIER_POINTER (get_attribute_name (attr)); + const char * value = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))); + tree chain = lookup_attribute (name, TREE_CHAIN (attr)); + + /* Hash for one tag depends on hash of next tag in the chain, because + the chain is part of structural equivalence. */ + struct annotation_node *chain_node = hash_btf_tag (chain); + gcc_checking_assert (chain == NULL_TREE || chain_node != NULL); + + /* Skip any non-btf-tag attributes that might be in the chain. */ + if (strcmp (name, "btf_type_tag") != 0 && strcmp (name, "btf_decl_tag") != 0) + return chain_node; + + /* Hash for a given tag is determined by the name, value, and chain of + further tags. */ + inchash::hash h; + h.merge_hash (htab_hash_string (name)); + h.merge_hash (htab_hash_string (value)); + h.merge_hash (chain_node ? chain_node->hash : 0); + + struct annotation_node node; + node.name = name; + node.value = value; + node.hash = h.end (); + node.next = chain_node; + + struct annotation_node **slot = btf_tag_htab->find_slot (&node, INSERT); + if (*slot == NULL) + { + /* Create new htab entry for this annotation. */ + struct annotation_node *new_slot + = ggc_cleared_alloc (); + new_slot->name = name; + new_slot->value = value; + new_slot->hash = node.hash; + new_slot->next = chain_node; + + *slot = new_slot; + return new_slot; + } + else + { + /* This node is already in the hash table. */ + return *slot; + } +} + +/* Generate (or reuse) DW_TAG_annotation DIEs representing the btf_type_tag or + btf_decl_tag user annotations in ATTR, and update DIE to refer to them + via DW_AT_annotation. If there are multiple type_tag or decl_tag + annotations in ATTR, they are all processed recursively by this function + to build a chain of annotation DIEs. + Return the first annotation DIE in the created (or reused) chain. */ + +static dw_die_ref +gen_btf_tag_dies (tree attr, dw_die_ref die, dw_die_ref context_die) +{ + if (attr == NULL_TREE) + return die; + + while (dw_get_die_tag (context_die) != DW_TAG_compile_unit) + context_die = context_die->die_parent; + + const char * name = IDENTIFIER_POINTER (get_attribute_name (attr)); + const char * value = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))); + + dw_die_ref tag_die, prev = NULL; + + /* Multiple annotations on the same item form a singly-linked list of + annotation DIEs; generate recursively backward from the end so we can + chain each created DIE to the next, which has already been created. */ + tree rest = lookup_attribute (name, TREE_CHAIN (attr)); + if (rest) + prev = gen_btf_tag_dies (rest, NULL, context_die); + + /* Calculate a hash value for the tag based on its structure, find the + existing entry for it (if any) in the hash table, or create a new entry + which can be reused by structurally-equivalent tags. */ + struct annotation_node *entry = hash_btf_tag (attr); + if (!entry) + return die; + + /* If the node already has an associated DIE, reuse it. + Otherwise, create the new annotation DIE, and associate it with + the hash table entry for future reuse. Any structurally-equivalent + tag we process later will find and share the same DIE. */ + if (entry->die) + tag_die = entry->die; + else + { + tag_die = new_die (DW_TAG_GNU_annotation, context_die, NULL); + add_name_attribute (tag_die, name); + add_AT_string (tag_die, DW_AT_const_value, value); + if (prev) + add_AT_die_ref (tag_die, DW_AT_GNU_annotation, prev); + + entry->die = tag_die; + } + + if (die) + add_AT_die_ref (die, DW_AT_GNU_annotation, tag_die); + + return tag_die; +} + +static void +gen_btf_type_tag_dies (tree t, tree attr, dw_die_ref target, + dw_die_ref context_die) +{ + if (t == NULL_TREE || !TYPE_P (t) || !target) + return; + + gen_btf_tag_dies (attr, target, context_die); +} + +static void +gen_btf_decl_tag_dies (tree t, dw_die_ref target, dw_die_ref context_die) +{ + if (t == NULL_TREE || !DECL_P (t) || !target) + return; + + tree attr = lookup_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t)); + if (attr == NULL_TREE) + return; + + gen_btf_tag_dies (attr, target, context_die); + + /* Strip the decl tag attribute once we have created the annotation DIEs + to avoid attempting process it multiple times. */ + DECL_ATTRIBUTES (t) + = remove_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t)); +} + /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging entry that chains the modifiers specified by CV_QUALS in front of the given type. REVERSE is true if the type is to be interpreted in the @@ -13774,10 +13962,44 @@ modified_type_die (tree type, int cv_quals, bool reverse, dquals &= cv_qual_mask; if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type)) - /* cv-unqualified version of named type. Just use - the unnamed type to which it refers. */ - return modified_type_die (DECL_ORIGINAL_TYPE (name), cv_quals, - reverse, context_die); + { + if (lookup_attribute ("btf_type_tag", TYPE_ATTRIBUTES (type))) + { + /* Use of a typedef with additional btf_type_tags. Create + a distinct typedef DIE for this version of the named type + so that the btf_type_tag annotations may be attached to + it without affecting other users of the plain typedef. */ + tree tags = lookup_attribute ("btf_type_tag", + TYPE_ATTRIBUTES (type)); + tree dtags = lookup_attribute ("btf_type_tag", + TYPE_ATTRIBUTES (dtype)); + + /* Remove type tags before the recursive call to avoid + processing the same attribute multiple times. */ + TYPE_ATTRIBUTES (type) + = remove_attribute ("btf_type_tag", TYPE_ATTRIBUTES (type)); + + dw_die_ref mod_die = modified_type_die (dtype, cv_quals, + reverse, context_die); + + /* Create a new typedef DIE since the btf_type_tag-ed use of + the typedef has really created a distinct type. */ + if (!attribute_list_equal (tags, dtags)) + { + mod_die = clone_die (mod_die); + add_child_die (comp_unit_die (), mod_die); + if (!lookup_type_die (type)) + equate_type_number_to_die (type, mod_die); + } + + gen_btf_type_tag_dies (type, tags, mod_die, context_die); + return mod_die; + } + /* cv-unqualified version of named type. Just use + the unnamed type to which it refers. */ + return modified_type_die (DECL_ORIGINAL_TYPE (name), cv_quals, + reverse, context_die); + } /* Else cv-qualified version of named type; fall through. */ } } @@ -13878,6 +14100,18 @@ modified_type_die (tree type, int cv_quals, bool reverse, first_quals |= dwarf_qual_info[i].q; } } + else if (lookup_attribute ("btf_type_tag", TYPE_ATTRIBUTES (type))) + { + /* Remove type tags before the recursive call to avoid processing the + same attribute multiple times. */ + tree attr = lookup_attribute ("btf_type_tag", TYPE_ATTRIBUTES (type)); + TYPE_ATTRIBUTES (type) = remove_attribute ("btf_type_tag", + TYPE_ATTRIBUTES (type)); + dw_die_ref mod_die = modified_type_die (type, cv_quals, reverse, + context_die); + gen_btf_type_tag_dies (type, attr, mod_die, context_die); + return mod_die; + } else if (code == POINTER_TYPE || code == REFERENCE_TYPE) { dwarf_tag tag = DW_TAG_pointer_type; @@ -23090,6 +23324,8 @@ gen_formal_parameter_die (tree node, tree origin, bool emit_name_p, else { add_child_die (context_die, parm_die); + + gen_btf_decl_tag_dies (node_or_origin, parm_die, context_die); return parm_die; } } @@ -23158,6 +23394,8 @@ gen_formal_parameter_die (tree node, tree origin, bool emit_name_p, gcc_unreachable (); } + gen_btf_decl_tag_dies (node_or_origin, parm_die, context_die); + return parm_die; } @@ -27342,6 +27580,9 @@ gen_decl_die (tree decl, tree origin, struct vlr_context *ctx, break; } + gen_btf_decl_tag_dies (decl_or_origin, lookup_decl_die (decl_or_origin), + context_die); + return NULL; } @@ -33245,6 +33486,9 @@ dwarf2out_early_finish (const char *filename) print_die (comp_unit_die (), dump_file); } + if (btf_tag_htab) + btf_tag_htab->empty (); + /* Generate CTF/BTF debug info. */ if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE || btf_debuginfo_p ()) && lang_GNU_C ()) @@ -33440,6 +33684,7 @@ dwarf2out_cc_finalize (void) switch_text_ranges = NULL; switch_cold_ranges = NULL; current_unit_personality = NULL; + btf_tag_htab = NULL; early_dwarf = false; early_dwarf_finished = false; diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-1.c b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-1.c new file mode 100644 index 00000000000..a1c1676a7ba --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-1.c @@ -0,0 +1,11 @@ +/* Test simple generation of DW_TAG_GNU_annotation DIE for + btf_decl_tag attribute. */ +/* { dg-do compile } */ +/* { dg-options "-gdwarf -dA" } */ + +int *foo __attribute__((btf_decl_tag ("my_foo"))); + +/* { dg-final { scan-assembler-times "DIE \\(\[^\n\]*\\) DW_TAG_GNU_annotation" 1 } } */ +/* { dg-final { scan-assembler-times " DW_AT_name: \"btf_decl_tag\"" 1 } } */ +/* { dg-final { scan-assembler-times " DW_AT_const_value: \"my_foo\"" 1 } } */ +/* { dg-final { scan-assembler-times " DW_AT_GNU_annotation" 1 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-2.c b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-2.c new file mode 100644 index 00000000000..76583840439 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-2.c @@ -0,0 +1,25 @@ +/* Test dwarf generation for btf_decl_tag on struct and union members. */ +/* { dg-do compile } */ +/* { dg-options "-gdwarf -dA" } */ + +#define __tag1 __attribute__((btf_decl_tag ("decl1"))) +#define __tag2 __attribute__((btf_decl_tag ("decl2"))) + +union U { + int i __tag1; + unsigned char ub[4]; +}; + +struct S { + union U u; + int b __tag2; + char *z __tag1; +}; + +struct S my_s __tag1 __tag2; + +/* We must have two occurrances of one of the two annotation DIEs due to + the different attribute sets between declarations above. */ +/* { dg-final { scan-assembler-times "DIE \\(\[^\n\]*\\) DW_TAG_GNU_annotation" 3 } } */ +/* { dg-final { scan-assembler-times " DW_AT_name: \"btf_decl_tag\"" 3 } } */ +/* { dg-final { scan-assembler-times " DW_AT_GNU_annotation" 5 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-3.c b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-3.c new file mode 100644 index 00000000000..f3fad8fe3d2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-3.c @@ -0,0 +1,21 @@ +/* Test dwarf generation for btf_decl_tag on functions and function args. */ +/* { dg-do compile } */ +/* { dg-options "-gdwarf -dA" } */ + +#define __tag1 __attribute__((btf_decl_tag ("decl1"))) +#define __tag2 __attribute__((btf_decl_tag ("decl2"))) + +int __tag1 __tag2 func (int arg_a __tag1, int arg_b __tag2) +{ + return arg_a * arg_b; +} + +int foo (int x) { + return func (x, x + 1); +} + +/* In this case one of the decl tag DIEs must be duplicated due to differing + DW_AT_GNU_annotation chain between the three uses. */ +/* { dg-final { scan-assembler-times "DIE \\(\[^\n\]*\\) DW_TAG_GNU_annotation" 3 } } */ +/* { dg-final { scan-assembler-times " DW_AT_name: \"btf_decl_tag\"" 3 } } */ +/* { dg-final { scan-assembler-times " DW_AT_GNU_annotation" 4 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-1.c b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-1.c new file mode 100644 index 00000000000..772aab09cfb --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-1.c @@ -0,0 +1,10 @@ +/* Test simple generation for btf_type_tag attribute. */ +/* { dg-do compile } */ +/* { dg-options "-gdwarf -dA" } */ + +int * __attribute__((btf_type_tag("__user"))) ptr; + +/* { dg-final { scan-assembler-times "DIE \\(\[^\n\]*\\) DW_TAG_GNU_annotation" 1 } } */ +/* { dg-final { scan-assembler-times " DW_AT_name: \"btf_type_tag\"" 1 } } */ +/* { dg-final { scan-assembler-times " DW_AT_const_value: \"__user\"" 1 } } */ +/* { dg-final { scan-assembler-times " DW_AT_GNU_annotation" 1 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-2.c b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-2.c new file mode 100644 index 00000000000..9c44e0ee0b9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-2.c @@ -0,0 +1,31 @@ +/* Test that DW_TAG_GNU_annotation DIEs for attribute btf_type_tag are shared + where possible. */ +/* { dg-do compile } */ +/* { dg-options "-gdwarf -dA" } */ + +#define __tag1 __attribute__((btf_type_tag("tag1"))) +#define __tag2 __attribute__((btf_type_tag("tag2"))) + +int __tag1 foo; +char * __tag1 __tag2 bar; + +struct S +{ + unsigned char bytes[8]; + unsigned long __tag1 t; + void *ptr; +}; + +struct S * __tag1 __tag2 my_S; + +/* Only 2 DW_TAG_GNU_annotation DIEs should be generated, one each for "tag1" + and "tag2", and they should be reused. */ +/* { dg-final { scan-assembler-times "DIE \\(\[^\n\]*\\) DW_TAG_GNU_annotation" 2 } } */ +/* { dg-final { scan-assembler-times " DW_AT_name: \"btf_type_tag\"" 2 } } */ +/* { dg-final { scan-assembler-times " DW_AT_const_value: \"tag1\"" 1 } } */ +/* { dg-final { scan-assembler-times " DW_AT_const_value: \"tag2\"" 1 } } */ + +/* Each attribute-ed type shall refer via DW_AT_GNU_annotation to the + appropriate annotation DIE, including the annotation DIE for "tag2" which + is always chained to the DIE for "tag1" in this construction. */ +/* { dg-final { scan-assembler-times " DW_AT_GNU_annotation" 5 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-3.c b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-3.c new file mode 100644 index 00000000000..d02144c8004 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-btf-type-tag-3.c @@ -0,0 +1,15 @@ +/* Test dwarf generation for btf_type_tag with cv-quals and typedefs. */ +/* { dg-do compile } */ +/* { dg-options "-gdwarf -dA" } */ + +#define __tag1 __attribute__((btf_type_tag ("tag1"))) +#define __tag2 __attribute__((btf_type_tag ("tag2"))) + +typedef const int foo; +typedef int __tag1 bar; + +foo __tag2 x; +const bar y; + +/* { dg-final { scan-assembler-times "DIE \\(\[^\n\]*\\) DW_TAG_GNU_annotation" 2 } } */ +/* { dg-final { scan-assembler-times " DW_AT_name: \"btf_type_tag\"" 2 } } */ diff --git a/include/dwarf2.def b/include/dwarf2.def index 66c7fa1220f..6a3a986cf70 100644 --- a/include/dwarf2.def +++ b/include/dwarf2.def @@ -174,6 +174,9 @@ DW_TAG (DW_TAG_GNU_formal_parameter_pack, 0x4108) are properly part of DWARF 5. */ DW_TAG (DW_TAG_GNU_call_site, 0x4109) DW_TAG (DW_TAG_GNU_call_site_parameter, 0x410a) + +DW_TAG (DW_TAG_GNU_annotation, 0x6001) + /* Extensions for UPC. See: http://dwarfstd.org/doc/DWARF4.pdf. */ DW_TAG (DW_TAG_upc_shared_type, 0x8765) DW_TAG (DW_TAG_upc_strict_type, 0x8766) @@ -453,6 +456,7 @@ DW_AT (DW_AT_GNU_pubtypes, 0x2135) DW_AT (DW_AT_GNU_discriminator, 0x2136) DW_AT (DW_AT_GNU_locviews, 0x2137) DW_AT (DW_AT_GNU_entry_view, 0x2138) +DW_AT (DW_AT_GNU_annotation, 0x2139) /* VMS extensions. */ DW_AT (DW_AT_VMS_rtnbeg_pd_address, 0x2201) /* GNAT extensions. */ From patchwork Wed Oct 30 18:31:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 99838 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E2C93857737 for ; Wed, 30 Oct 2024 18:33:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 5BDA73857C6D for ; Wed, 30 Oct 2024 18:32:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BDA73857C6D Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5BDA73857C6D Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313141; cv=pass; b=pol0XF1sO/iPIvLda0HVNr+fCDiJs9P9oYx3yNEU+kdbc8yObzCC2yKLLjICfkJ9PEftd4hz+UgktpUYEuHFKzj9piKKS/jqEtYeBG1ZWq2NuNuJVjomi6Qm+m6d/0v/WPxM+e3F7wVHAAYW+L1IKDq0RCLaAjwb6q1bsxIu7ao= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313141; c=relaxed/simple; bh=/g6sYqVhdSWcBn2Kcy71W/+gSldHkrddaOcAsihGEFY=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=tLmtbA7beeu0KHtDklpCNmnY+cenrGshe1CEFsbyTkOQoFDgc3rkO6WB8KhcQ1d8PREmoxdm3qp4C7GjJyjq9blCEW5y8yS8qr9uBR5BcuBTXbmm8sgosg+c+Hbp6cZoKpJl2jyGP4j6YXQrQhqBc81Ynqg6V+ra0rfiJ35FgaM= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49UGXZ6u017446; Wed, 30 Oct 2024 18:32:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=7u1EAHFlQGVqWiYgXIuVDs5iod4HdjzW27O9NZhAKc8=; b= jIjf0jnPw5sjcBGpZ5wKhQARKVeyu62n4fDS3WLqrswFcAAbNp8lUSY3B6M8WK0/ DFZwEU28xNUAnuGgFL2diNwJftE0pl5QociRTj9LY/hrW0yrs7G/NbvJQK3216FA rWXBWt//BMyk5ErdCUFYkXgsMebXAEdV/LZmcLr+fgFDdjIayhx4E5mHQNl2nDmA /w4oac2REnyNMjNMFV7moqBLkHfhCE9EUw1jehPoLpn6TuljIBDKIQDOVeDyhf75 b/3M+v9bsQ+g0Kpx0Vxg0wFXIBd5JrcFmML/2pyNiwylQ+1SNCO86fmhn4yqe/Pt XX1192cJX6yA9o/Fqg/+2Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdxrr3p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:14 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49UHsren040543; Wed, 30 Oct 2024 18:32:13 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2174.outbound.protection.outlook.com [104.47.56.174]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42hnaqxyya-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZK8FHwrv3nxqNS+GyYr4G1Bc4zkCRPVMBaA73QMDCpWypmGjc14nODvTDBNM6fPmH8fJvA/emma4RZ0H3ZuQRAOz2EBk4xhuSWfyCPqTDVeEBHLkvbDWOJZOeOmkx9CdW3EcTL7LJu6eYcUQoScUwI3IvVbnKj7Cxg+8xYXK7v3SaCMk8UvOjq4yOZsiAy0e7icG5WHkA5wlUqjhYVQ76QjldNQQYHz+7+4WxuAIEamXN+UM9fzsfDTITTTWDKTh2UIpSnMbR7XY13eDsKIXwSwyMkt1dvvUUrpmPIXrPvvOT8hIvcnvgphX7AzzvnZw2y6VOpH6EPmxfzV5OXJt6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7u1EAHFlQGVqWiYgXIuVDs5iod4HdjzW27O9NZhAKc8=; b=sTyuWR7ww7Tgz5bz7UUudL1J7/6+LSQrjXejuTpi3p8C3Px/0A6ytxL6v7jhqcCA7QYjxshWWvXN+zuHB1a3KTwQxjEKWeKMpVDDXwkxzuYYNRM3DJAxtBesl47aN68Rr39IBnuIpCphMze4YJsLxr5bGqd6uFQ2HTi99XtYk2tNyrkDfUs+2UJ6dE+FBZ6Iki2k1hTkta5w3mjU2JqCI/w861DKRq8lpeMkSHankq8U2kDrtt8R7/5nGjAzXQSQYdGYe2RX5f51OLwfQ3wjFzzqpS9iC4A70YEZxYBQfCGzoyiEhl8E7UDh7ERXics+5nHCsLgoJ7RCY0xHUjC+7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7u1EAHFlQGVqWiYgXIuVDs5iod4HdjzW27O9NZhAKc8=; b=VELyic2jVt5kpY050tx6G8HkrPP820hE5UM7Llg8CEFbDP0yXbqubBjZRvS0+yXvf+m7nzXMCFQ0cyj3IxelzFdsBSPnUbkUAZG2KeHW6OrX2+4M6mJ3Nn1EbIGKDLBd21iJCxUgM9itSD3dXPOv0pq9N5BW3ThgoUNX9qhIUGA= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by SJ0PR10MB4672.namprd10.prod.outlook.com (2603:10b6:a03:2af::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Wed, 30 Oct 2024 18:32:10 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%4]) with mapi id 15.20.8093.024; Wed, 30 Oct 2024 18:32:10 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, yonghong.song@linux.dev Subject: [PATCH 3/5] ctf: translate annotation DIEs to internal ctf Date: Wed, 30 Oct 2024 11:31:53 -0700 Message-ID: <20241030183155.2038501-4-david.faust@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241030183155.2038501-1-david.faust@oracle.com> References: <20241030183155.2038501-1-david.faust@oracle.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|SJ0PR10MB4672:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c5b100c-b6b2-4b99-77e2-08dcf9112ac2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: 3G0JU0721IMebPMQuyum2lcGFQ3LUlp0zy6+cl/uJ+PC+bHS2ODKadgoKumGpUQAK+IJlCk1dPUud80Z/FCMqFXnlb4nWPqq4NbQSIa3Epfv3PsT8w9eg0PiddKt9f8daEW3dIWQ4cTH3tcRDasYePeoqh7yMAPXM2UvlsccyGUZw1g5DGLQM255A7VPeaGzBEvJHbG+wAArOC+pBhMtyT6CGs4hJBYRcpYP/vG6szP4SuqVbQsWG0NmQB0GhhyBVC6hUdnlUVjHgJ6lqJ4kNiScB0N7frORdRcl/xbbS/7BAb7BN8boP4iJpN3vHGudiEeXIZhXMNPIrrLzxZnhb4ISuG0fkj+8PcnCMp3le5jKSQtOAWjsonbU6Tt+Zhyr/5Re4ztEMuAEiaDA9n580PIGFWDREO+XiiNmPZgkP8ECgO17aw6VDDL4maq2Rn58oNxw70XcbOSV/vTqOIr9zPukG0geDdTo0AckmqJoelqXR1ExPCUUKBBANBqKfM8pAkpcOe4H/ESmCmOiKCufvwmZeAnLObY5BaVpXF6lTZEQouBcBVSokEJLkgpLTQVPAnnh27SB0bnhH/vjKteVQvhbWfx1WsFx1y/Q5Bf2xwGE/4RHXrRSWinQ2Yg6VsUoqnF+QjODHQP55URgCbFILvG0f4G88uKdY8bb/VHHgXHbeN7FhqRYF5IJJ9QS0TLMR5IVAGIiGL07TQ1AO4vuUVcgWPyXMkOfXV6ji1c54W77g4uJ0WbHx9WwjwFxnkCtNmR45gxr7rYjsTpY5+QYpooKbTj5Kr/roXrXvia1M7vnVMlL1ODVs/BWDOLg6psWmz0NHtMVug/I17QtsYDE1Ufd0+jWYi6WKPjH9fsFOA6cj95Yaw1DQxsZJekT95kcTNMe/YRBIuIUY0edO39tjxzdG8Ibbmafv+sDGk6Gig/U+5KfeuCygOn2Co6ovlODUamlT8ghJTKRCX18rDjmTzsbBmbPIJ8+cIELXJljdkfq3tFzsC9pkJK8V0B7/SlOrG5BPjvNz7CB5vENc3hR8Q/yvEEqZKFUGNX5jM6+JADe2dZC4QMYxcN+r45iymW2XU/bTgmOwxM29Gm7C6/ozqOgU+7k1zWVkAbYdZklL8BhIuFzcRphPGKqy8KqtC+BlEL8klpdBL8Fdcs7LmhHtE6EWPXz5wQ7QGsqWC/rElddXNDUSHCe6qnCIJU1I11C0hqm0FhP+SyIoA9WlR/oWjuLtlhXQ0HBOZXx+CPIliWBn+wgCuuuBqrDVdlPBpJTW+ySiM8mR104vc4rtDMzudnhqmglMCZJlObyLHBBNFACLxnmEj55mKMe7qKX8frV X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR10MB7953.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hevYwhbe2h46UqAAmr0+ao/J+awZGxBdI+12Gcn220bvGPdxzO/EfdVd3lQ3bMiBbka6hxz+1F6akaKG5JMybVo/jXBGLj8hldtCciwG+jz0umqtE85/l8sQZ7ZGGTL1OUM5SHY/kojCFqjdyqp7b9naxTMnHoZwa21RYgOd7yqolRblXaTt/tgUO5HVzJ3VYdey6WQicqfN/ol5FA1oPU3xIQWY53fkVqp50W0QXPkvq66SrjETsXr1bDg/A2Pas/GiHAEsQFn8cJgCuF6/CZ+8TzeJL48A5bpikUHhv1TZizR8gJ3Bsq0Bv6DZMEBVzkyycSulKw4gBaFejPBlJb5StVlZv9mgwgmCeTEEktet9WvqkZu2z6LFwJ2wwBKPbihibF3T9qdlrRDXy3cmwp/UAznBpeVCfrhoeQ1MAaXum/TqahY8oNWvAwgbA7l9Ilbn/utDHk2qe7CvtbDjEtqDAIze10I53xUvy2A/GNwmjQbTZDXfnTLsPBT5Xv1LtIg9fKrSXBNo2ntaYhRDBFolOu4kvyWssSBYw4WqrMubBgFNgqYM0sow+2XO/5rQ91SpIW2q7vo0mXicucu2yEAyCKdoVj9CaDhiAisgQ59Ts0uyvcIoktS7Y3gPsdqyOdpUTJnK/FkTYhU364UXO7w7Y2ng4vxHF2H8uWcfoDuJvNq6VyZTzne6OJwFfdnlT05qH521ZciprLmq/XOT3s9Yy8JOTtANMslTGSXXIoK/e1Mb2eSEFVdG+b5UGj+I7J9EhsODW/IukluwNapZEaGr1Ey0hiURjtGcf9PFPOhKqmlIEIRQVdY/+AZr6CiMO7TFeoIkCgfXN+8x1uxjQPPL+hEeSLJtlZcjl+PWUh5byb4qDbrUETPFvKKJRyvE+hfjOpWHwyXLuKsbMcwkZjyFF8QEDs/Pqh2BRdzpoiWSg3KpQmaiQinJnnVqcmvGn09nQyl0BKx8YVYw3R3/SjqjWsEidW9BnUi1cAV4rf2Oe6r1ub6HTSoKf4xq6VLqw3QLhFlYBscov9XBQX4h0CB/VO3gaV7c81SuBqPjuBJwXiJ9AmM43MzH7/kQA4uncK/w1uOE50Qk0li6TpaJndlguSZ7uSQVexGrHriQEZgo4vbsodKsv686Bd0BOhuav0RnXNEFL1JXIvZ/dEuUGmZhc+w+LwpNlIBB9tviWUvqtywGN8tmM+qvXUGODL1AuWWg8QX8iKbt02oWkXHCHifvGhcJBKSilDkMJhmg2SBdwhZqraLrhNUOGbpWwkAVC2IpMWhsZdlNbxmxV0hZhCcYYupTVSzB6rRQBnhHhD3naU0YRK7RBxqNRI7kE0R9G0eK7/qAZtE0L5wSA2bGfnLK7KAHeWSmfm4LD8RdJxL1in+d02v+jlF663D/HcbaIPjPLqjn9nJt26iXpUTiOKc/X119GC0YjKlqx6A0Kxm4U4wO5+5hfqkUMvzv5q6O2cf9Aa5qdSrTn7wHUTh/UibucrXmlcjqSYCuFp6bFkREvLjCM1WaXyOwc3YLSGGRCZU8HAo2GbEsxupx0toftTV67jRiWVRXRv01sAaUVUBGudz74ibwIUn5m0K4Oq917fxHv94Iu8s6lGVCLzjbpQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: dMnqGlL47nc6OEbyZUMbd714njfhQiEmbDkf61xIvLy3Y7auWncOR7OYbjIJpvbWog+8PtOIvXTF0mBPdg7BQb08AMGdSPXYM/kIrjGRCW3XbGLdDceHeg8NwZep8eZ1GXdAN5ESV6JIUe38JvZ3/ocDVuKPzKRAUIMobchIyzzoHreA1LckiEHxmghvWFZJEzJCHNvrJ9+v15jmpuuJk3w7OjfAhE6eLcbaYqOifVxkOdhvCzzAAzdrwY0Ovwx682nbW7o4/sjlUMB4N2yynRR1eJc/MI5G7EUen7kJHN5ImAeZvfRAAItuuK2NLzcOPja/1SD1rkeImfRmTYO/NeYRHymInRTQ8qqzjeF35xtjmpquYVkPYBid87jf+2umBRuM3yVBFgXCqnuQ/yJD4T+ytlmYk5xu/rLawnR5x7s5Y6Jmwc4KSoyRptXdPO5eND8OE5TUSXOC4Q7PoE+G0fyT22oqM1rxrOGCRCeTMoJCy9lY90uXt5BaQL7yVSWgKEqMP2lrTY/zNYWVVUIz18ZblX8x2JVNTd7oKXfF8imSa8lL7rpLQbJgxRmHlrtUcL99c6OSHIVnrigMGXIM3G0MEyOC7YhEneWWPwPDgts= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c5b100c-b6b2-4b99-77e2-08dcf9112ac2 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 18:32:10.8628 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3UKPrK6XxgwreScwfbYjTMc3zOMZ0wxQsNDIAWxeOp23pYie+71imVUhSDt1nSc5wRzwSs+V639etNRe2mh6OA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4672 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-30_14,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410300145 X-Proofpoint-GUID: Qwxqi_LV_Lsh7BuLPVx6TlMLzloFEBUj X-Proofpoint-ORIG-GUID: Qwxqi_LV_Lsh7BuLPVx6TlMLzloFEBUj X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Translate DW_TAG_GNU_annotation DIEs created for C attributes btf_decl_tag and btf_type_tag into an in-memory representation in the CTF/BTF container. They will be output in BTF as BTF_KIND_DECL_TAG and BTF_KIND_TYPE_TAG records. The new CTF kinds used to represent these annotations, CTF_K_DECL_TAG and CTF_K_TYPE_TAG, are expected to be formalized in the next version of the CTF specification. For now they only exist in memory as a translation step to BTF, and are not emitted when generating CTF information. gcc/ * ctfc.cc (ctf_dtu_d_union_selector): Handle CTF_K_DECL_TAG and CTF_K_TYPE_TAG. (ctf_add_type_tag, ctf_add_decl_tag): New. (ctf_add_variable): Return the new ctf_dvdef_ref rather than zero. (new_ctf_container): Initialize new members. (ctfc_delete_container): Deallocate new members. * ctfc.h (ctf_dvdef, ctf_dvdef_t, ctf_dvdef_ref): Move forward declarations earlier in file. (ctf_tag_t): New typedef. (ctf_dtdef): Add ctf_tag_t member to dtd_u union. (ctf_dtu_d_union_enum): Add new CTF_DTU_D_TAG enumerator. (ctf_container): Add ctfc_tags vector and ctfc_tags_map hash_map members. (ctf_add_type_tag, ctf_add_decl_tag): New function protos. (ctf_add_variable): Change prototype return type to ctf_dvdef_ref. * dwarf2ctf.cc (gen_ctf_type_tags, gen_ctf_decl_tags) (gen_ctf_decl_tags_for_var): New static functions. (gen_ctf_modifier_type): Handle type tags on types with cv-quals. (gen_ctf_sou_type): Handle decl tags. (gen_ctf_function_type): Likewise. (gen_ctf_variable): Likewise. (gen_ctf_function): Likewise. (is_cvr_die): New helper function. (gen_ctf_type): Handle type tags. include/ * ctf.h (CTF_K_DECL_TAG, CTF_K_TYPE_TAG): New defines. --- gcc/ctfc.cc | 66 ++++++++++++++++- gcc/ctfc.h | 41 +++++++++-- gcc/dwarf2ctf.cc | 180 +++++++++++++++++++++++++++++++++++++++++++++-- include/ctf.h | 4 ++ 4 files changed, 277 insertions(+), 14 deletions(-) diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc index 8f531ffebf8..8fca36caa1e 100644 --- a/gcc/ctfc.cc +++ b/gcc/ctfc.cc @@ -107,6 +107,9 @@ ctf_dtu_d_union_selector (ctf_dtdef_ref ctftype) return CTF_DTU_D_ARGUMENTS; case CTF_K_SLICE: return CTF_DTU_D_SLICE; + case CTF_K_DECL_TAG: + case CTF_K_TYPE_TAG: + return CTF_DTU_D_TAG; default: /* The largest member as default. */ return CTF_DTU_D_ARRAY; @@ -445,6 +448,54 @@ ctf_add_reftype (ctf_container_ref ctfc, uint32_t flag, ctf_dtdef_ref ref, return dtd; } +ctf_dtdef_ref +ctf_add_type_tag (ctf_container_ref ctfc, uint32_t flag, const char *value, + ctf_dtdef_ref ref_dtd) +{ + ctf_dtdef_ref dtd; + /* Create a DTD for the tag, but do not place it in the regular types list; + ctf format does not (yet) encode tags. */ + dtd = ggc_cleared_alloc (); + + dtd->dtd_name = ctf_add_string (ctfc, value, &(dtd->dtd_data.ctti_name), + CTF_AUX_STRTAB); + /* Tags uniquely have a one-to-many relationship where one die may translate + to many ctf types. Therefore we cannot key the tags by die. */ + dtd->dtd_key = NULL; + dtd->ref_type = ref_dtd; + dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_TYPE_TAG, flag, 0); + dtd->dtd_u.dtu_tag.ref_var = NULL; /* Not used for type tags. */ + dtd->dtd_u.dtu_tag.component_idx = -1U; /* Not used for type tags. */ + + /* Insert tag directly into the tag list. Type ID will be assigned later. */ + vec_safe_push (ctfc->ctfc_tags, dtd); + return dtd; +} + +ctf_dtdef_ref +ctf_add_decl_tag (ctf_container_ref ctfc, uint32_t flag, const char *value, + ctf_dtdef_ref ref_dtd, uint32_t comp_idx) +{ + ctf_dtdef_ref dtd; + /* Create a DTD for the tag, but do not place it in the regular types list; + ctf format does not (yet) encode tags. */ + dtd = ggc_cleared_alloc (); + + dtd->dtd_name = ctf_add_string (ctfc, value, &(dtd->dtd_data.ctti_name), + CTF_AUX_STRTAB); + /* Tags uniquely have a one-to-many relationship where one die may translate + to many ctf types. Therefore we cannot key the tags by die. */ + dtd->dtd_key = NULL; + dtd->ref_type = ref_dtd; + dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_DECL_TAG, flag, 0); + dtd->dtd_u.dtu_tag.ref_var = NULL; + dtd->dtd_u.dtu_tag.component_idx = comp_idx; + + /* Insert tag directly into the tag list. Type ID will be assigned later. */ + vec_safe_push (ctfc->ctfc_tags, dtd); + return dtd; +} + ctf_dtdef_ref ctf_add_forward (ctf_container_ref ctfc, uint32_t flag, const char * name, uint32_t kind, dw_die_ref die) @@ -691,12 +742,12 @@ ctf_add_member_offset (ctf_container_ref ctfc, dw_die_ref sou, return 0; } -int +ctf_dvdef_ref ctf_add_variable (ctf_container_ref ctfc, const char * name, ctf_dtdef_ref ref, dw_die_ref die, unsigned int external_vis, dw_die_ref die_var_decl) { - ctf_dvdef_ref dvd, dvd_ignore; + ctf_dvdef_ref dvd = NULL, dvd_ignore; gcc_assert (name); @@ -732,7 +783,7 @@ ctf_add_variable (ctf_container_ref ctfc, const char * name, ctf_dtdef_ref ref, ctfc->ctfc_strlen += strlen (name) + 1; } - return 0; + return dvd; } int @@ -949,6 +1000,10 @@ new_ctf_container (void) tu_ctfc->ctfc_ignore_vars = hash_table::create_ggc (10); + vec_alloc (tu_ctfc->ctfc_tags, 100); + tu_ctfc->ctfc_tags_map + = hash_map::create_ggc (100); + return tu_ctfc; } @@ -1003,6 +1058,11 @@ ctfc_delete_container (ctf_container_ref ctfc) ctfc->ctfc_ignore_vars->empty (); ctfc->ctfc_ignore_vars = NULL; + ctfc->ctfc_tags = NULL; + + ctfc->ctfc_tags_map->empty (); + ctfc->ctfc_tags_map = NULL; + ctfc_delete_strtab (&ctfc->ctfc_strtable); ctfc_delete_strtab (&ctfc->ctfc_aux_strtable); if (ctfc->ctfc_vars_list) diff --git a/gcc/ctfc.h b/gcc/ctfc.h index 41e1169f271..cf73a566c3d 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -52,6 +52,10 @@ struct ctf_dtdef; typedef struct ctf_dtdef ctf_dtdef_t; typedef ctf_dtdef_t * ctf_dtdef_ref; +struct ctf_dvdef; +typedef struct ctf_dvdef ctf_dvdef_t; +typedef ctf_dvdef_t * ctf_dvdef_ref; + /* CTF string table element (list node). */ typedef struct GTY ((chain_next ("%h.cts_next"))) ctf_string @@ -155,6 +159,14 @@ typedef struct GTY (()) ctf_func_arg #define ctf_farg_list_next(elem) ((ctf_func_arg_t *)((elem)->farg_next)) +/* Declaration Tag. */ + +typedef struct GTY (()) ctf_tag +{ + uint32_t component_idx; /* Index of component to which tag applies. */ + ctf_dvdef_ref ref_var; /* Non-null iff this tag applies to a variable. */ +} ctf_tag_t; + /* Type definition for CTF generation. */ struct GTY ((for_user)) ctf_dtdef @@ -184,6 +196,8 @@ struct GTY ((for_user)) ctf_dtdef ctf_func_arg_t * GTY ((tag ("CTF_DTU_D_ARGUMENTS"))) dtu_argv; /* slice. */ ctf_sliceinfo_t GTY ((tag ("CTF_DTU_D_SLICE"))) dtu_slice; + /* tag. */ + ctf_tag_t GTY ((tag ("CTF_DTU_D_TAG"))) dtu_tag; } dtd_u; }; @@ -201,9 +215,6 @@ struct GTY ((for_user)) ctf_dvdef ctf_id_t dvd_id; /* ID of this variable. Only used for BTF. */ }; -typedef struct ctf_dvdef ctf_dvdef_t; -typedef ctf_dvdef_t * ctf_dvdef_ref; - /* Location information for CTF Types and CTF Variables. */ typedef struct GTY (()) ctf_srcloc @@ -222,7 +233,8 @@ enum ctf_dtu_d_union_enum { CTF_DTU_D_ARRAY, CTF_DTU_D_ENCODING, CTF_DTU_D_ARGUMENTS, - CTF_DTU_D_SLICE + CTF_DTU_D_SLICE, + CTF_DTU_D_TAG, }; enum ctf_dtu_d_union_enum @@ -287,6 +299,17 @@ typedef struct GTY (()) ctf_container /* CTF variables to be ignored. */ hash_table * GTY (()) ctfc_ignore_vars; + /* BTF type and decl tags. Not yet represented in CTF. These tags also + uniquely have a one-to-many relation with DIEs, meaning a single DIE + may translate to multiple tags. For both of these reasons, they cannot + be stored in the regular types table. */ + vec * GTY (()) ctfc_tags; + /* Type tags logically form part of the type chain similar to cv-quals. + Therefore references to types need to know if the referred-to type has + any type tags, and if so to refer to the outermost type tag. This map + maps a type to the outermost type tag created for it, if any. */ + hash_map * GTY (()) ctfc_tags_map; + /* CTF string table. */ ctf_strtable_t ctfc_strtable; /* Auxilliary string table. At this time, used for keeping func arg names @@ -440,15 +463,19 @@ extern ctf_dtdef_ref ctf_add_function (ctf_container_ref, uint32_t, dw_die_ref, bool, int); extern ctf_dtdef_ref ctf_add_sou (ctf_container_ref, uint32_t, const char *, uint32_t, size_t, dw_die_ref); - +extern ctf_dtdef_ref ctf_add_type_tag (ctf_container_ref, uint32_t, + const char *, ctf_dtdef_ref); +extern ctf_dtdef_ref ctf_add_decl_tag (ctf_container_ref, uint32_t, + const char *, ctf_dtdef_ref, uint32_t); extern int ctf_add_enumerator (ctf_container_ref, ctf_dtdef_ref, const char *, HOST_WIDE_INT, dw_die_ref); extern int ctf_add_member_offset (ctf_container_ref, dw_die_ref, const char *, ctf_dtdef_ref, uint64_t); extern int ctf_add_function_arg (ctf_container_ref, dw_die_ref, const char *, ctf_dtdef_ref); -extern int ctf_add_variable (ctf_container_ref, const char *, ctf_dtdef_ref, - dw_die_ref, unsigned int, dw_die_ref); +extern ctf_dvdef_ref ctf_add_variable (ctf_container_ref, const char *, + ctf_dtdef_ref, dw_die_ref, unsigned int, + dw_die_ref); extern ctf_dtdef_ref ctf_lookup_tree_type (ctf_container_ref, const tree); diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index d948c4da0f4..d7a3073395c 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -32,6 +32,15 @@ along with GCC; see the file COPYING3. If not see static ctf_dtdef_ref gen_ctf_type (ctf_container_ref, dw_die_ref); +static ctf_dtdef_ref +gen_ctf_type_tags (ctf_container_ref, dw_die_ref, ctf_dtdef_ref); + +static void +gen_ctf_decl_tags (ctf_container_ref, dw_die_ref, ctf_dtdef_ref, uint32_t); + +static void +gen_ctf_decl_tags_for_var (ctf_container_ref, dw_die_ref, ctf_dvdef_ref); + /* All the DIE structures we handle come from the DWARF information generated by GCC. However, there are three situations where we need to create our own created DIE structures because GCC doesn't @@ -500,6 +509,34 @@ gen_ctf_modifier_type (ctf_container_ref ctfc, dw_die_ref modifier) if (!ctf_type_exists (ctfc, modifier, &modifier_dtd)) modifier_dtd = ctf_add_reftype (ctfc, CTF_ADD_ROOT, dtd, kind, modifier); + /* If the qual_type has any type tag(s), then the dtd we get above is for + the outermost type tag. BTF requires that if a type has both cv-quals and + type tags, the type tags are always "outermost" in the type chain. + e.g. [tag1 -> const -> int] rather than [const -> tag1 -> int] + Fix the order of modifiers by making modifier_dtd point to the underlying + qualified type, and making the innermost type tag refer to the + modifier_dtd. */ + if (CTF_V2_INFO_KIND (dtd->dtd_data.ctti_info) == CTF_K_TYPE_TAG) + { + ctf_dtdef_ref inner = dtd, root = dtd; + while (CTF_V2_INFO_KIND (root->dtd_data.ctti_info) == CTF_K_TYPE_TAG) + { + inner = root; + root = root->ref_type; + } + + /* Fix the modifier order: + 1: Innermost type tag points to (outermost) cv-qual. */ + inner->ref_type = modifier_dtd; + inner->dtd_data.ctti_type = (uint32_t) modifier_dtd->dtd_type; + /* 2: cv-qual points to the base type. */ + modifier_dtd->ref_type = root; + modifier_dtd->dtd_data.ctti_type = (uint32_t) root->dtd_type; + + /* Return the outermost type tag with the now-fixed modifier chain. */ + return dtd; + } + return modifier_dtd; } @@ -532,6 +569,7 @@ gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) /* Now process the struct members. */ { dw_die_ref c; + int idx = 0; c = dw_get_die_child (sou); if (c) @@ -616,6 +654,9 @@ gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind) field_name, field_dtd, field_location); + + gen_ctf_decl_tags (ctfc, c, sou_dtd, idx); + idx++; } while (c != dw_get_die_child (sou)); } @@ -699,14 +740,18 @@ gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, gcc_assert (i == num_args - 1); /* Add an argument with type 0 and no name. */ ctf_add_function_arg (ctfc, function, "", NULL); + /* Handle any declaration tags on the argument. */ + gen_ctf_decl_tags (ctfc, c, function_dtd, i); } else if (dw_get_die_tag (c) == DW_TAG_formal_parameter) { - i++; arg_name = get_AT_string (c, DW_AT_name); arg_type = gen_ctf_type (ctfc, ctf_get_AT_type (c)); /* Add the argument to the existing CTF function type. */ ctf_add_function_arg (ctfc, function, arg_name, arg_type); + /* Handle any declaration tags on the argument. */ + gen_ctf_decl_tags (ctfc, c, function_dtd, i); + i++; } else /* This is a local variable. Ignore. */ @@ -797,6 +842,7 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die) dw_die_ref var_type = ctf_get_AT_type (die); unsigned int external_vis = get_AT_flag (die, DW_AT_external); ctf_dtdef_ref var_dtd; + ctf_dvdef_ref dvd; /* Avoid duplicates. */ if (ctf_dvd_lookup (ctfc, die)) @@ -817,10 +863,13 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die) var_dtd = gen_ctf_type (ctfc, var_type); /* Generate the new CTF variable and update global counter. */ - (void) ctf_add_variable (ctfc, var_name, var_dtd, die, external_vis, decl); + dvd = ctf_add_variable (ctfc, var_name, var_dtd, die, external_vis, decl); /* Skip updating the number of global objects at this time. This is updated later after pre-processing as some CTF variable records although generated now, will not be emitted later. [PR105089]. */ + + /* Handle declaration tags on the variable. */ + gen_ctf_decl_tags_for_var (ctfc, die, dvd); } /* Add a CTF function record for the given input DWARF DIE. */ @@ -838,8 +887,119 @@ gen_ctf_function (ctf_container_ref ctfc, dw_die_ref die) counter. Note that DWARF encodes function types in both DW_TAG_subroutine_type and DW_TAG_subprogram in exactly the same way. */ - (void) gen_ctf_function_type (ctfc, die, true /* from_global_func */); + function_dtd = gen_ctf_function_type (ctfc, die, true /* from_global_func */); ctfc->ctfc_num_global_funcs += 1; + + /* Handle declaration tags on the function. */ + gen_ctf_decl_tags (ctfc, die, function_dtd, -1U); +} + +/* Handle any DW_AT_GNU_annotation on type DIE by constructing a CTF_K_TYPE_TAG + type for the DW_TAG_GNU_annotation DIE to which it points, if this has not + previously been constructed. There may be multiple annotations chained + together by further occurances of DW_AT_GNU_annotation in the annotation + DIEs themselves, in which case a corresponding chain of CTF_K_TYPE_TAG + records is created. The final TYPE_TAG in the chain refers to the dtd for + the annotated type, which should be supplied in REF_DTD. + + Return the ctf_dtdef_t for the outermost TYPE_TAG created, since anything + referring to this type should refer to it via the chain of type tags. */ + +static ctf_dtdef_ref +gen_ctf_type_tags (ctf_container_ref ctfc, dw_die_ref die, + ctf_dtdef_ref ref_dtd) +{ + if (!btf_debuginfo_p ()) + return ref_dtd; + if (!die || !ref_dtd) + return NULL; + + ctf_dtdef_ref *existing = ctfc->ctfc_tags_map->get (ref_dtd); + if (existing) + return *existing; + + dw_die_ref annot_die = get_AT_ref (die, DW_AT_GNU_annotation); + ctf_dtdef_ref tag_dtd = ref_dtd; + + /* Recurse first; build the chain from back to front. */ + if (annot_die) + tag_dtd = gen_ctf_type_tags (ctfc, annot_die, ref_dtd); + + /* If this is an annotation die, make the tag. */ + if (dw_get_die_tag (die) == DW_TAG_GNU_annotation) + { + const char *name = get_AT_string (die, DW_AT_name); + const char *value = get_AT_string (die, DW_AT_const_value); + if (strcmp (name, "btf_type_tag") == 0) + { + tag_dtd = ctf_add_type_tag (ctfc, CTF_ADD_ROOT, value, tag_dtd); + ctfc->ctfc_tags_map->put (ref_dtd, tag_dtd); + } + } + + return tag_dtd; +} + +/* Handle any DW_AT_GNU_annotation on decl DIE by constructing a CTF_K_DECL_TAG + type for the DW_TAG_GNU_annotation DIE to which it points, if this has not + been previously constructed. There may be multiple annotations chained + together by further occurances of DW_AT_GNU_annotation in the annoation DIEs + themselves, in which case a corresponding CTF_K_DECL_TAG type is created for + each. Unlike TYPE_TAGs, which form a chain, each DECL_TAG individually + refers directly to the annotated decl, which should be supplied in REF_DTD. + IDX is the zero-based component index indicating to which function parameter + or struct or union member the DECL_TAG refers, or (uint32_t) -1 if it refers + to a function decl itself. */ + +static void +gen_ctf_decl_tags (ctf_container_ref ctfc, dw_die_ref die, + ctf_dtdef_ref ref_dtd, uint32_t idx) +{ + if (!btf_debuginfo_p () || !die || !ref_dtd) + return; + + dw_die_ref annot_die = get_AT_ref (die, DW_AT_GNU_annotation); + while (annot_die) + { + const char *name = get_AT_string (annot_die, DW_AT_name); + const char *value = get_AT_string (annot_die, DW_AT_const_value); + + if (strcmp (name, "btf_decl_tag") == 0) + (void) ctf_add_decl_tag (ctfc, CTF_ADD_ROOT, value, ref_dtd, idx); + + annot_die = get_AT_ref (annot_die, DW_AT_GNU_annotation); + } +} + +/* Like gen_ctf_decl_tags above, but specifically for variables. Declaration + tags may appear on variables or other declarations like functions, but due + to the distinction in CTF between variables and types the processing in + each case is slightly different. REF_DVD is the CTF record for the variable + which is annotated. */ + +static void +gen_ctf_decl_tags_for_var (ctf_container_ref ctfc, dw_die_ref die, + ctf_dvdef_ref ref_dvd) +{ + if (!die || !ref_dvd) + return; + + ctf_dtdef_ref tag_dtd = NULL; + + dw_die_ref annot_die = get_AT_ref (die, DW_AT_GNU_annotation); + while (annot_die) + { + const char *name = get_AT_string (annot_die, DW_AT_name); + const char *value = get_AT_string (annot_die, DW_AT_const_value); + + if (strcmp (name, "btf_decl_tag") == 0) + { + tag_dtd = ctf_add_decl_tag (ctfc, CTF_ADD_ROOT, value, NULL, -1U); + tag_dtd->dtd_u.dtu_tag.ref_var = ref_dvd; + } + + annot_die = get_AT_ref (annot_die, DW_AT_GNU_annotation); + } } /* Add CTF type record(s) for the given input DWARF DIE and return its type id. @@ -857,7 +1017,12 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) int unrecog_die = false; if (ctf_type_exists (ctfc, die, &dtd)) - return dtd; + { + if (btf_debuginfo_p ()) + return gen_ctf_type_tags (ctfc, die, dtd); + else + return dtd; + } switch (dw_get_die_tag (die)) { @@ -906,6 +1071,10 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) break; } + case DW_TAG_GNU_annotation: + dtd = NULL; + unrecog_die = true; + break; case DW_TAG_reference_type: dtd = NULL; break; @@ -916,6 +1085,9 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) break; } + if (dtd) + dtd = gen_ctf_type_tags (ctfc, die, dtd); + /* For all types unrepresented in CTF, use an explicit CTF type of kind CTF_K_UNKNOWN. */ if ((dtd == NULL) && (!unrecog_die)) diff --git a/include/ctf.h b/include/ctf.h index f188202d120..d1873556644 100644 --- a/include/ctf.h +++ b/include/ctf.h @@ -423,6 +423,10 @@ union #define CTF_K_CONST 12 /* ctt_type is base type. */ #define CTF_K_RESTRICT 13 /* ctt_type is base type. */ #define CTF_K_SLICE 14 /* Variant data is a ctf_slice_t. */ +#define CTF_K_DECL_TAG 15 /* Declaration tag. Internal use only. + Not valid externally until CTF V4. */ +#define CTF_K_TYPE_TAG 16 /* Type tag. Internal use only. + Not valid externally until CTF V4. */ #define CTF_K_MAX 63 /* Maximum possible (V2) CTF_K_* value. */ From patchwork Wed Oct 30 18:31:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 99841 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8092385783B for ; Wed, 30 Oct 2024 18:34:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 4AFEF3857C6E for ; Wed, 30 Oct 2024 18:32:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4AFEF3857C6E Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4AFEF3857C6E Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313144; cv=pass; b=IFhNWcJVKJsJaIYeNchZNKZlQR615ZXKLxngrTEaUshnCqHNj7W8fbuA8xDUwjkzsg7YWskxgKuGWO6DBYYwYUaLs65iMdXncJAzRg4CXKkHF4raRYmvE8c2nAMx8jl+vWx2g7uCf3lu+9hwRoTbenakfMm7ltqmNichv/aBB7o= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313144; c=relaxed/simple; bh=OkE62SzvIIBUpX9DxPSUypWeFQmAVJmZpPVoxVpdLd4=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=FQdzPkHhSvhkLYLjcSQLNPcpAGEiTM70hMEq48zhfo5MDI7wjINGHZHNAd+MAXBN39WkXZqapspb99XqvHb7jM1rLvZWa5XAn1aONYFaPoiUHOhAYOtaTglnbhW1yUHbNUNyp10BLMI9tXi/dYiPfVSR5SmLxp8ib4ztsLDXaFg= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49UGXYX8017359; Wed, 30 Oct 2024 18:32:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=2I2nGJCrSNGlix2tK72vpDplalsn6tvrolm7Fdi+J4o=; b= DJu0rTDoynRr36GzU+vAxwSG8P0AloDx3wRIAe7qfdZJdkwd7Jqwmdma4H4odhNX GxaVz3dhFvs+XgeYYLgNBn84QcJiY8eZ5TZHpGcWFLgGI+zYmKCNLR5+WFR4wfEh FomqdOIj/9hEWE6+XCb7EGWOnnupZddvO3RyZcP37I+CiYc5si5t9BtAPyGqTUZv wvB4k99ZftV+CLexEiZhi/odXnOuYkwX4JeXLV+iHgwk3hIcpmNLIL6getMW3KhC d83Hlv0V9OGdDksHl57dv2HRYcyGgGnR+AiZYoIW8d7HL1goHlD7x2uFmATWrVNn YPXugwU8V3To+iMC/ia1qA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdxrr3x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:18 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49UHiNhr034961; Wed, 30 Oct 2024 18:32:17 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2170.outbound.protection.outlook.com [104.47.56.170]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42hnd9grv8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GUQjzMv1s4/vmMQnZL48Fkk1AGJ4claWIhQbTz60X+EGoFCt6vO/lG4kJul9WLIknuGLWPnim1FAzRGIMWDL0I17QId3IwDYnbtZHwVhQArIjZ3kyVPiENG32pWvSmnkDAYpnzG3DdXqgSvMjTQ67QuYePpDYVdwKLb+Cm0BJmz0AG7bGJjwofwadHH9EAQqn8KGi5z4ZECzesIhNGz4rPaTmTN5K026zp0wxyS8CcO8wVIv8+n/RvC0yxui8NEiYKdAFX/z3yhY1fdrEiGbfumFuFNk59bIVlMx+v74Z3bM48P8Ehu0bk9DiaCSN2t47zDVC0SvAYT/dY5a7O5CEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2I2nGJCrSNGlix2tK72vpDplalsn6tvrolm7Fdi+J4o=; b=uKsFV7D/+0P6Vu28QgHjbbihGTK8Dy9AdgmZlWlzgUws5vB0Pq6YXpRXIMWqV8LN8ARxh6Ng6P5Y6YHmv4ihegCq2ENYtMPYHeOYmyY3B1yOE/ic4Fz4/0vCJBO484zKF+BCwNiCGcx1N55WJOl+AmOIOmARuaxp1wHKm4/A/l9o3HLbwBI8SLP5FHe3gKRq3Zc2fOQane/dA92SLlXwkmcS32CKMLIN5xr5iBudxgUFxyxNCh8sbdVXAELIJszRR4Vg+JzMLtSDezG9o+7igTwrCUT4WJxaQkeN0h5kRXWoo1/iykSmRBF88kMKpDrq8kLptVtmAUQA+vdA++vocg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2I2nGJCrSNGlix2tK72vpDplalsn6tvrolm7Fdi+J4o=; b=lkGJpxb7FzxfkDmF9rOssYe1rJqT7TtMCJy2Jy4YR16kdDBfu4pYqLXdS7sl3Flzz+PRK0+RYA02QV2JhmOxGV1JkrJzjeoAmQVcmaGeJXbwqQrLNeH1cQGP0cKYPKSuU7CzmzeQ6sOZfRlbV3F0aRB3J1CknX8/itmVz7/kol8= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by SJ0PR10MB4672.namprd10.prod.outlook.com (2603:10b6:a03:2af::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Wed, 30 Oct 2024 18:32:13 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%4]) with mapi id 15.20.8093.024; Wed, 30 Oct 2024 18:32:13 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, yonghong.song@linux.dev Subject: [PATCH 4/5] btf: generate and output DECL_TAG and TYPE_TAG records Date: Wed, 30 Oct 2024 11:31:54 -0700 Message-ID: <20241030183155.2038501-5-david.faust@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241030183155.2038501-1-david.faust@oracle.com> References: <20241030183155.2038501-1-david.faust@oracle.com> X-ClientProxiedBy: MW2PR16CA0040.namprd16.prod.outlook.com (2603:10b6:907:1::17) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|SJ0PR10MB4672:EE_ X-MS-Office365-Filtering-Correlation-Id: 3341b7cb-bf87-4376-9813-08dcf9112c77 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: f0xWWKyvWE2yIxZ7pvlPYY5vCS4DvbEgzFQQjfH1sHeFbBnjyaLdu7XsUeDspnGP+/3EKGZmlgHkm6c45yYE+sYmSaVe99MWE1WaeaVd285wrS514PVzpjPHYDSluA1/W8lP4HBrOwYvVU8fXCYQJSwN0zrTtlkqaqggsyUYavYWumRyClHsISq1wSshB4r9k4GINVYO8P1xG8GpJImZOPinSM3Wjc07RrMtVE4wOqAeKUs1p1nVh6QJT0XUXx1BuHUvcQqNMib6NCU3dYJ8itWJnIPZxLGmLROojXqpEDK0rcYW0vk6o2mTm001cl8plTStsrE0xC69yLRjVPs0n6p2tRbmA6WUJoQIPEiteOg6HMjSy6REA9tuHn7Dh+1pABgYIZcobTE2hNsQP6fffq2X1+9IvDHFEA/IhR9vE1RCXsU9Nzy8qDWxckAPOibDD2sPGVgYmUBsd2P9VETj9LWafz8J1TMqV58bD3q02qHzoQCs1bCS4Imfh/7z7UPRnFJL7NbTzlKIJOjX7o/Zog7rfrafola+0lkhvaHr9ir6EZF7Kye1niGur2jB/tCQBjJxWITR1e2qe8mBk40edQXWwSl2Ddcjt+PQmVTCR+7yvvGKdQsPjyq/7u5BtRvCzrIlYtC6ZFKguNZzTvpBy9E70Jhh+tAI7H3AVcc9E+3u1pfn/QHpopRcwBWWI50HVsRJb57tAy6U9Y56BSdffefgBTAnbPlXy6hzPdUhtyLqZK1hVRi1kt7Yy2KjUVTONCj/DeUchyAXH4QK5N8StqHRswnNEKU9bP465e/yknRRGqmSU1y9k3YZNayx02Aj6uRxYU4llu4AosNw6yArV18UNsDmW+lFwN4cejtZhw3hU7YQtBYB8E2bxvMdNZXkaxIDnnD72u1YijVCNh/dr75uoKvbRIhMvKG7I9F3p6aut3VDzFJNtXeJxEb9vrZXpvXHA4xtTvXKE6Hn5y/Wf4+P3zh2Ll0iEDKslCg3z0/2MooTuyKy7+0NK7of+RHSdsYsUjJFEWQ2j2Z7hhWfBZiwdsSSmB0I9U7p6kkhpGMZ6qkbrv9q/Yi65NZfyWEZrvF1RIiB7I3pX0o3t9nHNJzHbPiZLpWAC5zlu7KakotnrnTy9MABRS2p502p35m1TuOeHw2zHGKV7pDoR4tfwaoJnEQEXn90S4X02EsWJVJDWKN8JoSchHeN0C+7Ji/CrQwllhL8KnWHOu3b69GQwSWK7kiE2IuvRrPBwphmMPlyURMPAK6l2hIF87xi3fhX/LDIINvCJFApVZOgmaYYAQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR10MB7953.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZdOBjT1uu6ZeeE3ABzc4Agh8XqQbMw8YjMVkbZ/o4hWWcZdlxL1sJlSqcSS6uM8aKc3nNRQmdtgBt0zTqo5t7nWfmYbmjfKTpEASQ3+uEJVZEBKbax4MBayFOjaMDDkZ40xiZCE9lRUiBEWyz7BLRLi5aFGHcqLC4GHmLUX61Mg/jZ8Xs46yrDh9FOk4AKgAXU8D+Pbv9H0AThX1C2HvhffHbQua/kpSo4wZDpYtdaK3aG/KqMr2xUFKiC5vG7ks2FFy32t5UrPtIXVCiW/AxJHcYYSlaJXk4A4lHVooYe52BH+AY4o36qluR+bh+P+QuFwIOUpsCJ+UMNcv9lrtSy04wpqyffD3zDWdTe1ipimM+MBLPbODw66p1LeT0s5MmSTG3clF73IgvGUR6d31Mdnz0D+jWEg1LRdg8jqIoHXU1MW1jTOdfZ/mFfRv4R/0/fRtE3fW/CuoqBIYDPMkJEMPRgQB2f591thp8YR4V6566C13bNwOEFHTkOJurO4XHl4HO+OIYbWS5/yzfMRLoWz9nEEyGwEwFu3aGAcBnLWIlTuNhDity861TY9olBZzUsAjYazPg7u3rGuipZXjPBFbWR8rDxpezs6E/kXAJcpe0/ffO5cpHoSe8OFMD6o1sHwMhYvGbqitLddbsIOBzni+T5W/74RY66OTfOL8U3POfPaEsmWKcFu9ARpZOlyESMejZWSbdqGg+/7EJpGLqof/h50m2lm4tDZFnz1lDUt0wfSFGkZRopX53dkMqBY95w3yo/t+LC7db9C3Mg1GcKOuXoCRAsBhCh0L0MX5TxjWf+7UcZSyxY4SYuq/MbfP4jtH5OZOHwdiz1fPRQe6Fn+PB7/M0lokG9Szlw5xnqa24lqS76XREV6HIRNeHHA6+pfiTd8q/patskFMZsWX5kDXp60QEnF8rmFwXIzfALv7fX4aknJjjpNg9ODxv7ARvLd/yXVGRUTIUgruhDxoZ9T0sPXWXIQUqQj+2ha7sx59nrB1k3ukdyWx7vyBe4obW0lxBMAGaTUfesaoq8dcGBGJNHdloI1pJuqnFkCa1KWQewXKVEoVal2brDWu1EzpTVt9o/crGawVRIKyRjOS1BS9BG0nhawbUYHtjXvN1W9kWFx6JsB6awlbdXDeJWg3uYStW5Vw4GcGdYqsuz8clym59foFDD72Oh+rrdT6WzGm1reAORBnAdx8xkUHf667NDJzpde8HyT3TFy9v5Py9lh3ETvXP/+1xz1VouQ7o2ETrjreA14EkjiDlZuMv+RO5smKnb7QzLFZ7cSXKtOKpQCuLTpVIBpgeGiy5VZSGTbbw+CDUm6qXF/GkD4jJABzdKyoXxJVmy9LriZotI+wuxsf59h9rOfzXL85+zQPnT0cGAgc8Q44FAiO1JMZLDtHXI9XIYAfpWXIjwwui09fJ57dKQeX6IXh2b/CyPOQbGZMeG395+nH6V2XCFvLT3AtT9Wby/h4HnGE6bgh7FU4TweC+zd8gpLv1Cl1nKUFp3iXnTrMMVigVulHYNtvqP65MkSCZYrM90xvR/QvC7JNNfB2nC89vlVZlz1SurYY5kNdBkkrQ6HcgeuuQFshzDoUuZZ4ygKlEVSrND3vgS7bQw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: j6ftK28Mx8WnMulVsrrUdhHXO9Usme7HVbQXzlpYngfX964Gw26OkU3GArqW6yJylaPLHjbZIa7JmLN+nkBBrLIurT1hcB5saWREcIQwsWg8kSvVMvVFGK6tA1Oi0CRGeqCkUoRoaJqZjudrBUEnFDxHKN8w7mtUFcEx+7DeDt8oEqN933CvtbryZ6YUaSouwvurbEgo1xgdCj0dq6uew5YIO7rdHTFAb60+LiERQoe255XwSZRLPLQdwR93Ef1tEtlarOuVnoIPkoTbmX88h5+hKcEw0zorgus6aDYCCPtv1kj1Nt0h2AS9WYEn3uz1JScgd0slDxeQWoNrZTtSUKYtF1DHjnlDUX4Jm33EwZC1sQAs3Cd23zae5pITdIlePHGl/1w9Qpl/cbq+hAyVrM1EazfTMgX50+pGa4FxPiwsc8ZvxKXI8WvLuk4kAcLuVB1ARe07CWgpJpU4hU26KGMXEJ00LnTZ9wS8v+XcRCF1kmd/D1g2wT6wkD3MJp/QVxYF7+lmk0JrXr9pmWEAbVivvvzml60YmdxWUO/q+1ROM7Sw5HN6WkoEyefOFUQJk7pZIffiJhiG981OgwvPPOUXFd+DgLmiNfr+5qCKXoc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3341b7cb-bf87-4376-9813-08dcf9112c77 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 18:32:13.7631 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QwRUf8IEVlh0TAi2df4b4Rr0dgQYOnz+6mf1eWFl8+N9jwuB2Q3MmBJY1q4P7pjuqtsgEu5mvaVImoxLrodZkA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4672 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-30_14,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410300145 X-Proofpoint-GUID: _ub0riLvnyLDmjrEKwtYzZyglTObDAwm X-Proofpoint-ORIG-GUID: _ub0riLvnyLDmjrEKwtYzZyglTObDAwm X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Support the btf_decl_tag and btf_type_tag attributes in BTF by creating and emitting BTF_KIND_DECL_TAG and BTF_KIND_TYPE_TAG records, respectively, for them. Some care is required when -gprune-btf is in effect to avoid emitting decl or type tags for declarations or types which have been pruned and will not be emitted in BTF. gcc/ * btfout.cc (get_btf_kind): Handle DECL_TAG and TYPE_TAG kinds. (btf_calc_num_vbytes): Likewise. (btf_asm_type): Likewise. (output_asm_btf_vlen_bytes): Likewise. (output_btf_tags): New. (btf_output): Call it here. (btf_add_used_type): Replace with simple wrapper around... (btf_add_used_type_1): ...the implementation. Handle BTF_KIND_DECL_TAG and BTF_KIND_TYPE_TAG. (btf_add_vars): Update btf_add_used_type call. (btf_assign_tag_ids): New. (btf_mark_type_used): Update btf_add_used_type call. (btf_collect_pruned_types): Likewise. Handle type and decl tags. (btf_finish): Call btf_assign_tag_ids. gcc/testsuite/ * gcc.dg/debug/btf/btf-decl-tag-1.c: New test. * gcc.dg/debug/btf/btf-decl-tag-2.c: New test. * gcc.dg/debug/btf/btf-decl-tag-3.c: New test. * gcc.dg/debug/btf/btf-decl-tag-4.c: New test. * gcc.dg/debug/btf/btf-type-tag-1.c: New test. * gcc.dg/debug/btf/btf-type-tag-2.c: New test. * gcc.dg/debug/btf/btf-type-tag-3.c: New test. * gcc.dg/debug/btf/btf-type-tag-4.c: New test. * gcc.dg/debug/btf/btf-type-tag-c2x-1.c: New test. include/ * btf.h (BTF_KIND_DECL_TAG, BTF_KIND_TYPE_TAG) New defines. (struct btf_decl_tag): New. --- gcc/btfout.cc | 176 +++++++++++++++--- .../gcc.dg/debug/btf/btf-decl-tag-1.c | 14 ++ .../gcc.dg/debug/btf/btf-decl-tag-2.c | 22 +++ .../gcc.dg/debug/btf/btf-decl-tag-3.c | 22 +++ .../gcc.dg/debug/btf/btf-decl-tag-4.c | 34 ++++ .../gcc.dg/debug/btf/btf-type-tag-1.c | 27 +++ .../gcc.dg/debug/btf/btf-type-tag-2.c | 17 ++ .../gcc.dg/debug/btf/btf-type-tag-3.c | 21 +++ .../gcc.dg/debug/btf/btf-type-tag-4.c | 25 +++ .../gcc.dg/debug/btf/btf-type-tag-c2x-1.c | 23 +++ include/btf.h | 14 ++ 11 files changed, 371 insertions(+), 24 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-2.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-3.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-4.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-2.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-3.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-4.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-c2x-1.c diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 083ca48d627..e8190f685f9 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -141,6 +141,8 @@ get_btf_kind (uint32_t ctf_kind) case CTF_K_VOLATILE: return BTF_KIND_VOLATILE; case CTF_K_CONST: return BTF_KIND_CONST; case CTF_K_RESTRICT: return BTF_KIND_RESTRICT; + case CTF_K_DECL_TAG: return BTF_KIND_DECL_TAG; + case CTF_K_TYPE_TAG: return BTF_KIND_TYPE_TAG; default:; } return BTF_KIND_UNKN; @@ -217,6 +219,7 @@ btf_calc_num_vbytes (ctf_dtdef_ref dtd) case BTF_KIND_CONST: case BTF_KIND_RESTRICT: case BTF_KIND_FUNC: + case BTF_KIND_TYPE_TAG: /* These kinds have no vlen data. */ break; @@ -256,6 +259,10 @@ btf_calc_num_vbytes (ctf_dtdef_ref dtd) vlen_bytes += vlen * sizeof (struct btf_var_secinfo); break; + case BTF_KIND_DECL_TAG: + vlen_bytes += sizeof (struct btf_decl_tag); + break; + default: break; } @@ -452,6 +459,20 @@ btf_asm_type (ctf_dtdef_ref dtd) and should write 0. */ dw2_asm_output_data (4, 0, "(unused)"); return; + case BTF_KIND_DECL_TAG: + { + if (dtd->ref_type) + break; + else if (dtd->dtd_u.dtu_tag.ref_var) + { + /* ref_type is NULL for decl tag attached to a variable. */ + ctf_dvdef_ref dvd = dtd->dtd_u.dtu_tag.ref_var; + dw2_asm_output_data (4, dvd->dvd_id, + "btt_type: (BTF_KIND_VAR '%s')", + dvd->dvd_name); + return; + } + } default: break; } @@ -801,6 +822,12 @@ output_asm_btf_vlen_bytes (ctf_container_ref ctfc, ctf_dtdef_ref dtd) at this point. */ gcc_unreachable (); + case BTF_KIND_DECL_TAG: + dw2_asm_output_data (4, dtd->dtd_u.dtu_tag.component_idx, + "component_idx=%d", + dtd->dtd_u.dtu_tag.component_idx); + break; + default: /* All other BTF type kinds have no variable length data. */ break; @@ -851,6 +878,20 @@ output_btf_func_types (void) btf_asm_func_type (ref); } +static void +output_btf_tags (ctf_container_ref ctfc) +{ + /* If pruning, tags which are not pruned have already been added to + the used list and output by output_btf_types. */ + if (debug_prune_btf) + return; + + ctf_dtdef_ref dtd; + unsigned i; + FOR_EACH_VEC_ELT (*ctfc->ctfc_tags, i, dtd) + output_asm_btf_type (ctfc, dtd); +} + /* Output all BTF_KIND_DATASEC records. */ static void @@ -869,6 +910,7 @@ btf_output (ctf_container_ref ctfc) output_btf_types (ctfc); output_btf_vars (ctfc); output_btf_func_types (); + output_btf_tags (ctfc); output_btf_datasec_types (); output_btf_strs (ctfc); } @@ -985,7 +1027,8 @@ static vec fixups; is created and emitted. This vector stores them. */ static GTY (()) vec *forwards; -/* Recursively add type DTD and any types it references to the used set. +/* Implementation of btf_add_used_type. + Recursively add type DTD and any types it references to the used set. Return a type that should be used for references to DTD - usually DTD itself, but may be NULL if DTD corresponds to a type which will not be emitted. CHECK_PTR is true if one of the predecessors in recursive calls is a struct @@ -996,8 +1039,8 @@ static GTY (()) vec *forwards; CREATE_FIXUPS is false. */ static ctf_dtdef_ref -btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, - bool check_ptr, bool seen_ptr, bool create_fixups) +btf_add_used_type_1 (ctf_container_ref ctfc, ctf_dtdef_ref dtd, + bool check_ptr, bool seen_ptr, bool create_fixups) { if (dtd == NULL) return NULL; @@ -1029,8 +1072,9 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, fixups.unordered_remove (i); /* Add the concrete base type. */ - dtd->ref_type = btf_add_used_type (ctfc, dtd->ref_type, check_ptr, - seen_ptr, create_fixups); + dtd->ref_type = btf_add_used_type_1 (ctfc, dtd->ref_type, + check_ptr, seen_ptr, + create_fixups); return dtd; } default: @@ -1044,8 +1088,8 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, the reference to the bitfield. The slice type won't be emitted, but we need the information in it when writing out the bitfield encoding. */ - btf_add_used_type (ctfc, dtd->dtd_u.dtu_slice.cts_type, - check_ptr, seen_ptr, create_fixups); + btf_add_used_type_1 (ctfc, dtd->dtd_u.dtu_slice.cts_type, + check_ptr, seen_ptr, create_fixups); return dtd; } @@ -1069,7 +1113,11 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, case BTF_KIND_INT: case BTF_KIND_FLOAT: case BTF_KIND_FWD: - /* Leaf kinds which do not refer to any other types. */ + case BTF_KIND_DECL_TAG: + /* Leaf kinds which do not refer to any other types. + DECL_TAG is a special case: we treat it as though it does not refer + to any other types, since we only want the DECL_TAG to be added if + the type to which it refers has already been added. */ break; case BTF_KIND_FUNC: @@ -1082,6 +1130,7 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, case BTF_KIND_CONST: case BTF_KIND_VOLATILE: case BTF_KIND_RESTRICT: + case BTF_KIND_TYPE_TAG: { /* These type kinds refer to exactly one other type. */ if (check_ptr && !seen_ptr) @@ -1106,18 +1155,18 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, } /* Add the type to which this type refers. */ - dtd->ref_type = btf_add_used_type (ctfc, dtd->ref_type, check_ptr, - seen_ptr, create_fixups); + dtd->ref_type = btf_add_used_type_1 (ctfc, dtd->ref_type, check_ptr, + seen_ptr, create_fixups); break; } case BTF_KIND_ARRAY: { /* Add element and index types. */ ctf_arinfo_t *arr = &(dtd->dtd_u.dtu_arr); - arr->ctr_contents = btf_add_used_type (ctfc, arr->ctr_contents, false, - false, create_fixups); - arr->ctr_index = btf_add_used_type (ctfc, arr->ctr_index, false, false, - create_fixups); + arr->ctr_contents = btf_add_used_type_1 (ctfc, arr->ctr_contents, + false, false, create_fixups); + arr->ctr_index = btf_add_used_type_1 (ctfc, arr->ctr_index, false, + false, create_fixups); break; } case BTF_KIND_STRUCT: @@ -1133,8 +1182,8 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, /* Add member type for struct/union members. For enums, only the enumerator names are needed. */ if (kind == BTF_KIND_STRUCT || kind == BTF_KIND_UNION) - dmd->dmd_type = btf_add_used_type (ctfc, dmd->dmd_type, true, - false, create_fixups); + dmd->dmd_type = btf_add_used_type_1 (ctfc, dmd->dmd_type, true, + false, create_fixups); ctf_add_string (ctfc, dmd->dmd_name, &(dmd->dmd_name_offset), CTF_STRTAB); } @@ -1143,16 +1192,17 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, case BTF_KIND_FUNC_PROTO: { /* Add return type. */ - dtd->ref_type = btf_add_used_type (ctfc, dtd->ref_type, false, false, - create_fixups); + dtd->ref_type = btf_add_used_type_1 (ctfc, dtd->ref_type, false, false, + create_fixups); /* Add arg types. */ ctf_func_arg_t * farg; for (farg = dtd->dtd_u.dtu_argv; farg != NULL; farg = (ctf_func_arg_t *) ctf_farg_list_next (farg)) { - farg->farg_type = btf_add_used_type (ctfc, farg->farg_type, false, - false, create_fixups); + farg->farg_type = btf_add_used_type_1 (ctfc, farg->farg_type, + false, false, + create_fixups); /* Note: argument names are stored in the auxilliary string table, since CTF does not include arg names. That table has not been cleared, so no need to re-add argument names here. */ @@ -1166,6 +1216,16 @@ btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, return dtd; } +/* Recursively add type DTD and any types it references to the used set. + Return a type that should be used for references to DTD - usually DTD itself, + but may be NULL if DTD corresponds to a type which will not be emitted. */ + +static ctf_dtdef_ref +btf_add_used_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) +{ + return btf_add_used_type_1 (ctfc, dtd, false, false, true); +} + /* Initial entry point of BTF generation, called at early_finish () after CTF information has possibly been output. Translate all CTF information to BTF, and do any processing that must be done early, such as creating @@ -1402,7 +1462,7 @@ btf_add_vars (ctf_container_ref ctfc) ctf_dmdef_t *dmd; for (dmd = dtd->dtd_u.dtu_members; dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd)) - btf_add_used_type (ctfc, dmd->dmd_type, false, false, true); + btf_add_used_type (ctfc, dmd->dmd_type); } } } @@ -1488,6 +1548,50 @@ btf_assign_var_ids (ctf_container_ref ctfc) } } +/* Assign BTF IDs for type and decl tags and account for their size. */ + +static void +btf_assign_tag_ids (ctf_container_ref ctfc) +{ + /* Both decl and type tags may be pruned if the types/decls to which they + refer are pruned. This is handled in collect_pruned_types, and through + that process they have also been assigned ids already. */ + if (debug_prune_btf) + return; + + size_t num_tags = vec_safe_length (ctfc->ctfc_tags); + if (num_tags == 0) + return; + + unsigned int i; + ctf_dtdef_ref dtd; + FOR_EACH_VEC_ELT (*ctfc->ctfc_tags, i, dtd) + { + /* Assign BTF id. */ + ctf_id_t id = ctfc->ctfc_nextid++; + gcc_assert (id <= BTF_MAX_TYPE); + dtd->dtd_type = id; + + /* Tags on functions will have a ref_type pointing to the + FUNC_PROTO, we want them to point the FUNC record instead. */ + ctf_dtdef_ref *pdtd = NULL; + if (dtd->ref_type && (pdtd = func_map->get (dtd->ref_type)) != NULL) + { + dtd->ref_type = *pdtd; + } + + /* Strings for tags are stored in the auxilliary strtab, which is + concatenated after the regular strtab. ctti_name only accounts + for offset in the auxilliary strtab until this point. */ + dtd->dtd_data.ctti_name += ctfc_get_strtab_len (ctfc, CTF_STRTAB); + + ctfc->ctfc_num_types++; + + if (btf_dtd_kind (dtd) == BTF_KIND_DECL_TAG) + ctfc->ctfc_num_vlen_bytes += sizeof (struct btf_decl_tag); + } +} + /* Assign BTF IDs for datasec records and account for their size. */ static void @@ -1522,7 +1626,7 @@ btf_mark_type_used (tree t) if (!dtd) return; - btf_add_used_type (ctfc, dtd, false, false, true); + btf_add_used_type (ctfc, dtd); } /* Callback used for assembling the only-used-types list. Note that this is @@ -1549,7 +1653,7 @@ btf_collect_pruned_types (ctf_container_ref ctfc) size_t i; FOR_EACH_VEC_ELT (*funcs, i, dtd) { - btf_add_used_type (ctfc, dtd->ref_type, false, false, true); + btf_add_used_type (ctfc, dtd->ref_type); ctf_add_string (ctfc, dtd->dtd_name, &(dtd->dtd_data.ctti_name), CTF_STRTAB); } @@ -1558,10 +1662,33 @@ btf_collect_pruned_types (ctf_container_ref ctfc) for (i = 0; i < ctfc->ctfc_vars_list_count; i++) { ctf_dvdef_ref dvd = ctfc->ctfc_vars_list[i]; - btf_add_used_type (ctfc, dvd->dvd_type, false, false, true); + btf_add_used_type (ctfc, dvd->dvd_type); ctf_add_string (ctfc, dvd->dvd_name, &(dvd->dvd_name_offset), CTF_STRTAB); } + /* Used type tags will be added by recursive btf_add_used_type calls above. + For decl tags, scan the list and only add those decl tags whose referent + types are marked as used. We may have pruned a struct type with members + annotated by a decl tag. */ + FOR_EACH_VEC_ELT (*ctfc->ctfc_tags, i, dtd) + { + /* Only add decl tags whose referent types have not been pruned. + Variables are never pruned, so decl tags on variables are always + used. */ + if (btf_dtd_kind (dtd) == BTF_KIND_DECL_TAG + && ((dtd->ref_type && btf_used_types->contains (dtd->ref_type)) + || (dtd->dtd_u.dtu_tag.ref_var))) + btf_add_used_type (ctfc, dtd); + + /* Tags on functions or function args will have a ref_type pointing to the + FUNC_PROTO, we want them to point the FUNC record instead. */ + ctf_dtdef_ref *pdtd = NULL; + if (dtd->ref_type + && btf_used_types->contains (dtd->ref_type) + && (pdtd = func_map->get (dtd->ref_type)) != NULL) + dtd->ref_type = *pdtd; + } + /* Process fixups. If the base type was never added, create a forward for it and adjust the reference to point to that. If it was added, then nothing needs to change. */ @@ -1634,6 +1761,7 @@ btf_finish (void) btf_assign_var_ids (tu_ctfc); btf_assign_func_ids (tu_ctfc); + btf_assign_tag_ids (tu_ctfc); btf_assign_datasec_ids (tu_ctfc); /* Finally, write out the complete .BTF section. */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-1.c new file mode 100644 index 00000000000..c933d84b497 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-1.c @@ -0,0 +1,14 @@ +/* Test simple BTF decl tag generation for variables. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_decl_tag ("decl1"))) +#define __tag2 __attribute__((btf_decl_tag ("decl2"))) +#define __tag3 __attribute__((btf_decl_tag ("decl3"))) + +int x __tag1 __tag2; +int y __tag1; + +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 'x'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 'x'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 'y'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-2.c b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-2.c new file mode 100644 index 00000000000..c4f09ca839c --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-2.c @@ -0,0 +1,22 @@ +/* Test BTF decl tag generation for structs. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_decl_tag ("decl1"))) +#define __tag2 __attribute__((btf_decl_tag ("decl2"))) +#define __tag3 __attribute__((btf_decl_tag ("decl3"))) + +struct Foo { + int a; + int b __tag3 __tag2; + char *z __tag1; +}; + +struct Foo f __tag1 __tag2; + +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_STRUCT 'Foo'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl3'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_STRUCT 'Foo'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_STRUCT 'Foo'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=2" 1} } */ + +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 'f'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 'f'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-3.c b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-3.c new file mode 100644 index 00000000000..7eb8a93ec12 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-3.c @@ -0,0 +1,22 @@ +/* Test BTF decl tag generation for functions and function args. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_decl_tag ("decl1"))) +#define __tag2 __attribute__((btf_decl_tag ("decl2"))) +#define __tag3 __attribute__((btf_decl_tag ("decl3"))) + +int __tag1 __tag2 func (int arg_a __tag3 __tag1, int arg_b __tag2) +{ + return arg_a * arg_b; +} + +int foo (int x) { + return func (x, x + 1); +} + +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=0" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl3'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=0" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=1" 1} } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-4.c b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-4.c new file mode 100644 index 00000000000..a9022375529 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-decl-tag-4.c @@ -0,0 +1,34 @@ +/* Test BTF decl tag generation with BTF pruning. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -gprune-btf -dA" } */ + +#define __decl1 __attribute__((btf_decl_tag ("decl1"))) +#define __decl2 __attribute__((btf_decl_tag ("decl2"))) +#define __decl3 __attribute__((btf_decl_tag ("decl3"))) + +struct S { + /* This tag on S.v shall not be emitted, because struct S is pruned and + replaced with a FWD, which does not hold any member info. */ + int v __decl3; + int w; +}; + +struct T { + int a; + struct S *s __decl1; + int c __decl2; +}; + +struct T t __decl1; + +int __decl1 func (struct T *t __decl2) +{ + return t->a + t->c; +} + +/* { dg-final { scan-assembler-not " BTF_KIND_DECL_TAG 'decl3'" } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_STRUCT 'T'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_STRUCT 'T'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=2" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VAR 't'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=-1" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_DECL_TAG 'decl2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_FUNC 'func'\\)\[\\r\\n\]+\[^\\r\\n\]*component_idx=0" 1} } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-1.c new file mode 100644 index 00000000000..750add9d923 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-1.c @@ -0,0 +1,27 @@ +/* Test simple generation of BTF type tags. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_type_tag("type1"))) +#define __tag2 __attribute__((btf_type_tag("type2"))) +#define __tag3 __attribute__((btf_type_tag("type3"))) + +int __tag1 __tag2 x; +int __tag1 y; + +struct Foo { + char a; + int b; +}; + +struct Foo * __tag1 __tag3 f; + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'x'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type2'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1} } */ + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'y'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1 } } */ +/* { dg-final { scan-assembler " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_INT" } } */ + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'f'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type3'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type3'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_PTR" 1 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-2.c b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-2.c new file mode 100644 index 00000000000..35126fc84ae --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-2.c @@ -0,0 +1,17 @@ +/* Test BTF type tag generation with cv-quals. + BTF format requires that type tags precede cv-quals on a given + type in the type chain. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_type_tag("type1"))) +#define __tag2 __attribute__((btf_type_tag("type2"))) +#define __tag3 __attribute__((btf_type_tag("type3"))) + +/* var (a) -> tag2 -> tag1 -> const -> int */ +const int __tag1 __tag2 a; + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'a'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type2'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_CONST ''\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_CONST ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_INT" 1 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-3.c b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-3.c new file mode 100644 index 00000000000..c6523830f07 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-3.c @@ -0,0 +1,21 @@ +/* Test BTF type tag generation with typedefs. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 __attribute__((btf_type_tag("type1"))) +#define __tag2 __attribute__((btf_type_tag("type2"))) +#define __tag3 __attribute__((btf_type_tag("type3"))) + +typedef const int foo; +typedef int __tag1 bar; + +foo __tag2 x; +const bar y; + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'x'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type2'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPEDEF 'foo'\\)" 1 } } */ + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'y'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_CONST" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_CONST ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPEDEF 'bar'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPEDEF 'bar'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_INT" 1 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-4.c b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-4.c new file mode 100644 index 00000000000..1fb97232242 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-4.c @@ -0,0 +1,25 @@ +/* Test BTF type tag generation with BTF pruning. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -gprune-btf -dA" } */ + +#define __tag1 __attribute__((btf_type_tag("type1"))) +#define __tag2 __attribute__((btf_type_tag("type2"))) +#define __tag3 __attribute__((btf_type_tag("type3"))) + +struct S { + int v ; + /* This tag on S.w shall not be emitted because struct S is pruned. */ + int __tag3 w; +}; + +struct T { + int __tag1 a; + struct S * __tag2 s; + int c; +}; + +struct T t; + +/* { dg-final { scan-assembler-not " BTF_KIND_TYPE_TAG 'type3'" } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_INT" 1} } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_PTR" 1} } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-c2x-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-c2x-1.c new file mode 100644 index 00000000000..c6129d6dd56 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-type-tag-c2x-1.c @@ -0,0 +1,23 @@ +/* Test BTF type tag generation using C2x standard attribute syntax. + Note: in more complicated cases the __attribute__ syntax causes BTF type tags + to "slide around" in defined, but often unexpected ways. */ + +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +#define __tag1 [[gnu::btf_type_tag ("type1")]] +#define __tag2 [[gnu::btf_type_tag ("type2")]] +#define __tag3 [[gnu::btf_type_tag ("type3")]] + +/* var (z) -> tag2 -> tag3 -> const -> ptr -> tag2 -> ptr -> tag1 -> volatile -> int */ +volatile int __tag1 * __tag2 * __tag3 __tag2 const z; + +/* { dg-final { scan-assembler-times " BTF_KIND_VAR 'z'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type2'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type3'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type3'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_CONST" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_CONST ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_PTR" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_PTR ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type2'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type2'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_PTR" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_PTR ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_TYPE_TAG 'type1'\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_TYPE_TAG 'type1'(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_VOLATILE ''\\)" 1 } } */ +/* { dg-final { scan-assembler-times " BTF_KIND_VOLATILE ''(\[\\r\\n\]+\[^\\r\\n\]*){2}\\(BTF_KIND_INT" 1 } } */ diff --git a/include/btf.h b/include/btf.h index 0c3e1a1cf51..ff152362530 100644 --- a/include/btf.h +++ b/include/btf.h @@ -114,6 +114,8 @@ struct btf_type #define BTF_KIND_VAR 14 /* Variable. */ #define BTF_KIND_DATASEC 15 /* Section such as .bss or .data. */ #define BTF_KIND_FLOAT 16 /* Floating point. */ +#define BTF_KIND_DECL_TAG 17 /* Declaration tag. */ +#define BTF_KIND_TYPE_TAG 18 /* Type tag. */ #define BTF_KIND_ENUM64 19 /* Enumeration up to 64 bits. */ #define BTF_KIND_MAX BTF_KIND_ENUM64 #define NR_BTF_KINDS (BTF_KIND_MAX + 1) @@ -227,6 +229,18 @@ struct btf_enum64 uint32_t val_hi32; /* high 32-bit value for a 64-bit value Enumerator */ }; +/* BTF_KIND_DECL_TAG is followed by a single struct btf_decl_tag, which + describes the item to which the tag applies: + - If component_idx == -1, then the tag applies to item referred to by + the type_id. + - Otherwise, the tag applies to the struct or union member, or function + argument of the type referred to by type_id with the 0-based index + given by component_idx. */ +struct btf_decl_tag +{ + int32_t component_idx; +}; + #ifdef __cplusplus } #endif From patchwork Wed Oct 30 18:31:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 99839 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4DA03857C6A for ; Wed, 30 Oct 2024 18:33:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 746A63857BB6 for ; Wed, 30 Oct 2024 18:32:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 746A63857BB6 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 746A63857BB6 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313144; cv=pass; b=ZUz1cX7DZk9it4qLvmnMH+KApMu308rCo9wXA5nEJ1AxzcBrSKYiLcjTWMvfaWd68ZQ1YSeO2UgqgIr55oxDalQoyRDKiHrJsSnAOwjlv57LyGSI29GhRGmWvcBJVRmg9g2YRRfwro/X4os3T/AOh5s1dFCMVl+oKMATvZZY7tw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313144; c=relaxed/simple; bh=nkOLhlDifUdHP9uHJ2Nh3s6ZFGdAe32NvdbU9wbjNdA=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=Wmey5OLtrJZJNyrXAqBiWt+glrmYih4ETZJd0kvaDs7YJUqkyXJ8JTPb5iUH0WfDk3sK4WOf/Cnt1fuENEqbZ5KecdfceTiRp6u6K5c7IO4ocA1hAMs6sdYvKxu7B14l18eWNCC03E6BWT7+37rHExQWO/yCK9ccVmDb/BfaKO8= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49UGXb2D019158; Wed, 30 Oct 2024 18:32:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=BbM7y/YJP8BRdqlV4BBhm1T92g5HX71KHak3DJdaNZc=; b= Cn6hNzjQwx8+SlToXeL0Lvtvy67hEPXLWxjS5W4TAPmQAP3cCNPr5A6b0O5KPOPT a3EHFuajCiIKo0wUvvZjJ0swRrFmwcx2dZR6Vwx9N9o1lhu4JkngzHVhZFYDStIs f+0hPl1eunQDnPKbhYxkacmI6y1pIhAA5n/F3STXpWKt7TKM/sdSbd/CZjruoG7V 4qWng2ZkwyxeY3f+MsPdIOUNMmgotbtKBYHUUgW+12oc/ZBnMY3l7wjIrTy5zE5G 6we4/2CHWbprlb/Isgf/hr41Xsu4zo0pdB+bhZdNfS8vxRrYfGCLUgxpvwlF9EIO KG+TGC7IjMmznT9l55OZoQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grgwgnu2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:20 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49UHR8KX004777; Wed, 30 Oct 2024 18:32:19 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2177.outbound.protection.outlook.com [104.47.58.177]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42jb2w3ayh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 18:32:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jOfPH5Me20jGfJqffBo4CIMzFWPVQuuHFWw2fQYXxtwcDpizGMoXl+nWLNmhAeAQEv2ukJ74XGqunIzx1YWaAAxavoOf7QFmU7AO0xzoywOwg5hkfJNjpwC8M9hlGpc22uDwOM3VtE6/o5V/dGgtSzfWKAmbGbjZFtEnd6wi75riypAS1D3IsXdnxUTteV/1+pilLadR40YywOB821tHfOze1cXH5R5jq3ZJjbbtn4tary5SXHtzf6y8NxZTcW3jLBhFkjr1+BOjunfIXSCpXLdhBXDMGNxSkUgW5nZZrNty6cH/ZEd23jxwxVWd7vL12JV/R/yDJZapwwd1FiLKGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BbM7y/YJP8BRdqlV4BBhm1T92g5HX71KHak3DJdaNZc=; b=oLLn3+rUkc1kxcqK7RAqK+PbOrVf7MV3gwP9L9q9/BdTipB4oL7/MvUVEvlZ2Mo0ASOVow+0fWh4/LEdvcXP93TqX0ZI/bNQjjG0SGxlpa/07qHPRPQR979mDW+0gzMHQ89RnW+8Lu0vTpDaNm9pG3UtvAFesxhORcifphmCf9ArFGaoqLa8nsceheekn2ehExnriOY5qslLk0SE8Ij3l86s75MWGKLMWX+H3swfzfF7hA2Y8usrCgJo3c9DSmkAOWariqt5m1PEbbUoJ/vgOua39hB2Ir+U6me76TQuMkXWkTB0A+UvZHPa4uI8BVvQVP8wfXNTa24cNmhzqDrcHA== 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=BbM7y/YJP8BRdqlV4BBhm1T92g5HX71KHak3DJdaNZc=; b=w/Y4taGZuZYocwZ1WEPHypxTaaSD+ZquzkmaProKGq8pc1GLDCmIBSxV3F+LqJKXzUzAAXkKnCsOmH8M5qc7AkBHE+mZuVIho3RwwgPnXlmJKYrfO2qknoN7bxpwtLT4sJeAG2zxyJ4SLwce9nUY/vvd+qoIbJ6as1vi3dvHEI4= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by SJ0PR10MB4672.namprd10.prod.outlook.com (2603:10b6:a03:2af::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Wed, 30 Oct 2024 18:32:16 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%4]) with mapi id 15.20.8093.024; Wed, 30 Oct 2024 18:32:16 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, yonghong.song@linux.dev Subject: [PATCH 5/5] doc: document btf_type_tag and btf_decl_tag attributes Date: Wed, 30 Oct 2024 11:31:55 -0700 Message-ID: <20241030183155.2038501-6-david.faust@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241030183155.2038501-1-david.faust@oracle.com> References: <20241030183155.2038501-1-david.faust@oracle.com> X-ClientProxiedBy: MW4PR03CA0065.namprd03.prod.outlook.com (2603:10b6:303:b6::10) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|SJ0PR10MB4672:EE_ X-MS-Office365-Filtering-Correlation-Id: f6d7a4be-561c-4f93-3683-08dcf9112e1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: xE0qb+KiblHaiO9nDrj2SkUiRyBQycZEWEuqNB8aHX+2U34qKV/D+teWxT7qx6PxKz/mE2Azmdep9AwyyLNaQeWP2PVpFIncVwal+3VnE9ScXNLXrRtZJyaMPRiGiog6dWCWAzebikPS5N+kHQjjA9KeMqRjq0FYWxZHPhz1091NtLSbs9hmPjup3T9/fDfAIttebcfxPba3mU4Wqqmbpy7YTuW5cmx4NLkDbASWmHPpkgSPiZsUVJVsEs7rFKhj0CJ3SMKimnAW+TkoizE4HuEX6GWsO7T/Wf9tiIbhK//PeMjTnMV0y4HbUXKFXKIq5/2m5pGnFWcX/uEfFGVRSgC/bbVxhBymkGoMJK4ZFVjyc9XmXR2VSzqEcjtRkAu6I5LSw9skkFGAqelmuI3M+IeHUvViuw8SsKpOZgh3ujugD8gxXrA5Zew9Fr8e8AyJxur7aQrnZF8uP3krk8FqZuZtZXVRnEXLqtZTzJ4OqZAttlJCLOafCDXyO8d9Zhcih33UO3xM6FItm9K6ntyEpmVVstsgf502U0nk/Jyh8FXcuz1AIX04Ukk7v4mf2YJ2oMegZzhH66dQnPGW9aC05z3GlA7XfbxJ9lfHMkZ2Sg//7FiM4Fmrmh9LbzI4ok06XpgPzalNhM4gn9rg0Mr4hK8+QRIZ8Hy3p9yazlAANSPer+XtF9bGgZnyfpg37SXOOW038Gw9aBURAYGW7+DmknsBZowl+S9X20r9SWjCMIB01T9huN45MmZgW0u0rwhgG4rmdSwA3kC6BWxY4CEsPg9Eh2pLgwFaWD9x2cCKahrzBoGPoJVMl61HVCkAd3M1pfRnfAdprBXxj+Us3gjbTXtCFPXgO7hngjzIl3LCxxcv6X0KaknfGxxlMVwKEfGGY0QSDDm5+lCi5k5q3qdKd3IE1itVC2EPSXLw3N0T6ubaorF/PlN/C3CjCGO38bxd/Ml6macWYB8ZS9rViVh454dda7RU+C3+IppfNEB433mbKPMbvKRwWp5lZoDwIGFh/vYkrU2AK99TkExn3BQTHg3PHpmsRW6JGFMdomQ/guyFVeofIMesa5UMnjMOR7WDVkrgcxwYJtOGydxqnFrLInSX4KoFwtj/NmlQJPj9BkWLPjM+K5uOQ1W+vBz0ITYuTJgaAU0tQ/hxg+tE6wmkWUjX1Ct4xCo8ssPT4j7hF1SpxRyhkrSxJlv/rc1JluHeQ3POddRWB5NZZEFylXD6TYKn2qaSowhQir0bnvvs7v0/vcK7aOEN0iSeSmp96cVyH1U5q6/2hlgQgcfgxWN4vv+BcX7oLNaBnpBhaiv3Jhk= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR10MB7953.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tBbvPOOrM6uhI8KIYMDZP1aJuKushCzGo07IeZT4TEuOtbkDyEcclO3jXD3aa1iZMiOLPyrK1akSckp1X1ZKDV1YCKDU2ubX1d33Uzw/L6PMbdzBUw1pzR0QvrRZ+Oq5A6gHcotOUg6F8vE5gLWtZ/XT7ad+Ta2lE5bSACUlDUwvgJ5GyEm5XAtamx118SFaL8EFif1uiwyuyZ6gFAmZXvIUxoe67NAMkewKX4WegJTWEiNLEmUtO3ajABmfdWG7P0r+wWVxQw9kcw5DcpceqOxHsvIJdju85goeobb380D27zPwEHiDs+BWzcuQvUOoDpATHEm/gJs88BCqMC1bb6eLeFGT5V1wRbCYuzuE8xRlERaL6/wRkP03tcgPt8aTx0lELy8mUwtIYjiHjLmOVT/bLVgKziYTBIMIldwb6gRsj1PJDfc7pViggMDDuP2utOzFP/CDFaT4XPWssN1c8jmuJCKWPdmEaIFiAtN5dVfuCMr/1GrvQo/HyWzefQdFfKGYhPWZZzfQCnBTS4EGmmjv5Sw010j59ATTI9CE3nOs4PImN6WTRN+iODNvyYFeVEU+H/rU+isM78kdEHO0i7Qr8J1XQgY4u0BO8cPKkRu+48HWQsAhAXLsJGfim/A3hlOjX71eBkITyjLtNritxjcb9Q3fxy6f4vnnF1H1vQj38JpZUkS8hJhJsiebBpVPCAfFXBEC77gN5HqtsR7X3cCEpSSlQllf9o4LqdAKQ+i5wKDbtO3AiydOIPs+1HPZAeBK+5VBa0D/5FuKFgH1XfPu+YmtRS+YfsDjNMVJbh9KVKC8hIcfBm1j3aas4CeEO8ZAG3mIj/+ScERqRUG7xDOjNxA6r4N6hQfmDQq+rtdQra2zfqqeSrzwqedXFY5pT1oOB+YhSFr6YNQT0YbSF7Q+EpSs78prMADeBVplKlYIehV9/ZeU/egx0R5ckc+X9qdsEk6VxrSFs7q35CD6VcdOuehJDavNiB8wgvd44EG4TRsBv4qsPfbjIYBYBMFZTJkysyxIVa2fzQz3IcX/gDWeaCLjgp2cuXoeVoj6WazqaOqxZM9ewfGVC/QXrJPz16znkHeUDcO36NmG/aslzNUf3eWkg537WRzXmyn7j5m7lTSG4J0pl+ACZ18xqu5i8mJoL8VXblKPLz2+JqVqJH6A1kSYXtVsyOb/yLpN3tW6MNLFURl1kI9NT0zQN9ydOx4mpceAn2nowSbnU7JI+trIwnot/g6jfm8ISPMUlhZEurA36N2ru6JQVnYrr7S4YwfQi0lyHxIgiKlc8vjCiX2HOUoKH49MejUrrgt8VyrrJj91unIk/mT7g6kSkWUd7MueV2njjeXuTz4ZCgbrIB6Dt0wLpTK5+ZIU+G5PCYJ6elT1G/8jSkv3vh/nHwU2v7Nd+S8PXsl6jM5k0CW6GB9NGA/J9nB81uE/MeKee8fAa7joL15ZsYNsOJvcBIEdyuU0oF1v6EcA31wTO28YchaAYRCXc39WB9vsUldkN/p7LyX7KP/FWz9lqCWqqA3FNcA7oW0QylwcqAgbNI6ayzVr+VA18JohASctrm3uf8I3IUxswdnkLDoW5fktV+Ys9pTzGE0wV616ZgxXgR4AnA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: dHVcBi2Ge2/n5Hzs+K61+46O6eziFSHJkEXIqFInLW1aTpku4rq2l8uq5lqXdlhiCfk40Z+ghhxQoTNTkPvEH30P9MHtzS9shLlIcMlE1ybpUcCwmoRJ8sB1gwROtnRa7WTSWQYnmay/zfDuNnsZWsMqJckckK/SbcctDDjqeoB+wxdZHwkk0+3FaeQk2bDKl9ohRVn2A7xmhLXjVJazJor90Q0fSK9ZIzp80DZ4ixDJqVeA9d9sB8cdda9g9pRTzdaiO7dUIfAZIuzhbfsqAwVEozTdZzTTkhU0g+9uWR/xlEQb+oSI5Q7FmRTL+X5nRYlIVimtT4Os561PHUdglPzyXgvToVHhoB+94HMPrqAAy5vZ3b7ITOg7p59+M5PKsDcuXU5nEfxCyIYcLHxq5kyxTRxOulkQbbFmnDp2OgQ9n31KZ/z3pb+RlOr/l/4kpJ+USsKCVrSw6NfUPvdxh9akb2QpgXESJqWbSUZAvwstWby0U5s/wJSfNGMD36nS6yKA9eBI/Ug/IoTQej/okAswAICZFkSn8jICzlAM8J14RZ9dMBANTz+LYHw2HJOUo9SHeuLzz4z/kguVij5Gxk2UmbpHgavujCut3vmeLAA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6d7a4be-561c-4f93-3683-08dcf9112e1e X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 18:32:16.5805 (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: XsBT0QNUTfdawQWRZY4R83F/xKqfSo0jR1sJ10S2Ju4PA+TYnSl7RYUQ8ZDDVIBffdLDwKgVaI+e1DL24EsKgQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4672 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-30_14,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410300145 X-Proofpoint-ORIG-GUID: FA_5CoEPIQtzJxvw3e49mtTCXTIiPjUN X-Proofpoint-GUID: FA_5CoEPIQtzJxvw3e49mtTCXTIiPjUN X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org gcc/ * doc/extend.texi (Common Variable Attributes): Document new btf_decl_tag attribute. (Common Type Attributes): Document new btf_type_tag attribute. --- gcc/doc/extend.texi | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 42bd567119d..fd8f2425947 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -7920,6 +7920,41 @@ align them on any target. The @code{aligned} attribute can also be used for functions (@pxref{Common Function Attributes}.) +@cindex @code{btf_decl_tag} variable attribute +@item btf_decl_tag (@var{argument}) +The @code{btf_decl_tag} attribute may be used to associate variable +declarations, struct or union member declarations, function +declarations, or function parameter declarations with arbitrary strings. +These strings are not interpreted by the compiler in any way, and have +no effect on code generation. Instead, these user-provided strings +are recorded in DWARF (via @code{DW_AT_GNU_annotation} and +@code{DW_TAG_GNU_annotation} extensions) and BTF information (via +@code{BTF_KIND_DECL_TAG} records), and associated to the attributed +declaration. If neither DWARF nor BTF information is generated, the +attribute has no effect. + +The argument is treated as an ordinary string in the source language +with no additional special rules. + +The attribute may be supplied multiple times for a single declaration, +in which case each distinct argument string will be recorded in a +separate DIE or BTF record, each associated to the declaration. For +a single declaration with multiple @code{btf_decl_tag} attributes, +the order of the @code{DW_TAG_GNU_annotation} DIEs produced is not +guaranteed to maintain the order of attributes in the source code. + +For example: + +@smallexample +int * foo __attribute__ ((btf_decl_tag ("__percpu"))); +@end smallexample + +@noindent +when compiled with @code{-gbtf} results in an additional +@code{BTF_KIND_DECL_TAG} BTF record to be emitted in the BTF info, +associating the string ``__rcu'' with the normal @code{BTF_KIND_VAR} +record for the variable ``foo''. + @cindex @code{counted_by} variable attribute @item counted_by (@var{count}) The @code{counted_by} attribute may be attached to the C99 flexible array @@ -9109,6 +9144,39 @@ is given by the product of arguments 1 and 2, and that @code{malloc_type}, like the standard C function @code{malloc}, returns an object whose size is given by argument 1 to the function. +@cindex @code{btf_type_tag} type attribute +@item btf_type_tag (@var{argument}) +The @code{btf_type_tag} attribute may be used to associate (to ``tag'') +particular types with arbitrary string annotations. These annotations +are recorded in debugging info by supported debug formats, currently +DWARF (via @code{DW_AT_GNU_annotation} and @code{DW_TAG_GNU_annotation} +extensions) and BTF (via @code{BTF_KIND_TYPE_TAG} records). These +annotation string are not interpreted by the compiler in any way, and +have no effect on code generation. If neither DWARF nor BTF +information is generated, the attribute has no effect. + +The argument is treated as an ordinary string in the source language +with no additional special rules. + +The attribute may be supplied multiple times for a single declaration, +in which case each distinct argument string will be recorded in a +separate DIE or BTF record, each associated to the type. For a single +type with multiple @code{btf_decl_tag} attributes, the order of the +@code{DW_TAG_GNU_annotation} DIEs produced is not guaranteed to +maintain the order of attributes in the source code. + +For example + +@smallexample +int * __attribute__ ((btf_type_tag ("__user"))) foo; +@end smallexample + +@noindent +associates the string ``__user'' to the pointer-to-integer type of +the declaration. This string will be recorded in DWARF and/or BTF +information associated with the appropriate pointer type DIE or +@code{BTF_KIND_PTR} record. + @cindex @code{copy} type attribute @item copy @itemx copy (@var{expression})