Message ID | 20241030183155.2038501-1-david.faust@oracle.com |
---|---|
Headers |
Return-Path: <gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org> 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 99E8C3857C6D for <patchwork@sourceware.org>; Wed, 30 Oct 2024 18:33:01 +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 3F3F73858429 for <gcc-patches@gcc.gnu.org>; Wed, 30 Oct 2024 18:32:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F3F73858429 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 3F3F73858429 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=1730313134; cv=pass; b=rQDzuA784cKIm5t1sXV7tSQNQf6COzze0gOjRSwxaSrBZ3kPt8Dz5yvE8/LXzMDAYEoixpRd3whRz2wiA8QPtyOHqOgkcK2y+ec7kmmS20VwzxwQBvXu2SoIfFPZnSHil1g/xj+d60C9z8KS9I6mGAQnl3ED5cclN1CFdUY8tQ0= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730313134; c=relaxed/simple; bh=YduicxpOGeiVpE/zY4eqohV4gu+3GHwGwGHGipoo8KA=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=eTSzP8P8eRKHljAUAbGpSGLY1nuq7vRsrtzV9pfh1A5l4/yysUbwVMy0gC0X/xqgoj77jrFh+W0hpJMNmT1Qa8Do4i6P7wB3v5x7kZol3iO0hgDzJIDz82GNF8FFzdvVgF8jthYS+0vmxoq3c/KCA85naA9X4PqiUnRExGJWuzY= 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 49UGXYHf017391; Wed, 30 Oct 2024 18:32:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=corp-2023-11-20; bh=ielXmI89fkhvB89O fPI0Mwp9NGIqxXjKs312TBCdR2g=; b=kWlhZds1rxg3VMN8EIKJ/OQyHUWJnc0q GLJyefANSKdH6fS3GOU/9ARyf92TTpZB3AbfVw/ZbQDNqnGVGOhkZYhcsi3xALRC 1mLb5FYJcZkex/osgQdyMxjVH9eU/6+cfl+LzzvogJ90VqDahiaB8qxxRNvixw14 F+8THbP0zMwkrLiXU2dC0tGQa1Si4sPPMxK7tXrqh+IVYjmbKHe+zaZaidy8xhYX 6pODRC7bGXqMSnul096Z2p2LryuMYVo/vKA9OLOGrP9srfKqxWWXKMbdcoez67PX mOTHnpCfcFUZp/5qzpJCX1vQPf7raVsO+2QHRDktuCxjMIA6p5EY9A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdxrr3e-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 49UGuvgk040314; Wed, 30 Oct 2024 18:32:09 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-2 (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=UYGa/hF/pwQiFoeJY2c5hCTORBvPOFZ3dZixNKqo+lOitY2MZPMJ6xNXdkLQpeHnQiY5tgnjqJ01hfCc+251ua4emXHXy5GZb94y0iS5817iXYfVasTT5P6J06rzoLLSujSaCu836Zktiu1qtzY83hD9p1q2N2MrQYvk0oluVx84c/ou9WYOMOQwTpIwDCLOWNlO8eEqnFqbVSA7XfyB/gR31H6hplMhgiFJIjriayPfFo99mUPWnBWwm8GpSwY/NUM0H6NRZfUCSIWVdcNuOLn+GmcxE0lVN/hm+2dLI55U4ged+gX11lo8afGtFpTNa4MQwcJDyUgxzrGkBNokeg== 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=ielXmI89fkhvB89OfPI0Mwp9NGIqxXjKs312TBCdR2g=; b=TgvkSqhlt2Ne6uVmeCkrT4nf2GfjG9OqhdtBtDYAtpDMY5TuoLQTg6uSjLhdjxBdgclqrBL3wO8XChSsFQvkUKLpTP1jFy7GYVXtwEp+iNQDURWat1OK6cFHF4M9p93Wz5NffSfT/UVDnCLaZvM9jV1wRZHgH6fTvtiSXhTD5Pklwl/nZy1YHtgPmuSQrsRhDP+nTDdP/+foj7tU4T6Kx7bxExUz3Qm/Cny4EWwBuEhSaFU/Rx4j1E5yU8O2yaAfRnmWZi6Q760/1cHzwEB0x1bNKdCJBkRZFTt6sOy58LpmzChyJzRYFoGdn2iGPil2W7nhnc3mTdzhTj16IfrFgA== 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=ielXmI89fkhvB89OfPI0Mwp9NGIqxXjKs312TBCdR2g=; b=HmGLB/5v6eXYreDHu6ASisZEMX6Ak6UlX+KmxVkWMu0bMUHaDchITIvLspqoBgRaBPlugqJc2HzMlJKLQZ8ZnjIhjHHkENErH6S4Qb8ZGBBPw28IYxAC97Z5tfPJCwr4U6XuBfafHZ/bOhEF/QHTCT1mYcma+gIt+bZICJJ7RLg= 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:02 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%4]) with mapi id 15.20.8093.024; Wed, 30 Oct 2024 18:32:02 +0000 From: David Faust <david.faust@oracle.com> To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, yonghong.song@linux.dev Subject: [PATCH 0/5] Add btf_decl_tag and btf_type_tag C attributes Date: Wed, 30 Oct 2024 11:31:50 -0700 Message-ID: <20241030183155.2038501-1-david.faust@oracle.com> X-Mailer: git-send-email 2.45.2 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW2PR16CA0067.namprd16.prod.outlook.com (2603:10b6:907:1::44) 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: c1e1eb6b-f801-46a6-2f5e-08dcf9112594 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: 3ihAs0iCBj31+66PZWQ29v3FOFTBPV+jrnLcGhlSh4hbNnMXiL8+QaBc5oAuhvmpRLQu26iZNFqs6GymSv2LlD98WfnAwnKtu18Is/l2v1yQ65tPwnZDda7yEMzg58C8p27o6D2pE1/vlqpB+gFll9hgmvtZgoy1OPixYn/lI8KbV6ODa8aQvuS7HvOGFfukQqeOsNF31DeIqUNq7x4AEnlyFTM6R5c3PyxgPAjp1DpN2wcihH3YwOGq4J4bMUFbQvCaFk459uyamZLEI0C4Di2FUuEUBdPukVj0SSMrQXRGVDJoH0oWF0XjLjP24d6UBtceEUrHyPyFqw9cZZw8Vfb0haBSTBeEcYwUUi1tAMesiM/hrCgpOte3+RQcka0mhLiam/+Yr6wVkBZRZ5cmh9BU21GUcl2XXfoNM7Zs1x6xOo0g+A3qY4fDiTScwC6DoDsC08hgZySOr5l6bvC3oOcZN3qzakQy+2qp9o2zPAY5Kebqx3ys44A6Z2Iaj2e85Rr2ZP+FLSkRuNQXrLF1jXPUYrTHbuuo2qXvXGtSHHRm0V9qlFnY9ZmmDMIlY2CAErGROihZpW5u4UE4eAubiLvwb3TsigQOON5MV8fIu8ut61jtG7DFniXqhlQRbEZtR6kwFSPp0qXyMwKQemGTIRKlDaXSRsfyemwy5kQKzKBRTqEleyaXleIpcF72qXnf1eAya8AFMrQq62i5YwU4LIhzzYBaXslHtEUDUj7Te6D/3FUEc4lLWG6bBHMnvFjZSjRoMaTqugzGuqAtnY5HfeAtJnohDBlIF+/cvg7dnfyQvrwq2zjEVcVhLVkb/JcLb5sdt/K6Ehr73DTt8nG3oBhN7gpiGaQkb5BSBqSA8S66smHS8VaJd9JPN/pj6Xcgd3auRFe6Zy1W5Nn9USeiCQB6xeKf/PAQeU8UslLPkRsALhzzdJr4LBKP3FgTJ/niJdbhaeFIIHHbm+DeG7a+GCT9pgtDC/R0pLccIO0BwcOfVWXUTiwTeN8uspKCqowWfs5300pj6PIC/NxMTzrZQ8pFT6y1I1AJORvA3rIwYGN1sQqSwXvzVpcxo34ASnKmTOxVYWJCxjr+XX7l4Dg9ijlFBRrxX5Pi2mbmHOGW8TjWRNwGHCn5XeMCuLTtFTTZOR/3BPUE6KixzqPqVPiTVql6PBCJHWfqaFFOM/E4PwcAiuRzHxsdSyL6fUdShUlzmrlRibNGLdMlweQ7DYjJKssgaAyiU2TkIZXcKo2VaDnhijblnWPligfrRBRzhsYqmTyACAfUowzNTfkXSbyeew== 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: VLyNo8Vy95T4pS12TJjZHn7Y/+zlk+O1Z4984jIGiVl4dT/Km9d4RxnK3fR8cIIl4OF9wjHBFmJDnvFYMI2x/i86vvP2LcNin/TqeQDJzpT5xPFF1Y4tMtXI9H51kd3FD2R+0NZ3xdrerLq6tsbSBsb7gNQp7aFpPZC8nn9DfaJ8mMuPMbM4Y34Hi4ykgkHtGTfgx/paoQsrvu27OIPGYAFjDkJx87dshNSCxfPEcCDvR6BV/2rm39Flk5+MRLN6KyeqoIyC6eO0J+uCowWqnIEc+w/z+DO/Vbn0vcA8+1s1nQ/yzdrwt3DAM1udEqYbiWVok8cSkAo1cQwDI3Tkp9BBl+eELGjaBCbun8PUSOhyrSYGbobxquWc6XEefko06yvRqIwSXt8KAZT6LiIIbI5q5DgRCfMzFoBgvY+9FcEUbLFNFrHe6evT0GsB1wUXt/AOjMl9JTzEhEw6i5YRMaBufTPJXCDAi5dj6H8jWTYi97aiM2uXxlXcBipMCMGHl/iyCezJT0yqmr6Q9qwbfnWnsN28Ist0wtlLO1Qb7DXadTOHX9T8ZmnGR0T5vOCx8NtJQYGMtnyGsB62L9UTDh0TNqrx4DJ7GX62zPdsV6ySFlB1tZl7dTM8IYGJye2jyhL/E4R+V0ruUmoVTpVHzpnK4YksPtBVf24oCLG8PKAE467V22jicd559U9P33y2QlAHavbILs2wr3/BcSWTOo/YQgu0F9BLnbxGwUiSbhNB7OXWeeIAQK/bmHc/wiy4f7D4ZUGEE/CRimEKcj99+kadVGK2a+/JJejqXPgTi8ai+W++Gi7PixW1k/+myo9Tq56/SimiRaayAgxBbPCgjNWYjO1FqP+lvgIDgr9IPB4X9yuKQ4b17YJlUv2VLlTF3GbfiD4DSHvM/C2jXvAKsISa/AuIoTIVApB5eo7c87gUGvSgWsIctuZVi2UwHMAjh6ar+sukxCfXF6dKquEpYphPszdg+UNvPVIEdSjt+CG+PqrOb36o0g9l+Fx8FkReR6qJgtVT4dj8WJpkvr9bE2SLCauCQongguebJvycnSlHCYNBPy6420sv6h0BGsMCSQulB9euLZk2PkPSDvNq7HLUkqnC+aN1YJaNieBXJ74YqTqMmlgj2dF35poz8lsdTBU9brRDeL2OW8pVBM8TM8xY8j4dGIZtb07IGSJ/KQF/o5uCnjMGG5gkFaeFywYoIYHvPw+cxDky4ffiQPSV5cbtP6etiEETBtzgEUOLgNcy7Zdz/rnr1g9O0fUj3RAOCkq+w7Ik4uz2BGBVAGj0GInG1lvYpS6bL9yJTBXj4m3LTBNfcBjdBGU/1wLKcJ9BLLf/bUDu40sbIND0Rsw4xNBQ8ySA0wSko0/fpG28fEwYCwbc2plb0O/PZEC6ItRHVWX11oWyhWiibppDWzmn2dSdTEI1Fqfb6Ah51NaAQhKd35UG55yl3rQqK+JjAsFOh5kES70cwUsEwTziuOYlGlfX5JCU+gujieTK/vPBLR63D2s6UmA6EDYd0rdoFDCtm6dleF9cna+UhTf9GSKWFzqcv6MHS2f7LPadxTa2jiln/z2gigja0whl71tzxE0Ps5zVChRce+gM5PdQkKc02A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Rrg7PxvgG37MFy/3FBzOQpl2e33FpREYWwUXDdpM+9birU3G5hDD0Wl7C75E2UFqYU1TLnH15ig9Ga8rMU5jBo0uruvZo2AyTbEczcS3Ec1nKofqoWpvAtkXpu7FVH/RUDdynklEljAXaBtMlFc1QPrIbKnePz+iIVF8wExWYv4XSx0CHSzq04m+OFbNIkLEGAejTz/grMs6ZmshUtnj0ipy9igCrYy3Zq9mODSqmEa+KOeGzfW/40Xly/Hb02ZEvYE9TN3wphyrd8FRFx4cVrRsENjw3O5vKCSTsZrh6R1Tqg66ORemly/JHxYdKsSJVFY3zxZjZET4zKbJoGT+NcJj0EDe8VdkgRukwuW+y3iYEFyb6oBg/3gFx9Yw6N+rawJFs9YVMIvKzFKhg8lyITA3HlFLGZJz0I1b5aMWctfRWR/NUdx2LjLLDels1Usm86pxlKyewI8BYN+6ksvfREaOjM22R0BIhrbo4QNKJPTjOEScc1yQuEi5ZnE8eVRGSfg1cN4+xK8RdQrIMViFpQF5RS/tW8Ij8fsaxGvWz9qZAn94vMwcjgw2Ubtv3/6KaHSvhVkgf0VNc9K5KezbAk0+y2a1kJpeGF8jCl0sghI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c1e1eb6b-f801-46a6-2f5e-08dcf9112594 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:02.2722 (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: 5vDXtRzmBQf0xo/ekng3fJ7IEsjy0nMk6WTK15aDP99KhchLH1UCZA+VNcGFmmUHTYWDb5Oiixc4mVfx66YAeg== 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=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: Ew2hgtuMJwhZO94ORiCKJCrMA1ibOO55 X-Proofpoint-ORIG-GUID: Ew2hgtuMJwhZO94ORiCKJCrMA1ibOO55 X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org |
Series |
Add btf_decl_tag and btf_type_tag C attributes
|
|
Message
David Faust
Oct. 30, 2024, 6:31 p.m. UTC
This patch series adds support for the btf_decl_tag and btf_type_tag attributes to GCC. This entails: - Two new C-family attributes that allow to associate (to "tag") particular declarations and types with arbitrary strings. As explained below, this is intended to be used to, for example, characterize certain pointer types. A single declaration or type may have multiple occurrences of these attributes. - The conveyance of that information in the DWARF output in the form of a new DIE: DW_TAG_GNU_annotation, and a new attribute: DW_AT_GNU_annotation. - The conveyance of that information in the BTF output in the form of two new kinds of BTF objects: BTF_KIND_DECL_TAG and BTF_KIND_TYPE_TAG. These BTF kinds are already supported by LLVM and other tools in the BPF ecosystem. Both of these attributes are already supported by clang, and beginning to be used in various ways by eBPF users and inside the Linux kernel. Purpose ======= 1) Addition of C-family language constructs (attributes) to specify free-text tags on certain language elements, such as struct fields. The purpose of these annotations is to provide additional information about types, variables, and function parameters of interest to the kernel. A driving use case is to tag pointer types within the Linux kernel and eBPF programs with additional semantic information, such as '__user' or '__rcu'. For example, consider the Linux kernel function do_execve with the following declaration: static int do_execve(struct filename *filename, const char __user *const __user *__argv, const char __user *const __user *__envp); Here, __user could be defined with these annotations to record semantic information about the pointer parameters (e.g., they are user-provided) in DWARF and BTF information. Other kernel facilities such as the eBPF verifier can read the tags and make use of the information. 2) Conveying the tags in the generated DWARF debug info. The main motivation for emitting the tags in DWARF is that the Linux kernel generates its BTF information via pahole, using DWARF as a source: +--------+ BTF BTF +----------+ | pahole |-------> vmlinux.btf ------->| verifier | +--------+ +----------+ ^ ^ | | DWARF | BTF | | | vmlinux +-------------+ module1.ko | BPF program | module2.ko +-------------+ ... This is because: a) Unlike GCC, LLVM will only generate BTF for BPF programs. b) GCC can generate BTF for whatever target with -gbtf, but there is no support for linking/deduplicating BTF in the linker. In the scenario above, the verifier needs access to the pointer tags of both the kernel types/declarations (conveyed in the DWARF and translated to BTF by pahole) and those of the BPF program (available directly in BTF). Another motivation for having the tag information in DWARF, unrelated to BPF and BTF, is that the drgn project (another DWARF consumer) also wants to benefit from these tags in order to differentiate between different kinds of pointers in the kernel. 3) Conveying the tags in the generated BTF debug info. This is easy: the main purpose of having this info in BTF is for the compiled eBPF programs. The kernel verifier can then access the tags of pointers used by the eBPF programs. For more information about these tags and the motivation behind them, please refer to the following Linux kernel discussions: [1], [2], [3]. DWARF Representation ==================== Compared to prior iterations of this work, this patch series introduces a new DWARF representation meant to address issues in the previous format. The format is detailed below. New DWARF extension: DW_TAG_GNU_annotation. These DIEs encode the annotation information. They exist near the top level of the DIE tree as children of the compilation unit DIE. The user-supplied annotations ("tags") are encoded via DW_AT_name and DW_AT_const_value. DW_AT_name holds the name of the attribute which is the source of the annotation (currently only "btf_type_tag" or "btf_decl_tag"). DW_AT_const_value holds the arbitrary user string from the attribute argument. DW_TAG_GNU_annotation DW_AT_name: "btf_decl_tag" or "btf_type_tag" DW_AT_const_value: <arbitrary user-provided string from attribute arg> DW_AT_GNU_annotation: see below. New DWARF extension: DW_AT_GNU_annotation. If present, the DW_AT_GNU_annotation attribute is a reference to a DW_TAG_GNU_annotation DIE holding annotations for the object. If a single declaration or type at the language level has multiple occurrences of btf_decl_tag or btf_type_tag attribute, then the DW_TAG_GNU_annotation DIE referenced by that object will itself have DW_AT_GNU_annotation referring to another annotation DIE. In this way the annotation DIEs are chained together. Multiple distinct declarations or types may refer via DW_AT_GNU_annotation to the same DW_TAG_GNU_annotation DIE, if they share the same tags. For more information on this format, please refer to recent talks at GNU Tools Cauldron [4] and Linux Plumbers Conference [5]. Older iterations of this work and related discussions may be found in [6,7,8]. BTF Representation ================== In BTF, BTF_KIND_DECL_TAG and BTF_KIND_TYPE_TAG records convey the annotations. These records hold the annotation value in their name field, and refer to the annotated object by BTF ID. BTF_KIND_DECL_TAG records are followed by an additional 32-bit 'component_idx', which indicates to which component of an object the tag applies. This index is -1 if the tag applies to a variable or function declaration itself, otherwise it is a 0-based index indicating to which function argument or struct or union member the tag applies. Example: btf_decl_tag ===================== Consider the following declarations: int *x __attribute__((btf_decl_tag ("rw"), btf_decl_tag ("devicemem"))); struct { int size; char *ptr __attribute__((btf_decl_tag("rw"))); } y; These declarations produce the following DWARF information: <1><1e>: Abbrev Number: 3 (DW_TAG_variable) <1f> DW_AT_name : x <24> DW_AT_type : <0x36> <28> DW_TAG_GNU_annotation: <0x4a> ... <1><36>: Abbrev Number: 1 (DW_TAG_pointer_type) <37> DW_AT_byte_size : 8 <37> DW_AT_type : <0x3b> <1><3b>: Abbrev Number: 4 (DW_TAG_base_type) <3e> DW_AT_name : int ... <1><42>: Abbrev Number: 5 (DW_TAG_GNU_annotation) <43> DW_AT_name : (indirect string, offset: 0): btf_decl_tag <47> DW_AT_const_value : rw <1><4a>: Abbrev Number: 6 (DW_TAG_GNU_annotation) <4b> DW_AT_name : (indirect string, offset: 0): btf_decl_tag <4f> DW_AT_const_value : (indirect string, offset: 0x1f): devicemem <53> DW_AT_GNU_annotation: <0x42> <1><57>: Abbrev Number: 7 (DW_TAG_structure_type) ... <2><60>: Abbrev Number: 8 (DW_TAG_member) <61> DW_AT_name : (indirect string, offset: 0x1a): size <68> DW_AT_type : <0x3b> ... <2><6d>: Abbrev Number: 9 (DW_TAG_member) <6e> DW_AT_name : ptr <75> DW_AT_type : <0x7f> <7a> DW_AT_GNU_annotation: <0x42> ... <2><7e>: Abbrev Number: 0 <1><7f>: Abbrev Number: 1 (DW_TAG_pointer_type) <80> DW_AT_byte_size : 8 <80> DW_AT_type : <0x84> <1><84>: Abbrev Number: 10 (DW_TAG_base_type) <85> DW_AT_byte_size : 1 <86> DW_AT_encoding : 6 (signed char) <87> DW_AT_name : (indirect string, offset: 0x5e): char <1><8b>: Abbrev Number: 11 (DW_TAG_variable) <8c> DW_AT_name : y <91> DW_AT_type : <0x57> ... The variable DIE for 'x' refers by DW_AT_GNU_annotation to the DIE holding the annotation for the "devicemem" tag, which in turn refers to the DIE holding the annotation for "rw". The DW_TAG_member DIE for the member 'ptr' of the struct refers to the annotation die for "rw" directly, which is thereby shared between the two declarations. And BTF information: [1] STRUCT '(anon)' size=16 vlen=2 'size' type_id=2 bits_offset=0 'ptr' type_id=3 bits_offset=64 [2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED [3] PTR '(anon)' type_id=4 [4] INT 'char' size=1 bits_offset=0 nr_bits=8 encoding=SIGNED [5] PTR '(anon)' type_id=2 [6] DECL_TAG 'devicemem' type_id=10 component_idx=-1 [7] DECL_TAG 'rw' type_id=10 component_idx=-1 [8] DECL_TAG 'rw' type_id=1 component_idx=1 [9] VAR 'y' type_id=1, linkage=global [10] VAR 'x' type_id=5, linkage=global Note how the component_idx identifies to which member of the struct type the decl tag is applied. Example: btf_type_tag ===================== Consider the following code snippet: int __attribute__((btf_type_tag("rcu"), btf_type_tag ("foo"))) x; void do_thing (struct S * __attribute__((btf_type_tag ("rcu"))) rcu_s, void * __attribute__((btf_type_tag("foo"))) ptr) { ... } The relevant DWARF information produced is as follows: <1><2e>: Abbrev Number: 3 (DW_TAG_structure_type) <2f> DW_AT_name : S ... <1><46>: Abbrev Number: 5 (DW_TAG_base_type) <47> DW_AT_byte_size : 4 <48> DW_AT_encoding : 5 (signed) <49> DW_AT_name : int <1><4d>: Abbrev Number: 6 (DW_TAG_variable) <4e> DW_AT_name : x <53> DW_AT_type : <0x61> ... <1><61>: Abbrev Number: 7 (DW_TAG_base_type) <62> DW_AT_byte_size : 4 <63> DW_AT_encoding : 5 (signed) <64> DW_AT_name : int <68> DW_AT_GNU_annotation: <0x75> <1><6c>: Abbrev Number: 1 (DW_TAG_GNU_annotation) <6d> DW_AT_name : (indirect string, offset: 0x13): btf_type_tag <71> DW_AT_const_value : rcu <1><75>: Abbrev Number: 8 (DW_TAG_GNU_annotation) <76> DW_AT_name : (indirect string, offset: 0x13): btf_type_tag <7a> DW_AT_const_value : foo <7e> DW_AT_GNU_annotation: <0x6c> <1><82>: Abbrev Number: 9 (DW_TAG_subprogram) <83> DW_AT_name : (indirect string, offset: 0x20): do_thing ... <2><a1>: Abbrev Number: 10 (DW_TAG_formal_parameter) <a2> DW_AT_name : (indirect string, offset: 0x5): rcu_s <a9> DW_AT_type : <0xc0> ... <2><b0>: Abbrev Number: 11 (DW_TAG_formal_parameter) <b1> DW_AT_name : ptr <b8> DW_AT_type : <0xca> ... <2><bf>: Abbrev Number: 0 <1><c0>: Abbrev Number: 12 (DW_TAG_pointer_type) <c1> DW_AT_byte_size : 8 <c2> DW_AT_type : <0x2e> <c6> Unknown AT value: 6000: <0x6c> <1><ca>: Abbrev Number: 13 (DW_TAG_pointer_type) <cb> DW_AT_byte_size : 8 <cc> DW_AT_GNU_annotation: <0xd0> <1><d0>: Abbrev Number: 1 (DW_TAG_GNU_annotation) <d1> DW_AT_name : (indirect string, offset: 0x13): btf_type_tag <d5> DW_AT_const_value : foo Note how in this case, two annotation DIEs for "foo" are produced, because it is used in two distinct sets of type tags which do not allow it to be shared. The DIE for "rcu", however, is shared between uses. And BTF information: [1] FUNC_PROTO '(anon)' ret_type_id=0 vlen=2 'rcu_s' type_id=2 'ptr' type_id=6 [2] TYPE_TAG 'rcu' type_id=3 [3] PTR '(anon)' type_id=4 [4] STRUCT 'S' size=4 vlen=1 ... [6] TYPE_TAG 'foo' type_id=7 [7] PTR '(anon)' type_id=0 [8] TYPE_TAG 'foo' type_id=9 [9] TYPE_TAG 'rcu' type_id=10 [10] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED [11] VAR 'x' type_id=8, linkage=global [12] FUNC 'do_thing' type_id=1 linkage=global References ========== [1] https://lore.kernel.org/bpf/20210914223004.244411-1-yhs@fb.com/ [2] https://lore.kernel.org/bpf/20211012164838.3345699-1-yhs@fb.com/ [3] https://lore.kernel.org/bpf/20211112012604.1504583-1-yhs@fb.com/ [4] https://gcc.gnu.org/wiki/cauldron2024#cauldron2024talks.what_is_new_in_the_bpf_support_in_the_gnu_toolchain [5] https://lpc.events/event/18/contributions/1924/ [6] https://gcc.gnu.org/pipermail/gcc-patches/2022-April/592685.html [7] https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596355.html [8] https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624156.html Bootstrapped and tested on x86_64-linux-gnu. No known regressions. Also testsed with bpf-unknown-none, and with the Linux kernel BPF selftests which make use of the two attributes. David Faust (5): c-family: add btf_type_tag and btf_decl_tag attributes dwarf: create annotation DIEs for btf tags ctf: translate annotation DIEs to internal ctf btf: generate and output DECL_TAG and TYPE_TAG records doc: document btf_type_tag and btf_decl_tag attributes gcc/btfout.cc | 176 ++++++++++-- gcc/c-family/c-attribs.cc | 25 +- gcc/ctfc.cc | 66 ++++- gcc/ctfc.h | 41 ++- gcc/doc/extend.texi | 68 +++++ gcc/dwarf2ctf.cc | 180 ++++++++++++- gcc/dwarf2out.cc | 253 +++++++++++++++++- .../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 ++ .../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/btf.h | 14 + include/ctf.h | 4 + include/dwarf2.def | 4 + 25 files changed, 1106 insertions(+), 43 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 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