From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by sourceware.org (Postfix) with ESMTPS id 634C83858D32 for ; Wed, 15 Jun 2022 05:53:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 634C83858D32 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25EMcrLd006349; Tue, 14 Jun 2022 22:53:29 -0700 Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2102.outbound.protection.outlook.com [104.47.58.102]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gpht17v1w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jun 2022 22:53:29 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hxQZElwZkJBg7vY54Jnv30ajZdYA8zbsTQT8QlNNMm65Fro8z4kvuQEVhycUZA3c9GPmSN62ckH9OtmNd+HurIFZSHw3jqNFDpVgYJ04tcjf4zYBLN0dq/3/0OxuDdGc6ryIu/38xvxqNSlvnObWf4qVjw3/QQCtA+qXmiYWdXhJNCmcNnwn3JvSNoaxaF9hx+/K2XX44KqrdwLZ4VDHagYBPx/SsSKaL8XGMIcIlap0zHJ0uPnflOS6vUMDhnScEhojP0J9OgUv6GEo7Rn6knt+rObtvL7aEAvgwBLhT1Rgz9mGojZE+C0oru4IK05b4mNdhRgkEufERyEWZn5K+A== 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=Phz9ziC8NuX5TECtassR4kmjqwQHprSEpFsTozPRRY4=; b=HvnzsjiUp10hE4OdLZlp3rm+AaefdQXqMiCkrsKXnF2aaToV3SxkmeQAzbruagazd2fehR2EOtgS6ZyeLK1Mvbo62msEjTwp6Lucfe5guNVdEuVbdqaMDRgNwSHl/xclbdhI//5rIKquvQ75AQNEh+2bQuJ79rv5Ov1fCYVkh7oyIXSI2Uyff22NwckPej1NN7SlMjf7qJwkXS5nAf+cH2fqa/T0Gkd15ryeRNMxV8ju/8Ep9PdQAt/yDj782X81tG7Fs/YZPh9ReMTj0UZCjHdlNEZE8NRFZfNl5DqmKiwhNhhfgZeY013ba1vfTEXDUhHZXJnUSHhHGOY9DErgYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from DM5PR1501MB2055.namprd15.prod.outlook.com (2603:10b6:4:a1::13) by DM6PR15MB3783.namprd15.prod.outlook.com (2603:10b6:5:2b5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.14; Wed, 15 Jun 2022 05:53:27 +0000 Received: from DM5PR1501MB2055.namprd15.prod.outlook.com ([fe80::acda:cdec:5c2f:af77]) by DM5PR1501MB2055.namprd15.prod.outlook.com ([fe80::acda:cdec:5c2f:af77%7]) with mapi id 15.20.5332.020; Wed, 15 Jun 2022 05:53:27 +0000 Message-ID: <2ab1d9a1-0077-a1e7-f212-556fcf8c8883@fb.com> Date: Tue, 14 Jun 2022 22:53:24 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH 0/9] Add debug_annotate attributes Content-Language: en-US To: David Faust , gcc-patches@gcc.gnu.org References: <20220607214342.19463-1-david.faust@oracle.com> From: Yonghong Song In-Reply-To: <20220607214342.19463-1-david.faust@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed X-ClientProxiedBy: BYAPR21CA0005.namprd21.prod.outlook.com (2603:10b6:a03:114::15) To DM5PR1501MB2055.namprd15.prod.outlook.com (2603:10b6:4:a1::13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: db884614-9492-4d3a-c34f-08da4e935dca X-MS-TrafficTypeDiagnostic: DM6PR15MB3783:EE_ X-Microsoft-Antispam-PRVS: X-FB-Source: Internal X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D3dX86NkBPY2EqteVm7GE6SEvZuRGRKQZVvhCrT7bT6CKUJOy/SXqMcvkFspmiL7jMuD1B5A9HfOA6O/bQ53MEKL5YvNa74XsvLxO4mYLUfwKlTOpZN4I6NsDBZhZtG9bp0oNY9KKvewx98MDQrD9efoZ+NJMKQ1TBq7v7iI+Sk7Jb1BswqerwbCqtiZWOQzbRlsa2uDcvev2Yct51tvrOUIfAjFksrG5VaTLBSXelVU4n39fZTk4DJSwtOMhvvXShY358IAJbvZvA3+jXVgMAdOPo1IjrwSGu5gh6GzRErqCno+xgPRGeoP8mxEmdgNUrNXapk9H0Pkhn5tfPy1SUYFCljw/7bysuz5nyv5E/o0kqUQs1HE5Ld4RZILAnROnZ3itZnSABzSpCw0aQERmGhKgOXFlYEA73GVq9e7IBULAZ1WWfhDxURDRWC8Cun3lp5YecS8P8hke3ofx4F6by6gW3cDdWWmcEzOYpcbvMyjVQtCT8oWzFQVu7udtF4CSFgRR/mqfcjxntnn4cfam6j0WcKyHI7z4zimTKhzQZSqqWn3ylCkxpEeAzm6XS7/BiQ49Xz4W9We9VqNGF+THAdbjPcLOmLY5DujaihVL5aOQxd+cmdyZ84BGcxfjywqh84jKdxUGgvVTRufbEZ3WNWhMZmLYudFLiw2/uHk40bvEp/cW8wEUFJeBpDndT6BzmAcNFyD93Tme7G91T6YhnbA8KkZdDs23wk4aZvyWkabkCp7rKkioBi2vewB8P5d3pZmaZcfmNWznbQcYtaMaejjQ4W9hG83ZjCm8TIZh5Q7ioLayqw1Nk/McfePOSRtjIP5JhzRJDVz8zMcMy8KW5QDsNLXSViT4goKjGrVG9k= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR1501MB2055.namprd15.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(36756003)(5660300002)(31686004)(83380400001)(2906002)(186003)(316002)(6512007)(2616005)(8936002)(66556008)(8676002)(4326008)(66946007)(508600001)(66476007)(31696002)(53546011)(6506007)(86362001)(38100700002)(6486002)(966005)(6666004)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?V1poSVpkMVQrM2p6VlNWQkl0L2ZMcjVhUlgyOFQyeHR0ZzdZYTFoejgxYU00?= =?utf-8?B?RjhnTEhBK3J6aG1hWkNneTBMeUtsekY2bUFhbnJORk4wM0J2S3B1UytGQ2ow?= =?utf-8?B?UCszZlBnbWJSQmFXb0lnWGE1bkNiL0x3MTdoTDdNQ2pNUFp0NXV0Rk5UejlZ?= =?utf-8?B?UTIzWmszbjQ3SDdMR3RrazhodGxzMCt4ZVdMbXZGN2ZxSTFCQ3BjM3czZ1Nj?= =?utf-8?B?KzF6NU9KdU1LMm91VVJCelNPR0lHOHJFMDFmbnAvRFZrZkdueThxeWVJblBX?= =?utf-8?B?b2txNjBiTGI3NlczUUp6ZVdvdWhrY0czTE5rUjNSZ1JCS1hFYXJRQWJkVFdR?= =?utf-8?B?MUdYQkNwRmxIYVJXNFZJVTVYSHovOE1aLytPVmN4cURGUElyYld3dnhvc3VQ?= =?utf-8?B?MHNiU1ZWendCa3pZUXZ1SjZMcm8yMUp5cWpJNFoyVDE5NmNPTmYrd0dWcUh0?= =?utf-8?B?K3FPZ0JQS2RHUEF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TI5RVBZd3pIV3dtZG9BdW0vMTJUTElpWU1NKzMrSmFzRWNXTFg5SHpiM1JJ?= =?utf-8?Q?rXDKe1fQDVpwTZEo=3D?= X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-Network-Message-Id: db884614-9492-4d3a-c34f-08da4e935dca X-MS-Exchange-CrossTenant-AuthSource: DM5PR1501MB2055.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2022 05:53:26.8949 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TRO2bPd4CH5QxpxKZNQjZb2iYLnbQFOFenSREaFdf1DrtjusKnzkPSUclFifBiQa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR15MB3783 X-Proofpoint-GUID: Li1dIFyu1eo23KUuCci6Y36Om3b4P_9n X-Proofpoint-ORIG-GUID: Li1dIFyu1eo23KUuCci6Y36Om3b4P_9n Content-Transfer-Encoding: 7bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-15_02,2022-06-13_01,2022-02-23_01 X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jun 2022 05:53:32 -0000 On 6/7/22 2:43 PM, David Faust wrote: > Hello, > > This patch series adds support for: > > - Two new C-language-level attributes that allow to associate (to "annotate" or > 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. > > - The conveyance of that information in the DWARF output in the form of a new > DIE: DW_TAG_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. > > All of these facilities are being added to the eBPF ecosystem, and support for > them exists in some form in LLVM. > > 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 facilites 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: > > https://lore.kernel.org/bpf/20210914223004.244411-1-yhs@fb.com/ > https://lore.kernel.org/bpf/20211012164838.3345699-1-yhs@fb.com/ > https://lore.kernel.org/bpf/20211112012604.1504583-1-yhs@fb.com/ > > > Implementation Overview > ======================= > > To enable these annotations, two new C language attributes are added: > __attribute__((debug_annotate_decl("foo"))) and > __attribute__((debug_annotate_type("bar"))). Both attributes accept a single > arbitrary string constant argument, which will be recorded in the generated > DWARF and/or BTF debug information. They have no effect on code generation. > > Note that we are not using the same attribute names as LLVM (btf_decl_tag and > btf_type_tag, respectively). While these attributes are functionally very > similar, they have grown beyond purely BTF-specific uses, so inclusion of "btf" > in the attribute name seems misleading. > > DWARF support is enabled via a new DW_TAG_GNU_annotation. When generating DWARF, > declarations and types will be checked for the corresponding attributes. If > present, a DW_TAG_GNU_annotation DIE will be created as a child of the DIE for > the annotated type or declaration, one for each tag. These DIEs link the > arbitrary tag value to the item they annotate. > > For example, the following variable declaration: > > #define __typetag1 __attribute__((debug_annotate_type ("typetag1"))) > > #define __decltag1 __attribute__((debug_annotate_decl ("decltag1"))) > #define __decltag2 __attribute__((debug_annotate_decl ("decltag2"))) > > int * __typetag1 x __decltag1 __decltag2; Based on the above example static int do_execve(struct filename *filename, const char __user *const __user *__argv, const char __user *const __user *__envp); Should the above example should be the below? int __typetag1 * x __decltag1 __decltag2 > > Produces the following DWARF information: > > <1><1e>: Abbrev Number: 3 (DW_TAG_variable) > <1f> DW_AT_name : x > <21> DW_AT_decl_file : 1 > <22> DW_AT_decl_line : 7 > <23> DW_AT_decl_column : 18 > <24> DW_AT_type : <0x49> > <28> DW_AT_external : 1 > <28> DW_AT_location : 9 byte block: 3 0 0 0 0 0 0 0 0 (DW_OP_addr: 0) > <32> DW_AT_sibling : <0x49> > <2><36>: Abbrev Number: 1 (User TAG value: 0x6000) > <37> DW_AT_name : (indirect string, offset: 0xd6): debug_annotate_decl > <3b> DW_AT_const_value : (indirect string, offset: 0xcd): decltag2 > <2><3f>: Abbrev Number: 1 (User TAG value: 0x6000) > <40> DW_AT_name : (indirect string, offset: 0xd6): debug_annotate_decl > <44> DW_AT_const_value : (indirect string, offset: 0x0): decltag1 > <2><48>: Abbrev Number: 0 > <1><49>: Abbrev Number: 4 (DW_TAG_pointer_type) > <4a> DW_AT_byte_size : 8 > <4b> DW_AT_type : <0x5d> > <4f> DW_AT_sibling : <0x5d> > <2><53>: Abbrev Number: 1 (User TAG value: 0x6000) > <54> DW_AT_name : (indirect string, offset: 0x9): debug_annotate_type > <58> DW_AT_const_value : (indirect string, offset: 0x1d): typetag1 > <2><5c>: Abbrev Number: 0 > <1><5d>: Abbrev Number: 5 (DW_TAG_base_type) > <5e> DW_AT_byte_size : 4 > <5f> DW_AT_encoding : 5 (signed) > <60> DW_AT_name : int > <1><64>: Abbrev Number: 0 Maybe you can also show what dwarf debug_info looks like? > > In the case of BTF, the annotations are recorded in two type kinds recently > added to the BTF specification: BTF_KIND_DECL_TAG and BTF_KIND_TYPE_TAG. > The above example declaration prodcues the following BTF information: > > [1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED > [2] PTR '(anon)' type_id=3 > [3] TYPE_TAG 'typetag1' type_id=1 > [4] DECL_TAG 'decltag1' type_id=6 component_idx=-1 > [5] DECL_TAG 'decltag2' type_id=6 component_idx=-1 > [6] VAR 'x' type_id=2, linkage=global > [7] DATASEC '.bss' size=0 vlen=1 > type_id=6 offset=0 size=8 (VAR 'x') > > [...]