From patchwork Tue Jul 30 15:37:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Alcock X-Patchwork-Id: 94799 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 D7543385DDD8 for ; Tue, 30 Jul 2024 15:43:10 +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 AE79B385B532 for ; Tue, 30 Jul 2024 15:38:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE79B385B532 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 AE79B385B532 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=1722353894; cv=pass; b=HWFk+d5aSpaUbfK6OrNKn0G1APhzV/XjwC9ciEL1/aT50DgY7Wb6zTN2ICdXJrqtlGNNKIy65RwK6PYLWyZHch5iMY52WIeVvLsg3omCg7sx1FmVILwQbvAIkYlWKYGYtIFVuUsdNHKhouN3FUfG0ivHdjfltAq/3FrZfvbP9Bg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1722353894; c=relaxed/simple; bh=ceJRhz+DSWeOsH4XaXZ57dJQ42PCR4vq0NlC0KJ+KX8=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=dvsVVMd2kMae0vlJrcWK5K6p/qtOO1T3dkh5dofpZkTqM1j/uawj7+ZScB16/jxi2T+rH3zWaqeoQxgTC3SXfaoLp56Qt5AyKXAyY2Ed3Fp+YQewIA0HI8t9GA5EnsInMJQWlnXoUIa+CNlWUDt4JuDbsOjU52H/v2uYqjKvM3Y= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46UFMXcX032652 for ; Tue, 30 Jul 2024 15:38:11 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=ZRKnDCwOVOfeeOfAuwp2oVsCls9SxZOnAy/VBlCrgZs=; b= efR4SNPV3xM+tLWpZ4nV+49sWih/cs2xu/ADb191BQahv2zJFG6N6pysgN5TShno 2XGdOLm7KkG0cyHW9eVyU+scJ9C1OU8e3ptv5jannLpxL0egV9r0BTsOLBdCaAjV HbliiswTjSY50atfoER8QtKG7TSjUKyFIMGV5Z8m7uNZ/0zR+tPuD89AQgWQAziy k/72Qga+i2HGpwTbLZOrtoAAe5JzdO4nHsMU2fd/izNt+TpiSUmzb/duoOaIcGW1 fRtwR/bxQolMBYJnFIWB1XXT8hKWf9pxD8i991VuF9qAFyZZ9XHFVkYYhoLmTJOm j5Xrharpwx8P9fTSNA7peg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40mrgs5bw3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 30 Jul 2024 15:38:10 +0000 (GMT) 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 46UFDK7a005913 for ; Tue, 30 Jul 2024 15:38:09 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 40p4c0975j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 30 Jul 2024 15:38:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pc2IShURQIVphTJAOeckXqARfJ2pumn4wafEGr5rSMET6fUcA0opejO1e9uP/BqY/v9yHiXGF/jbE+YA/rSu7SdubywZWeNMzAAErxi7XgCq9I1TkmrMNLZu4WDOUR3EkJAzA9/jIje8kDinFBPMnaln2LNdpCRcNWIUAqF+RK/L/cJ2QResRlzluNQZfxOus1fY9V4AJQY4FdpD+Zf+hw2zRpvIWOZlRVb2Hy81PZmsXOQaAu/QYvd02PTsrP+EkOtoSS97th9PJAMydKuvBwzfFvrFd0Tzxzt8dHkIYSysyB+8BZ2Z1wUyqjarCYnrEyT6KCWF0aPd86iFwVvkLw== 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=ZRKnDCwOVOfeeOfAuwp2oVsCls9SxZOnAy/VBlCrgZs=; b=YK8zAZzHbVuxFwPUMVLfeo/yVezpktvT64kHqCrmPZr1N9jfKYTWiE7MG0zYVdHTCET55UIVBBanrZ5Wz+Fn9yjdQQuDeXPXx9rsjBYzpZbA0HpLZpO5C7LAvGqLa5gQHN6KOgfSthZ1RbXCE0nwHsEk1u/LzyzLdD9CyoOVO3Cxo990d6V/tMmnEmG7htLhMKfEysZXgFuGBLrb2gBCa5VTSU9/nMNA3IgHdg1LLo9OZzf1Pr+QMvdDbS55JLMwJDBPHfrgYYRK2uoKrnsIk/iD3cTdsNu85B32QvDPIB9uVhEwH19O8ellnq6Xh4AeHZKx4lCJotEFHFZYzQibHA== 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=ZRKnDCwOVOfeeOfAuwp2oVsCls9SxZOnAy/VBlCrgZs=; b=ig0H6vW9bzdhaZgjff3jFIJ/xhx5GlS0AKXgHD3+yvVqrm2ddRYltHF/EOnTPfwO2sB9cIBlnpyo3ZvI3A8Fopso76EeAyHoVCA8rym4qQ0LoZ0mPxY1goQuiDTKNUvGGrAEahVYQoGVMXgjAJP4SzyCDyY7QR3aN7pRJRyMpMk= 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:38:07 +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:38:07 +0000 From: Nick Alcock To: binutils@sourceware.org Subject: [PATCH 16/19] libctf: clean up hashtab error handling mess Date: Tue, 30 Jul 2024 16:37:04 +0100 Message-ID: <20240730153707.168357-17-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: LO4P123CA0138.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:193::17) 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: 5b2742a1-7865-4f74-5c28-08dcb0ad9c06 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: oYiE7/2Hlfz1caSTX86rCAUMajWlWDzjMJpVr8bBdJKBWTc/kb3xLgHaCkJrgFkomiSwWxB5olzD3nxs1UqABYEFCDuTwTfLFiXXsCxHZ3gPuRnYCd4s1TG+MeKUcucK+AlRhj0RM6T2+ACq5MYpGtaMGq8I7s6jnOyUSZ6S/F2wrVHKCIH9aQrZrissf7p6b6ZCInBHyb3V7miZpFXnph6ecV4JfOLO6U3lJa5jYBwe5X91lpBDd4E+MB8CqtRZNMa9EmXMzd4egnTv8q99cx9fPte0WSVw01V4yuZClaM79rsdYk0J5Obq2KoZdSal03I7GkZwuItakRcFc21kPW4gWNLim11HW+FOp0gqi360lptkQFAENYknsdyDAsCDswj237J11ljTVGGe2m2LX+ySfJMKPFf+rKBlnxHEE260p+k0L2DXfWWNSd/6Rghy8dD2J8j9WwMio3aACw1SJRyZDkR5xcyJYdFftf7M0cC/mNXPA5AR6QH+u9QilHNKhhh7GZh5AEa2hgaw7MZ0GdHrjN4aWXr2/t1S+YZWAnVj/DSUspee2uzlAS2dXp8lO+JbNY5Qx+R+LHSiWVRr6bd5n1SnjvLADMcXsjTmEpwyeDHj1MiM7U++wixC4jLe4a2EoIbo1xE6IeTkBWjN8eNdalxNk8p9ZwG2xdR5dIINK5xNhyq5k03e9MCyntHQXq7g2zF9qigqPfn9Q1MDX6ozNWwhNeDl18he3e5/D9Q7ta9COr4mC42VOp2URZwCLYTp81dRMNH8F9wRDIuHv0TUG/qmRNufTRiPJbqMHebijCS5zds05yfEa78fkFg2M83e2zgdUK/FIDygHF/l8kkIA0z6VGcKGD3pAXpShJtme+UGuXzkd8BUIVzhyHdDyL1ZaUMkb250DC/bOQ/o0zuKxzKQl2f+Cr88To+awjS/7IVD4N5ALugIflnFBw2sW15wEyzme0pCN+MaXvV52KsYMCZMZA/KC/hEnhfcBXfybKFhUyuK76KxnlJLq6q63kVOCjUTPApFbFLs3rvxjj0vtfxkpWo7ylnTIrPam8On7AUHdKaA7p/LETpEda2ms4FPqRQy6fm4lD2W9GlcRWS/DDBU95EWTLtSG5TTg8mKFdybpkjV0Rgm7tqDVumAw8xNrYpl2IXZXqXjweXAObvt1AX+PuKCT2j6ghjA+uC6eIcLs2WG6Ahv7wckWHo/I3AVbLLP4lEHribNOPwwx7uBBj1gaQiV9MsrkHjFIKiqLIcTbumDdzdA4GD7KbVirNxOiqd8H1kCfIqilgro2Sogq+hLRUj/Ccn32CGk83TOVFyg4vxPrGG0APsDGjvKQN5wy3pmdM6S9hlB+ZucMw== 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: H2A5H/aVnFsLMnI+0IiwMEOlWbciJFkIjVuuxCo5dnYaM6pEokd92hqPz+FEan6sqwZPNzujlq4rpT5iv0IN9qT5+2iy3DLSr1pbhV8gXzbG59IKBZ/zVng36/llRH8K/8XBcoDEw/9ojgEp9dxTpH1USYETTmMRyAP/+FNeRGHKX+H+qbwWQVmvOAzfcMhbTj4Ebyrz94d7xLOxS78OSVF1p8xeKBhcH2GsfC3EJLEJ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742a1-7865-4f74-5c28-08dcb0ad9c06 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:38:07.5429 (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: 67mTj4sjqCAWHN654c1IL3LV5Z1rBkikgR/1JP1vFnqCMzcQTOpWoD8IdKGnGIa5iahe0xeCALaFds3XW2nIAA== 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 phishscore=0 mlxscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2407300106 X-Proofpoint-GUID: TQw9GE2ZEutGl7w9fMjPRIznurMpGGL6 X-Proofpoint-ORIG-GUID: TQw9GE2ZEutGl7w9fMjPRIznurMpGGL6 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 The dict and archive opening code in libctf is somewhat unusual, because unlike everything else, it cannot report errors by setting an error on the dict, because in case of error there isn't one. They get passed an error integer pointer that is set on error instead. Inside ctf_bufopen this is implemented by calling ctf_set_open_errno and passing it a positive error value. In turn this means that most things it calls (including init_static_types) return zero on success and a *positive* ECTF_* or errno value on error. This trickles down to ctf_dynhash_insert_type, which is used by init_static_types to add newly-detected types to the name tables. This was returning the error value it received from a variety of functions without alteration. ctf_dynhash_insert conformed to this contract by returning a positive value on error (usually OOM), which is unfortunate for multiple reasons: - ctf_dynset_insert returns a *negative* value - ctf_dynhash_insert and ctf_dynset_insert don't take an fp, so the value they return is turned into the errno, so it had better be right, callers don't just check for != 0 here - more or less every single caller of ctf_dyn*_insert in libctf other than ctf_dynhash_insert_type (and there are a *lot*, mostly in the deduplicator) assumes that ctf_dynhash_insert returns a negative value on error, even though it doesn't. In practice the only possible error is OOM, but if OOM does happen we end up with a nonsense error value. The simplest fix for this seems to be to make ctf_dynhash_insert and ctf_dynset_insert conform to the usual interface contract: negative values are errors. This in turn means that ctf_dynhash_insert_type needs to change: let's make it consistent too, returning a negative value on error, putting the error on the fp in non-negated form. init_static_types_internal adapts to this by negating the error return from ctf_dynhash_insert_type, so the value handed back to ctf_bufopen is still positive: the new call site in ctf_track_enumerator does not need to change. (The existing tests for this reliably detect when I get it wrong. I know, because they did.) libctf/ChangeLog: * ctf-hash.c (ctf_dynhash_insert): Negate return value. (ctf_dynhash_insert_type): Set de-negated error on the dict: return negated error. * ctf-open.c (init_static_types_internal): Adapt to this change. --- libctf/ctf-hash.c | 7 +++++-- libctf/ctf-open.c | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libctf/ctf-hash.c b/libctf/ctf-hash.c index 7f291e3ac27..cd7473419cb 100644 --- a/libctf/ctf-hash.c +++ b/libctf/ctf-hash.c @@ -256,7 +256,7 @@ ctf_dynhash_insert (ctf_dynhash_t *hp, void *key, void *value) key_free, value_free); if (!slot) - return errno; + return -errno; /* Keep track of the owner, so that the del function can get at the key_free and value_free functions. Only do this if one of those functions is set: @@ -786,7 +786,7 @@ ctf_dynhash_insert_type (ctf_dict_t *fp, ctf_dynhash_t *hp, uint32_t type, return EINVAL; if ((str = ctf_strptr_validate (fp, name)) == NULL) - return ctf_errno (fp); + return ctf_errno (fp) * -1; if (str[0] == '\0') return 0; /* Just ignore empty strings on behalf of caller. */ @@ -795,6 +795,9 @@ ctf_dynhash_insert_type (ctf_dict_t *fp, ctf_dynhash_t *hp, uint32_t type, (void *) (ptrdiff_t) type)) == 0) return 0; + /* ctf_dynhash_insert returns a negative error value: negate it for + ctf_set_errno. */ + ctf_set_errno (fp, err * -1); return err; } diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c index 3f624987f90..942a53a8f2c 100644 --- a/libctf/ctf-open.c +++ b/libctf/ctf-open.c @@ -681,6 +681,8 @@ init_static_types_internal (ctf_dict_t *fp, ctf_header_t *cth, the latest supported representation in the process, if needed, and if this recension of libctf supports upgrading. + Returns zero on success and a *positive* ECTF_* or errno value on error. + This is a wrapper to simplify memory allocation on error in the _internal function that does all the actual work. */ @@ -886,7 +888,7 @@ init_static_types_internal (ctf_dict_t *fp, ctf_header_t *cth, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); if (err != 0) - return err; + return err * -1; } break; } @@ -905,7 +907,7 @@ init_static_types_internal (ctf_dict_t *fp, ctf_header_t *cth, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); if (err != 0) - return err; + return err * -1; break; case CTF_K_STRUCT: @@ -920,7 +922,7 @@ init_static_types_internal (ctf_dict_t *fp, ctf_header_t *cth, tp->ctt_name); if (err != 0) - return err; + return err * -1; break; @@ -936,7 +938,7 @@ init_static_types_internal (ctf_dict_t *fp, ctf_header_t *cth, tp->ctt_name); if (err != 0) - return err; + return err * -1; break; case CTF_K_ENUM: @@ -949,14 +951,14 @@ init_static_types_internal (ctf_dict_t *fp, ctf_header_t *cth, tp->ctt_name); if (err != 0) - return err; + return err * -1; /* Remember all enums for later rescanning. */ err = ctf_dynset_insert (all_enums, (void *) (ptrdiff_t) LCTF_INDEX_TO_TYPE (fp, id, child)); if (err != 0) - return err; + return err * -1; break; } @@ -968,7 +970,7 @@ init_static_types_internal (ctf_dict_t *fp, ctf_header_t *cth, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); if (err != 0) - return err; + return err * -1; break; case CTF_K_FORWARD: @@ -985,7 +987,7 @@ init_static_types_internal (ctf_dict_t *fp, ctf_header_t *cth, err = ctf_dynhash_insert_type (fp, h, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); if (err != 0) - return err; + return err * -1; } break; } @@ -1010,7 +1012,7 @@ init_static_types_internal (ctf_dict_t *fp, ctf_header_t *cth, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); if (err != 0) - return err; + return err * -1; break; default: ctf_err_warn (fp, 0, ECTF_CORRUPT,