From patchwork Wed Mar 30 23:31:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 1611469 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ysi3g3Ph; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTN8f4hQ9z9sBy for ; Thu, 31 Mar 2022 10:35:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E9D6385741A for ; Wed, 30 Mar 2022 23:35:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E9D6385741A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648683328; bh=y15jPu3R8cFM0NEXGFfaGcspH+xns4NypYDOKdTrxQU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ysi3g3Ph/sPhcnnt/k+p3XFa7cEDV2U7O1Y26RfAMgOWP2HyYqtENCaLX4RgK/pkk CWVGmPFQQjaUbBBv/7cLMoJgYCl7qfCy4uFhcrChwdl9b3VBq2BDyufeEtBn8LmPor AS6ow37Nx87s79iWmPHncukXgamcoZjMCeGxCulw= 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 319EE385840F for ; Wed, 30 Mar 2022 23:31:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 319EE385840F Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UL8MIV032396 for ; Wed, 30 Mar 2022 23:31:50 GMT Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1uctu2ve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 30 Mar 2022 23:31:49 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 22UNMbIS007313 for ; Wed, 30 Mar 2022 23:31:48 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f1s979708-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 30 Mar 2022 23:31:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EWWqdkOicpIYqAYy5e10bZqilLFDwe3rKzuTFTuxpZ2z47tDzRUPPH9DoE5HaYBaKDB2ARH/0CedKV1B+XDgAax30gpkhjqgif16nrRDFvh1POOqZDsRXd/2bj+Od9P4v2P533dGopiQAhLgj7/LIAFzG83E7+7mo0cdnwWregxrfyIt1GTUEhWZP9NxMNCVFHZxuk09re5qvr1Q0d5EIa5EwTGFNbNryX5yhFy+5J1abI4UBy2wUpCGHmQ/6CP1CgMi/dS1yhpaoSkVZU+hU0zZjRNabp8UN0EOkb1cojfgAtAgkyg2xsb0r7AhrypIg8i1NA3R1EFfAK6h0cBdZQ== 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=y15jPu3R8cFM0NEXGFfaGcspH+xns4NypYDOKdTrxQU=; b=kycGd+H4R+MtJ4TyZOLsn6cFcEE4hXeEZKvcAqXB08V+DePruURWqJCsi2cLPlYZ0GT1Wa2XPzZdWOpbhYg6b2lpo/F6OtxsMynfyQcf2Rs9OnOVjoYpDpFCWdipS3c2w+hpJWLEF32n8faffUWogUede3w6Ac9M4W6RRqCkw5eALBh6P033VEgOM++vDhhVLklNz7O+fwEjseNWepHgf+Ay//HIbviD1VIWKEJLspOTaEJFpjSMYauz0OQz5iiGbBqFvqEPXIu0SyCA/KFXfCP8JQOISw5RWcuO3WwvHrlc9vrybNbFs7u/EIYxOLb2s1jzbOs0rw77ialxCnShDA== 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 MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by CO6PR10MB5538.namprd10.prod.outlook.com (2603:10b6:303:135::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.20; Wed, 30 Mar 2022 23:31:46 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::b1f2:a803:163b:aad5]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::b1f2:a803:163b:aad5%4]) with mapi id 15.20.5102.022; Wed, 30 Mar 2022 23:31:46 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/3] CTF for extern variable fix [PR105089] Date: Wed, 30 Mar 2022 16:31:34 -0700 Message-Id: <20220330233135.1762317-3-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220330233135.1762317-1-indu.bhagat@oracle.com> References: <20220330233135.1762317-1-indu.bhagat@oracle.com> X-ClientProxiedBy: MW4PR03CA0205.namprd03.prod.outlook.com (2603:10b6:303:b8::30) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e91af83b-50d4-4552-bfb5-08da12a57481 X-MS-TrafficTypeDiagnostic: CO6PR10MB5538:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hUBw4F3gfJHOUrJPUuXv9GEJtVaNRhj9Ss2Fkp0wKH75clcI8/LckxQDq9+OS2NLgDSUlFV48q6Kxsj4NMdO0Vp5/DqZSv11pkfgOuKPBkOSxmpFZMhov5Y3AN1YewovI3AIGG54fPXWChSIoKGo2o62AE9wnZjYu9aoTjw8/E3sHHxU2QW/duW8PYlq7F0XXzK2gUdZ6THMqeA9DIjTwGzEKK5yQCJCnklhEgQPV6YEtmL49k7FeaC62LRTd1gq3P6QjJRaAIoA+LnfXWcebN4YUtmC1WWv8hAcKf5QcJKPoukU0kg/n4C7Bj13Lf52CysslFzgtcjjAax4Zc2VOKo5nD04ri3bRIP85/adZ0Y6Z32qu/2aokGOXhGfaNvPzk6eP2Gl9X1QcjWf1EcmgXUBtVJ/8OIBr5AncC5IeX17h3TcOgzor2aDUeasTfCOBK1pOWxPXrxuIYCPK+Bc9UStLVYJS8lvEpQyqiMKOaHYm2t5ep3weXAXR3dQlgq+iiPRGACqwN10LZEgFEFSIT56QezVk/SuMF1nvqE8vWCivnzW4CDHdUh9o9E8C938Z7fZDYR2t6MtSx0bHuQ1/tUfxIcDQRqUI2hVRX74RpARMtsFQbLTjht0YgLprU4HXMnFs+FFmlF/e6BJFOl/84o/OWQJWMklXlCEcVL0+XlMsBjFcabJbFjTM/NEaRzFhYfUmyWgqbLBE8AuirRBDg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR1001MB2158.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6512007)(316002)(52116002)(6506007)(186003)(1076003)(36756003)(6666004)(83380400001)(86362001)(26005)(30864003)(2906002)(6916009)(38350700002)(2616005)(44832011)(508600001)(6486002)(5660300002)(66476007)(66946007)(66556008)(8676002)(38100700002)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Act8Hqbpm0Y8jY87S55P0/60qTwRF1NTOPjcZZizpV6dh3PEwK4PlP0yssEAtp/u/v4lsrM+qv8GVJPt+rNwTPW4Q0XwZCeLWlRoqukSi11XAv8XtE578DIXkr2/SGViBvLTyVuCXCl4nzcfMWdng4q1tZkR1yKZ7D0sMu3NAI3TQoMOgh1NO8BHb4A+RrZZdbN9dgZzP05A3oOmJVEMXmb7G4qvMY/6hIDffI2JHys/RbTtoM88Tw/XhbPxem8PZmhykudh5zbOpmOJzz2tZkoLGoi6MUeFDpZfxWYm9hvcHwZTXD5iyLJawZ5ZzwzWAvhoooAMyAabXe1VhM5RKd1Vz+8feXdxD/MCvnSt4GORcS5LuaxbY/PKCH50Rqu7p2JMwroAQWnklfcLDdjz9jsAYwhY5t4baIu9lMTLijp5NlO4kuQWoO1g20L0n7Ld8uFCucyOqJca9tp0dO8+RIfKYWyVsZBoWp0hovZ0Y5bqn0SZ9mlrZn8h8c9NmQ2UYDStI0hkAq+0ManQhkRtJ+DBHaH7XlDXYvBHH3/5QxWxFnnKefQkwF/02w2k+SX3spgUfoiFEZIx9e/hZV25sPpQLWtVLIXyBO4TTUfSkThey9m7aQqpOFqgDN87SMP0Rs6lX7u5zxLm3UkET/kow/xXC6VMPxVjHpJX4/qB1J5mvG++WENtYPp1cui6YEpt2ZL3bDzgnAVYjEHTFVCLoDLm8Y/cu6griP81tggtYzC64mxcuysCF8/ci9+jQDE9oBd0oAcIjLElPv+9PhR9MjkWO0G8/E38fenyQebYKW7fJu5WgBbpwBK1qfQYO4K8NIkmqKz3idBFKinF+vawS6qXSvgYaXGDnIohOXYu1Y1R95UWzaWiEITzxrkj3IlqB6WmZVPQgPtI6S+sbRVljUm9RwZJcLT7lXrUZO+ip1dn9Br3bZy3mHXwsExLwyPckircZ27rTXqb28iosoLwTXacAG4NQzIeNH4aXpEoe6BHvcJnuA6y52NqWirORej88vnxgZXU+SMPoOeuDTUK8swP9CVaWqdWbzbk5AJ1+03VPKZ0BWA7NkdueOMohU9OQkxQaG7EMeyb6/daQaRn2Yv2XjyhuR+hjWDcHSKWb5ynyOB9+d4FME+Nbo2SVI/iL+yAZLT+WTY2OybOG90ROqYeodZTL/3qX2qo0/HrGOUFnuj3ihyc3FVYF4Js9H800Yek2mu21eM6oTLyOzw4t1GEMsTGXbjW8DT9efbgKLhOSPgBPCgmMIiEQzN8qms1LfIb0Kcg2HN5IIlIP5Ixl4Bx4slvWMQTVKi6JFjk6wdWt0gLVbG6zq/2iwXV2iXX7MppK/zzv0lg1QagDVoXjdcopCMnVgVlZq0tjqouEC/915hiyjejWzudbTy1iUn6jLWlYiDu/W/NAGcNJuxKGKTGC/YIPQxzTRumrjjqimMJ8qF5sKE0m+/+UDW6LyEc2Scp6jSFE7+B/t0nsmFeEoBUxfSPhvfnL2ohUuXxJO6YA2GyxZvKMdy5x6rshQ1rqwCe05Xq48t7+ajD59u4bKa6qr4OBTb+6MmQjvwNe7YcwSJYtBvP3HIzxiYzrE5hJ/z/GMI6YnXrtvMXHjXlkM7SwZG9LUVPIhD7U6ijEWk0DQWHeFMo4RL5LXtcu5sOViPbyzBVLHjO5T8wGihZUG0RjpO6+sJHGIbmNV/+Z4Vb6nwT4NNIGPJGaHPKIilEgDzq8uP4j7gBssQYaWhNZA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e91af83b-50d4-4552-bfb5-08da12a57481 X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2022 23:31:46.1941 (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: sxuW1mWrOqV7l3bpiorV6/ogss4L/xdkDARJitU2HKCVuNw5oCRwS1x0J9MlVLIMotaDHXeoFz1JOFj1ezH6nQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR10MB5538 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-03-30_06:2022-03-29, 2022-03-30 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300112 X-Proofpoint-ORIG-GUID: rO37bePpgCi_9cukNHDzHUZ7iAIecLZ5 X-Proofpoint-GUID: rO37bePpgCi_9cukNHDzHUZ7iAIecLZ5 X-Spam-Status: No, score=-13.5 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_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Indu Bhagat via Gcc-patches From: Indu Bhagat Reply-To: Indu Bhagat Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The CTF format cannot differentiate between a non-defining extern variable declaration vs. a defining variable declaration (unlike DWARF). So, the correct behaviour wrt the compiler generating CTF for such extern variables (i.e., when both the defining and non-defining decl are present in the same CU) is to simply emit the CTF variable correspoding to the defining declaration. To carry out the above, following changes are introduced via the patch: 1. The CTF container (ctfc.h) now keeps track of the non-defining declarations (by noting the DWARF attribute DW_AT_specification) in a new ctfc_ignore_vars hashtable. Such book-keeping is necessary because the CTF container should not rely on the order of DWARF DIEs presented to it at generation time. 2. At the time of ctf_add_variable (), the DW_AT_specification DIE if present is added in the ctfc_ignore_vars hashtable. The CTF variable generation for the defining declaration continues as normal. 3. If the ctf_add_variable () is asked to generate CTF variable for a DIE present in the ctfc_ignore_vars, it skips generating CTF for it. 4. Recall that CTF variables are pre-processed before emission. Till now, the only pre-processing that was being done was to sort them in order of their names. Now an additional step is added: If the CTF variable which corresponds to the non-defining declaration is indeed present in the ctfc_vars hashtable (because the corresponding DWARF DIE was encountered first by the CTF generation engine), skip that CTF variable from output. An important side effect of such a workflow above is that CTF for the C type of the non-defining decl will remain in the CTF dictionary (and will be emitted in the output section as well). This type can, however, be pruned by the link-time de-duplicator as usual, if deemed unused. 2022-03-30 Indu Bhagat gcc/ChangeLog: PR debug/105089 * ctfc.cc (ctf_dvd_ignore_insert): New function. (ctf_dvd_ignore_lookup): Likewise. (ctf_add_variable): Keep track of non-defining decl DIEs. (new_ctf_container): Initialize the new hash-table. (ctfc_delete_container): Empty hash-table. * ctfc.h (struct ctf_container): Add new hash-table. (ctf_dvd_ignore_lookup): New declaration. (ctf_add_variable): Add additional argument. * ctfout.cc (ctf_dvd_preprocess_cb): Skip adding CTF variable record for non-defining decl for which a defining decl exists in the same TU. (ctf_preprocess): Defer updating the number of global objts until here. (output_ctf_header): Use ctfc_vars_list_count as some CTF variables may not make it to the final output. (output_ctf_vars): Likewise. * dwarf2ctf.cc (gen_ctf_variable): Skip generating CTF variable if this is known to be a non-defining decl DIE. --- gcc/ctfc.cc | 62 ++++++++++++++++++++++++++++++++++++++++++++++-- gcc/ctfc.h | 6 ++++- gcc/ctfout.cc | 24 +++++++++++++------ gcc/dwarf2ctf.cc | 18 ++++++++++++-- 4 files changed, 98 insertions(+), 12 deletions(-) diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc index 6fe44d2e8d49..f24e7bff9487 100644 --- a/gcc/ctfc.cc +++ b/gcc/ctfc.cc @@ -179,6 +179,40 @@ ctf_dvd_lookup (const ctf_container_ref ctfc, dw_die_ref die) return NULL; } +/* Insert a dummy CTF variable into the list of variables to be ignored. */ + +static void +ctf_dvd_ignore_insert (ctf_container_ref ctfc, ctf_dvdef_ref dvd) +{ + bool existed = false; + ctf_dvdef_ref entry = dvd; + + ctf_dvdef_ref * item = ctfc->ctfc_ignore_vars->find_slot (entry, INSERT); + if (*item == NULL) + *item = dvd; + else + existed = true; + /* Duplicate variable records not expected to be inserted. */ + gcc_assert (!existed); +} + +/* Lookup the dummy CTF variable given the DWARF die for the non-defining + decl to be ignored. */ + +bool +ctf_dvd_ignore_lookup (const ctf_container_ref ctfc, dw_die_ref die) +{ + ctf_dvdef_t entry; + entry.dvd_key = die; + + ctf_dvdef_ref * slot = ctfc->ctfc_ignore_vars->find_slot (&entry, NO_INSERT); + + if (slot) + return true; + + return false; +} + /* Append member definition to the list. Member list is a singly-linked list with list start pointing to the head. */ @@ -666,9 +700,10 @@ ctf_add_member_offset (ctf_container_ref ctfc, dw_die_ref sou, int ctf_add_variable (ctf_container_ref ctfc, const char * name, ctf_id_t ref, - dw_die_ref die, unsigned int external_vis) + dw_die_ref die, unsigned int external_vis, + dw_die_ref die_var_decl) { - ctf_dvdef_ref dvd; + ctf_dvdef_ref dvd, dvd_ignore; gcc_assert (name); @@ -680,6 +715,24 @@ ctf_add_variable (ctf_container_ref ctfc, const char * name, ctf_id_t ref, dvd->dvd_name = ctf_add_string (ctfc, name, &(dvd->dvd_name_offset)); dvd->dvd_visibility = external_vis; dvd->dvd_type = ref; + + /* If DW_AT_specification attribute exists, keep track of it as this is + the non-defining declaration corresponding to the variable. We will + skip emitting CTF variable for such incomplete, non-defining + declarations. + There could be some non-defining declarations, however, for which a + defining declaration does not show up in the same CU. For such + cases, the compiler continues to emit CTF variable record as + usual. */ + if (die_var_decl) + { + dvd_ignore = ggc_cleared_alloc (); + dvd_ignore->dvd_key = die_var_decl; + /* It's alright to leave other fields as zero. No valid CTF + variable will be added for these DW_TAG_variable DIEs. */ + ctf_dvd_ignore_insert (ctfc, dvd_ignore); + } + ctf_dvd_insert (ctfc, dvd); if (strcmp (name, "")) @@ -900,6 +953,8 @@ new_ctf_container (void) = hash_table::create_ggc (100); tu_ctfc->ctfc_vars = hash_table::create_ggc (100); + tu_ctfc->ctfc_ignore_vars + = hash_table::create_ggc (10); return tu_ctfc; } @@ -952,6 +1007,9 @@ ctfc_delete_container (ctf_container_ref ctfc) ctfc->ctfc_vars->empty (); ctfc->ctfc_types = NULL; + ctfc->ctfc_ignore_vars->empty (); + ctfc->ctfc_ignore_vars = NULL; + ctfc_delete_strtab (&ctfc->ctfc_strtable); ctfc_delete_strtab (&ctfc->ctfc_aux_strtable); if (ctfc->ctfc_vars_list) diff --git a/gcc/ctfc.h b/gcc/ctfc.h index 4ce756c728a7..001e544ef083 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -274,6 +274,8 @@ typedef struct GTY (()) ctf_container hash_table * GTY (()) ctfc_types; /* CTF variables. */ hash_table * GTY (()) ctfc_vars; + /* CTF variables to be ignored. */ + hash_table * GTY (()) ctfc_ignore_vars; /* CTF string table. */ ctf_strtable_t ctfc_strtable; @@ -394,6 +396,8 @@ extern ctf_dtdef_ref ctf_dtd_lookup (const ctf_container_ref ctfc, dw_die_ref die); extern ctf_dvdef_ref ctf_dvd_lookup (const ctf_container_ref ctfc, dw_die_ref die); +extern bool ctf_dvd_ignore_lookup (const ctf_container_ref ctfc, + dw_die_ref die); extern const char * ctf_add_string (ctf_container_ref, const char *, uint32_t *, int); @@ -430,7 +434,7 @@ extern int ctf_add_member_offset (ctf_container_ref, dw_die_ref, const char *, extern int ctf_add_function_arg (ctf_container_ref, dw_die_ref, const char *, ctf_id_t); extern int ctf_add_variable (ctf_container_ref, const char *, ctf_id_t, - dw_die_ref, unsigned int); + dw_die_ref, unsigned int, dw_die_ref); extern ctf_id_t ctf_lookup_tree_type (ctf_container_ref, const tree); extern ctf_id_t get_btf_id (ctf_id_t); diff --git a/gcc/ctfout.cc b/gcc/ctfout.cc index 28a873b2027d..3cf89b94f993 100644 --- a/gcc/ctfout.cc +++ b/gcc/ctfout.cc @@ -212,6 +212,13 @@ ctf_dvd_preprocess_cb (ctf_dvdef_ref * slot, void * arg) ctf_dvdef_ref var = (ctf_dvdef_ref) *slot; ctf_container_ref arg_ctfc = dvd_arg->dvd_arg_ctfc; + /* If the CTF variable corresponds to an extern variable declaration with + a defining declaration later on, skip it. Only CTF variable + corresponding to the defining declaration for the extern variable is + desirable. */ + if (ctf_dvd_ignore_lookup (arg_ctfc, var->dvd_key)) + return 1; + ctf_preprocess_var (arg_ctfc, var); /* Keep track of global objts. */ @@ -276,16 +283,16 @@ static void ctf_preprocess (ctf_container_ref ctfc) { size_t num_ctf_types = ctfc->ctfc_types->elements (); + size_t num_ctf_vars = ctfc_get_num_ctf_vars (ctfc); /* Initialize an array to keep track of the CTF variables at global - scope. */ - size_t num_global_objts = ctfc->ctfc_num_global_objts; + scope. At this time, size it conservatively. */ + size_t num_global_objts = num_ctf_vars; if (num_global_objts) { ctfc->ctfc_gobjts_list = ggc_vec_alloc(num_global_objts); } - size_t num_ctf_vars = ctfc_get_num_ctf_vars (ctfc); if (num_ctf_vars) { ctf_dvd_preprocess_arg_t dvd_arg; @@ -299,8 +306,11 @@ ctf_preprocess (ctf_container_ref ctfc) list for sorting. */ ctfc->ctfc_vars->traverse (&dvd_arg); /* Sort the list. */ - qsort (ctfc->ctfc_vars_list, num_ctf_vars, sizeof (ctf_dvdef_ref), - ctf_varent_compare); + qsort (ctfc->ctfc_vars_list, ctfc->ctfc_vars_list_count, + sizeof (ctf_dvdef_ref), ctf_varent_compare); + /* Update the actual number of the generated CTF variables at global + scope. */ + ctfc->ctfc_num_global_objts = dvd_arg.dvd_global_obj_idx; } /* Initialize an array to keep track of the CTF functions types for global @@ -476,7 +486,7 @@ output_ctf_header (ctf_container_ref ctfc) /* Vars appear after function index. */ varoff = funcidxoff + ctfc->ctfc_num_global_funcs * sizeof (uint32_t); /* CTF types appear after vars. */ - typeoff = varoff + ctfc_get_num_ctf_vars (ctfc) * sizeof (ctf_varent_t); + typeoff = varoff + (ctfc->ctfc_vars_list_count) * sizeof (ctf_varent_t); /* The total number of bytes for CTF types is the sum of the number of times struct ctf_type_t, struct ctf_stype_t are written, plus the amount of variable length data after each one of these. */ @@ -595,7 +605,7 @@ static void output_ctf_vars (ctf_container_ref ctfc) { size_t i; - size_t num_ctf_vars = ctfc_get_num_ctf_vars (ctfc); + unsigned int num_ctf_vars = ctfc->ctfc_vars_list_count; if (num_ctf_vars) { /* Iterate over the list of sorted vars and output the asm. */ diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index 747b2f661072..a6329ab6ee48 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -808,12 +808,26 @@ gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die) if (ctf_dvd_lookup (ctfc, die)) return; + /* Do not generate CTF variable records for non-defining incomplete + declarations. Such declarations can be known via the DWARF + DW_AT_specification attribute. */ + if (ctf_dvd_ignore_lookup (ctfc, die)) + return; + + /* The value of the DW_AT_specification attribute, if present, is a + reference to the debugging information entry representing the + non-defining declaration. */ + dw_die_ref decl = get_AT_ref (die, DW_AT_specification); + /* Add the type of the variable. */ var_type_id = gen_ctf_type (ctfc, var_type); /* Generate the new CTF variable and update global counter. */ - (void) ctf_add_variable (ctfc, var_name, var_type_id, die, external_vis); - ctfc->ctfc_num_global_objts += 1; + (void) ctf_add_variable (ctfc, var_name, var_type_id, die, external_vis, + decl); + /* Skip updating the number of global objects at this time. This is updated + later after pre-processing as some CTF variable records although + generated now, will not be emitted later. [PR105089]. */ } /* Add a CTF function record for the given input DWARF DIE. */