From patchwork Thu Apr 11 21:01:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1922712 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=aSQdYKBD; 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=VeHg1yGV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VFsb44hchz1yYB for ; Fri, 12 Apr 2024 07:02:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2CFC385840E for ; Thu, 11 Apr 2024 21:02:22 +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 06F103858D20 for ; Thu, 11 Apr 2024 21:02:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 06F103858D20 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 06F103858D20 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=1712869321; cv=pass; b=foPk9SpjfF2U5uZmTblcCdgmH3SKPHKuV6bQau7bxQ2tWcQ0IPWMv3u4WpY9xMpnlh4mLnP3ymiZ+CZ4l1Ugfpxt8YLU3NUqIIZCQ6ClRsF+AmsMt2ncKAtvEKWVm4DdCS2JLjHuJDH77dQB24iqXktFbjsz+n9JiuUK1j5fSxw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1712869321; c=relaxed/simple; bh=m8+ayL3Vk9Y0vad9tdjloK8hjMxkkOKxMRZ3r4P5VFU=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=imOTkzaB/PRviZ5uMa36jGrbFjbY2d3Ty0SPppJHgDR/4YKvubSLc2RRfNfsYvcFjcLOlqVnnWKFmYjyscbouPd5Yau1+Xm6YsD4o9ztM2wPoZQuw7e0yUeyRR5Tev6tMudjX6RCpI/vMQ1q20KjoY2OhWRIKtNtOUwIbBeHciM= 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 43BH8E2w025465 for ; Thu, 11 Apr 2024 21:01:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=tI14dA75qnFdFms6GQA9HznhYDHmHClvg8P3PLqYRcs=; b=aSQdYKBDw+sljz9y+z3GPN8/RCegOEIezvM3kECTuAaO8Jd+HG0p3+79+tvP1K9shM9c K5AKbBS1t5uOc/TZW/lvxQd3clN0iE0euPWP01UA+FoaXYamJnhzb9OI6yb5KFyD/giD Qkb8Eil9jhEaq25WlGVJsUhiyvt4p817/96prIKJ3OazSNN3DtPbhMxcqCRzmYkjB603 dBcUnszwbFkucztAKG5waGkD7QURtD42bDlQKdJJTnryUjbsXsRIF7QQHCduqfDXW3y9 cfJSzEY2R63Xq40b0ctQyP/U+Tkv+ARb/NSDg6wvxK/4m1SFTY0md6pNEqZVZggf9qzq /g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xed4jscbh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 Apr 2024 21:01:59 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43BKNxFR008049 for ; Thu, 11 Apr 2024 21:01:58 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2101.outbound.protection.outlook.com [104.47.55.101]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xavua3gm7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 Apr 2024 21:01:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZQoZPGl3GEWg0yd95besvHXcYXvJitsG5eMHTNGlRKbPNcBlvORJwF+82jp5n0sxdg3zVnmvjXk6T776FBPs6Z1sKttEqEIz/mlRlU59npbavzBTAD3VrEOf40kl+CE4R2naYkLp/EghldAC9nrf09HYVjFU/ZPgL5Rt7Iax1Fa7bjaf41KSNhZfF3m/KhooQtTCFP5r1NrUDJRh8k6FyqA3Yho4Dn/82wSOo1worCeFkabY8Js5Fmp2BwfaOIawXQ55RWQHVExq34wqDah2GuV7gkTN5Izv23HEcHX5gHxWdXn250MWVorqESlBRufRLLuuKd/5LddgYlli0A8llQ== 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=tI14dA75qnFdFms6GQA9HznhYDHmHClvg8P3PLqYRcs=; b=dMijUy869lS+LHboBcrgr5G70wDeMD1HDssdoZerfEmGqGe7C+Dq9lzgd63xKO7UuEl5NGWqc/BsXoL9KbCRWujvYx/RnDRcDw2EXOV+rvAtSSekD+s0nOh10sftTLtwqVly6hCNUnzI+uherewAKtuP0//oAZPY/xPIE9jjZtFMEyxAL6qbjqZcGskdiH0X7WmI7qYQRD0kpZ79Lruguryqau+cS1VceRNIQVwwF52WC0VZw7jB3nj3X2yZF14RarMbpIoaUJzBYqOWNzpm4lb1RTYYOWisVK+se4qNr8HbIQykQGkkQ6cdgkvEhMiFRYQ01OAVXLX1u/ZZCIgIWg== 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=tI14dA75qnFdFms6GQA9HznhYDHmHClvg8P3PLqYRcs=; b=VeHg1yGVbBUicX8zn/qDM/h5rbsYOgYqb2O4PGprFwPbVc+DCZ+ZNAcSLoMURTeZ2+cWYGyP40Bh/+z4jbNWiPVEmISV1KP2Hq2mxWxtuYxVumdBGI1vL4lt+Q6BZJCV4vPCYOsY7EO71gY0IQwU35AKqloX0iMnHrewSmk5goo= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by CO6PR10MB5554.namprd10.prod.outlook.com (2603:10b6:303:141::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.55; Thu, 11 Apr 2024 21:01:54 +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; Thu, 11 Apr 2024 21:01:54 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com Subject: [PATCH v2] btf: emit non-representable bitfield as void Date: Thu, 11 Apr 2024 14:01:47 -0700 Message-ID: <20240411210147.16974-1-david.faust@oracle.com> X-Mailer: git-send-email 2.44.0 X-ClientProxiedBy: MN2PR10CA0031.namprd10.prod.outlook.com (2603:10b6:208:120::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_|CO6PR10MB5554:EE_ X-MS-Office365-Filtering-Correlation-Id: 43ab712d-5288-47f2-c50b-08dc5a6a9e0a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q5kIY6L3JJMV3vn4XPbjk3B9qLGmzqhvTCTKU6nOfRH0jkUPN73pkQiZLjubXui8CalfElYImYdhoc349YCbvTt41LSuy0GFaHqChMK8lLZ2RuQpDPS8UKkWEDQ/wxCzoOD6MirXxkVzphT83oz3ZaH0ZNnGpst/NZDDkfCNPb7jL1r1VVr0B2Rl2wGoLqZdNUUZm5k6Brm3/CoXM/CTCcnfYJBVDNcLHXkTO4hOvpYStNSK6F5vWElMPmyTlAtDuvorKqm6wTUOaW7ZSMgBuuitJAgkhWoZPc7UeZvo/2IzkL9oOkU0riz62hng+xyn2b9HfJqEl42ZZSfQzDiljvQO++8XzBzpb4Oa8v3nlIC2noSZHeB71QS+L62BBGGPvWi+sFabC9vVFURbFVaSGxtZMtXKPyWALLzr+nWI14coDcf7oneID+oFBJsxN4lxk2GtE2uQuwmvGgeSqGCTa4dr0XrghNSqKhlVDL08e1A9QXGusQ1RsM3jc4U3qepjDJ9QuI8Nzt24AqwMpT1xcnOExiKotHK+ce7A9GXzroy55D9qqgfKiRTic6Lwx2aWPt3QsTLO/kDMibEy1UH6na7sMpTxxU20QXlI3QpWtd8= 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)(1800799015)(376005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FbYyc1FZkoaytX4WJNtGv9H6Bg1NFtDPdNzFf0HUKYj1aTmq61Y0Vd4uGSlwT8FO1f9AmmGs6DQRdIZdD+BKsIrHVCLWqPNsZ4nHPasyv48L/z5qFE/IH75oM6vlQXip5SnkcEngbG0rCqLx2HgmLd21TUxgjM/RfuOLNP+ST0hcQZj9AvyqHkFNkBXMVccQ4YPlARs7fVxjBCvCyqgCnGGIkp4nkCqWB9HHLTrb8GP3TMhbKiiF8cpMgX3gi5KnMrbqPKLNoNcq4lwKxNt+71ja8uK54+N42RSn9VVNAtzXIt6hhgvQjqwKimt+guy3WwvvqP/dl6gwrKmIW6qlIEDwbGL4rTsTCbCLOZn2/AD4AipxcKjidzBGIT0UD8GjG0Uznur0msnnrEWAMsZLjtQW7uH8y02F888r7BlNIiLEESMye4AOw2lr3uYbHTc8Luv9RcdbSe+/Z4wq3Yo3wIgN0Hf61JfZwwCqSRs/u2evMfcJwXtsRoAKMLfHuHm2Qzjx9es2d9k383BEJYeEWEPWmUs4EwoUkAASmYzheJBLPN6Ga3giQwfPUjR3HtlVq420sQ5J+OEQ6i5zj4IwnykRDGqvZqj4fd1UD27gB9ws3TIK8DUVxxJZv8/0+q7Roe+j8LdIduBJKEkVWBqtIhl2nWE52UuXwlULE/2MCmK+H8suepnPlTrQhGKDloxeYJImVbrA+M28y96dNkgOIoNsVnwTCr6q5cZifFJ70fp/mMBQIx80UrhtHGOxoGEjpPqa9KO4nBPl/l/MzbTDBiRvTryrnIbAh3LDV6dXM73uH/Oxk4SuUX0TK5JXi45mA9r1RlXcePGU+lJeCzOsgMiUF38ost5SKzjK8WMZcleQ5lHIQUe5/vN+bFoKrMX9Wfbx6L7Otrj21NFcNrR5TPNZliggZwBcUOb7ag/9srY779RxSsvyT6Vb+Hf8Rlv0SUVO+KFscej9Yr3vMJtC0BKK+PXffB1cbUZwJ+PQLTyW1MEYc8NoRHzMGxIYPoasc87l+hCqv53X22CrjvUQzRv8rOkBK/Mu8H+soE2cGvZGlro4ExWdj8ibtXrbcG8NdS0zfRAVaAUBX+2Hm7Us/AoT3zgwe6ffdohPg4ewrlHQ9i/vFDg9Th/hsloS5JGVJRCIo8S5bjLHjRYt1YWd2ikIdpMI+343W4wb+ppx+nHMn9IRZUZ/98ZOhxeDlf2f+Nv2E54aVZufBqvtClBjOm7pCP8IsvG6qEngiOkeI97I0DYknYkV7prCfx6oqK64IFP+FIA++neVKqinYkUvwjdeKKjk/Q5BRTAO4i/UdLEH4BBmw4hXKBPxieB77EG3zVLv1zVdTkdZ3fAs/WwWFRmuVVgK/7zxS1gzLCouCRiyUkMNHjl1ihDZffh4nRCmUIdgN7CghJhcsvx+eaCYs40vNkJYAS93Hbsp7dFIx2n9bswz5pz5Y83pDbh7ZLmjbyllEzB3e92+SkaFX+oEUeGxLfCpQetthrfGelJRQG1tii/JlRergZ6BJ21ckOc39xJN43tT+D8Pn1pCRPwq8IjpLjPtfn4q2Kvin2zJP4vO9AK/6NmGPiP1yaqTph9/ X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: +chs9Wx+3NAwB2NVXF/+6jOgFRLdWs09ef3dn/b8qfr3qZnHREhz9fWVPeL9KrdF8i+bfgnof4r7Z50zh1AznKTFYFHCgHlXcqzKw5+JcPaIaHsgtAGMSTw82Jczc4eUTHaQrxJoayqETZ8zqndFWnjoTVXj/Q7uv0xNLM8HcGDp0jlyeDsa4RTbXklolOg3eJo08oBG4PMdEYqUrVoj06SMS05E3HdHMKfsXy9yPimXlVBRK2bRuwaaixXhQs9k3+2uh1Zr/71oVcVKErnWZj2wmAkBUlZEXbIMaR+WsgzevEULCA/ushdd8kAUYALPJsIJdnVAaLmc2YKVhjbYdbCteWROYm2t+qymt33SxnTBq3TxBiXWJat+O5Fxxl5ndchoeX/Hv57nJFJaYJ6s2eeEb+2N6bgp75peWAn7N9LAKLyoCczmEC9LQ8gNiMGDKqM4rQHNwnGfUYeCfR93tiLBW5H6Px+82p2JOTXBrhgznLigLBowSs5URjTs9XFveRirsBA0XZIQVetxBDkAOyDyIx17BkQv99Bh9r8ZffYTzS2ad05fDdlMEizzVOq40Oxd0uJI89QiHH1rPN9VplxlCbXmTg9dsyT6GMj8Z3A= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 43ab712d-5288-47f2-c50b-08dc5a6a9e0a X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2024 21:01:54.5885 (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: PnpvvdCo0KsgL8hVuUQ4G8J2iqECON+gS2LipURDw50zu4Ghy8jkaz7Tacjn49c20Oez9wGZG7oxtiYGq7VxeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR10MB5554 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-11_10,2024-04-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 mlxscore=0 adultscore=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404110152 X-Proofpoint-GUID: 3sWpgRJ8f3ldm1iNTz7MnKZI_KpWBqE1 X-Proofpoint-ORIG-GUID: 3sWpgRJ8f3ldm1iNTz7MnKZI_KpWBqE1 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 [Changes from v1: use btf_dmd_representable_bitfield_p in btf_asm_sou_member, instead of a slightly incorrect equivalent check.] This patch fixes an issue with mangled BTF that could occur when a struct type contains a bitfield member which cannot be represented in BTF. It is undefined what should happen in such cases, but we can at least do something reasonable. Commit 936dd627cd9 "btf: do not skip members of data type with type id BTF_VOID_TYPEID" made a similar change for un-representable non-bitfield members, but had an unintended side-effect of mangling BTF for un-representable bitfields: the struct (or union) would account for the offending bitfield in its member count but the bitfield member itself was not emitted, making the member count incorrect. This change ensures that non-representable bitfield members of struct and union types are always emitted with BTF_VOID_TYPEID. This avoids corrupting the BTF information for the entire struct or union type. Tested on x86_64-linux-gnu and x86_64-linux-gnu host for bpf-unknown-none target. gcc/ * btfout.cc (btf_asm_sou_member): Always emit non-representable bitfield members as having 'void' type. Refactor slightly. gcc/testsuite/ * gcc.dg/debug/btf/btf-bitfields-4.c: Add two new checks. --- gcc/btfout.cc | 54 +++++++++---------- .../gcc.dg/debug/btf/btf-bitfields-4.c | 2 + 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/gcc/btfout.cc b/gcc/btfout.cc index ab491f0297f..a1510574a93 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -922,41 +922,39 @@ static void btf_asm_sou_member (ctf_container_ref ctfc, ctf_dmdef_t * dmd, unsigned int idx) { ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type]; + ctf_id_t base_type = get_btf_id (dmd->dmd_type); + uint64_t sou_offset = dmd->dmd_offset; + + dw2_asm_output_data (4, dmd->dmd_name_offset, + "MEMBER '%s' idx=%u", + dmd->dmd_name, idx); /* Re-encode bitfields to BTF representation. */ if (CTF_V2_INFO_KIND (ref_type->dtd_data.ctti_info) == CTF_K_SLICE) { - ctf_id_t base_type = ref_type->dtd_u.dtu_slice.cts_type; - unsigned short word_offset = ref_type->dtd_u.dtu_slice.cts_offset; - unsigned short bits = ref_type->dtd_u.dtu_slice.cts_bits; - uint64_t sou_offset = dmd->dmd_offset; - - /* Pack the bit offset and bitfield size together. */ - sou_offset += word_offset; - - /* If this bitfield cannot be represented, do not output anything. - The parent struct/union 'vlen' field has already been updated. */ - if ((bits > 0xff) || (sou_offset > 0xffffff)) - return; + if (btf_dmd_representable_bitfield_p (ctfc, dmd)) + { + unsigned short word_offset = ref_type->dtd_u.dtu_slice.cts_offset; + unsigned short bits = ref_type->dtd_u.dtu_slice.cts_bits; - sou_offset &= 0x00ffffff; - sou_offset |= ((bits & 0xff) << 24); + /* Pack the bit offset and bitfield size together. */ + sou_offset += word_offset; + sou_offset &= 0x00ffffff; + sou_offset |= ((bits & 0xff) << 24); - dw2_asm_output_data (4, dmd->dmd_name_offset, - "MEMBER '%s' idx=%u", - dmd->dmd_name, idx); - /* Refer to the base type of the slice. */ - btf_asm_type_ref ("btm_type", ctfc, get_btf_id (base_type)); - dw2_asm_output_data (4, sou_offset, "btm_offset"); - } - else - { - dw2_asm_output_data (4, dmd->dmd_name_offset, - "MEMBER '%s' idx=%u", - dmd->dmd_name, idx); - btf_asm_type_ref ("btm_type", ctfc, get_btf_id (dmd->dmd_type)); - dw2_asm_output_data (4, dmd->dmd_offset, "btm_offset"); + /* Refer to the base type of the slice. */ + base_type = get_btf_id (ref_type->dtd_u.dtu_slice.cts_type); + } + else + { + /* Bitfield cannot be represented in BTF. Emit the member as having + 'void' type. */ + base_type = BTF_VOID_TYPEID; + } } + + btf_asm_type_ref ("btm_type", ctfc, base_type); + dw2_asm_output_data (4, sou_offset, "btm_offset"); } /* Asm'out an enum constant following a BTF_KIND_ENUM{,64}. */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-bitfields-4.c b/gcc/testsuite/gcc.dg/debug/btf/btf-bitfields-4.c index d4a6ef6a1eb..20cdfaa057a 100644 --- a/gcc/testsuite/gcc.dg/debug/btf/btf-bitfields-4.c +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-bitfields-4.c @@ -14,6 +14,8 @@ /* Struct with 4 members and no bitfield (kind_flag not set). */ /* { dg-final { scan-assembler-times "\[\t \]0x4000004\[\t \]+\[^\n\]*btt_info" 1 } } */ +/* { dg-final { scan-assembler-times " MEMBER" 4 } } */ +/* { dg-final { scan-assembler-times " MEMBER 'unsup' idx=2\[\\r\\n\]+\[^\\r\\n\]*0\[\t \]+\[^\n\]*btm_type: void" 1 } } */ struct bigly {