From patchwork Tue Jul 30 15:36:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Alcock X-Patchwork-Id: 94796 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 D2940385DDDE for ; Tue, 30 Jul 2024 15:41:47 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 9D023385840F for ; Tue, 30 Jul 2024 15:37:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D023385840F Authentication-Results: sourceware.org; dmarc=pass (p=reject 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 9D023385840F Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1722353861; cv=pass; b=HEax3793Z0cHNLr0ADIqeevCKoc98i5iyNbVp8E4794NxQHxnesfC1GWtNSfwIQMSTVy1WsXd3+mWdVYZs27Akv18xn9puJiQESCEmWlpAdaeNf7R/A1u2xoIueWZFEoHsyKp4JA2nVrrjHFEHkvWOEhWvJVlnX4dorKCRwYZkA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1722353861; c=relaxed/simple; bh=EOasx6JgMEJekzBUuuXMWhXL53+S2D9EhPDZUJKqs0E=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=FPtZlY0LoVkYiolYe3mjGL4rhSSALRvIHkiMkJQyr8dqrZ7z13VTfF+qw/9g9gwW4IlNYXQyhXhEbDoH91RADKipLYZbaGov0qwffnHrwUrRLjanHXXOjbyFwTookF+mkbk1U3/HzjxHYGEDc9XKNNvmnY6LlmjzjnI0IQ9vHN4= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46UFMXrD006674 for ; Tue, 30 Jul 2024 15:37:37 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=9daVSGhLoIutCKRFjmVP2Goydw3WL0tp0SONh8Cys0o=; b= hH4im5YzZY8sRL3pHDn+dKb29N9xwwuy69e1R9QiI098YXoEM8mMFS+7X6g+208d 9TpHv0QkknHsxK3qsXKDb5RNNgacDPUTWw9G1vC4eyUYS9NTHNTe6l3WKVqgxHVl oJwR8KZ7xvSJjgKhWDTSdwQ85gMnisCfrzRBxCNwK94jE6X9JEdvRuchigAgOuQm RpRnHvKZk5Y8SnPNIocj8C6PN4gXAenJj9g164tpQIdF9G3Ql52xkAIrk1Rdb449 m+D0EoiQepa47PhNa9NdSj8hAnlD4oOj9WDYhnVK9aF9h8Nga1666GlI8yduq/PQ NjrIdZEE1GbzoRhZN/iEYQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40mrs8n9yt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 30 Jul 2024 15:37:37 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46UEtOUS030693 for ; Tue, 30 Jul 2024 15:37:35 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2048.outbound.protection.outlook.com [104.47.70.48]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 40neht6s34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 30 Jul 2024 15:37:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qPfTC+HiRjwEiIVpHogyJSI2N3UaDzRKyoiD+PVCFd36SZhiWTNCpEfgJ2f2dD9eashBBnLQ8IZ/v4/nI7/rG9lrsH+ShPnVyhyEwyxEPnDHP5gcf+ZHMAmIsf736POjxeHd4iJy1eJ+XFwnLGACIU0h5R2Ff11AxOqqgIvEWe/xM7MerOWq+2f7IY+rtYZAdVwueWJoAXPxDGvpp7ZGy6EmTQZApKloyaezdJIls40b1lHLHmvZwfL2nKtRR/3sz8QYE53FJvQ4EeWUTS7CrgtCaGqf9rfrIhEYkUZXGDxLDFTjO3FsOlF1xTbUxLghbmbO64BPAcI2w08WARO6jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=9daVSGhLoIutCKRFjmVP2Goydw3WL0tp0SONh8Cys0o=; b=PFFfhxmeQ0mS/GqVx/iX94m2srKeXP3Xa4EmqD2cSrf83nDVBGMp0rO5IX6DecI9DaIKtdF8t6N5LEUjiXDQkNsekpCf4v2RmGr0UrB3rZOhpoobUWvFOz/AxRL91NfIBWk12SXzmXPqWCyfzqdnt0FrljWSd6QlCf6BG8Ve7DgJcv5soGPSmTCZuizGOVirOU0WoIGo66+M0yamVrlwDLmY35KRiX0nYG2BTbJB8NYHfDCckXgFVAjH/auJqUxXTK4y3XfivHxoNwE/dTgaBbASo5RuZCenbsEyj0smDNFVk6do+1yRxhfw2bT7jPPSUpfS5JpGmQgVrlrodiQN0A== 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=9daVSGhLoIutCKRFjmVP2Goydw3WL0tp0SONh8Cys0o=; b=qj0/dKwE/4CaaRXsa93Yn0lxxpNWBBZRwSEpfQmh8JOXg0Mz6Idf9TPBYyVCkoxmd/b16CwQP+g6XNe/s+MGBhihjRlgJpIeD8JGfTCRTI7x6y5gHZAPe2ysiEVty7g60acOLRznNhteZovclifGx1qahFHZKq8V7ppPyp7OvGg= Received: from MW4PR10MB6608.namprd10.prod.outlook.com (2603:10b6:303:22e::8) by DM4PR10MB7476.namprd10.prod.outlook.com (2603:10b6:8:17d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Tue, 30 Jul 2024 15:37:33 +0000 Received: from MW4PR10MB6608.namprd10.prod.outlook.com ([fe80::b53a:ccc1:c190:c5df]) by MW4PR10MB6608.namprd10.prod.outlook.com ([fe80::b53a:ccc1:c190:c5df%6]) with mapi id 15.20.7807.026; Tue, 30 Jul 2024 15:37:33 +0000 From: Nick Alcock To: binutils@sourceware.org Subject: [PATCH 05/19] libctf: fix linking of non-root-visible types Date: Tue, 30 Jul 2024 16:36:53 +0100 Message-ID: <20240730153707.168357-6-nick.alcock@oracle.com> X-Mailer: git-send-email 2.45.2.276.g4ac82df17e In-Reply-To: <20240730153707.168357-1-nick.alcock@oracle.com> References: <20240730153707.168357-1-nick.alcock@oracle.com> X-ClientProxiedBy: LO4P123CA0320.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:197::19) To MW4PR10MB6608.namprd10.prod.outlook.com (2603:10b6:303:22e::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR10MB6608:EE_|DM4PR10MB7476:EE_ X-MS-Office365-Filtering-Correlation-Id: b69acd3a-a577-4f17-b94a-08dcb0ad8795 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: WwgB4ctwSGNqs1TDt6xMlHdMfD6vNN2DTtMU3vsOURmFNFzBZZRH6Dz+wOU9AA3NqQetMf7THUQLeGvpExkD5Ysyh/jPoU8L2Z6f8/DqIGuD47q1xLCz/UbHE2mtIeOZyHGq93X5KHJ+F7hSBlNCCc27ZHYFMdQbhwhTV3VZ2CqFqTvTWFKYa1yrQjjESxAt32U0VWLi6DFf3czeCa6a4oTRvNCSaPJEoIjOzln1fgOr07gAqAvEYHmuZ59XqBxpmcSAL/3DLHA2kscxLUq5uIYb9aqdZ3+q8XntWW8NHe4+YkAZMOODpq0kzLi65Hos4g3nwW765E5zbmL0nfrfIJHIG6d2OHdWWUslT2vgbvmOB9llZTPSKBmnAtOuYEqApa072SRYm+Eevm6vEG5h27MFjdXxZidbtGJaYCrBI/doxCIqsqP7CyQY5bOYT+5vN288COEUYAM1xy5rfrsA410sW9unXLnw9SqrTKigVowrX5cLz9D/4PtodEYRzT2+/hXMZqsbLt1coOckuXwzF9dn3c5aJ5Gz3OdLg0wAK8yVP5spXuUhmn9BrqgXjslpzvCa8udbweSBYugL4JPDcVFybw+IrtBSNdBRQHxxBRQpm4AyNFlqfiS42zSPO1OkVPhhuV3YMT3AG0EhkArzc3EAv72EaHy3ObXfElmacpfx1a0ESS4e6AGbFDAwU94WNSVjLAravLmcmqgsUZVkMusjqaw/Zek4/+f7GuMqFP+x9OJTCVvBqThOgEyqC9djHN2k+sAELNtPdv8QYw2sjwHSwetnxW6WmeOHysxvqEqqR4nCfdihMS2y1pVrj16H365emTkDjf5HGzR+UCTZe6owHsK98CFFiqQ/hOzU8txxO7vdHhmXHzEJ81dPb6ipdTvT8NiJb5nSUaJ6MCgaOwg7jNZ4R4H62z3y81MXZGDtuqeroNTDO3tuJstoedpZNypD7+VTjYZCRIY/O5fxJvFYpcEtZ0IZv1WjwtXr9H0VOi7bxJ7Up2FMB6YvaDBL/5w18U2SNgduoKb8hfOMrUWmGKGKhVJ8ILzjZPLxkBucmEW/1mVSjlWZfKhOqbWfmTN2z2ZiA1ON52N6UJBzIRDoOSupdt2sx4U/ZKF/oXDPz8cpzyjs3BVV1kgkoDtWVzu+u9W8vtRyrR/qMfLYxZ1KSFC+qO3MtJqckAyZAQEg/SCXZ16MIdPzwcmWomKYF2/GJm5cORRh35C+2cCi2FOSFPSjtSi67rT4L4Q9bERdDMm9OFGOA7idt+Xx2jg/M9fH25kx6SDMEvbOcb51roIPcPKJT7lypJ3nF/3rshA= 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:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z6V1Lgom9QT5ihvqOruCEXQ8POw8cYDyUYD80jd4Ua5+tDPpj1aQrkfWFIvYEr8SyiXeGyEj2bGXrOnf4ptS5iIgoWvOQBakxCrYxNwQXRKK2qJ67xzldsBU04hwTSkHofiH+AXpbSW68yg1sSp2q6L9foe+3y3oGcHtUr5Bc64kmxSxu0IVDnHrMq8WzGaPxCY1hcrTWqUthvSgHrE2kKiBfbUnimXospsdZrNZmgYGvVgJzwA6Ayepa2nv3YD7vxmwa4EFQXtAplHNmWX8do8JP57OTP+LO3X18aTPEkGlJS8gkhJxvSNO2ZgmGMCN3pUSp8GluASvsc05M9jhtq9nKHE8sACZYv7H/RciQRnlnyPCJ2nNqn9ambOtKSJYS+6J0dbAlR0yp4zGT/ckBgfY71x945qgH5u6s+5k5A0Bv7nnBQIZ2X9Bz8jcxN1hIx5HXPb+QbPhXXiXu/PDP7Zvg04EIzmLxQHrbD5emIREx8bgsN6QXzLJpmkopMI39YflTfO8dpQXyXjCF20IZT7nV4npiGL7G6/TKbKC5HwMcF0B+C46zd7V93HS/j8fVZFEpGVrTMLvpGNBpgrjS0usABalXKdCErfUfKd0rJMmGiRYE+VE7+jcE3SeDFHePbR0ccZ5i1UUxNjdqVrnR2JBaRDKFnIlhvkG2XK73ZKbILpRveNsZSV6sQP1SbKg+O1A8AnOynrr7u3D4oF24LJ/z2Fkm/jkbFcOgz/DqD+HpwvMTTm5mcoWLVV3e9K9zUQ+IE+vhRUuA0bdOunuPvhQd+ChHZOpy/lmGIZYJDAWtobW03TFwb6/VYhWlzzfbXMrreq6fT4roKaGf9gU/n8cTZVZ2iSRakS6sOvvoD85IVBecNonp8Qw3Gu1PfYGyEwALf5zfXJkTEgjNfF1avlOS6yt9i5lTvpEhdb042RKzQTbXZSTDEbEolrMHWrymK5JzmQqaGdVRLdaT4tSHieSzjXBgOMpqGfI2E/pGsChsqgGicELFSESLmBBCPhw6bo3rUVt7l9oVMnxlB1NMkrbwzFdVm3X/57Sppppa252/ry4KjNoSmIKjGMdwSfHk8mrvzn9+ZfOEjoR1k+ycP/6Nf4bxc6JECez/BWs8U8x4zqyXgvLZhHolsActMmreNisjV+Pp/8Y+Rpt0ah5XBhsXtimZfA7epyCtrPAtrQN6iExoVAujqH9KQAySaf8efCXP03KENwsLpczCmwZIaMxGYgGJWj4VoU9M4dKFHuOWtOnGn8IwCAzsUaPw0W1XjY9aye7K/U1HiJIOY9CDsebtaMo9lVCmQh1GygDtULCnCObyNRwIgWbBXxweykeWSlFylz2/pGktG1mL98ywjLIzaH7f8iOe1RFez3vVkgbmIHyDrbCpq+zswwKe1BNxBFEXS+4FHtu+cL5KzLfMenith2Y60vLeuC/2c3/Vq2NsY/q5kkhgwyFF2VNaNGuLEaKlZA/YcgbCTu7vDqxGxmqUO5PORniDibYnhA5SvcBwEMi2q3e5a1mFPghGN3HTmAfjVgELJcNt4pIo5UwL4DIK19JpEzWyaaskHx17TVezQW+vHX1uP868zZWW12EHRM3XMnNP2f387ocKAL1FA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: PJi+Ju0yrbYmzj7fQOr1ZCLsKlD2uObQdZkdaDiqziMMlSvlEEhE24GLgxxk83MtBuW/fyXqnbnfTpJ0+s+qm3y15Gewrv79nM9/AIcHnx5JuUZSOrSrZDPdD2zECVYmignxbkcsG/dyr3iTXQ8lAXMzcwyptai+/gq8iBZfDBtiFOxes3++HbtK6jG+E++FwmDW9WaINe2pO8J85BZwzJlfbuS4Nyau7BTeqLzs8cLrZWsmw+bk5qICCQ2REDZY422hDg+M2ZEkQzilIIdkkttjJEHJ1SmxVYuWHLoFQ6PCWbbmTUXpPa1GWMNZrucfL7wD59B5H8nkrRVZtxm02d6NnhzCXL83Sn8I2WvBYu+YJF1XSu+CiX6BRCKs8at/m9ncyc0ZEt8+V6Hpxq5vqImukxO+W3bwdm76XkSeXBWSG3xh8DThKesbmVmWYExeQ86kO5A+6kiSinEc+m+3KrpZGW1ipx+bEDUAHrizfddNW60AU0LZvf6ADvUIA7fTGkY8P1N/TK6S1EaQgE1Y7e6DwC/tK8cPfRUhVvlakbzoQie8udq2LfGQRISvv9mXG6pVm93IfjvQf2S4BRFWbT0wFSx47GmrA8+Bfe7BTAI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b69acd3a-a577-4f17-b94a-08dcb0ad8795 X-MS-Exchange-CrossTenant-AuthSource: MW4PR10MB6608.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2024 15:37:33.2400 (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: 120SOIyjeDRfqqkaTbuSbtmH5kQO5bQ/tOCZyfRsgtJJIz9U1qQuExJyH0OCMhXytyiXMv48b+GTOjQHe6rA1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB7476 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-30_13,2024-07-30_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 mlxlogscore=879 suspectscore=0 bulkscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2407300106 X-Proofpoint-GUID: 6ySgKiARu8FMtCUs3qTQAKU4zK3pkl6Z X-Proofpoint-ORIG-GUID: 6ySgKiARu8FMtCUs3qTQAKU4zK3pkl6Z X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, 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 If you deduplicate non-root-visible types, the resulting type should still be non-root-visible! We were promoting all such types to root-visible, and re-demoting them only if their names collided (which might happen on cu-mapped links if multiple compilation units with conflicting types are fused into one child dict). This "worked" before now, in that linking at least didn't fail (if you don't mind having your non-root flag value destroyed if you're adding non-root-visible types), but now that conflicting enumerators cause their containing enums to become conflicted (enums which might have *different names*), this caused the linker to crash when it hit two enumerators with conflicting values. Not testable in ld because cu-mapped links are not exposed to ld, but can be tested via direct creation of libraries and calls to ctf_link directly. (This also tests the ctf_dump non-root type printout, which before now was untested.) libctf/ * ctf-dedup.c (ctf_dedup_emit_type): Non-root-visible input types should be emitted as non-root-visible output types. * testsuite/libctf-writable/ctf-nonroot-linking.c: New test. * testsuite/libctf-writable/ctf-nonroot-linking.lk: New test. --- libctf/ctf-dedup.c | 6 +- .../libctf-writable/ctf-nonroot-linking.c | 127 ++++++++++++++++++ .../libctf-writable/ctf-nonroot-linking.lk | 1 + 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 libctf/testsuite/libctf-writable/ctf-nonroot-linking.c create mode 100644 libctf/testsuite/libctf-writable/ctf-nonroot-linking.lk diff --git a/libctf/ctf-dedup.c b/libctf/ctf-dedup.c index 6c58daae324..8bfd839524e 100644 --- a/libctf/ctf-dedup.c +++ b/libctf/ctf-dedup.c @@ -2640,7 +2640,7 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs, int input_num = CTF_DEDUP_GID_TO_INPUT (id); int output_num = (uint32_t) -1; /* 'shared' */ int cu_mapped = *(int *)arg; - int isroot = 1; + int isroot; int is_conflicting; ctf_next_t *i = NULL; @@ -2708,9 +2708,11 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs, } name = ctf_strraw (real_input, tp->ctt_name); + isroot = LCTF_INFO_ISROOT (real_input, tp->ctt_info); /* Hide conflicting types, if we were asked to: also hide if a type with this - name already exists and is not a forward. */ + name already exists and is not a forward, or if this type is hidden on the + input. */ if (cu_mapped && is_conflicting) isroot = 0; else if (name diff --git a/libctf/testsuite/libctf-writable/ctf-nonroot-linking.c b/libctf/testsuite/libctf-writable/ctf-nonroot-linking.c new file mode 100644 index 00000000000..6edd189b360 --- /dev/null +++ b/libctf/testsuite/libctf-writable/ctf-nonroot-linking.c @@ -0,0 +1,127 @@ +/* Make sure linking a non-root-visible type emits a non-root-visible + type, rather than silently promoting it to root-visible. Do it by dumping, + thus also testing the {non-root sigils} you get when dumping + non-root-visible types. */ + +#include +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + ctf_dict_t *in1; + ctf_dict_t *fp; + ctf_dict_t *dump_fp; + ctf_archive_t *arc1; + ctf_archive_t *final_arc; + ctf_sect_t s; + ctf_encoding_t encoding = { CTF_INT_SIGNED, 0, sizeof (char) }; + unsigned char *buf1, *buf2; + size_t buf1_sz, buf2_sz; + ctf_dump_state_t *dump_state = NULL; + ctf_next_t *i = NULL; + int err; + + /* Linking does not currently work on mingw because of an unreliable tmpfile + implementation on that platform (see + https://github.com/msys2/MINGW-packages/issues/18878). Simply skip for + now. */ + +#ifdef __MINGW32__ + printf ("UNSUPPORTED: platform bug breaks ctf_link\n"); + return 0; +#else + + if ((fp = ctf_create (&err)) == NULL) + goto create_err; + + if ((in1 = ctf_create (&err)) == NULL) + goto create_err; + + /* A non-root addition. */ + + if ((ctf_add_integer (in1, CTF_ADD_NONROOT, "foo", &encoding)) == CTF_ERR) + { + fprintf (stderr, "Cannot add: %s\n", ctf_errmsg (ctf_errno (in1))); + return 1; + } + + /* Write it out and read it back in, to turn it into an archive. + This would be unnecessary if ctf_link_add() were public :( */ + if ((buf1 = ctf_write_mem (in1, &buf1_sz, -1)) == NULL) + { + fprintf (stderr, "Cannot serialize: %s\n", ctf_errmsg (ctf_errno (in1))); + return 1; + } + + s.cts_name = "foo"; + s.cts_data = (void *) buf1; + s.cts_size = buf1_sz; + s.cts_entsize = 64; /* Unimportant. */ + + if ((arc1 = ctf_arc_bufopen (&s, NULL, NULL, &err)) == NULL) + goto open_err; + + ctf_dict_close (in1); + + /* Link! Even a one-file link does deduplication. */ + + if (ctf_link_add_ctf (fp, arc1, "a") < 0) + goto link_err; + + if (ctf_link (fp, 0) < 0) + goto link_err; + + /* Write it out. We need a new buf here, because the archive is still + using the other buf. */ + + if ((buf2 = ctf_link_write (fp, &buf2_sz, 4096)) == NULL) + goto link_err; + + /* Read it back in. */ + + s.cts_data = (void *) buf2; + s.cts_size = buf2_sz; + + if ((final_arc = ctf_arc_bufopen (&s, NULL, NULL, &err)) == NULL) + goto open_err; + + /* Dump the types, and search for the {sigils of non-rootedness}. */ + while ((dump_fp = ctf_archive_next (final_arc, &i, NULL, 0, &err)) != NULL) + { + char *dumpstr; + + while ((dumpstr = ctf_dump (dump_fp, &dump_state, CTF_SECT_TYPE, + NULL, NULL)) != NULL) + { + if (strchr (dumpstr, '{') != NULL && strchr (dumpstr, '}') != NULL) + printf ("Non-root type found.\n"); + free (dumpstr); + } + ctf_dict_close (dump_fp); + } + if (err != ECTF_NEXT_END) + { + fprintf (stderr, "Archive iteration error: %s\n", ctf_errmsg (err)); + return 1; + } + + ctf_arc_close (final_arc); + free (buf1); + free (buf2); + ctf_dict_close (fp); + return 0; + + create_err: + fprintf (stderr, "Cannot create: %s\n", ctf_errmsg (err)); + return 1; + open_err: + fprintf (stderr, "Cannot open: %s\n", ctf_errmsg (err)); + return 1; + link_err: + fprintf (stderr, "Cannot link: %s\n", ctf_errmsg (ctf_errno (fp))); + return 1; +#endif +} diff --git a/libctf/testsuite/libctf-writable/ctf-nonroot-linking.lk b/libctf/testsuite/libctf-writable/ctf-nonroot-linking.lk new file mode 100644 index 00000000000..e3edda05c5c --- /dev/null +++ b/libctf/testsuite/libctf-writable/ctf-nonroot-linking.lk @@ -0,0 +1 @@ +Non-root type found.