From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 4C89D3858D20 for ; Thu, 11 Apr 2024 16:35:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C89D3858D20 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 4C89D3858D20 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=1712853306; cv=pass; b=GxpSWKaZprThr3+uDuRdrUNx/Gb/LyX85kqXtdgOYM1dSy5jPRdfGpmpexRHJdUpoXKqtlOEN+euMI9zWmDmYKQ3QTclqYvg1m2KDa2i2fJtgBUg6aYN1R81Ts7TL3esitOZW5Xu0Q42B8tnDqkyXwVQZ6kaKxRHwJYMz6MH7B0= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1712853306; c=relaxed/simple; bh=dnzXnUEqO9HE2u7T4fFdlbqeaK1vlSOBEgZpuvuowOE=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=HsCTO9I3icKh/zdsCbxgcpgzvA9hKVnNvGksW8aIZLHSZqPYpFXLrzzEt3tFHFf63lqNQY9TRSgA5lwP/3U9S2fyp9zQr+lYQ+wkUaClVqALYO9KccIKx0DSASFJdk4aq/ikg+OHGzDplmgUF+Lx1ScfhQ/oToGMBGQRWoTJ0yg= 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 43BGYfjA014843 for ; Thu, 11 Apr 2024 16:35:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2023-11-20; bh=3RfgP4rtQOuZqGMq1WaXuTp87Rtv73uSlKy03d4u3DA=; b=kzGNvpm1haMJICFeh3yF2Jqtf2hh313NgWX1ieDJYTDYkqzj2fu7NuwbfEth7fSL8mhw iZP7/KjwtlteNIgUsvXZl/S0bk5kOJ7rZ8ndbx6m9YW9RfoVbXuM0FprjdECTtMy1DIw q093u/K7ncN5OSweoR6xmfVuJW/5TGwTbCmJqVl9WyP+WhTFNHWdk0Q6xVbtTWOkd58N a/yh5MnkUUhQL5ebcFCABGMEv2Rv8HB9oOdm3pia68nqDJO+V32Ozsa4IL31zBlg0upr 86vmyTPb/1dLDKU0yZLjiH3p03RCPRCLbHZ70H2zb1MpytAWDIXPMEL+afqRv+WykG2o 4A== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xed4jrtw8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 Apr 2024 16:35:04 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43BG4Zvt040728 for ; Thu, 11 Apr 2024 16:35:04 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2041.outbound.protection.outlook.com [104.47.57.41]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xavug24c7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 Apr 2024 16:35:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GYVClXHT+kdaY6H7GFR7pTwqh8VyIraEwn/qLk8W5mIYVeRYR6uqT4VNOAPMvpGyWTEvrSMQ5hXh7c4QI1rPU0pIhefOYrgVaItv2FzcEciNDe573JGoJlGqbT2L3pHldHZoXBWo8TmM5rb7Qaa/ED1YukU6BcKM4Gb5DtE4xP8IvGYtq0etSVOGGyMOJwE/mxKSCPslWwRD8LMoNmteiGholl/ppCTb/ovE4MSv9pbfmwXB2703wOfCyE8UtXcxKvpxUslgu492hC30JLLwX1axDeHbvZvQu9Epzc8/WgrL/Rx5Xs3eNTYM9lGu3Lzkp7n3V2pcW8pMoSE8IXreXw== 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=3RfgP4rtQOuZqGMq1WaXuTp87Rtv73uSlKy03d4u3DA=; b=cDdB6X9Xu1Xqs6uACcjFs0XNofTMOSzxY4uhqp1b9IzKkHwCyS+0Mf01r22aGbGcpV6dWg0zZnKvOL1dbfvJNQzatLJx2wWUXOiclKhwozzHEMe3RKQYpXK17rfyAIhuIj7RZTa1hDUx1B3J5dk76x04XMHf0dKMYAIDci+ZNCuI7mSL/rgILbp3NappAnlLSOkX+ShrXtXUiQWasgsWTLFUS+qEZCJfJM8RfMJSNv+1wdnDdcTnICogPyQj2bnEhGIFXPviNkzpUu8m8XclDb1tT5FAVd/qomgWqcROLSzEhRWoa2pF3Y0pHaYh/m/9PGjQwX2xNx40XamE4y3EEg== 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=3RfgP4rtQOuZqGMq1WaXuTp87Rtv73uSlKy03d4u3DA=; b=AFzuOP12jv1SUw+0XFqpXGZGyZ1EZtIDGpXY/xaigy+o9dUuSZdxhy1uHX3LPcm8UUsIX6oKnTp+LQhAuty77vllWwmkJrkK5Q5+Ichd7k30s7mXjHuW8xOMxXe4YMfCSgH55pp9r+OM1dbzAQBXxKbzGYF15kOt/tnPUkElHkg= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by PH0PR10MB4440.namprd10.prod.outlook.com (2603:10b6:510:35::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.55; Thu, 11 Apr 2024 16:35:02 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::ddec:934d:1117:499d]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::ddec:934d:1117:499d%3]) with mapi id 15.20.7409.042; Thu, 11 Apr 2024 16:35:02 +0000 Message-ID: <7365c55a-9704-46e8-8413-42e88a865a73@oracle.com> Date: Thu, 11 Apr 2024 09:34:59 -0700 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] bpf: remove huge memory waste with string allocation. To: Cupertino Miranda Cc: gcc-patches@gcc.gnu.org, jose.marchesi@oracle.com, elena.zannoni@oracle.com References: <20240411111118.215612-1-cupertino.miranda@oracle.com> <20240411111118.215612-2-cupertino.miranda@oracle.com> From: David Faust Content-Language: en-US In-Reply-To: <20240411111118.215612-2-cupertino.miranda@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BYAPR01CA0053.prod.exchangelabs.com (2603:10b6:a03:94::30) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|PH0PR10MB4440:EE_ X-MS-Office365-Filtering-Correlation-Id: 9cb43419-030e-4dc1-84b8-08dc5a4555c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tXtfhQWLEF+hQ7ufL3DFmsZwxEzcJ00zuUKEYKGDvg92aHxoLWtcQJKPoBNORlAVnpNZl3K5/C3AXgWzt6g9WE5hny4Ja3SAWTQ5odKb5J4HUSTvomfeVeoeTAQnqzV7GO1WsonMbUCIW+ziUmuOALQKipwNGZoWNUd2is3xbws1TPimxAmQI4ANaTvwVvHNqlvWKAWHs/Bm5XVzJ4A3RglvLNi0fqNna4cv1p+CjqNjmKCdkFGdKl1eToprOTtMV8fdYBGh9v2WLS1aStsQDQREUs5IQV6mR/7zM/9/0KAbf+E7OCPRzR8Chvn2IRdTYWOeSwHrPSOPCA64KY/0pHYr83n4HUJ3XSISwzqBcmOgQiLAVY3wXLC16WdiII8Q+A+CsUjJR5XxPsxHEkZUhmucc794KuPwtAXVzXIFfBmJCnQ3gyngjTBqm1QixTev2bmXqNGpaUfKG+ZYzBaMcH2LYOZtom6nJA1e/C4/BBWqBZ39B2muPG9CfkMmaVsTl8FaMtkjCqYuD37WliD/59WyA1yqDn3H0J4tCIwsjC2K5B1R754xKLJFwJbKJON1XRcsetQ8eQH+1R2PUynn4DetxFMKFbLlqQGseFagd5FmWNbKTNRTMLNTdagxD3nXkZ8gmK1bw5/ytVu27yMRmNks82aEu5dCqZkt1OE72bQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR10MB7953.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-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Pe5xkjhWo+PqevS3SyEFgT+EKqdMaCPNm0pesIbyOmdOaitTKXwKtWIcwaO49Vw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9cb43419-030e-4dc1-84b8-08dc5a4555c0 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2024 16:35:01.9408 (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: 5dE46b2ut2Q2WcLxPfeUoq5c5Kng235gFi0Kgt3MnBvtcIjQ/VlZjzahrgQkJDuEFHkc4BXpDzSOkQO9oYZXqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4440 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-11_09,2024-04-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404110122 X-Proofpoint-GUID: 5VppzkB8BP52lbqv2h4129hHzgL_TjLi X-Proofpoint-ORIG-GUID: 5VppzkB8BP52lbqv2h4129hHzgL_TjLi X-Spam-Status: No, score=-13.7 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 List-Id: Hi Cupertino, On 4/11/24 04:11, Cupertino Miranda wrote: > Code was allocating way too much space for the string. A little bit more description would not hurt. Perhaps you could say something like: "The BPF backend was allocating an unnecessarily large string when constructing CO-RE relocations for enum types." > > gcc/ChangeLog: > * config/bpf/core-builtins.cc (process_enum_value): Corrected > string allocation. nit: present tense, i.e. "Correct" rather than "Corrected" > --- > gcc/config/bpf/core-builtins.cc | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc > index e03e986e2c1..ead1777d465 100644 > --- a/gcc/config/bpf/core-builtins.cc > +++ b/gcc/config/bpf/core-builtins.cc > @@ -872,10 +872,11 @@ process_enum_value (struct cr_builtins *data) > { > if (TREE_VALUE (l) == expr) > { > - char *tmp = (char *) ggc_alloc_atomic ((index / 10) + 1); > + /* Array size is 21 = ceil(log_10(2^64)) + 1 to hold string > + representations of 64 bit integers. */ > + char tmp[21]; > sprintf (tmp, "%d", index); It looks like `index' is an `unsigned int', so this sprintf should use %u rather %d, no? Also, it occurs to me that the `vlen' of BTF types is only 16 bits, so BTF has no way currently to represent enums with more than 65535 enumerators. It may be worth adding a sanity check to bail out (error) here if we're going to claim an index higher than that. And if that is validated before the printf, the buffer can be 6 bytes ("65535\0"). > - ret.str = (const char *) tmp; > - > + ret.str = CONST_CAST (char *, ggc_strdup(tmp)); > break; > } > index++;