From patchwork Wed Apr 17 20:20:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Alcock X-Patchwork-Id: 88609 Return-Path: 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 358183846062 for ; Wed, 17 Apr 2024 20:25:41 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 0547A385842D for ; Wed, 17 Apr 2024 20:21:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0547A385842D 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 0547A385842D 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=1713385284; cv=pass; b=f8GuqWmORRAO8JtyhG8K5fSwpr2KnNtfSWXk86od8vc2LDaEr77sh7yo0W6qm7UaYL6D5fr0zYSwPXgHevjErcNgay1p3xsvhCOUZIRXUUhpA52yBTSJ1/eS3a1bjIdFlnacf2utzyidf3pXmlm/B4h8PVsCEAHXdPTg5CcFN10= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713385284; c=relaxed/simple; bh=iqXO6EBSZm8sYL7yOlZoS+cpaFRR7ydPhalccMIE5oI=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=TZz9LAeC5MOmmv39meEofPQin6wrFgBYaRvKMJV1KwGX1OyrUECxV4m1o9ZLZIIr9hX/DlpgMpHXit18mjrPRhp6Zhn0V+FnPhyHhukQfXF+TE0MBGN7tc9MBiyZPaGTldvKZaRsmVC7EFwO2JNs+YdrCG9aJaaXu4YFaZKO0og= 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 43HHhq7I007997 for ; Wed, 17 Apr 2024 20:21:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=6jeGfQR/TOwn+w7v65zFaG74gamWI/nWVDmCQYpkKJ4=; b=Dj2EZm9w7Q9YjColy46s5ciY5RZvt1CkNjZ2WK6Eud5u1v3D4ayc+xgm2X6PkbiXa2V4 yDXpFV+LnRRcm9z/dsfO/JpCP/oUS2KlLcQx0yPDqO9oRlMQjQjWhf4mNIR4UeV8WMu7 m3C9WKMLZz7tPpEqFSMqUsbQlqQBVjLeT7MS9mJGTmZfQo+PCMfooAgK/EgUuU6EBanK 5OS2uNo+naP9sdrrPINkng2Q9NKokw8MKtTtYyul7mQwu1K50JrNJ35LkC5ztlh1+NMv ka8WHVTd+unqZ00j858M79Ar2Y5lpDaii8VzHzqHpsdG1j6/X0GmvltNdN9v8mSYWV1z qw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfgujs013-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 17 Apr 2024 20:21:20 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43HIi7HY004428 for ; Wed, 17 Apr 2024 20:21:19 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2169.outbound.protection.outlook.com [104.47.73.169]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xfggfnqqm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 17 Apr 2024 20:21:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oFGQoNapA5Fx3O+Tr2eENVk96wWAUg8n/lDdZIzajMVC3jTI31lTvIjp90ujplCZZdQzA47bXsbmgdSDk/tX3Lox2gApgzvoSIb1Cqv0QvwgjEcoYp9zHGgaK7/1q8pr/rC/q4XcfBacuU7UKB0aH0zNYwVsDKOsWmbADC4WZv56HCOMtOwR32By4JV/Wl6yPYS7N/X+xswNsdNfQY+Xpye9OpxGqHYSstDTVysFrpTgXM+lip41NfRxZQYgdOdDhhbzlmpAR1+dCdN4Vmc9zXjvpqV7H1HslaIhB2CDMmE+Q+z+GQdF/VDNRTrVNQS5o1T8LlF/DISXNoSyNQJDdw== 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=6jeGfQR/TOwn+w7v65zFaG74gamWI/nWVDmCQYpkKJ4=; b=OjDHbJYNo5sWAnt/8aQm+Zqv6S208AxlBvA0IYc/ySOlcK3ete9lRBhA0/j7BfIVmIXJ/Lj6594T+tUEhROSueVUEI1ydSWVw5oZOQSmfJ3MnyPCyYYFRd4HBHge4QhLf7snc2PyTXivO62sRpncrusT1db+E1XfOUE7yrdB9fWks8PSioVQ/DdLnDRs7HrJubnpinZ7RZ2VJzzX9aTL5P6wx71Z9VeaKLGGlQaLV41HVd04sgwRYmATxG4RP2D9vReDmhB3Z/vNgDCloQwRfpH8U4JEB8Eq447go61ocaqXnRK7sojDzUw4eIvINdxZ5EfhR3MUuSu0Mq6sI+ZQ3A== 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=6jeGfQR/TOwn+w7v65zFaG74gamWI/nWVDmCQYpkKJ4=; b=TxH2/lezCqVAXIfbIV9wNIkZ6IdT8NVuDpesxKeSPdxiho1P5/uUck8KBAW0e5S2uQpXxXHocTHbvQFXergw7q0m4IUKuKNXeoOBZ/NQ3pkjOkDv9WXUwRpEuubr3OzHFnPShD6kRaXW7uCdJY88JcYXcj81l5ShqxC03R9k3BQ= Received: from MW4PR10MB6608.namprd10.prod.outlook.com (2603:10b6:303:22e::8) by LV8PR10MB7966.namprd10.prod.outlook.com (2603:10b6:408:202::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Wed, 17 Apr 2024 20:21:08 +0000 Received: from MW4PR10MB6608.namprd10.prod.outlook.com ([fe80::67a4:9544:7249:7751]) by MW4PR10MB6608.namprd10.prod.outlook.com ([fe80::67a4:9544:7249:7751%7]) with mapi id 15.20.7472.037; Wed, 17 Apr 2024 20:21:08 +0000 From: Nick Alcock To: binutils@sourceware.org Subject: [PATCH 10/22] Revert "libctf: do not corrupt strings across ctf_serialize" Date: Wed, 17 Apr 2024 21:20:06 +0100 Message-ID: <20240417202018.34966-11-nick.alcock@oracle.com> X-Mailer: git-send-email 2.44.0.273.ge0bd14271f In-Reply-To: <20240417202018.34966-1-nick.alcock@oracle.com> References: <20240417202018.34966-1-nick.alcock@oracle.com> X-ClientProxiedBy: LNXP123CA0013.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::25) To MW4PR10MB6608.namprd10.prod.outlook.com (2603:10b6:303:22e::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR10MB6608:EE_|LV8PR10MB7966:EE_ X-MS-Office365-Filtering-Correlation-Id: 30f1d1ec-d9ce-4dd4-8eee-08dc5f1beab0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2zt/Ly/HxYo9j9ZYDwoDS8uPIYf9oyATwQ/YmwHZvIFmODRBwCPo5vye/uXlOh9RoEietlwfjAV0lU3ehxJ/NnLDQtRe+RlAwmHk3tt+SAkj0oy+HDRrYJ9Rg+r9GjPFzo6XQCjLB9gleP6MqWBT+v6dB5ZCh+UwIpG1qFKfUM+c/WRE/VrHBBsYrXYLOMc5TULcInd6AzLNW/7AgAW+YBdYB2wAKBcZvlcGzYlj4/iIr/xJEuUUpvkSJm+sqcgA7Kkfo+N87zP0MSpmp2tCopukl3/6NZ6btSG2afogbCSr8OthuXESHj2VLLh76jAOrFUy//QuB/lExEtqv1NSOiPf1HlM6bpsyKqUkon4BmoFPZ2s9f5j9jW9AXmE65tZvoUK1q0HUOr+8uV73TDnAQpA5ecrtp2T9N+Js5mcu3tbqDbxkht6t9do9qjy+i8hVkLiWGxiZ+7ji34AJBVqVc8nOykTs+WCAICSD1IuxO85e6MyiDvuFpWmvw1jMcvdJBOnnIH4UiVVRquSVkp/3FQBDBFU49A+qo2n4MBeFwcfogx/JHZe7bWhRyhxyvfZdm+/O1D7CfAaMe8h61qhhejQBTKb3iiFC1KWIM6cXKLYilk5UdskMpBk0YVp4MtasNzXqeXc9EgzTKREeakTgIdRwfZlyO/18QfqOGCyygY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW4PR10MB6608.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: WCQQiLkJL+hVV87yQKBnNKvwdnD1SWP9XVH7X4my9SC6O8RgLwpFOkPZEPo3JMO7VNSFG+R8PMEb+kTXAJ56o86yZSNEMvv1Fx9plqiQfYz6XvLEwsKhRjDAq2R31o9sKxOJknS/5gK9lNWPFb+1w4lP69nn+sbmCsZi7A0WFovDiWp/kHqR9krlEFZ0p+uVtuYkl8uP+lt25o/MXfRZ+lHCDkwKxlVs8RJnAr6Z+HUUfmen2jMF3fq37sGM0Iv/+e/5oqmrqfUgZQQcIXh3fYim1Ry3zUDKFbVpBbplvErxXPjqjBOlOy0R7lPkXnMHoMKL/y0mCoR8OSKUV+/Ch65+yy6M2ZcFN+aGAhcF+HHFWQh1sl7mPodX3w5MvXxOZ3DvvQSuzy66QEWrVaexMLO9YJ1pZUjcDD59BuDvZGyHPoFxGDLyXx6PxJqaMMq/i48Y/YHJmmcibRFfI91zkLXztqxlmtwhX+KNhG/DzW02FUXhTTgDxjfIt7IOLo1XqCU9w54YJUKDpMxgH/Gj+l8tlKJC6jX2OitPQNbsyraatoK7YqrAmMbqtlsk9Duc9ZsZaTPgfzhRL2khzhOUyXJ9/dmM8E2sM7prh6mnUfZ1DjSeZyZTv2V7BEewYx25qJaif3xa7L/RWntOxTGfPFua54ld5K19mi9/rxD9GOUyFQEadVhow6MqABOLwkkgWJ+DTylCqgAFtN7S3D5UcTs+p0gOYTxxrMf2sMX8T0xVHy/g0lOAzItD9WkYIi/8VWc68hM/pcRgtEy90Nx7YoO20z2g4G3P5+lFegFGEIWOR/OwnAaIM185DjE4oQ8/c2jWiZDTotc3dSfsnJF32mceEcqsS7DJ+C4TaMyrNXEMoEJJAvpXtls+l72NQZBBYk85vBp18YN9ecEDzPeV6JAX4iZv/LI7E24yLT8EJ4zdrTacQDJehU7MzeqhGZRsnUOQBsjcSXZLvteEd6p54Hp+DKq8Zn82Mj3HNkHFW2fT3xZCiOhXLtq9eeOKy5LoHpF/qAOT3wceS4qAYauDe5c4bqH8jECDsXjTHvznuP5Juq0ol7rgKCqDf448fbTU6MoG9WH9x1b4tByVFUD7uWt1bbK29g+WGAnylNQY9HBShQdJkuN0l3b60tJbylbuKJed+ljyOM0DaC3VjDfx0XoS5JjV47hvjgaj42EG1aI07tLAJCaRiY9ueuqjLB+d89f8VaVJEfGKl0HeWzW34MQDLOdqn49DMA+CL/wJyM61BICcuxebaKrt+h1YErQvnE25jXUYYm/0mlM7Fa635P7guPOK4vCP3fWF67KK3L/mWY9iulfLevnirce1pdig1a6dmXMTbtz9zN1EGGi8vx8LjQmHYwTyAPQXwdP6pfPd/5kvq/LlEYUQ/itkGLve41yjC4tMJlVfyAdqKnQ6K8ynzcE+D4vSQxnkN1Zwjn5rkduh0rZFZc0fr8SHFkNQkWWXTMDJrIR8QzjhD0huIxzjTNzkrLlbjbZk2HK2vfZvb0nNzCC5SluhEFAG/LI35YKqltPYFrSETmOqjaPDrDsGi2vlQhdNAj5Cm9RRY88OVa1RvP2emrbDLMYeKYVpG94NZaJQnsQ1vO1qpKGM7g== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 0Xk2Ob49523fRTluBc447KT3zM+lhjig9Ad6/L7pRc4/RPt5YApeEtdzz/vqO7xKIdx+X8W7Qa88EWZpbKoUB0p90LC9fUXT3N/jq+iXy9Zq8dN2XVkeuiyJoc9Hd+HaxFlbHJr8IYmzQ1L6aXlmJaeqgI9uluU89aTI6hfFGSalJstKoOH4GeZPgmkGOqoOhIgBH5eOGFyi45lb3i18IqUFZksSWBGcLFEdj63KEfY5p5DRuKYOmwZgYWmByWT1U3GDHVbm8vhjfPf+jbAbnqsDfDqKJcexJX7UmIyN2EzCcrh0RZY0LOR0/aw0IeWKjPCr2PjUq01AR/1+RCQDM3LdlskFMJ+YIoFzkL+B/3OJnHFE+0CJ2t3knoEgfQ/Ac8BUha44RAJPWtj5IRrZtxTP9WsM61+t1t7cQ7PkygKHpRSbI+cSsHRz5bgZtXkow4LuMW15eVRdlflAPm7Cnly8X2YqNrZvP+c7K0JAL/s+sHvTOrPjSb2P6u6j0qE19mfFM94AGOwMeHD+CCmv4wkLtRbvfu/5w+noDejbui/2qecWzyE1VkWuCtwvRPvOnnSEiZjXbepg3rJkRzJEes86TU/3jd1Zkv+DXeZOt10= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30f1d1ec-d9ce-4dd4-8eee-08dc5f1beab0 X-MS-Exchange-CrossTenant-AuthSource: MW4PR10MB6608.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 20:21:08.8104 (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: AlYsMSYmLGqkPDSEcrapLeBNSWRbGvNszOZE6RAaKSENZvWMWNsysIJoi2PA5ij9tW/aNZ3T8hHQXPv93i9fFQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR10MB7966 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-17_17,2024-04-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 spamscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404170143 X-Proofpoint-ORIG-GUID: Fcy5pTDw-c-HZaAzA7z1qWsWhr0kt73m X-Proofpoint-GUID: Fcy5pTDw-c-HZaAzA7z1qWsWhr0kt73m X-Spam-Status: No, score=-12.3 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org This reverts commit 986e9e3aa03f854bedacef7fac38fe8f009a416c. (We do not revert the testcase -- it remains valid -- but we are taking a different, less complex and more robust approach.) This also deletes the pending refs abstraction without (yet) replacing it, so some tests will fail for a commit or two. --- libctf/ctf-create.c | 27 ++------------- libctf/ctf-hash.c | 6 ---- libctf/ctf-impl.h | 6 +--- libctf/ctf-serialize.c | 24 +------------ libctf/ctf-string.c | 76 +++++------------------------------------- 5 files changed, 14 insertions(+), 125 deletions(-) diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index 23bbf92ff1a..9d86b961132 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -464,8 +464,7 @@ ctf_add_generic (ctf_dict_t *fp, uint32_t flag, const char *name, int kind, type = ++fp->ctf_typemax; type = LCTF_INDEX_TO_TYPE (fp, type, (fp->ctf_flags & LCTF_CHILD)); - dtd->dtd_data.ctt_name = ctf_str_add_pending (fp, name, - &dtd->dtd_data.ctt_name); + dtd->dtd_data.ctt_name = ctf_str_add_ref (fp, name, &dtd->dtd_data.ctt_name); dtd->dtd_type = type; if (dtd->dtd_data.ctt_name == 0 && name != NULL && name[0] != '\0') @@ -1080,21 +1079,11 @@ ctf_add_enumerator (ctf_dict_t *fp, ctf_id_t enid, const char *name, return -1; /* errno is set for us. */ en = (ctf_enum_t *) dtd->dtd_vlen; - if (dtd->dtd_vlen != old_vlen) - { - ptrdiff_t move = (signed char *) dtd->dtd_vlen - (signed char *) old_vlen; - - /* Remove pending refs in the old vlen region and reapply them. */ - - for (i = 0; i < vlen; i++) - ctf_str_move_pending (fp, &en[i].cte_name, move); - } - for (i = 0; i < vlen; i++) if (strcmp (ctf_strptr (fp, en[i].cte_name), name) == 0) return (ctf_set_errno (ofp, ECTF_DUPLICATE)); - en[i].cte_name = ctf_str_add_pending (fp, name, &en[i].cte_name); + en[i].cte_name = ctf_str_add_ref (fp, name, &en[i].cte_name); en[i].cte_value = value; if (en[i].cte_name == 0 && name != NULL && name[0] != '\0') @@ -1154,16 +1143,6 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name, return (ctf_set_errno (ofp, ctf_errno (fp))); memb = (ctf_lmember_t *) dtd->dtd_vlen; - if (dtd->dtd_vlen != old_vlen) - { - ptrdiff_t move = (signed char *) dtd->dtd_vlen - (signed char *) old_vlen; - - /* Remove pending refs in the old vlen region and reapply them. */ - - for (i = 0; i < vlen; i++) - ctf_str_move_pending (fp, &memb[i].ctlm_name, move); - } - if (name != NULL) { for (i = 0; i < vlen; i++) @@ -1193,7 +1172,7 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name, return -1; /* errno is set for us. */ } - memb[vlen].ctlm_name = ctf_str_add_pending (fp, name, &memb[vlen].ctlm_name); + memb[vlen].ctlm_name = ctf_str_add_ref (fp, name, &memb[vlen].ctlm_name); memb[vlen].ctlm_type = type; if (memb[vlen].ctlm_name == 0 && name != NULL && name[0] != '\0') return -1; /* errno is set for us. */ diff --git a/libctf/ctf-hash.c b/libctf/ctf-hash.c index f8032ae4d86..77b8478479e 100644 --- a/libctf/ctf-hash.c +++ b/libctf/ctf-hash.c @@ -669,12 +669,6 @@ ctf_dynset_lookup (ctf_dynset_t *hp, const void *key) return NULL; } -size_t -ctf_dynset_elements (ctf_dynset_t *hp) -{ - return htab_elements ((struct htab *) hp); -} - /* TRUE/FALSE return. */ int ctf_dynset_exists (ctf_dynset_t *hp, const void *key, const void **orig_key) diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index 8ce489a55ba..c16ef185fdc 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -383,8 +383,7 @@ struct ctf_dict ctf_dynhash_t *ctf_names; /* Hash table of remaining type names. */ ctf_lookup_t ctf_lookups[5]; /* Pointers to nametabs for name lookup. */ ctf_strs_t ctf_str[2]; /* Array of string table base and bounds. */ - ctf_dynhash_t *ctf_str_atoms; /* Hash table of ctf_str_atoms_t. */ - ctf_dynset_t *ctf_str_pending_ref; /* Locations awaiting ref addition. */ + ctf_dynhash_t *ctf_str_atoms; /* Hash table of ctf_str_atoms_t. */ uint64_t ctf_str_num_refs; /* Number of refs to cts_str_atoms. */ uint32_t ctf_str_prov_offset; /* Latest provisional offset assigned so far. */ unsigned char *ctf_base; /* CTF file pointer. */ @@ -664,7 +663,6 @@ extern int ctf_dynset_insert (ctf_dynset_t *, void *); extern void ctf_dynset_remove (ctf_dynset_t *, const void *); extern void ctf_dynset_destroy (ctf_dynset_t *); extern void *ctf_dynset_lookup (ctf_dynset_t *, const void *); -extern size_t ctf_dynset_elements (ctf_dynset_t *); extern int ctf_dynset_exists (ctf_dynset_t *, const void *key, const void **orig_key); extern int ctf_dynset_next (ctf_dynset_t *, ctf_next_t **, void **key); @@ -727,8 +725,6 @@ extern int ctf_str_create_atoms (ctf_dict_t *); extern void ctf_str_free_atoms (ctf_dict_t *); extern uint32_t ctf_str_add (ctf_dict_t *, const char *); extern uint32_t ctf_str_add_ref (ctf_dict_t *, const char *, uint32_t *ref); -extern uint32_t ctf_str_add_pending (ctf_dict_t *, const char *, uint32_t *); -extern int ctf_str_move_pending (ctf_dict_t *, uint32_t *, ptrdiff_t); extern int ctf_str_add_external (ctf_dict_t *, const char *, uint32_t offset); extern void ctf_str_remove_ref (ctf_dict_t *, const char *, uint32_t *ref); extern void ctf_str_rollback (ctf_dict_t *, ctf_snapshot_id_t); diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c index 9dd7fbda285..2afc7be7c48 100644 --- a/libctf/ctf-serialize.c +++ b/libctf/ctf-serialize.c @@ -822,10 +822,7 @@ ctf_emit_type_sect (ctf_dict_t *fp, unsigned char **tptr) copied = (ctf_stype_t *) t; /* name is at the start: constant offset. */ if (copied->ctt_name && (name = ctf_strraw (fp, copied->ctt_name)) != NULL) - { - ctf_str_add_ref (fp, name, &copied->ctt_name); - ctf_str_add_ref (fp, name, &dtd->dtd_data.ctt_name); - } + ctf_str_add_ref (fp, name, &copied->ctt_name); copied->ctt_size = type_ctt_size; t += len; @@ -960,7 +957,6 @@ ctf_serialize (ctf_dict_t *fp) ctf_varent_t *dvarents; ctf_strs_writable_t strtab; int err; - int num_missed_str_refs; int sym_functions = 0; unsigned char *t; @@ -980,16 +976,6 @@ ctf_serialize (ctf_dict_t *fp) if (fp->ctf_stypes > 0) return (ctf_set_errno (fp, ECTF_RDONLY)); - /* The strtab refs table must be empty at this stage. Any refs already added - will be corrupted by any modifications, including reserialization, after - strtab finalization is complete. Only this function, and functions it - calls, may add refs, and all memory locations (including in the dtds) - containing strtab offsets must be traversed as part of serialization, and - refs added. */ - - if (!ctf_assert (fp, fp->ctf_str_num_refs == 0)) - return -1; /* errno is set for us. */ - /* Fill in an initial CTF header. We will leave the label, object, and function sections empty and only output a header, type section, and string table. The type section begins at a 4-byte aligned @@ -1103,12 +1089,6 @@ ctf_serialize (ctf_dict_t *fp) assert (t == (unsigned char *) buf + sizeof (ctf_header_t) + hdr.cth_stroff); - /* Every string added outside serialization by ctf_str_add_pending should - now have been added by ctf_add_ref. */ - num_missed_str_refs = ctf_dynset_elements (fp->ctf_str_pending_ref); - if (!ctf_assert (fp, num_missed_str_refs == 0)) - goto err; /* errno is set for us. */ - /* Construct the final string table and fill out all the string refs with the final offsets. Then purge the refs list, because we're about to move this strtab onto the end of the buf, invalidating all the offsets. */ @@ -1211,10 +1191,8 @@ ctf_serialize (ctf_dict_t *fp) ctf_str_free_atoms (nfp); nfp->ctf_str_atoms = fp->ctf_str_atoms; nfp->ctf_prov_strtab = fp->ctf_prov_strtab; - nfp->ctf_str_pending_ref = fp->ctf_str_pending_ref; fp->ctf_str_atoms = NULL; fp->ctf_prov_strtab = NULL; - fp->ctf_str_pending_ref = NULL; memset (&fp->ctf_dtdefs, 0, sizeof (ctf_list_t)); memset (&fp->ctf_errs_warnings, 0, sizeof (ctf_list_t)); fp->ctf_add_processing = NULL; diff --git a/libctf/ctf-string.c b/libctf/ctf-string.c index 63dced02e2f..af16e862f4b 100644 --- a/libctf/ctf-string.c +++ b/libctf/ctf-string.c @@ -127,7 +127,7 @@ ctf_str_create_atoms (ctf_dict_t *fp) { fp->ctf_str_atoms = ctf_dynhash_create (ctf_hash_string, ctf_hash_eq_string, free, ctf_str_free_atom); - if (!fp->ctf_str_atoms) + if (fp->ctf_str_atoms == NULL) return -ENOMEM; if (!fp->ctf_prov_strtab) @@ -137,13 +137,6 @@ ctf_str_create_atoms (ctf_dict_t *fp) if (!fp->ctf_prov_strtab) goto oom_prov_strtab; - if (!fp->ctf_str_pending_ref) - fp->ctf_str_pending_ref = ctf_dynset_create (htab_hash_pointer, - htab_eq_pointer, - NULL); - if (!fp->ctf_str_pending_ref) - goto oom_str_pending_ref; - errno = 0; ctf_str_add (fp, ""); if (errno == ENOMEM) @@ -154,9 +147,6 @@ ctf_str_create_atoms (ctf_dict_t *fp) oom_str_add: ctf_dynhash_destroy (fp->ctf_prov_strtab); fp->ctf_prov_strtab = NULL; - oom_str_pending_ref: - ctf_dynset_destroy (fp->ctf_str_pending_ref); - fp->ctf_str_pending_ref = NULL; oom_prov_strtab: ctf_dynhash_destroy (fp->ctf_str_atoms); fp->ctf_str_atoms = NULL; @@ -169,13 +159,8 @@ ctf_str_free_atoms (ctf_dict_t *fp) { ctf_dynhash_destroy (fp->ctf_prov_strtab); ctf_dynhash_destroy (fp->ctf_str_atoms); - ctf_dynset_destroy (fp->ctf_str_pending_ref); } -#define CTF_STR_ADD_REF 0x1 -#define CTF_STR_MAKE_PROVISIONAL 0x2 -#define CTF_STR_PENDING_REF 0x4 - /* Add a string to the atoms table, copying the passed-in string. Return the atom added. Return NULL only when out of memory (and do not touch the passed-in string in that case). Possibly augment the ref list with the @@ -183,7 +168,7 @@ ctf_str_free_atoms (ctf_dict_t *fp) provisional strtab. */ static ctf_str_atom_t * ctf_str_add_ref_internal (ctf_dict_t *fp, const char *str, - int flags, uint32_t *ref) + int add_ref, int make_provisional, uint32_t *ref) { char *newstr = NULL; ctf_str_atom_t *atom = NULL; @@ -191,7 +176,7 @@ ctf_str_add_ref_internal (ctf_dict_t *fp, const char *str, atom = ctf_dynhash_lookup (fp->ctf_str_atoms, str); - if (flags & CTF_STR_ADD_REF) + if (add_ref) { if ((aref = malloc (sizeof (struct ctf_str_atom_ref))) == NULL) { ctf_set_errno (fp, ENOMEM); @@ -202,9 +187,8 @@ ctf_str_add_ref_internal (ctf_dict_t *fp, const char *str, if (atom) { - if (flags & CTF_STR_ADD_REF) + if (add_ref) { - ctf_dynset_remove (fp->ctf_str_pending_ref, (void *) ref); ctf_list_append (&atom->csa_refs, aref); fp->ctf_str_num_refs++; } @@ -224,7 +208,7 @@ ctf_str_add_ref_internal (ctf_dict_t *fp, const char *str, atom->csa_str = newstr; atom->csa_snapshot_id = fp->ctf_snapshots; - if (flags & CTF_STR_MAKE_PROVISIONAL) + if (make_provisional) { atom->csa_offset = fp->ctf_str_prov_offset; @@ -235,14 +219,8 @@ ctf_str_add_ref_internal (ctf_dict_t *fp, const char *str, fp->ctf_str_prov_offset += strlen (atom->csa_str) + 1; } - if (flags & CTF_STR_PENDING_REF) + if (add_ref) { - if (ctf_dynset_insert (fp->ctf_str_pending_ref, (void *) ref) < 0) - goto oom; - } - else if (flags & CTF_STR_ADD_REF) - { - ctf_dynset_remove (fp->ctf_str_pending_ref, (void *) ref); ctf_list_append (&atom->csa_refs, aref); fp->ctf_str_num_refs++; } @@ -271,7 +249,7 @@ ctf_str_add (ctf_dict_t *fp, const char *str) if (!str) str = ""; - atom = ctf_str_add_ref_internal (fp, str, CTF_STR_MAKE_PROVISIONAL, 0); + atom = ctf_str_add_ref_internal (fp, str, FALSE, TRUE, 0); if (!atom) return 0; @@ -289,47 +267,13 @@ ctf_str_add_ref (ctf_dict_t *fp, const char *str, uint32_t *ref) if (!str) str = ""; - atom = ctf_str_add_ref_internal (fp, str, CTF_STR_ADD_REF - | CTF_STR_MAKE_PROVISIONAL, ref); + atom = ctf_str_add_ref_internal (fp, str, TRUE, TRUE, ref); if (!atom) return 0; return atom->csa_offset; } -/* Like ctf_str_add_ref(), but notes that this memory location must be added as - a ref by a later serialization phase, rather than adding it itself. */ -uint32_t -ctf_str_add_pending (ctf_dict_t *fp, const char *str, uint32_t *ref) -{ - ctf_str_atom_t *atom; - - if (!str) - str = ""; - - atom = ctf_str_add_ref_internal (fp, str, CTF_STR_PENDING_REF - | CTF_STR_MAKE_PROVISIONAL, ref); - if (!atom) - return 0; - - return atom->csa_offset; -} - -/* Note that a pending ref now located at NEW_REF has moved by BYTES bytes. */ -int -ctf_str_move_pending (ctf_dict_t *fp, uint32_t *new_ref, ptrdiff_t bytes) -{ - if (bytes == 0) - return 0; - - if (ctf_dynset_insert (fp->ctf_str_pending_ref, (void *) new_ref) < 0) - return (ctf_set_errno (fp, ENOMEM)); - - ctf_dynset_remove (fp->ctf_str_pending_ref, - (void *) ((signed char *) new_ref - bytes)); - return 0; -} - /* Add an external strtab reference at OFFSET. Returns zero if the addition failed, nonzero otherwise. */ int @@ -340,7 +284,7 @@ ctf_str_add_external (ctf_dict_t *fp, const char *str, uint32_t offset) if (!str) str = ""; - atom = ctf_str_add_ref_internal (fp, str, 0, 0); + atom = ctf_str_add_ref_internal (fp, str, FALSE, FALSE, 0); if (!atom) return 0; @@ -390,8 +334,6 @@ ctf_str_remove_ref (ctf_dict_t *fp, const char *str, uint32_t *ref) free (aref); } } - - ctf_dynset_remove (fp->ctf_str_pending_ref, (void *) ref); } /* A ctf_dynhash_iter_remove() callback that removes atoms later than a given