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 D76073858D20 for ; Wed, 17 Apr 2024 19:22:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D76073858D20 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 D76073858D20 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=1713381730; cv=pass; b=rzs0FMvN77W42wO22HOyr+m8FHA+KHsD+rBpgi59ZtqT3VHZ4t7rlIUDjmJCYIlIkvMi5uBTnIuYID/f7RyTjM66FAYIpWlj1/Sj0XMNp8DLYAwTsMOLsgyZoZQCCu8+5OTNoNxzJ1E/ucvzIQ8/9Vujpd3LzuoN5FYoFbBFNIg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713381730; c=relaxed/simple; bh=tAR/cP9++ZYQaSrmPexDM7zbUY+vt4rTLNjm6Z6vUFk=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=LhGU0mdvT0V6EA9g8FvkeEVYu5CtDS+0lpWP+bTDeRwdHoPe1Kd+sBRku1s8Tr9qvQaGB98xGTNReA2/QL7dC0+Jq7nzp7VdBXPmF5yp2AHW6WE9Yp3TlAdmqYXdkB3bnMhLWei8eQPrrYrC3+1uTmmdVL2fYZ7i7LMv6zcDlLA= 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 43HHhqnV007971 for ; Wed, 17 Apr 2024 19:22:06 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=krZt2HS+Fgm8SUfSdaVGrfEIOvlt7VD8dALOYNAfMoc=; b=dwvvh+dN3lfQWEi9h0aH3UhwonOHU9XzW0zEPfRbCqGLDQoPAj22yKbGQ5l4El1j2Pkt hhaxVRw7kA4KbRVuEtWdtVhCg7psP8IAFQNgf2Ktf3sZPmlqWuBQeEkqOFzhL49Vbr3n HzKd0OG9ju5n6ntvpgR6CP+znqrGzt19h0jrExrw5RU/+XuZR0ZH1F4mGzPWcyHB+qTt C1Yzhk8UCI6Z8Z8tFEhPAxe157hVCYZfa/rwTRuyPubd1xbb45jMDxafDHCup9+4GJ9X r41xFOyTKSO6WETEe076HJPfERooIj3qVttiULQqF1+QKg74qlkPLsZiazllc4Z/JmMb Yw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfgujrv1h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 17 Apr 2024 19:22:06 +0000 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 43HIouDI022408 for ; Wed, 17 Apr 2024 19:22:05 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xfggfm2fj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 17 Apr 2024 19:22:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=esPlI/O4SVkjTguRcVJDNEnwliHYFK3v0s314Vq26ggw+xoMClu+/BEURTiedPqTiDjMAIiFeNN1iJ+C/3e62PuMbKPbG+/vQ+WbbTlCsLyv2ZhsSlrjgBJLhV+2cUuIeEW1DfnPX5wp4gyka3bVaJH1iw47wEjqO6vsN1lTtU9+VINnkyUCgpkGLlELQkLxuJOTYeyd6phLvTBdea7lQcYLn0qOToE5kwXY0VMmx6I+lXDpOitFqIuvLAKNak7g9bIz3X2ASOl+V6iGgA/pOUC45RAr/MfjFrNyQ1FYjksWtRdZCdLiToYBd/9ybcrMAvhWby44NgJWuvV9r7kNRA== 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=krZt2HS+Fgm8SUfSdaVGrfEIOvlt7VD8dALOYNAfMoc=; b=bnZZ1osI9iyJ0FozIYpIlKP1D/7T+zqEnlhrTnfbv+9vTAXFD8XvdJWIv4huhJGgpX3gjOtiVRk4UemZTy7czrWoAfyAFqGtjypW+G+f0DOksGJPMAs0lkGvZrZ9x/GTJNH4v/jhVojC69ppDSnUfk1qiR5Hwmza8ynRQw6tm+hJDPpdKjPlHYUQ8s1aTvpoPtM3MoLr5mcmqmno9FQRhjj3T1WYnZACU/JaSNck8NfukqqxESlDYaMsu+/jFUALk5iCz4+0m9m7v6E/vWz5y5kpDp+QR0yX5RPSPKAPByuR4AdEonge+38uGK5nzS4U+rFAOgBG4jBEhga5/+ndfQ== 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=krZt2HS+Fgm8SUfSdaVGrfEIOvlt7VD8dALOYNAfMoc=; b=lwML+NuMoTGF9DdIux98ulpZYEZfAWfFzxNET0bKHwMVvEW21S25bgnkL52ik+cpL9ctuVE156LK8dseWyBXFAsNXSSXvF2LICrP8SilknYnD75WIolQg6Vjtruvy6HeoEBMFiHeQwA0wNyKYKwYDT1GkI7UTN1GQXe1pzXkpFM= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by MW4PR10MB6370.namprd10.prod.outlook.com (2603:10b6:303:1eb::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Wed, 17 Apr 2024 19:22:03 +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; Wed, 17 Apr 2024 19:22:03 +0000 Message-ID: <67dd0e90-4091-4a48-a348-fc68b3a7f130@oracle.com> Date: Wed, 17 Apr 2024 12:21:59 -0700 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] 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: <20240417184441.339037-1-cupertino.miranda@oracle.com> From: David Faust Content-Language: en-US In-Reply-To: <20240417184441.339037-1-cupertino.miranda@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BL0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:208:2d::21) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|MW4PR10MB6370:EE_ X-MS-Office365-Filtering-Correlation-Id: 14dd0463-9c32-4fd2-aa30-08dc5f13a992 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AagepZxfLP6cSFkOZF3SraiFdjyvvAPJjGhvrZkRj14FrYcHVQclJG0xVzhwKmg0+uAyswBEQd8JZhAgB2FHGLzCZ+Vu8v+/eWgYHrXI/nUZRashNQeaqNg5DGToVoaJhAS8Iok7WerfF9ATgwGvN2PiOIKkDF4Icm79F6Abt8q98O88NUl7LD1nlKhvUCTuX3KhyhKuon5m4ZWjyvwiFhizjjd0HB8xVjkGtatsIEqFp7GuqOFvqPkfBvvXPjFRNQJ1mdj71kGq7cvXgYJ50rHJ1Nto2KMi8kW5SSBNiia09mD6nEOoMLvKpM6u4pOGMYP1jeVYskYAup6Lo7ycmKDrLMmnqi4C0fLe5JItcs//kpQzFsY91p5by9WU2qnPUIZ6LgWEDUhIFG8A0KBsdCNbDW79KSSK3vw+y+jXDNVE0YZsuyT4MbNXhpPccNjq5Tbdf6XXBWKtOeo718hhk/ZTx9VAAknrIws+fruW1w3kqEB3aBUB9CiQFz8Rp7fMU+g8Tbl4y76kbFCcSL2HkkfN5h8ZqWwOTOZViN68TrCLdu22Y6G8wiQyYt2OPXWdRIvIDNp9ixTHNJfSXKpHCgk6PkI7oTXz65L+IvPNqvmywmuAstylrn/af7FaNCEUumjBK3G4RXh2hnz440mJKaR3HsIY0fkvVi8w0tpZqZc= 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-Exchange-AntiSpam-MessageData-0: =?utf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hv1KaKXW1UaFFoD0WtDoYT9zXOWOhkrNM/gcPxJbC+RLmroptZ928= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 14dd0463-9c32-4fd2-aa30-08dc5f13a992 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 19:22:03.5836 (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: OAgg5rgcJzBqF++LWGlOJ3Q13tCyU4dTKkRRNPIiYNBgoqit2KRY+7YFPA2zRHRQcyFXoXN0Oic7x/+TRfv0rQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6370 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_16,2024-04-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404170137 X-Proofpoint-ORIG-GUID: Zcwo-ZqQKVd0cdUm9pNZuqqdEjZl2_e1 X-Proofpoint-GUID: Zcwo-ZqQKVd0cdUm9pNZuqqdEjZl2_e1 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: On 4/17/24 11:44, Cupertino Miranda wrote: > 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): Correct > string allocation. > --- > gcc/config/bpf/core-builtins.cc | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc > index e03e986e2c1..beb039ea6e0 100644 > --- a/gcc/config/bpf/core-builtins.cc > +++ b/gcc/config/bpf/core-builtins.cc > @@ -870,12 +870,14 @@ process_enum_value (struct cr_builtins *data) > unsigned int index = 0; > for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l)) > { > + gcc_assert (index < (1 << 16)); Since the index here is computed from the TREE node and not BTF, is it somehow already enforced that this code won't be run if the enum can't be represented in BTF? If not, I don't think the assert is a good idea. The TREE node could be an enum too large for BTF, but not too large for gcc. So the assert will cause an ICE for something that is a representation limit (in BTF and by extension .BTF.ext i.e. CO-RE) rather than a compiler bug. IMO an error or warning makes more sense here, something like: if (index >= (1 << 16)) { bpf_error ("enumerator in CO-RE relocation cannot be represented"); break; } WDYT? > if (TREE_VALUE (l) == expr) > { > - char *tmp = (char *) ggc_alloc_atomic ((index / 10) + 1); > - sprintf (tmp, "%d", index); > - ret.str = (const char *) tmp; > - > + /* Index can only be a value up to 2^16. Should always fit > + in 6 chars. */ > + char tmp[6]; > + sprintf (tmp, "%u", index); > + ret.str = CONST_CAST (char *, ggc_strdup(tmp)); > break; > } > index++;