From patchwork Wed Sep 28 21:15:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guillermo E. Martinez" X-Patchwork-Id: 1513 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f2ce:0:0:0:0:0 with SMTP id d14csp373417wrp; Wed, 28 Sep 2022 14:16:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5DoByYKJA9lzYVZMun8DeAJVMun1+up7YJD3rWs6lpbTO2KOXWdgaJiyvHp+rv9f1jfe9a X-Received: by 2002:a17:907:744:b0:741:36b9:d2cc with SMTP id xc4-20020a170907074400b0074136b9d2ccmr28497596ejb.613.1664399768806; Wed, 28 Sep 2022 14:16:08 -0700 (PDT) Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q13-20020a50cc8d000000b00445d0be02e7si5158090edi.624.2022.09.28.14.16.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 14:16:08 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gqdBF3zF; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7E223858400 for ; Wed, 28 Sep 2022 21:16:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7E223858400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664399767; bh=C1RdZhYf1R4UIOp8ldmWCX3DzVNBZm1KvWRj3wQr7NI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gqdBF3zF+om62tV3KKkPjUXCM7q5zFjXanVGsgDIP0wpNnVJZgRt3f53gMvv9O6hB 5euj0Oad+F/ZKfiSmoXPo/mJSCKPRBv7QUu7svuavCPa9OoFGyLIP6PjmHt5xPeHk6 F77sP9qDw+kgW2tzLyv2wUSTXFkdLtbf4deLgkBc= 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 053BF3858D28 for ; Wed, 28 Sep 2022 21:15:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 053BF3858D28 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SKdJfj017594 for ; Wed, 28 Sep 2022 21:15:11 GMT Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3jssubk4nc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 28 Sep 2022 21:15:11 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 28SIt4XN039244 for ; Wed, 28 Sep 2022 21:15:10 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3jtpq9cyd7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 28 Sep 2022 21:15:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YDyZkrcV5Givc3B9WixjuOiy/F4azv1HQchc50wl3n5pJsNka5dVB42EPagcunXsli0JUbdmCMYmki1swZ8hJcwKJ0O56/dyXoVwWEX9IgnxTcw0JpMpXnNJh6LIAd6mwsNM7Bsc3dP3AaJz8krZQpOn9h8qCPkknE0tAmUcunk1FXyy+neOCvZ4qU1zq89dmB12HjvSUjddTN0W/d1Y1v79s2menMXgobD+SnOvWWr/ILgKSiwH9udmbIq9TP/28HPMQDdS1I1n9h93xF3eZm7JtiSUL/If5cwni+Sc/Nx055D8wDKZ9xQ2C5/Tu5EisQOwWd4iRjz13O5KGNzgXw== 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=C1RdZhYf1R4UIOp8ldmWCX3DzVNBZm1KvWRj3wQr7NI=; b=M+xMd6a5jwwNndL2SgsbExa0/BUbw37VMSH7wkZm15bsmkkDCz4i5oNb4vax8Zhf5PEgenUFcWYo3m7QAjGERNimTuRiOGq9cLFoTNlJSssEPuNHlbT7qapfanuGcnwBhD2vk3prBdXXZltmUf8TYgaDiknwQ4JY0kD9xlicQMgEguY/8gRUUTv23E2/oJjQ1E4/4+XcqFYrP83qmHW0JoN+matwqdfl1m0tAgqcTh37owU4elBlRGn++rd7eVjoEvNQ82KsbJkLfhHzqPnAS6y1fI8CTblmHR6gMSJl467EkTKZhe2WvJpCHP3e3p2puLDpiccmW/I14kwWlIPkSQ== 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 Received: from MWHPR10MB1407.namprd10.prod.outlook.com (2603:10b6:300:23::20) by CH0PR10MB5050.namprd10.prod.outlook.com (2603:10b6:610:c3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.19; Wed, 28 Sep 2022 21:15:07 +0000 Received: from MWHPR10MB1407.namprd10.prod.outlook.com ([fe80::d05e:773d:2a05:eaed]) by MWHPR10MB1407.namprd10.prod.outlook.com ([fe80::d05e:773d:2a05:eaed%2]) with mapi id 15.20.5676.017; Wed, 28 Sep 2022 21:15:07 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] btf: Add support to BTF_KIND_ENUM64 type Date: Wed, 28 Sep 2022 16:15:01 -0500 Message-Id: <20220928211501.2647123-1-guillermo.e.martinez@oracle.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220829211106.427267-1-guillermo.e.martinez@oracle.com> References: <20220829211106.427267-1-guillermo.e.martinez@oracle.com> X-ClientProxiedBy: DS7PR03CA0123.namprd03.prod.outlook.com (2603:10b6:5:3b4::8) To MWHPR10MB1407.namprd10.prod.outlook.com (2603:10b6:300:23::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR10MB1407:EE_|CH0PR10MB5050:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b454a37-fe70-40d5-b393-08daa19684f1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tYhRNmMOTJpW2WSPDHdQii5emNoHtoDmPVZUwuLsiMFjUBM3+Q5DEJWOFPWIwr6KAV5lP8soS1Y8wGs7/ZqN/BnE5ZstTP/1QXkTJvblhFYcm18hAWkg84eyI3YqP0fkWIXAGGxrMPizcAijKOOwgmtQpK3eVbGGfq3SiUQhxXTCe6quAZ2sybQyX8CemF5iGpOG2QawR7W44KUHcgPk6ocddTrjJBIUxjI5Sp0moUmCyoUUOYVEQTp322/LJco1URWaHYpwOe+R2JE7jmA6eO5ltSTFeVv247Wuz/RQZVz6q2nqZk/h5bLz9V05vXiOsro/oBcExI1rx/BJDHQGPeLtBbaih2yIxpCLfd9yW99hkuT6+RHz84WpgMP7LXgIBTfQJojrzo08Fq4w+YUyrsoYzJEwUBSQtB7s1mOVrFz/2/t2yOghfJ8VleqvCFtCw/PNWUqqsHwjDMCX6NCNXjgXC7eNLGj6EymtdxxdhbIt/HsmHxr5m8rMV7OZq8Mtc5yhqpIMZ0otZI3dXPpunc07WF1zR3r7uVQ8e0CLxHqqxzWANZ1H+Kl095xZmT7+rtBvbEr1tK/iu6Tt7QP3AjVYAvMObxwX1+Gt8GymikWTwWrlDGQdB9zEO2jbO3cUjtuQiHlwVU5IIcjj3BkKvhctZcQ1czfkca5GoBinUYJNIZPyE2QawKHQ1Yomi8fS1Bwl9It2Ksk2uEoYIAwDMrXW9wu6xZqHEtQLhy7DHn3UtVKwY0/WYyCAxp/odrbgShpvu9GJBZMox/tE8ytz2g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR10MB1407.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(136003)(396003)(346002)(366004)(39860400002)(376002)(451199015)(2616005)(83380400001)(1076003)(38100700002)(6512007)(5660300002)(30864003)(2906002)(41300700001)(8936002)(478600001)(6506007)(6666004)(107886003)(6486002)(66476007)(8676002)(66946007)(4326008)(66556008)(316002)(6916009)(103116003)(36756003)(186003)(66899015)(86362001)(84970400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5XfjL+ia+QPdNWe0h11ip/pZS5b353npgVYdPZWcrC5I2HgkgVEq5Jm57iqe5pvMuHo8EiL46pNi93GP6ZcPB2ff8cpnyb8sB3gkzBAMDcKi+8EMwgpPF6FizQKoRMhlb9p6x7bJZJccCv9BUDESogr3pTx6taLjEzbkn4aD4OyTvlES40u529JLpwAcdHvgpGn+wmhEtIt3wR1CjnNYve5yWqJhWfFzg5GeELsyp0LITNyT2KksFvdWEtzVkRsqsnBZOzKPuvwde2AhSq8VmJMo9Vgf7rOUPOTMQm08QOyp5JxoNH3UDlYHgECUaaPRQMJYnolXDawePqmzHBBDlLdw8DoiJ9sKoUxCV+jzX1hWSjVhjEMhJ20Jhi+xiqTeh0KV0503GBgXd3Vot7TzNVZvAul4leXhjcTpTPD4sgwyYwMPmu430vGB4thSITXRLfjD8KbQQGdCxOfFWYvQgrIBrfVwAuC+TnuyPkJw2ucrUkpv2Zjrstbb6/bAk/VeLC4wnA1ZT0xW72bYQv3HkVmYrafTzKnUnEdhZmx6ro/0HFP7SCQ0lnpe54QvaqaNb7BsiOCJMTNxrsOLRrTpABjonWrf06nPwdFUpO9p4YfXJ0z1MlafrS5OyeNxzHwVb6KmAEPKNevN8xbNWj/C/K4bk3xV4uwfUspb1ZqKq+7fUB/83ooBq/ujJLIsVaRIG8mwVu9sTnizUD2M3/dnp20swjfB1dk3XgJx3296yTcJkQKMglHMzH/NQOQ2vXqM33ZQCeLC57pC0/APIgDTYJ8hGTpSppzE4zn4B47GrApst7NTCdYJPhWv0XrWeS5TBr6ou4444dSLa07L/+EqerSJpkHhx/z8KskvoG7KId6OY5iFAK8sdTKvt6qS/MzHsgtvbVyWxffsPJ2Rwk3FPfm8GMZ/godyNV7XCpCqbA1/s4q9Q9cpiReZYpP6bl9FG+YR8x/Zd8bVNdp1XRp8L/pjCKFTCRNWoV7SibD0KSOA0hWX8Blec1XX3E3EPxDwsv54D/GqrBQJYz9LETWUY3aeWn6Zork11cei4HRBCXFIhcWPX94NkQLn2lSg1r8hFkdxiMLq4Azcct/RdN61Pu0EC9rpI3LTx9t2z5Nr8Cq/NEv4JbKWKa5EQL9s3SVKkPVd2vWLUVFdZ+Ah//Iiyelx76BZ4DuIQTOIO55nA+H/M0wbCYAm7XPrDYa24Xka5PJqZ/0wTXaFafuDqrt4yC0Fcpeq9TuGtKCvcRpU/Z/8KTIfZWX/A+u/OhdJYfsf2LkNHgVnFSH0a/QIXGBArMc5KVVCulIQgsjhy1PAf2R1uJC68/WanAyCmRVFacntzNzchtucSYyryO0VwoX9fWGd1PbVGvI31zKNqrVHszscsP8ticLBMXov0CVfg5/fpOT8ttOvvbxN5/8xHR/VzT0Yt+uijxm36gMXcSpmjfk5n6+TCeUoMdUpUjkSOVk/cwhF+nehoyxSIZK0vNe/q9GIZi6XOezabCf5+qtJcCM/UMbI9RbhFKfu8446PCms+4vFjYBLvhPuETjCQywpkcseFklCFFQn21/Qy/5Qk3pNyMCCt0SgDKmEN1y6AXbrn+mKjfKIR+sqgCjdaU5c35jtwX7XY1F4Jwuk8CF4OgXZFKqR1sgODkP9ZwD7eDKf X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b454a37-fe70-40d5-b393-08daa19684f1 X-MS-Exchange-CrossTenant-AuthSource: MWHPR10MB1407.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2022 21:15:07.5976 (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: 9PK3csPwUdZ7dPfWrbBGa23Wi43LVsYalo6aj70hMi3A4jUO7TMIkXmz5riy2yiDErwSM7G0GbF5sOuiJOGXghfXMyPlpq2u42M9FgyXbZ0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5050 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-28_09,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 mlxscore=0 suspectscore=0 malwarescore=0 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209280124 X-Proofpoint-GUID: F0JT1_21RnLxSGNfHGuQ5WzIGwW0-Rd1 X-Proofpoint-ORIG-GUID: F0JT1_21RnLxSGNfHGuQ5WzIGwW0-Rd1 X-Spam-Status: No, score=-12.4 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_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Guillermo E. Martinez via Gcc-patches" From: "Guillermo E. Martinez" Reply-To: "Guillermo E. Martinez" Cc: indu.bhagat@oracle.com, "Guillermo E. Martinez" Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742531506171328821?= X-GMAIL-MSGID: =?utf-8?q?1745249652254470860?= Hello GCC team, The following is patch v2 to update BTF/CTF backend supporting BTF_KIND_ENUM64 type. Changes from v1: + Fix typo in commit message. + Fix changelog entries. Comments will be welcomed and appreciated!, Kind regards, guillermo --- BTF supports 64-bits enumerators with following encoding: struct btf_type: name_off: 0 or offset to a valid C identifier info.kind_flag: 0 for unsigned, 1 for signed info.kind: BTF_KIND_ENUM64 info.vlen: number of enum values size: 1/2/4/8 The btf_type is followed by info.vlen number of: struct btf_enum64 { uint32_t name_off; /* Offset in string section of enumerator name. */ uint32_t val_lo32; /* lower 32-bit value for a 64-bit value Enumerator */ uint32_t val_hi32; /* high 32-bit value for a 64-bit value Enumerator */ }; So, a new btf_enum64 structure was added to represent BTF_KIND_ENUM64 and a new field in ctf_dtdef to represent specific type's properties, in the particular case for CTF enums it helps to distinguish when its enumerators values are signed or unsigned, later that information is used to encode the BTF enum type. gcc/ChangeLog: * btfout.cc (btf_calc_num_vbytes): Compute enumeration size depending of enumerator type btf_enum{,64}. (btf_asm_type): Update btf_kflag according to enumerators sign, using correct BPF type in BTF_KIND_ENUMi{,64}. (btf_asm_enum_const): New argument to represent the size of the BTF enum type. * ctfc.cc (ctf_add_enum): Use and initialization of flag field to CTF_ENUM_F_NONE. (ctf_add_enumerator): New argument to represent CTF flags, updating the comment and flag vaue according to enumerators sing. * ctfc.h (ctf_dmdef): Update dmd_value to HOST_WIDE_INT to allow use 32/64 bits enumerators. (ctf_dtdef): Add flags to to describe specific type's properties. * dwarf2ctf.cc (gen_ctf_enumeration_type): Update flags field depending when a signed enumerator value is found. include/ * btf.h (btf_enum64): Add new definition and new symbolic constant to BTF_KIND_ENUM64 and BTF_KF_ENUM_{UN,}SIGNED. gcc/testsuite/ChangeLog: * gcc.dg/debug/btf/btf-enum-1.c: Update testcase, with correct info.kflags encoding. * gcc.dg/debug/btf/btf-enum64-1.c: New testcase. --- gcc/btfout.cc | 24 ++++++++--- gcc/ctfc.cc | 14 ++++--- gcc/ctfc.h | 9 +++- gcc/dwarf2ctf.cc | 9 +++- gcc/testsuite/gcc.dg/debug/btf/btf-enum-1.c | 2 +- gcc/testsuite/gcc.dg/debug/btf/btf-enum64-1.c | 41 +++++++++++++++++++ include/btf.h | 19 +++++++-- 7 files changed, 99 insertions(+), 19 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-enum64-1.c diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 997a33fa089..4b11c867c23 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -223,7 +223,9 @@ btf_calc_num_vbytes (ctf_dtdef_ref dtd) break; case BTF_KIND_ENUM: - vlen_bytes += vlen * sizeof (struct btf_enum); + vlen_bytes += (dtd->dtd_data.ctti_size == 0x8) + ? vlen * sizeof (struct btf_enum64) + : vlen * sizeof (struct btf_enum); break; case BTF_KIND_FUNC_PROTO: @@ -622,6 +624,15 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) btf_size_type = 0; } + if (btf_kind == BTF_KIND_ENUM) + { + btf_kflag = (dtd->flags & CTF_ENUM_F_ENUMERATORS_SIGNED) + ? BTF_KF_ENUM_SIGNED + : BTF_KF_ENUM_UNSIGNED; + if (dtd->dtd_data.ctti_size == 0x8) + btf_kind = BTF_KIND_ENUM64; + } + dw2_asm_output_data (4, dtd->dtd_data.ctti_name, "btt_name"); dw2_asm_output_data (4, BTF_TYPE_INFO (btf_kind, btf_kflag, btf_vlen), "btt_info: kind=%u, kflag=%u, vlen=%u", @@ -634,6 +645,7 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) case BTF_KIND_UNION: case BTF_KIND_ENUM: case BTF_KIND_DATASEC: + case BTF_KIND_ENUM64: dw2_asm_output_data (4, dtd->dtd_data.ctti_size, "btt_size: %uB", dtd->dtd_data.ctti_size); return; @@ -707,13 +719,13 @@ btf_asm_sou_member (ctf_container_ref ctfc, ctf_dmdef_t * dmd) } } -/* Asm'out an enum constant following a BTF_KIND_ENUM. */ +/* Asm'out an enum constant following a BTF_KIND_ENUM{,64}. */ static void -btf_asm_enum_const (ctf_dmdef_t * dmd) +btf_asm_enum_const (unsigned int size, ctf_dmdef_t * dmd) { dw2_asm_output_data (4, dmd->dmd_name_offset, "bte_name"); - dw2_asm_output_data (4, dmd->dmd_value, "bte_value"); + dw2_asm_output_data (size, dmd->dmd_value, "bte_value"); } /* Asm'out a function parameter description following a BTF_KIND_FUNC_PROTO. */ @@ -871,7 +883,7 @@ output_asm_btf_sou_fields (ctf_container_ref ctfc, ctf_dtdef_ref dtd) btf_asm_sou_member (ctfc, dmd); } -/* Output all enumerator constants following a BTF_KIND_ENUM. */ +/* Output all enumerator constants following a BTF_KIND_ENUM{,64}. */ static void output_asm_btf_enum_list (ctf_container_ref ARG_UNUSED (ctfc), @@ -881,7 +893,7 @@ output_asm_btf_enum_list (ctf_container_ref ARG_UNUSED (ctfc), for (dmd = dtd->dtd_u.dtu_members; dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd)) - btf_asm_enum_const (dmd); + btf_asm_enum_const (dtd->dtd_data.ctti_size, dmd); } /* Output all function arguments following a BTF_KIND_FUNC_PROTO. */ diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc index 9773358a475..253c36b6a0a 100644 --- a/gcc/ctfc.cc +++ b/gcc/ctfc.cc @@ -604,6 +604,7 @@ ctf_add_enum (ctf_container_ref ctfc, uint32_t flag, const char * name, gcc_assert (size <= CTF_MAX_SIZE); dtd->dtd_data.ctti_size = size; + dtd->flags = CTF_ENUM_F_NONE; ctfc->ctfc_num_stypes++; @@ -612,7 +613,7 @@ ctf_add_enum (ctf_container_ref ctfc, uint32_t flag, const char * name, int ctf_add_enumerator (ctf_container_ref ctfc, ctf_id_t enid, const char * name, - HOST_WIDE_INT value, dw_die_ref die) + HOST_WIDE_INT value, uint32_t flags, dw_die_ref die) { ctf_dmdef_t * dmd; uint32_t kind, vlen, root; @@ -630,10 +631,12 @@ ctf_add_enumerator (ctf_container_ref ctfc, ctf_id_t enid, const char * name, gcc_assert (kind == CTF_K_ENUM && vlen < CTF_MAX_VLEN); - /* Enum value is of type HOST_WIDE_INT in the compiler, dmd_value is int32_t - on the other hand. Check bounds and skip adding this enum value if out of - bounds. */ - if ((value > INT_MAX) || (value < INT_MIN)) + /* Enum value is of type HOST_WIDE_INT in the compiler, CTF enumerators + values in ctf_enum_t is limited to int32_t, BTF supports signed and + unsigned enumerators values of 32 and 64 bits, for both debug formats + we use ctf_dmdef_t.dmd_value entry of HOST_WIDE_INT type. So check + CTF bounds and skip adding this enum value if out of bounds. */ + if (!btf_debuginfo_p() && ((value > INT_MAX) || (value < INT_MIN))) { /* FIXME - Note this TBD_CTF_REPRESENTATION_LIMIT. */ return (1); @@ -649,6 +652,7 @@ ctf_add_enumerator (ctf_container_ref ctfc, ctf_id_t enid, const char * name, dmd->dmd_value = value; dtd->dtd_data.ctti_info = CTF_TYPE_INFO (kind, root, vlen + 1); + dtd->flags |= flags; ctf_dmd_list_append (&dtd->dtd_u.dtu_members, dmd); if ((name != NULL) && strcmp (name, "")) diff --git a/gcc/ctfc.h b/gcc/ctfc.h index bcf3a43ae1b..a22342b2610 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -125,6 +125,10 @@ typedef struct GTY (()) ctf_itype #define CTF_FUNC_VARARG 0x1 +/* Enum specific flags. */ +#define CTF_ENUM_F_NONE (0) +#define CTF_ENUM_F_ENUMERATORS_SIGNED (1 << 0) + /* Struct/union/enum member definition for CTF generation. */ typedef struct GTY ((chain_next ("%h.dmd_next"))) ctf_dmdef @@ -133,7 +137,7 @@ typedef struct GTY ((chain_next ("%h.dmd_next"))) ctf_dmdef ctf_id_t dmd_type; /* Type of this member (for sou). */ uint32_t dmd_name_offset; /* Offset of the name in str table. */ uint64_t dmd_offset; /* Offset of this member in bits (for sou). */ - int dmd_value; /* Value of this member (for enum). */ + HOST_WIDE_INT dmd_value; /* Value of this member (for enum). */ struct ctf_dmdef * dmd_next; /* A list node. */ } ctf_dmdef_t; @@ -162,6 +166,7 @@ struct GTY ((for_user)) ctf_dtdef bool from_global_func; /* Whether this type was added from a global function. */ uint32_t linkage; /* Used in function types. 0=local, 1=global. */ + uint32_t flags; /* Flags to describe specific type's properties. */ union GTY ((desc ("ctf_dtu_d_union_selector (&%1)"))) { /* struct, union, or enum. */ @@ -429,7 +434,7 @@ extern ctf_id_t ctf_add_sou (ctf_container_ref, uint32_t, const char *, uint32_t, size_t, dw_die_ref); extern int ctf_add_enumerator (ctf_container_ref, ctf_id_t, const char *, - HOST_WIDE_INT, dw_die_ref); + HOST_WIDE_INT, uint32_t, dw_die_ref); extern int ctf_add_member_offset (ctf_container_ref, dw_die_ref, const char *, ctf_id_t, uint64_t); extern int ctf_add_function_arg (ctf_container_ref, dw_die_ref, diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index 397100004c2..0ef96dd48fd 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -772,6 +772,7 @@ gen_ctf_enumeration_type (ctf_container_ref ctfc, dw_die_ref enumeration) const char *enumerator_name; dw_attr_node *enumerator_value; HOST_WIDE_INT value_wide_int; + uint32_t flags = 0; c = dw_get_die_sib (c); @@ -785,10 +786,14 @@ gen_ctf_enumeration_type (ctf_container_ref ctfc, dw_die_ref enumeration) == dw_val_class_unsigned_const_implicit)) value_wide_int = AT_unsigned (enumerator_value); else - value_wide_int = AT_int (enumerator_value); + { + value_wide_int = AT_int (enumerator_value); + flags |= CTF_ENUM_F_ENUMERATORS_SIGNED; + } ctf_add_enumerator (ctfc, enumeration_type_id, - enumerator_name, value_wide_int, enumeration); + enumerator_name, value_wide_int, + flags, enumeration); } while (c != dw_get_die_child (enumeration)); } diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-enum-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-enum-1.c index 728493b0804..7e940529f1b 100644 --- a/gcc/testsuite/gcc.dg/debug/btf/btf-enum-1.c +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-enum-1.c @@ -4,7 +4,7 @@ /* { dg-options "-O0 -gbtf -dA" } */ /* { dg-final { scan-assembler-times "\[\t \]0x6000004\[\t \]+\[^\n\]*btt_info" 1 } } */ -/* { dg-final { scan-assembler-times "\[\t \]0x6000003\[\t \]+\[^\n\]*btt_info" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]0x86000003\[\t \]+\[^\n\]*btt_info" 1 } } */ /* { dg-final { scan-assembler-times "ascii \"QAD.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ /* { dg-final { scan-assembler-times "ascii \"QED.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ /* { dg-final { scan-assembler-times "ascii \"QOD.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-enum64-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-enum64-1.c new file mode 100644 index 00000000000..da103842807 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-enum64-1.c @@ -0,0 +1,41 @@ +/* Test BTF generation for 64 bits enums. */ + +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +/* { dg-final { scan-assembler-times "\[\t \].size\[\t \]myenum1,\[\t \]8" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \].size\[\t \]myenum2,\[\t \]8" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \].size\[\t \]myenum3,\[\t \]8" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]0x13000003\[\t \]+\[^\n\]*btt_info" 2 } } */ +/* { dg-final { scan-assembler-times "\[\t \]0x93000003\[\t \]+\[^\n\]*btt_info" 1 } } */ +/* { dg-final { scan-assembler-times "ascii \"B1.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ +/* { dg-final { scan-assembler-times "ascii \"B2.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ +/* { dg-final { scan-assembler-times "ascii \"B3.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ +/* { dg-final { scan-assembler-times "ascii \"C1.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ +/* { dg-final { scan-assembler-times "ascii \"C2.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ +/* { dg-final { scan-assembler-times "ascii \"C3.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ +/* { dg-final { scan-assembler-times "ascii \"D1.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ +/* { dg-final { scan-assembler-times "ascii \"D2.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ +/* { dg-final { scan-assembler-times "ascii \"D3.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ +/* { dg-final { scan-assembler-times "bte_value" 9 } } */ + +enum default_enum +{ + B1 = 0xffffffffaa, + B2 = 0xbbbbbbbb, + B3 = 0xaabbccdd, +} myenum1 = B1; + +enum explicit_unsigned +{ + C1 = 0xffffffffbbUL, + C2 = 0xbbbbbbbb, + C3 = 0xaabbccdd, +} myenum2 = C1; + +enum signed64 +{ + D1 = 0xffffffffaa, + D2 = 0xbbbbbbbb, + D3 = -0x1, +} myenum3 = D1; diff --git a/include/btf.h b/include/btf.h index 78b551ced23..eba67f9d599 100644 --- a/include/btf.h +++ b/include/btf.h @@ -109,7 +109,8 @@ struct btf_type #define BTF_KIND_VAR 14 /* Variable. */ #define BTF_KIND_DATASEC 15 /* Section such as .bss or .data. */ #define BTF_KIND_FLOAT 16 /* Floating point. */ -#define BTF_KIND_MAX BTF_KIND_FLOAT +#define BTF_KIND_ENUM64 19 /* Enumeration up to 64 bits. */ +#define BTF_KIND_MAX BTF_KIND_ENUM64 #define NR_BTF_KINDS (BTF_KIND_MAX + 1) /* For some BTF_KINDs, struct btf_type is immediately followed by @@ -130,14 +131,17 @@ struct btf_type #define BTF_INT_BOOL (1 << 2) /* BTF_KIND_ENUM is followed by VLEN struct btf_enum entries, - which describe the enumerators. Note that BTF currently only - supports signed 32-bit enumerator values. */ + which describe the enumerators. */ struct btf_enum { uint32_t name_off; /* Offset in string section of enumerator name. */ int32_t val; /* Enumerator value. */ }; +/* BTF_KF_ENUM_ holds the flags for kflags in BTF_KIND_ENUM{,64}. */ +#define BTF_KF_ENUM_UNSIGNED (0) +#define BTF_KF_ENUM_SIGNED (1 << 0) + /* BTF_KIND_ARRAY is followed by a single struct btf_array. */ struct btf_array { @@ -190,6 +194,15 @@ struct btf_var_secinfo uint32_t size; /* Size (in bytes) of variable. */ }; +/* BTF_KIND_ENUM64 is followed by VLEN struct btf_enum64 entries, + which describe the 64 bits enumerators. */ +struct btf_enum64 +{ + uint32_t name_off; /* Offset in string section of enumerator name. */ + uint32_t val_lo32; /* lower 32-bit value for a 64-bit value Enumerator */ + uint32_t val_hi32; /* high 32-bit value for a 64-bit value Enumerator */ +}; + #ifdef __cplusplus } #endif