From patchwork Wed May 1 19:15:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1930346 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=mYJQcnaj; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=JNvT9Nvv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VV6H60fTvz1ymc for ; Thu, 2 May 2024 05:16:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 29DB03849AEA for ; Wed, 1 May 2024 19:16:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id D56F3385ED7A for ; Wed, 1 May 2024 19:14:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D56F3385ED7A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 D56F3385ED7A Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714590856; cv=pass; b=cHfPZ4LbzgO1qlxcsFFDkPkm+RaoPoE/IzpgmDgMK9VxTLqnZyJyMPh5nuX6XMeI/Im4ohAeAEFuHLx/0ib26kBBpKGdjYDvujxlYMhaWTfr4N5smVme2pMu8tzVPGciWaqEXC6ikZgjNIJBWGNrBg/mBR478JDDJMy0aUWY4qM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714590856; c=relaxed/simple; bh=9ttRPmN0bBkPsC/FaweNjVNBvDOkTzZIcMRlHQAzlR0=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=Y0u76FCynvk7jrRKRATTdFUZTJLlvv8HxzAEMgd4UFBQiuZjTWW2GUfqDJGk9PHwzCF/s8qPcHVcuMGIT/BspsaZuCRXkKP0KyWWylhX/WsS+zFkZqsQKWnAIMHOinsClnuKEiRWS+akHQV9lCRYe9Bm5BejI5wNz9I/MBq+Rxc= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 441ASNBi026160 for ; Wed, 1 May 2024 19:14:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=tjxtYoO2gMPwnsmaQdlH2PljSUkkd7nf4sRiRzpPHnM=; b=mYJQcnaj4yJYPzY+/grvVUNO4l5iYYbI8KcT2bnxDB57NEy9XU1JDNCvxUwMwWyo8g2F BKxc/Xe7zU1fIsEsBxCcGgF97TQW7M/aKgiLpH4d5l3QQT072u8AUtm7vLjTePzhBE/W dxiqUIXtXW+FQydGQIql2TjBIbfzfIFYZhkkf84COQd5f3pOgWGqyz1V/AL76na3jWQQ WA+zyjmIdpmO4yGN74kO7QrcWk2I0zLAWoVNsZ/+74QUhR1NEyIZ1wtwfG5xsB+0sHEH UDpS1eJtl2ycL8a0T9+ezxWjVF58PkllcuxhFihW/BocRyGL3HCSXqrZ1pYfmd95OWs7 zg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr54fvt5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 01 May 2024 19:14:10 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 441IwR2Z008556 for ; Wed, 1 May 2024 19:14:09 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2101.outbound.protection.outlook.com [104.47.58.101]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt9sfm4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 01 May 2024 19:14:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xj+Ij1ced/xpBvFrs2iVu9N4JLypTIX6WMrs3mT0Ahw4K5mzSYCneLEWUSUNVS4ZTIt3zDlCQUA1tYuSPzjhbEppuTDcz6UMXtbcsC2UiSV+Af5grB5Dxq0prW28TEAJZuQ8ScZYLoSLc/Y96ydEk/06lLv2cP96jhH88otfhljnlYqVebEVe3JSjfYqjPG7KI5ZQ1k63QIzj+I/l5zgk6Mvwy+3gv9tnvTpXgTcHxGSPYXLUjhkpVorQkX/YjaXrFAGmr4flDWjtnwSW52CU1NFas1xiWGUjOImKoApXhjN4+jCX0LKJtXU/wy4nFk+caWRsh0LPa73ODg3wThPig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tjxtYoO2gMPwnsmaQdlH2PljSUkkd7nf4sRiRzpPHnM=; b=OLziF9/j5DxIiuoL7PEXBObyW3B5G4bNH/HPjIommbcuvwbTHNVwFYWxFmb9p3Tvyc7n3R00T6C8TN7mUjOR8oF4NplFM7IW+N+u/X0GbcOTFBitOguMWI52VNuuQEwe3jMTj5G5YPPHCAEGjXK6u1IDar+yDInz6LWF4QBzFmnmFWl0ris+Wnnqve0aEdYtWirzgQAhKlVSZaXlNnJkw6BxPrrkdpRSABz0JyPdBKlFGdkDzpdCzOBw/VSQxzFwBygJTIrWt1HpCEE7c61Vu6LEipfTXLxQMGP073utrQED/Agjv2BDBKgEOFA2Yb+crSMLtqExsvBd3vL3+/crlA== 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=tjxtYoO2gMPwnsmaQdlH2PljSUkkd7nf4sRiRzpPHnM=; b=JNvT9NvvkfjW1nLvDbyOksLrIeSrR9rbSKCDCAu7yto7+fg3LQZTEm3Jw/BTQSSzouJMAPWfC+2f7QQCP4CLY8/xgEbMxW8fDzKBUSkXUUfiiOfPtLp5dn/xlFb/LJvUoL/mYbpEdfMqugpWzmmD6UzFYZeovkyhwwR7BXKgHdg= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by MN2PR10MB4237.namprd10.prod.outlook.com (2603:10b6:208:1dc::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.29; Wed, 1 May 2024 19:14:07 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::ddec:934d:1117:499d]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::ddec:934d:1117:499d%3]) with mapi id 15.20.7409.042; Wed, 1 May 2024 19:14:07 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com, jose.marchesi@oracle.com, cupertino.miranda@oracle.com Subject: [PATCH 5/6] btf: add -fprune-btf option Date: Wed, 1 May 2024 12:15:05 -0700 Message-ID: <20240501191506.4579-6-david.faust@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240501191506.4579-1-david.faust@oracle.com> References: <20240501191506.4579-1-david.faust@oracle.com> X-ClientProxiedBy: MW2PR16CA0026.namprd16.prod.outlook.com (2603:10b6:907::39) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|MN2PR10MB4237:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a25db77-4389-499b-1909-08dc6a12df59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|366007|376005|1800799015; X-Microsoft-Antispam-Message-Info: nUbOHptBzAM3N/Y3H+VoDiwpZuK1E8jr3DbfTwPemNFD4Wq5mTyLR8Yl1F+zgobXNf5ieNV16xg0ZrowDxBBiyu+8RJLl9jiYapfXUQMNqExwH6FnayR3vlIp1kG1nVf3uOcr/dJ1I5n4BbNP+wmARl6JYeL7NflCIoMB+NmOznMfUTK2GZsOOxHmAXTq7ChRfh0I3GQPVqfbLPExwZuV6A93uwA0fNg+tu/4kbdab9I4qGNvcth0jQ2MZ9h4ZUO5BZKg9SZFH6tEvRbWfK0TQjnwc2aCTYpgoxd/rTdb7RsRwtNHNlDSLH7C7g+FLLIyb0n6MlNGs+2K+iUD66Qqzw/TYt1KAHil/sdv5iUohW9Cg3XIwy46yx8vUJlJQn4Ytu5XYe6bSlIgqU4uXXQwGLqtkoTpnjGTkf2K8oYIR6946YommpdtR/Qq8MLIxe48sb5r9oTRcHW07XIDQ3tf+JtU6NLKK9S8mELwy9DuBtD8rVM7EZM3Igugc45QW71LRHTtVtA8/sMFUbaZsMiro8iV++sUvFGaqfGocCyb1p4tYfT94ac51IAtwdFV10Uvfl8fhkG7RVcY5sdcBAVl9RyCUTFuW2csTMa2M3rI+xPQE3j+q3kY0bXSDa646phRiOjhqyh7IRY0gV7WzBJWUlZcRciMpsMdA7nrfcdqPbJxV62hcQj17Q9eSmgA1JCunte2q8x17E4DO5wjOCDeukdh/+rHWNpONgGkl1gqUHJA9nS0GmwJq+bKvHGCbwHC9D8rzEVP7uOx5uM/CwE3IrCwQ1giU5Jgzc5b+90pbhgCKyLQp/k3wZiZ5lswkzLGU16JklqEW2uVvM6yHJ25upKFrRioUg+gnNC6RApJxmJbB4YG8FJBIAIerHUtuHSwjE4Z1aAh7DkSMhAr8nXmcHnaK7hLjRUFVVmuCjCJi+PgJRSRe2gd1gseNQLBLdLpNAiEpyePcgYxJnMu23mgiBMqKwqt615RnLo8vlYwWSB8/U1nL15gXp6tC6o5rb8SlRz8RzcozI8BApo/nrQgP/5tldszs3H01pjQFBlkkh8xJ7EeauMC7O+G16G/i4gLLDgZfpoDnO0ZDJz428lbx7vxwKcRkLUAM7wwQMzLmEtsBHKPxBJ1L8MxvJZvMXcH3BwPPYOgQMGB5fE35clfwtWJKKw1pUkc6xhmTtYnoaq4JoLbMbQ/yzNuPenGFibiZj98Vbz+GM7FOhc94o+nt2mMcQGx7Lsrk2Ua+GCtT0= 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:(13230031)(366007)(376005)(1800799015); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: avfmBfcXJdDxiqJH02GRYPtFAvTGhmWeC4ecBvJe+/SurUXJ1JUMmWfYbGAPJ5l4k4jBwHYO+N26jTy9u1R4sLf/B1VAIlF0m6249XjmStvgIFHj3lG0Ld6CIkorFk+ol20CMCtBUxNhyyUA2w5eQb5xms1mQmGEwxHXdiAGoNmyBi5dyPG/3hAd3MrfGzNpLcXB/Z2HMayD+vDppWGUYPOripXCAJfSh2wUi2bv8Jw1o2j9e3nZbephqhSWr+rrskHvG4us2/qQ2Y191uVfXDMf25VqteEHx9R0PJ0T1I1S4IUFWSVspR2eE9XR8RVrbtlbnC3Ax1eZ/VS6mic+TfgfT6Zv3lT+xXOAG2YQh9akO6u+5XjEWbjuDbk8vVSUs0QTRKXX2JegV4QqteUjXnj1qPBlcD8AczMc/mXjArUfBbNWDcJZOlKXqQn6NoMMfamk3ZriE7V0B3ld89mrwsCq0szQKsrt2iYvQLA27QuEdYZmvKjyB9mKswpOyorhu1o/WpCMEuUJLNSSqTL9NtzjxfupX3s3mFM+dV8s8VTyykFpLzXkSjE4BG0WWBJh5P2GYYm6OMewPHZWMxEEtUdc/59wiTeJv+FBD5FWvpEYO1gbTaX1qhXXDBDP9LAppzJVk2UBz+BRufjXtWD6iUrcjIjl0F7b6OUkW7w/Squ8b//gS4XmjxW3GVPabjfppp6enIDa6i8uwNfrAuHxzzpiochwLDa9QmaNKzwXEpQXmfFElaVL9xiHwVxneWWJqeUWYcWaUUnVG4wYs8QPd+LL2UdpKrz52h9k+pdgXQu4AajF2lw2mFO/tybB/sQQrKzDFwMhKrfwcLvBiQgbUnStj/Arj3jdHRv7W3K9QJKzQLCdVxlbbJXD2DsxmZH3Q3JOk7lB68nqbzPXeXTSJ6E5nLvrcgA1yg8n9TYFy+tAEIoASicBhmM6w0BLdlq/LT5A64d4SsYowcsEptnKu5cJHsDoCVaCbzq1gRTZAk8XK7+FCk9iQ7h9AWv2iZA7KurlY1AG98CPyoOOGlECl8U6tQVB/RTQ157uPrIzwoCF3rDODkNKfJWEjulmvGC6sjwa6dPP1ejnhd+kzfuwDn53lsPte9K3ATUtr44Hn/ZHzr1C2c0u0raaLpqB3iLrgNqIg+nhCe1GomGJFvS2f1XMvhBB3Lp20S0SqzKL3w7y684Kgh8ogdcgXVwauz5/9UcLXQDw1LEHzqgsBYStdDml269kcW9Fv6lwbXMPW0sWAmgZ+IAVY3rkm0mR1AghrtjF2WVKX7kF8YMi1wku/9ACBbWzzbpzfKe8P+ykh+f2TTUC5A7Uysq0DJWfcHXEE9/eAkhNoM4wipTIBkhOpklro/rx+u7VYu+lkqdu62X9XsP93z9UNduO3TWMIBE22eo+nMUSAkp7OUN/3hQMoi2LyzrOOVCsuTWhmJTPxL7v5UKGzJNanetlD6Cd3WmBdXtBZ9HX/SknqCgWH0u1yPhIRv6ogEmM/LBIi5ytME66AhDZy/1HG92xGVectUnyE+eyPJDQU28YeJHcFgNufwoh9J+a6x+PvPmF06FvxsTnlsVdn/NybZLYIORXbazTrMZW5OrwxxfpfMGcjjeoGA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: lj6R0WMJ0wp2cuYeTFYvod0rG7iogyvKWhcRpf/7p8fym1w7mHf3K1IHrn6H3tMqqMdOvrNHHxbiYvRazTXlkTIF8oPeLRBOFDEIUqhus30wjawkCUMU7+PN2U6232OE7QeNKOTUF0VIBPz0JGkuHiw7N/3wH9OwRMDpHrlLKaxvs5mEgMAO8CXAFMj7ZvI3uSseA9s96WGc4R5CmN66zm7hfwAcgiWckzgf/hR6dcUDmcLcB8iHfgzsLPLGM6NpP9vN+oAHLrJ4BUJGD2E3HKveUlDXXsIVupebjBj2ojQ45jVkHJVlX2javjjMMngdGs9Alv7qEDgjvD/zcew25+bTvxgfrs79ZEol36XddnixQey1yn8SE51VbZboocZ9RetBQovj4kD8cNUfqCKTB9L4a0410ow1sD+X1KF20tq2brRgWS6Z84s74HIlxes1YX6AMbNWd4d4EAMiDhu0G1DIPUQdWNJRWcTbUSRsEoRloZX0b07192L3HxTkyl72ohXw3QV6h1CvvGc8P/ocqLSejwf4aYQq177yQ+tLZfmIK6VEpMEdgVjIxXU7bxlBO396gx/gODoUZsBAYJbjAENe/0CY06gAvdpK5YJejbo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a25db77-4389-499b-1909-08dc6a12df59 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 19:14:07.0773 (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: IOGmKH3h4WNCnAs/e0Lf4oIWAjUf2OyuoK7pdkO1fobYaJaFwA0mBLdQZB3EOGwOMnY/j6uoEvi0FIOOgAEI9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4237 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-01_16,2024-04-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 adultscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2405010135 X-Proofpoint-ORIG-GUID: v7IUHmoCt1b58HwRSIBOq4AXTkxl-s5F X-Proofpoint-GUID: v7IUHmoCt1b58HwRSIBOq4AXTkxl-s5F X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch adds a new option, -fprune-btf, to control BTF debug info generation. As the name implies, this option enables a kind of "pruning" of the BTF information before it is emitted. When enabled, rather than emitting all type information translated from DWARF, only information for types directly used in the source program is emitted. The primary purpose of this pruning is to reduce the amount of unnecessary BTF information emitted, especially for BPF programs. It is very common for BPF programs to incldue Linux kernel internal headers in order to have access to kernel data structures. However, doing so often has the side effect of also adding type definitions for a large number of types which are not actually used by nor relevant to the program. In these cases, -fprune-btf commonly reduces the size of the resulting BTF information by approximately 10x. This both slims down the size of the resulting object and reduces the time required by the BPF loader to verify the program and its BTF information. Note that the pruning implemented in this patch follows the same rules as the BTF pruning performed unconditionally by LLVM's BPF backend when generating BTF. In particular, the main sources of pruning are: 1) Only generate BTF for types used by variables and functions at the file scope. 2) Avoid emitting full BTF for struct and union types which are only pointed-to by members of other struct/union types. In these cases, the full BTF_KIND_STRUCT or BTF_KIND_UNION which would normally be emitted is replaced with a BTF_KIND_FWD, as though the underlying type was a forward-declared struct or union type. gcc/ * btfout.cc (btf_minimal_types): New hash set. (struct btf_fixup): New. (fixups, forwards): New vecs. (btf_output): Calculate num_types depending on flag_prune_btf. (btf_early_finsih): New initialization for flag_prune_btf. (btf_mark_full_type_used): Likewise. (btf_minimal_add_type): New function. (btf_minimal_type_list_cb): Likewise. (btf_late_collect_pruned_types): Likewise. (btf_late_add_vars): Handle special case for variables in ".maps" section when generating BTF for BPF CO-RE target. (btf_late_finish): Use btf_late_collect_pruned_types when flag_prune_btf in effect. Move some initialization to btf_early_finish. (btf_finalize): Additional deallocation for flag_prune_btf. * common.opt (fprune-btf): New flag. * ctfc.cc (init_ctf_strtable): Make non-static. * ctfc.h (struct ctf_dtdef): Add visited_children_p boolean flag. (init_ctf_strtable, ctfc_delete_strtab): Make extern. * doc/invoke.texi (Debugging Options): Document -fprune-btf. gcc/testsuite/ * gcc.dg/debug/btf/btf-prune-1.c: New test. * gcc.dg/debug/btf/btf-prune-2.c: Likewise. * gcc.dg/debug/btf/btf-prune-3.c: Likewise. --- gcc/btfout.cc | 394 ++++++++++++++++++- gcc/common.opt | 4 + gcc/ctfc.cc | 2 +- gcc/ctfc.h | 5 + gcc/doc/invoke.texi | 20 + gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c | 25 ++ gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c | 33 ++ gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c | 35 ++ 8 files changed, 511 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 0af0bd39fc7..93d56492bbe 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -833,7 +833,10 @@ output_btf_types (ctf_container_ref ctfc) { size_t i; size_t num_types; - num_types = ctfc->ctfc_types->elements (); + if (flag_prune_btf) + num_types = max_translated_id; + else + num_types = ctfc->ctfc_types->elements (); if (num_types) { @@ -962,6 +965,211 @@ btf_early_add_func_records (ctf_container_ref ctfc) } } +/* The set of types used directly in the source program, and any types manually + marked as used. This is the set of types which will be emitted when + pruning (-fprune-btf) is enabled. */ +static GTY (()) hash_set *btf_minimal_types; + +/* Fixup used to avoid unnecessary pointer chasing for types. A fixup is + created when a structure or union member is a pointer to another struct + or union type. In such cases, avoid emitting full type information for + the pointee struct or union type (which may be quite large), unless that + type is used directly elsewhere. */ +struct btf_fixup +{ + ctf_dtdef_ref pointer_dtd; /* Type node to which the fixup is applied. */ + ctf_dtdef_ref pointee_dtd; /* Original type node referred to by pointer_dtd. + If this concrete type is not otherwise used, + then a forward is created. */ +}; + +/* Stores fixups while processing types. */ +static vec fixups; + +/* For fixups where the underlying type is not used in the end, a BTF_KIND_FWD + is created and emitted. This vector stores them. */ +static GTY (()) vec *forwards; + +/* Recursively add type DTD and any types it references to the used set. + Return a type that should be used for references to DTD - usually DTD itself, + but may be NULL if DTD corresponds to a type which will not be emitted. + CHECK_PTR is true if one of the predecessors in recursive calls is a struct + or union member. SEEN_PTR is true if CHECK_PTR is true AND one of the + predecessors was a pointer type. These two flags are used to avoid chasing + pointers to struct/union only used from pointer members. For such types, we + will emit a forward instead of the full type information. */ + +static ctf_dtdef_ref +btf_minimal_add_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, + bool check_ptr, bool seen_ptr) +{ + if (dtd == NULL) + return NULL; + + uint32_t ctf_kind = CTF_V2_INFO_KIND (dtd->dtd_data.ctti_info); + uint32_t kind = get_btf_kind (ctf_kind); + + /* Check whether the type has already been added. */ + if (btf_minimal_types->contains (dtd)) + { + /* It's possible the type was already added as a fixup, but that we now + have a concrete use of it. */ + switch (kind) + { + case BTF_KIND_PTR: + case BTF_KIND_TYPEDEF: + case BTF_KIND_CONST: + case BTF_KIND_VOLATILE: + case BTF_KIND_RESTRICT: + if (check_ptr) + /* Type was previously added as a fixup, and that's OK. */ + return dtd; + else + { + /* The type was previously added as a fixup, but now we have + a concrete use of it. Remove the fixup. */ + for (size_t i = 0; i < fixups.length (); i++) + if (fixups[i].pointer_dtd == dtd) + fixups.unordered_remove (i); + + /* Add the concrete base type. */ + dtd->ref_type = btf_minimal_add_type (ctfc, dtd->ref_type, + check_ptr, seen_ptr); + return dtd; + } + default: + return dtd; + } + } + + if (ctf_kind == CTF_K_SLICE) + { + /* Bitfield. Add the underlying type to the used set, but leave + the reference to the bitfield. The slice type won't be emitted, + but we need the information in it when writing out the bitfield + encoding. */ + btf_minimal_add_type (ctfc, dtd->dtd_u.dtu_slice.cts_type, + check_ptr, seen_ptr); + return dtd; + } + + /* Skip redundant definitions of void and types with no BTF encoding. */ + if ((kind == BTF_KIND_INT && dtd->dtd_data.ctti_size == 0) + || (kind == BTF_KIND_UNKN)) + return NULL; + + /* Add the type itself, and assign its id. + Do this before recursing to handle things like linked list structures. */ + gcc_assert (ctfc->ctfc_nextid <= BTF_MAX_TYPE); + dtd->dtd_type = ctfc->ctfc_nextid++; + btf_minimal_types->add (dtd); + ctf_add_string (ctfc, dtd->dtd_name, &(dtd->dtd_data.ctti_name), CTF_STRTAB); + ctfc->ctfc_num_types++; + ctfc->ctfc_num_vlen_bytes += btf_calc_num_vbytes (dtd); + + /* Recursively add types referenced by this type. */ + switch (kind) + { + case BTF_KIND_INT: + case BTF_KIND_FLOAT: + case BTF_KIND_FWD: + /* Leaf kinds which do not refer to any other types. */ + break; + + case BTF_KIND_FUNC: + case BTF_KIND_VAR: + /* Root kinds; no type we are visiting may refer to these. */ + gcc_unreachable (); + + case BTF_KIND_PTR: + case BTF_KIND_TYPEDEF: + case BTF_KIND_CONST: + case BTF_KIND_VOLATILE: + case BTF_KIND_RESTRICT: + { + /* These type kinds refer to exactly one other type. */ + if (check_ptr && !seen_ptr) + seen_ptr = (kind == BTF_KIND_PTR); + + /* Try to avoid chasing pointers to struct/union types if the + underlying type isn't used. */ + if (check_ptr && seen_ptr) + { + ctf_dtdef_ref ref = dtd->ref_type; + uint32_t ref_kind = btf_dtd_kind (ref); + + if ((ref_kind == BTF_KIND_STRUCT || ref_kind == BTF_KIND_UNION) + && !btf_minimal_types->contains (ref)) + { + struct btf_fixup fixup; + fixup.pointer_dtd = dtd; + fixup.pointee_dtd = ref; + fixups.safe_push (fixup); + break; + } + } + + /* Add the type to which this type refers. */ + dtd->ref_type = btf_minimal_add_type (ctfc, dtd->ref_type, + check_ptr, seen_ptr); + break; + } + case BTF_KIND_ARRAY: + { + /* Add element and index types. */ + ctf_arinfo_t *arr = &(dtd->dtd_u.dtu_arr); + arr->ctr_contents = btf_minimal_add_type (ctfc, arr->ctr_contents, + false, false); + arr->ctr_index = btf_minimal_add_type (ctfc, arr->ctr_index, + false, false); + break; + } + case BTF_KIND_STRUCT: + case BTF_KIND_UNION: + case BTF_KIND_ENUM: + case BTF_KIND_ENUM64: + { + /* Add members. */ + ctf_dmdef_t *dmd; + for (dmd = dtd->dtd_u.dtu_members; + dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd)) + { + /* Add member type for struct/union members. For enums, only the + enumerator names are needed. */ + if (kind == BTF_KIND_STRUCT || kind == BTF_KIND_UNION) + dmd->dmd_type = btf_minimal_add_type (ctfc, dmd->dmd_type, + true, false); + ctf_add_string (ctfc, dmd->dmd_name, &(dmd->dmd_name_offset), + CTF_STRTAB); + } + break; + } + case BTF_KIND_FUNC_PROTO: + { + /* Add return type. */ + dtd->ref_type = btf_minimal_add_type (ctfc, dtd->ref_type, + false, false); + + /* 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_minimal_add_type (ctfc, farg->farg_type, + false, false); + /* Note: argument names are stored in the auxilliary string table, + since CTF does not include arg names. That table has not been + cleared, so no need to re-add argument names here. */ + } + break; + } + default: + return NULL; + } + + return dtd; +} + /* Initial entry point of BTF generation, called at early_finish () after CTF information has possibly been output. Translate all CTF information to BTF, and do any processing that must be done early, such as creating @@ -977,6 +1185,27 @@ btf_early_finish (void) btf_early_add_const_void (tu_ctfc); btf_early_add_func_records (tu_ctfc); + + /* Note: from here on, destructive changes are made to the TU CTFC to + translate CTF to BTF. These fields are reset to count BTF types etc. */ + tu_ctfc->ctfc_num_types = 0; + tu_ctfc->ctfc_num_vlen_bytes = 0; + tu_ctfc->ctfc_vars_list_count = 0; + + if (flag_prune_btf) + { + btf_minimal_types + = hash_set::create_ggc (tu_ctfc->ctfc_types->elements ()); + tu_ctfc->ctfc_nextid = 1; + fixups.create (1); + + /* Empty the string table, which was already populated with strings for + all types translated from DWARF. We may only need a very small subset + of these strings; those will be re-added below. */ + ctfc_delete_strtab (&tu_ctfc->ctfc_strtable); + init_ctf_strtable (&tu_ctfc->ctfc_strtable); + tu_ctfc->ctfc_strlen++; + } } /* Push a BTF datasec entry ENTRY into the datasec named SECNAME, @@ -1134,6 +1363,51 @@ btf_emit_variable_p (ctf_container_ref ctfc, varpool_node *var, return true; } + +/* Recursively mark T and all children types as used to prevent them + being pruned. */ + +static void +btf_mark_full_type_used (ctf_container_ref ctfc, tree t) +{ + ctf_dtdef_ref dtd = ctf_lookup_tree_type (ctfc, t); + if (!dtd) + return; + + if (dtd->visited_children_p) + return; + + btf_minimal_add_type (ctfc, dtd, false, false); + dtd->visited_children_p = true; + + /* Note that it is only necessary here to visit descendents which may be + pruned by replacing with a forward, i.e. pointed-to struct/union types. */ + switch (TREE_CODE (t)) + { + case POINTER_TYPE: + case REFERENCE_TYPE: + btf_mark_full_type_used (ctfc, TREE_TYPE (t)); + break; + + case RECORD_TYPE: + case UNION_TYPE: + { + tree member = TYPE_FIELDS (t); + while (member != NULL_TREE) + { + if (DECL_ABSTRACT_ORIGIN (member)) + continue; + + btf_mark_full_type_used (ctfc, TREE_TYPE (member)); + member = DECL_CHAIN (member); + } + break; + } + default: + break; + } +} + /* Add BTF_KIND_VAR records for variables. */ static void @@ -1159,6 +1433,14 @@ btf_late_add_vars (ctf_container_ref ctfc) /* Add a BTF_KIND_DATASEC entry for the variable. */ btf_datasec_add_var (ctfc, var, dvd); + + /* Special case: for BPF CO-RE, the .maps section is special. + Full type info for anything in .maps is always required. */ + const char *section = var->get_section (); + if (section && (strcmp (section, ".maps") == 0) + && btf_with_core_debuginfo_p () && flag_prune_btf) + btf_mark_full_type_used (ctfc, TREE_TYPE (var->decl)); + } } @@ -1257,6 +1539,88 @@ btf_late_assign_datasec_ids (ctf_container_ref ctfc) } } +/* Callback used for assembling the only-used-types list. Note that this is + the same as btf_type_list_cb above, but the hash_set traverse requires a + different function signature. */ + +static bool +btf_minimal_type_list_cb (const ctf_dtdef_ref& dtd, ctf_container_ref ctfc) +{ + ctfc->ctfc_types_list[dtd->dtd_type] = dtd; + return true; +} + +/* Collect the set of types reachable from global variables and functions. + This is the minimal set of types, used when generating pruned BTF. */ + +static void +btf_late_collect_pruned_types (ctf_container_ref ctfc) +{ + vec_alloc (forwards, 1); + + /* Add types used from functions. */ + ctf_dtdef_ref dtd; + size_t i; + FOR_EACH_VEC_ELT (*funcs, i, dtd) + { + btf_minimal_add_type (ctfc, dtd->ref_type, false, false); + ctf_add_string (ctfc, dtd->dtd_name, &(dtd->dtd_data.ctti_name), + CTF_STRTAB); + } + + /* Add types used from global variables. */ + for (i = 0; i < ctfc->ctfc_vars_list_count; i++) + { + ctf_dvdef_ref dvd = ctfc->ctfc_vars_list[i]; + btf_minimal_add_type (ctfc, dvd->dvd_type, false, false); + ctf_add_string (ctfc, dvd->dvd_name, &(dvd->dvd_name_offset), CTF_STRTAB); + } + + /* Process fixups. If the base type was never added, create a forward for it + and adjust the reference to point to that. If it was added, then nothing + needs to change. */ + for (i = 0; i < fixups.length (); i++) + { + struct btf_fixup *fx = &fixups[i]; + if (!btf_minimal_types->contains (fx->pointee_dtd)) + { + /* The underlying type is not used. Create a forward. */ + ctf_dtdef_ref fwd = ggc_cleared_alloc (); + ctf_id_t id = ctfc->ctfc_nextid++; + gcc_assert (id <= BTF_MAX_TYPE); + + bool union_p = (btf_dtd_kind (fx->pointee_dtd) == BTF_KIND_UNION); + + fwd->dtd_name = fx->pointee_dtd->dtd_name; + fwd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_FORWARD, union_p, 0); + fwd->dtd_type = id; + ctfc->ctfc_num_types++; + ctfc->ctfc_num_vlen_bytes += btf_calc_num_vbytes (fwd); + ctf_add_string (ctfc, fwd->dtd_name, &(fwd->dtd_data.ctti_name), + CTF_STRTAB); + + /* Update the pointer to point to the forward. */ + fx->pointer_dtd->ref_type = fwd; + vec_safe_push (forwards, fwd); + } + } + + /* Construct the resulting pruned type list. */ + ctfc->ctfc_types_list + = ggc_vec_alloc (btf_minimal_types->elements () + 1 + + vec_safe_length (forwards)); + + btf_minimal_types->traverse + (ctfc); + + /* Insert the newly created forwards into the regular types list too. */ + FOR_EACH_VEC_ELT (*forwards, i, dtd) + ctfc->ctfc_types_list[dtd->dtd_type] = dtd; + + max_translated_id = btf_minimal_types->elements () + + vec_safe_length (forwards); +} + /* Late entry point for BTF generation, called from dwarf2out_finish (). Complete and emit BTF information. */ @@ -1268,13 +1632,22 @@ btf_finish (void) datasecs.create (0); - tu_ctfc->ctfc_num_types = 0; - tu_ctfc->ctfc_num_vlen_bytes = 0; - tu_ctfc->ctfc_vars_list_count = 0; - btf_late_add_vars (tu_ctfc); - btf_late_collect_translated_types (tu_ctfc); + if (flag_prune_btf) + { + /* Collect pruned set of BTF types and prepare for emission. + This includes only types directly used in file-scope variables and + function return/argument types. */ + btf_late_collect_pruned_types (tu_ctfc); + } + else + { + /* Collect all BTF types and prepare for emission. + This includes all types translated from DWARF. */ + btf_late_collect_translated_types (tu_ctfc); + } btf_late_add_func_datasec_entries (tu_ctfc); + btf_late_assign_var_ids (tu_ctfc); btf_late_assign_func_ids (tu_ctfc); btf_late_assign_datasec_ids (tu_ctfc); @@ -1307,6 +1680,15 @@ btf_finalize (void) func_map->empty (); func_map = NULL; + if (flag_prune_btf) + { + btf_minimal_types->empty (); + btf_minimal_types = NULL; + + fixups.release (); + forwards = NULL; + } + ctf_container_ref tu_ctfc = ctf_get_tu_ctfc (); ctfc_delete_container (tu_ctfc); tu_ctfc = NULL; diff --git a/gcc/common.opt b/gcc/common.opt index ad348844775..c430cfd0428 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2578,6 +2578,10 @@ fpatchable-function-entry= Common Var(flag_patchable_function_entry) Joined Optimization Insert NOP instructions at each function entry. +fprune-btf +Common Var(flag_prune_btf) Init(0) +Generate minimal BTF debug info. + frandom-seed Common Var(common_deferred_options) Defer diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc index d8f1037b4e0..7681af8542d 100644 --- a/gcc/ctfc.cc +++ b/gcc/ctfc.cc @@ -913,7 +913,7 @@ ctfc_get_dvd_srcloc (ctf_dvdef_ref dvd, ctf_srcloc_ref loc) /* Initialize the CTF string table. The first entry in the CTF string table (empty string) is added. */ -static void +void init_ctf_strtable (ctf_strtable_t * strtab) { strtab->ctstab_head = NULL; diff --git a/gcc/ctfc.h b/gcc/ctfc.h index 90421c72c09..bd3d98ffed9 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -168,6 +168,8 @@ struct GTY ((for_user)) ctf_dtdef BOOL_BITFIELD from_global_func : 1; /* Enum signedness. */ BOOL_BITFIELD dtd_enum_unsigned : 1; + /* Already visited children of this type, e.g. struct members. */ + BOOL_BITFIELD visited_children_p : 1; /* Lots of spare bits. */ union GTY ((desc ("ctf_dtu_d_union_selector (&%1)"))) @@ -369,6 +371,9 @@ extern unsigned int ctfc_get_num_ctf_vars (ctf_container_ref); extern ctf_strtable_t * ctfc_get_strtab (ctf_container_ref, int); +extern void init_ctf_strtable (ctf_strtable_t *); +extern void ctfc_delete_strtab (ctf_strtable_t *); + /* Get the length of the specified string table in the CTF container. */ extern size_t ctfc_get_strtab_len (ctf_container_ref, int); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 9456ced468a..2908afff7c6 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -533,6 +533,7 @@ Objective-C and Objective-C++ Dialects}. -gvms -gz@r{[}=@var{type}@r{]} -gsplit-dwarf -gdescribe-dies -gno-describe-dies -fdebug-prefix-map=@var{old}=@var{new} -fdebug-types-section +-fprune-btf -fno-prune-btf -fno-eliminate-unused-debug-types -femit-struct-debug-baseonly -femit-struct-debug-reduced -femit-struct-debug-detailed@r{[}=@var{spec-list}@r{]} @@ -12234,6 +12235,25 @@ compressed debug sections, the option is rejected. Otherwise, if the assembler does not support them, @option{-gz} is silently ignored when producing object files. +@opindex fprune-btf +@opindex fno-prune-btf +@item -fprune-btf +@itemx -fno-prune-btf +Prune BTF information before emission. When pruning, only type +information for types used by global variables and file-scope functions +will be emitted. If compiling for the BPF target with BPF CO-RE +enabled, type information will also be emitted for types used in BPF +CO-RE relocations. In addition, struct and union types which are only +referred to via pointers from members of other struct or union types +shall be pruned and replaced with BTF_KIND_FWD, as though those types +were only present in the input as forward declarations. + +This option substantially reduces the size of produced BTF information, +but at significant loss in the amount of detailed type information. +It is primarily useful when compiling for the BPF target, to minimize +the size of the resulting object, and to eliminate BTF information +which is not immediately relevant to the BPF program loading process. + @opindex femit-struct-debug-baseonly @item -femit-struct-debug-baseonly Emit debug information for struct-like types diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c new file mode 100644 index 00000000000..3c9b59a07ec --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c @@ -0,0 +1,25 @@ +/* Simple test of -fprune-btf option operation. + Since 'struct foo' is not used, no BTF shall be emitted for it. */ + +/* { dg-do compile } */ +/* { dg-options "-gbtf -fprune-btf -dA" } */ + +/* No BTF info for 'struct foo' nor types used only by it. */ +/* { dg-final { scan-assembler-not "BTF_KIND_STRUCT 'foo'" } } */ +/* { dg-final { scan-assembler-not "BTF_KIND_INT 'char'" } } */ + +/* We should get BTF info for 'struct bar' since it is used. */ +/* { dg-final { scan-assembler "BTF_KIND_STRUCT 'bar'"} } */ + +struct foo { + int a; + char c; +}; + +struct bar { + int x; + long z[4]; +}; + +struct bar a_bar; + diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c new file mode 100644 index 00000000000..20183dffcc7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c @@ -0,0 +1,33 @@ +/* Test that -fprune-btf does not chase pointer-to-struct members. */ + +/* { dg-do compile } */ +/* { dg-options "-gbtf -fprune-btf -dA" } */ + +/* Only use of B is via a pointer member of C. + Full BTF for B is replaced with a forward. */ +/* { dg-final { scan-assembler-not "BTF_KIND_STRUCT 'B'" } } */ +/* { dg-final { scan-assembler-times "TYPE \[0-9\]+ BTF_KIND_FWD 'B'" 1 } } */ + +/* Detailed info for B is omitted, and A is otherwise unused. */ +/* { dg-final { scan-assembler-not "BTF_KIND_\[A-Z\]+ 'A'" } } */ + +/* { dg-final { scan-assembler "BTF_KIND_STRUCT 'C'" } } */ + +struct A; + +struct B { + int x; + int (*do_A_thing) (int, int); + struct A *other; +}; + +struct C { + unsigned int x; + struct B * a; +}; + +int +foo (struct C *c) +{ + return c->x; +} diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c new file mode 100644 index 00000000000..57a079cf0b4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c @@ -0,0 +1,35 @@ +/* Test that -fprune-btf */ + +/* { dg-do compile } */ +/* { dg-options "-gbtf -fprune-btf -dA" } */ + +/* We expect full BTF information each struct. */ +/* { dg-final { scan-assembler "TYPE \[0-9\]+ BTF_KIND_FWD 'file'" } } */ +/* { dg-final { scan-assembler "TYPE \[0-9\]+ BTF_KIND_STRUCT 'A'" } } */ +/* { dg-final { scan-assembler "TYPE \[0-9\]+ BTF_KIND_STRUCT 'B'" } } */ +/* { dg-final { scan-assembler "TYPE \[0-9\]+ BTF_KIND_STRUCT 'C'" } } */ + +struct file; + +struct A { + void *private; + long (*read)(struct file *, char *, unsigned long); + long (*write)(struct file *, const char *, unsigned long); +}; + +struct B { + unsigned int x; + struct A **as; +}; + +struct C { + struct A *arr_a[4]; + struct A *lone_a; + unsigned int z; +}; + +unsigned int +foo (struct B *b, struct C *c) +{ + return b->x + c->z; +}