From patchwork Fri Nov 4 23:10:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13032690 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97780C43219 for ; Fri, 4 Nov 2022 23:11:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229545AbiKDXLM (ORCPT ); Fri, 4 Nov 2022 19:11:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiKDXLL (ORCPT ); Fri, 4 Nov 2022 19:11:11 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABCAFBC3D; Fri, 4 Nov 2022 16:11:10 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4Kj8qw012149; Fri, 4 Nov 2022 23:11:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=aLkIebTrAX0eLDCczskBmTOAqODqSM6eQeh1Ond8LoI=; b=XZt9GhxPecb9BsGQnZng5pNbbfbm/c+9SmDUpQR/AodRJ57Bd/lCQe9EKo3DFWSeYxGJ 7PrSEbYeBVWRlSDhxmIAyjHCUwxNwS5Rvo9NSey34qxjF/LA8RQITA8CjPFlOM2HEVns bfdiq+tKo9XL+44peIxpoLrkg7xLz5mea0x3d7FOmMypmBO9dGYX6Pod5Fb2HjLLNLXY zqrF4q8jPsouqTo/VvnoQ9gJN0o9hjaHzbqN/sasR9O3vjoCmF/OD9Md5nu/nz95ZOAh TwHKYu71thjaKSZBBKbVCyFWT2QqvS42l/W7HloeQ7sWR8XU4n8C7UcHfqKCWmil6+tH /w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgvqtshkf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:08 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4KwcgX032161; Fri, 4 Nov 2022 23:11:07 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2106.outbound.protection.outlook.com [104.47.70.106]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kmqb6r4v9-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bO2fD9ATUtB2UnJKi0vu/XCWFhI+EhE9C/0GALI4/XVwFG02zivaHGraZDbpI8erKZBRnrid4pkSu2HMToIVgI+VwN3NpvoPIRt1nR1zB3U5IhDxXKPV1ZwpbQrdy7myrmEnlfjDLDj5q94EVLH9N5e0wG9MCtYl/jtmUiCURdlEgbQHf0UoPxEit7bTa09DzX3WjVmox1VUcdPwBSzkrd3QJEeUZibktzgjjQfdyC0p4GQnbxxHYDOQ6rhgAjs+5fh/S9SkSPdomJ/eqYdAlMqG7kmk7+AiyBmqgPhhWEGpiLPzTQA0RRD6V7hYFNCIe5HygEIjQRZNYUuRSmyPhA== 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=aLkIebTrAX0eLDCczskBmTOAqODqSM6eQeh1Ond8LoI=; b=MhfLih9fNzvvnpWeUg1rrCEu/CeJ8DnzL/yl0IMp5KaHeKpuR6dNJLsuIt/lQoBIgu0xPhA6mkreP6Q4BrGiJDCG72SEF7E2Nk6MX4POGKYA34NKfA9IG0ZnoP4CzQpfJQ/itUO+/w8g6/g0ZGNMd69W23amuJumt5dy5Othrg3XqXFDOqkrjPD3nrTPAKBiWXDlfZS/oOb42/dnPk8zNGjF3+1xRG9eJUuGIneCpvBa4CJxjNgZ+ImTZ1ZHlXnBm66n+Zaw8FnCZO7hJNJcFbKWdpoLYTc2sBTOS0eEmZaPvcDjD5J4nhrV0k3HVOvqRICyf6VgaECRRRSBMSKgig== 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=aLkIebTrAX0eLDCczskBmTOAqODqSM6eQeh1Ond8LoI=; b=dzHpzeYeAOYu+MB+Vvk3CV4jBE8oGzKSEz50y4mgFvh9LQeerujXb7nGufOg4RSB/Uqr/4TBsDdAhv9DE96oU2jBe5QN39Wa+kkTEozScUyog+WspTkBxceDfNGWPOzPYuuxU+LMg+LBJ272az1fEZSbFq7aJOpWdXsc26dGZao= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH0PR10MB4972.namprd10.prod.outlook.com (2603:10b6:610:c0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.23; Fri, 4 Nov 2022 23:11:06 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%8]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 23:11:06 +0000 From: Stephen Brennan To: Stephen Brennan Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org, Arnaldo Carvalho de Melo , alan.maguire@oracle.com, Andrii Nakryiko Subject: [PATCH v2 dwarves 1/9] dutil: return ELF section name when looked up by index Date: Fri, 4 Nov 2022 16:10:55 -0700 Message-Id: <20221104231103.752040-2-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104231103.752040-1-stephen.s.brennan@oracle.com> References: <20221104231103.752040-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: BY3PR10CA0015.namprd10.prod.outlook.com (2603:10b6:a03:255::20) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|CH0PR10MB4972:EE_ X-MS-Office365-Filtering-Correlation-Id: 773f3fd8-965b-49ce-e704-08dabeb9da19 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uQ2wPspb0GNhsmkHG/qfqoJKh9OZNwSt618Gprz5Fg4M2aVkEteD8LV24A6M4wQd2GQzf8je7TKoKL7JVAfvKZPbedMeSLk0kYw/2VkKCofhAKtY9fUvIm0ScLiW9aRfhsX0XS7qqssCXniqUMK7Vz+iSi5voX0+/hK5Siy/WH+78uKQyw/3iGxrZ+9q6sovT1Xc7ZExdu+VcTAMh5VGQzXJclKrPpVQVSgolP7+nPBoCv4Q0+Wr1TOcakeJxCxF3FO+gbqdN7DIieL19Lc2GD8eYLIfflN+c5rN0QbFKqvRvj0LX+q4FzLRoi/VMtG26j1rRIOlKM8OnzSUBKQTCtXPsUQEWp2y3CMeFISTRzqnvGISKVXuUaAJ/r5WekG/ytE6XdtmkZkViEKf0c9OltYt6ZLEckGMwT9EiaBGy3vY2vHW7+N28S/pDzh5Xi82yzJl6thsw74CaImHO2jm/h5Iu3t5T/k2qeAAWVatxDmpZZdf6w/E3ht4QAkMVs0z6OF5Z86NwlusRV+s7aiScZFUJGIjQ+BzKyV8wkQR8wYUT+1t18fIbjeDD8uy2TKjeYyNFIdy4UOvYm2V/vbfjYLu6rVz8X3gcTs6Mp8lL4/XdQ+gSM9TenW4lliAPTkjw/wX8b2jQ/wD1rraY8FHONkCo9/LgS0vuxpbY9q+iRoHDvmg5mFdtzeTsDhFwiGUePo/sokX5WucctFANddVeA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(396003)(136003)(366004)(376002)(39860400002)(451199015)(36756003)(86362001)(103116003)(41300700001)(4326008)(6862004)(2906002)(5660300002)(83380400001)(478600001)(8936002)(6200100001)(316002)(66476007)(66946007)(66556008)(37006003)(8676002)(54906003)(6486002)(38100700002)(26005)(2616005)(186003)(1076003)(6512007)(6506007)(6666004)(7049001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: w5d5LAfWySYrkTKg6VAqHut9SN3QbvE272mav5xxedXswLSuV8V4G7lqy2Sc3T3uXM/IHKEoqtuXuubQCNK2Z/pUDKx1E/WtL88ciOXJZ2v601lHSym164O9k+x32MvZyfj4Doc+iCnmDVn7v8VDZT0IZwZCSeGr8aBkitmNXE2P6xsjEFtVl2qJa7CFdbxmFaGaYAiWu/zTnSjOa7zSP/BO0FugTqYHIwLaG5GVMWs1AnI5jUv9uXzkJQ0Ed6qyEIeUahF98JA7qDD3MM/R6DWSPqKB7sVyEJCJ4Hmvp29NGbqDiKaXFPx45A4yLP/7swELfPJCKtfMYem6pbSeM3tLiV7o7ea6tSi1UcTor/yAh64lUXQj7Z3GW0+DLzIyTQnm8CekYNNPBs059mfP4pfwDjSaorrcqGraEH5SNiXUdO+gQmEzAD3hySiJ4EAvnNZU6vXnNw1/iPjSXFIYhQvym/2vreno+wu1JIFMIQSsDFbHK2+5oILIzrpfD79qJku+IxgLfctrh/NHOt9gg8+u9O1Sjhpb5OlR+T5qnq3LmrHxL96sUqBWnyB/ZMOpvEIPIZlbdiZOBCiL3+UBew9tUO0ReNOzkPewJ9ghMR+xFkeZr+AZnGA4UyYNuiJYbNurfJ0tiaih2Idw3snJrJZEi/IdQbzxN/pLfqONxFgnmyMVAP0FlYI0+61etaiRCEEkfDuBAnhzF4gWakhhfVV7KNjOwNcsYjuCCdq/K3pzq0HhK96sY41JX64toef5StIptc85Jh/zdGJ+9AinjIsv3JnMXieoDcXOioBUiSQNSkuoETN/xcsualuqCk75CdmWEf2vSZBAgUbMmtpLcN2k/FhlLNMLT8FSalJpyU6J5B2KPTg34RWIgBn3l+tSDwLoyE0xThy85uwCUnZ9jDhv50pQeShu7nInApR0lWJIkuzprNKeMDJiklIkn8Zy9VM6A6RSFEOzSr6aG2DESI1VdtPjQWCdub6OclcBPoQ5Y/GiH7bdjlbSMkp8htI6gWRc8ye5MkCE127Jvb+/5iPB/UNmz11h8DWJWlEWEGzIGu2XddFxyFicNF/sD8ReDTzg2V47cMhvo4O6Xlb8Ykeay3xl/bYcxg76SSE+yoyPnrC/Psl9uBpTZDcEz4BkPUV+oatbcy5rh1hRxrE6sgIYkRmjfi9vNLirhIQ1lOm/WKTcInqq71Z6DII4GorAcdFXUih517Pb5YvvofaKBh43CynYR8dK/Y1x9BoDDPCAoB7zgX1H8dtwn8gjdUiwaxcEoppub4xDBwp6MuVfqP/3DHGdZoPx6vvhlgJIvUNxLXRjcW8dIEZEoWzsoJx3Q3x0Kak+j4Rzxatxq0Vxn8s7JSLd8vzSa7NiG6WGBhl8EAarAvKZiO4DPFEskTJ0DrRE00ttAr+OgtVxwhRXsfkkO3CQklZGZPI/kfA9vdXbxzR+dT94DgJEPG6Omrex05Bvx/4bNf4yGXcMZEnL4cBWSv4uG7MBvAmw4ucb0oV9yw3JnR2OsjKicRDm/9p9LxqJxI+xQKx56sIf4v1loqkTwrBnmQccd++IKkHbnVtUp55tv9gc8KX8GxYdaGLcBzQnIOgzL+s3Jzdip2zEgg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 773f3fd8-965b-49ce-e704-08dabeb9da19 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 23:11:06.5266 (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: BjFI2FLq+mu7u6Dl1vurhiAb6KtHVCxk6+zh5OxLH7YFkRvKylTmoVdTc9UQ+eIfN0++6+b3uoN/uFrHwphMn6CgGeN+zmvqJZWfYpAC2zo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4972 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-04_12,2022-11-03_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211040142 X-Proofpoint-GUID: _HW45WktzzNVoCH9gQxoDnKpn3zUYWNO X-Proofpoint-ORIG-GUID: _HW45WktzzNVoCH9gQxoDnKpn3zUYWNO Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Signed-off-by: Stephen Brennan --- dutil.c | 10 +++++++++- dutil.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dutil.c b/dutil.c index 97c4474..a4d55e6 100644 --- a/dutil.c +++ b/dutil.c @@ -2,6 +2,7 @@ SPDX-License-Identifier: GPL-2.0-only Copyright (C) 2007 Arnaldo Carvalho de Melo + Copyright (c) 2022, Oracle and/or its affiliates. */ @@ -207,13 +208,20 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Shdr *shp, const char *name, size_t return sec; } -Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx) +Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx, const char **name_out) { Elf_Scn *sec; + size_t str_idx; sec = elf_getscn(elf, idx); if (sec) gelf_getshdr(sec, shp); + + if (name_out) { + if (elf_getshdrstrndx(elf, &str_idx)) + return NULL; + *name_out = elf_strptr(elf, str_idx, shp->sh_name); + } return sec; } diff --git a/dutil.h b/dutil.h index 335a17c..ff78aa6 100644 --- a/dutil.h +++ b/dutil.h @@ -328,7 +328,7 @@ void *zalloc(const size_t size); Elf_Scn *elf_section_by_name(Elf *elf, GElf_Shdr *shp, const char *name, size_t *index); -Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx); +Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx, const char **name_out); #ifndef SHT_GNU_ATTRIBUTES /* Just a way to check if we're using an old elfutils version */ From patchwork Fri Nov 4 23:10:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13032691 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E54F2C4332F for ; Fri, 4 Nov 2022 23:11:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229588AbiKDXLQ (ORCPT ); Fri, 4 Nov 2022 19:11:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbiKDXLP (ORCPT ); Fri, 4 Nov 2022 19:11:15 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F5E62DA97; Fri, 4 Nov 2022 16:11:14 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4KhvCk026462; Fri, 4 Nov 2022 23:11:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=57Y33Ql7G0ZQhSLfkJnFQR+BgFa6VrYeTYMVVAgeDro=; b=taNUfKkSkAL2TAX/pV1lLQ6YDruuJozph9qR1OpI+c8+1PK1qwk/qoWh9g+Gb20W96Ee 0aamDF1nHYmL3hWJmW+X51n2hN/qikRHpPgL+QNYFYccNwA3jAYv0X0xL5Xzze9+9b6O V8cYB87QHR5RNmLhN+wRfsDxdJYa2yZOv+EIgt/I+ubUkoLRBn6+DflX2j10EMf8Wn9Q 85gTDyg4LXol7W7nXGTmzNot2UzafMEiGXN9ZWGmPYT0wT6+40WSXZXbOyHpveWkxTjw Pfg5Z5AHr5Af0Ly3amLpHo7vo3EhStjFNpgJUhMWlZy4NkGiRn7nPreNiQ5JBHZwF6WA QQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgtkdgend-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:10 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4MM3o5013931; Fri, 4 Nov 2022 23:11:09 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2102.outbound.protection.outlook.com [104.47.70.102]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3kmpr4t3wx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=duc/tVT9UY5hx1dkecld77EnQxPM/jYuCStRvhugq7FQ0CTPSILAw21A3SSqlBTpEWnKg8lWl+VVDi2smDijCe95GHyqetxVQOvrLKsK5A16/TcXCIQxWd+EvlLsMdzIOws/dOkEP8SsRBm5S81P3XWgOfrJiKXhVTKGsIL9LerRlZk7k/HqeXGyVU+nwAzuoTO0FLCCx4Edl+ZaG/MZwnSiAnom2XpfZ3KdnQUp7XdjzA62xQ50lQPMQr7XnJBFuym+5V/QfPyPwVvimlIFSFJBjWMAgvT6rSha/XZhSO+jG8aDX/fBBxAr0JTMBUdwBSwPWTMj9If/ySPw+MktOQ== 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=57Y33Ql7G0ZQhSLfkJnFQR+BgFa6VrYeTYMVVAgeDro=; b=XJQ2vcDtS2ev0h7SUb+fz0C50eLbt72160lk+qnmd8rJ9HoXeLy6K6wLkTykdzhKBKU7jZzTVWwVPwF7VNaAQWuQV8Khc8cBCLqDfFgsbeWhnT8ifvNgDv6wHbKFnA8ADGc3b3qjKz8pYS5PTPHG54d+Jh0DW9kVyoITnlrwDTPPv+D1WIaxD9b7hXsU7Ntbt1N35mKupUgXZ8MVO7pR30GckTZnPw6knVvXhXcvlCCy8ar1q0WbaMzgLBX8Gpwor4UTjoS2XuPrgXY1Qu40m3n1tbXpMRAZUufzJ0dLI+jNuToQWf64BU6lPc06V6jbX0+N4GyXCxrP/cNCgiurjA== 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=57Y33Ql7G0ZQhSLfkJnFQR+BgFa6VrYeTYMVVAgeDro=; b=zPTbY0po0lNs7Zelu59G2P11RG898HMda2JgfE8VpLXxyCoSDWymXA9MJi8CeFzBjZlmxjYCu4Zr2OHQR8B8lIgioSfuV4SllVVLk0vo/Lq1SFiuEnL65mezFy+dSasnGmy5FoJNRQlc53N+3EtkZ3yrXV1Nza8wm+2KhNnpfAc= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH0PR10MB4972.namprd10.prod.outlook.com (2603:10b6:610:c0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.23; Fri, 4 Nov 2022 23:11:08 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%8]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 23:11:08 +0000 From: Stephen Brennan To: Stephen Brennan Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org, Arnaldo Carvalho de Melo , alan.maguire@oracle.com, Andrii Nakryiko Subject: [PATCH v2 dwarves 2/9] btf_encoder: Rename percpu structures to variables Date: Fri, 4 Nov 2022 16:10:56 -0700 Message-Id: <20221104231103.752040-3-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104231103.752040-1-stephen.s.brennan@oracle.com> References: <20221104231103.752040-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: BY3PR10CA0018.namprd10.prod.outlook.com (2603:10b6:a03:255::23) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|CH0PR10MB4972:EE_ X-MS-Office365-Filtering-Correlation-Id: a1d54e16-8dfb-4c51-fe32-08dabeb9db11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cy6Rnst1RPyFeYkaEHlzZJ3NNgE7oKTG5F8ic8eVPbqfWZUfFberO6z1gxwMVtegtaqjDDAzctMXk1oxX7nAORnZZ7Xq6l6V/NJErLGb59/zeHPKHHRqAXt+i068Rxn/4Z4Sp65ZawjcH+Tqp3GJ2xoGUQ9i5ZKZKSg6Yo93zjes5oEY0xN1wfLbE4eG15OEYPQ4faNSAKUHApxm/BuTxow4jgZ78cVLfzMaCi4dsIcaQFgtxo+uDoTzhSnBeYhNiQiD8RSJmdNGEQABS6w/fIPZBx8B4qiiB2YqGgUMsfSrAKC8uCnGg+LO/qhW3Ly9QIbdBKzZ2M5PJOB9B2NjmGKyMndhKMSsumvAwDZRUg6xCYi3EhI8ig9QWxlXninSnTfdRKN7aMlw5OywAJQ0Gp3qeAyBE3e8Gtno484G3ADR0lOH2jX+T+9JNxH5Bhrz5Po067hA8dNBWSn6fLMcTJNK0RJyoAKAfjrlqTsYln6Wz5K3uoJw607f2q5TS7cLZFwO26CGG8RC/MbG5RGSBNscqKjVbVThDnNxumPVEmCNVc0rzJMkS1n2DYz+3Iv6XnZsUnZzUNsFkdg0t2xV0FjRFQyiuLLm7ILClcBw9RNFPULmpmytlvKpY3PIlkvzr68h4FPlKb0kA/Ididp++v3p50B2FCLNDzwBXpLq7HyMAWB7i8waNyjqoHyJfV2QaESxsxm3jK8kkfBGtPXO8Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(396003)(136003)(366004)(376002)(39860400002)(451199015)(36756003)(86362001)(103116003)(41300700001)(4326008)(6862004)(2906002)(5660300002)(83380400001)(478600001)(8936002)(6200100001)(316002)(66476007)(66946007)(66556008)(37006003)(8676002)(54906003)(6486002)(38100700002)(26005)(2616005)(186003)(1076003)(6512007)(6506007)(6666004)(7049001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fRrGmo8TZsecjU89NufnBUHrOtSJzJsgCsl8npY1AIu0nzKwL6Dzb+Gh3NbDqczvGMDURSS92TZyUX2hviqYeW4Mrr0Nsbw3egT8Z8ItEwtsD/Yt4bVERRxxDdRQnGax1ak7/H5We0+yeS7aJdhZ/CtEm+biCKBl42iFs0PH3KepC49Vm+qUKg2gTJYtPtbUurGu1W0LDXInF0HqHo/BWidzQgSiux7TJfGdll20tpzUE+rlxE5OZJZhXOvh/OlFjAZ57k1KkfCr8djKW+bG1cPHzVrOYiJqgIydHVBvUPInQFXEDtRaeokpdXgukAvZFX7FCtHW97Peft0J7cbICNfRnt0WhD5jRtIM7olsqxCsIkwB9I88zLG+IKvvQEfSNsRzJGgTwx0YvJdEqgx6ffzngG4BIy+F8babTObNRgaof+pIo5hk+sFldQxjRX07gU3bQG9Pkgho1U3sZBESDqljn+7cN0fgTvHVV+nor2RKgWZ2tFEYWleOH53Ijk0XLSBjvUWLUXiOVD/gyF0Vh7wH4Uveyh8ia4+13YXsVCR+8Qas0t7nx929glsIeOVH6F165hWjJgslgWJzuv9vicYJFuCR77heTWJ7bvZBON79YY8CQyt31tsVSL2x40Ua+1nSf0Nc5MaDaqkgaLISwpX/bF6xffnFxf/lE09AaJ9m9zrwXol97jbGCNU+QWahBxIZTep/UvmkE8kFCldZrhURuGWfX1x5295fb0UHtRtAlPnWme4uBXSkElPZX2/Lr/beOX9jYxQTj0bPF4KHVWe6eczivy6jgJTFrbevm9XGEU2TK8i8aMoDR3ePb/TLNXc4oaeufU88fdue9tlj5XZthp3m8425ZXgnQlPzy3xOlZ1TjBnT99Nw6lK/TRDP5PW/7xlgPleIWN6gJZ9SHiGagvoZSAMagRGjIR7SpWttB+bToM8YAiMvMxn4uCO6K7rFmp4yCp9PAWih3IsETE7ByJ0Gko8q5I6WXaJppnTB7idqmFoTvV5ICQU9kviV4VjNXEHYsWkaoSTUFeMPCALdmBirFfkylui7A7gtgPuFEoCowciuCHJ1pedE+cbRDxbLwFAMlmKH5sz0N8S5+Y5tvI2eMApmzRZa81Pb2Ffu3PPNM3a/394WxgJeLJQ/LQd1WHjgCyKoFNb9FDfys4MzvNE872IYpPlBHijynwh2rb3OECjsZtUyfC0QScUp9OYmzRMtxZ7Z0CP3fCBPQqd1oHExjyHFUHXUI4S4iVZQvE+MpLfmqiM/MOtsocWgewb8dQRFoJSjEhWU+GNiNFGXjSKSsMyzuQAc24T+0VEuOQRJknTEZUPWmp9Nams9pRqJp8/A52oRqgkYhTApyg5VzNpDUpOKwjrnUNc2NvkZzK0RyEpZKVD4v1MsXEWgDnufc/mNFuNE+vBPXRyxTy5didu5R8lfxr0Jlwz3AlK1gC8y3AFhWzRfkEi0OmhyCLaoyBZcgYYom15kvEWnmEmWj4s8yi1WHL9SBBI5qKjUTq0Ee3ytxorDg1+G9edq8iZEYrVUodtqoTnQ1la9b+aSsngHZ8cXXG628oCZi1K6WwfBYVhNGhh2VRQ7mkbwFrdu7DUmQrPBN8PTEE9g2g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1d54e16-8dfb-4c51-fe32-08dabeb9db11 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 23:11:08.1525 (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: bkatUO7TRIx8J1MOC6T9/PkLRPBE1FU/J1kLincAyCYMMD2x+/SZPaS+ursuyQMxmsaFlP6ggiTlDAwedIyz5QDHcv+p4GtdBiEGxJ1gfCE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4972 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-04_12,2022-11-03_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211040142 X-Proofpoint-ORIG-GUID: IsELa3COdVLHQWrtYMR3Eg4zSRy4OcAM X-Proofpoint-GUID: IsELa3COdVLHQWrtYMR3Eg4zSRy4OcAM Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org The BTF encoder will now be storing symbol data for more than just percpu variables. Rename the data structure fields so that they are more general. Signed-off-by: Stephen Brennan --- btf_encoder.c | 54 ++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index a5fa04a..c914647 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -2,6 +2,7 @@ SPDX-License-Identifier: GPL-2.0-only Copyright (C) 2019 Facebook + Copyright (c) 2022, Oracle and/or its affiliates. Derived from ctf_encoder.c, which is: @@ -36,7 +37,7 @@ struct elf_function { bool generated; }; -#define MAX_PERCPU_VAR_CNT 4096 +#define MAX_VAR_CNT 4096 struct var_info { uint64_t addr; @@ -64,12 +65,12 @@ struct btf_encoder { is_rel; uint32_t array_index_id; struct { - struct var_info vars[MAX_PERCPU_VAR_CNT]; + struct var_info vars[MAX_VAR_CNT]; int var_cnt; - uint32_t shndx; - uint64_t base_addr; - uint64_t sec_sz; - } percpu; + uint32_t percpu_shndx; + uint64_t percpu_base_addr; + uint64_t percpu_sec_sz; + } variables; struct { struct elf_function *entries; int allocated; @@ -1175,8 +1176,8 @@ static int percpu_var_cmp(const void *_a, const void *_b) static bool btf_encoder__percpu_var_exists(struct btf_encoder *encoder, uint64_t addr, uint32_t *sz, const char **name) { struct var_info key = { .addr = addr }; - const struct var_info *p = bsearch(&key, encoder->percpu.vars, encoder->percpu.var_cnt, - sizeof(encoder->percpu.vars[0]), percpu_var_cmp); + const struct var_info *p = bsearch(&key, encoder->variables.vars, encoder->variables.var_cnt, + sizeof(encoder->variables.vars[0]), percpu_var_cmp); if (!p) return false; @@ -1192,7 +1193,7 @@ static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym uint32_t size; /* compare a symbol's shndx to determine if it's a percpu variable */ - if (sym_sec_idx != encoder->percpu.shndx) + if (sym_sec_idx != encoder->variables.percpu_shndx) return 0; if (elf_sym__type(sym) != STT_OBJECT) return 0; @@ -1220,17 +1221,17 @@ static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym * ET_EXEC file) we need to subtract the section address. */ if (!encoder->is_rel) - addr -= encoder->percpu.base_addr; + addr -= encoder->variables.percpu_base_addr; - if (encoder->percpu.var_cnt == MAX_PERCPU_VAR_CNT) { + if (encoder->variables.var_cnt == MAX_VAR_CNT) { fprintf(stderr, "Reached the limit of per-CPU variables: %d\n", - MAX_PERCPU_VAR_CNT); + MAX_VAR_CNT); return -1; } - encoder->percpu.vars[encoder->percpu.var_cnt].addr = addr; - encoder->percpu.vars[encoder->percpu.var_cnt].sz = size; - encoder->percpu.vars[encoder->percpu.var_cnt].name = sym_name; - encoder->percpu.var_cnt++; + encoder->variables.vars[encoder->variables.var_cnt].addr = addr; + encoder->variables.vars[encoder->variables.var_cnt].sz = size; + encoder->variables.vars[encoder->variables.var_cnt].name = sym_name; + encoder->variables.var_cnt++; return 0; } @@ -1242,7 +1243,7 @@ static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collec GElf_Sym sym; /* cache variables' addresses, preparing for searching in symtab. */ - encoder->percpu.var_cnt = 0; + encoder->variables.var_cnt = 0; /* search within symtab for percpu variables */ elf_symtab__for_each_symbol_index(encoder->symtab, core_id, sym, sym_sec_idx) { @@ -1253,11 +1254,11 @@ static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collec } if (collect_percpu_vars) { - if (encoder->percpu.var_cnt) - qsort(encoder->percpu.vars, encoder->percpu.var_cnt, sizeof(encoder->percpu.vars[0]), percpu_var_cmp); + if (encoder->variables.var_cnt) + qsort(encoder->variables.vars, encoder->variables.var_cnt, sizeof(encoder->variables.vars[0]), percpu_var_cmp); if (encoder->verbose) - printf("Found %d per-CPU variables!\n", encoder->percpu.var_cnt); + printf("Found %d per-CPU variables!\n", encoder->variables.var_cnt); } if (encoder->functions.cnt) { @@ -1288,7 +1289,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ struct tag *pos; int err = -1; - if (encoder->percpu.shndx == 0 || !encoder->symtab) + if (encoder->variables.percpu_shndx == 0 || !encoder->symtab) return 0; if (encoder->verbose) @@ -1318,9 +1319,10 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ * always contains virtual symbol addresses, so subtract * the section address unconditionally. */ - if (addr < encoder->percpu.base_addr || addr >= encoder->percpu.base_addr + encoder->percpu.sec_sz) + if (addr < encoder->variables.percpu_base_addr || + addr >= encoder->variables.percpu_base_addr + encoder->variables.percpu_sec_sz) continue; - addr -= encoder->percpu.base_addr; + addr -= encoder->variables.percpu_base_addr; if (!btf_encoder__percpu_var_exists(encoder, addr, &size, &name)) continue; /* not a per-CPU variable */ @@ -1468,9 +1470,9 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam if (encoder->verbose) printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION); } else { - encoder->percpu.shndx = elf_ndxscn(sec); - encoder->percpu.base_addr = shdr.sh_addr; - encoder->percpu.sec_sz = shdr.sh_size; + encoder->variables.percpu_shndx = elf_ndxscn(sec); + encoder->variables.percpu_base_addr = shdr.sh_addr; + encoder->variables.percpu_sec_sz = shdr.sh_size; } if (btf_encoder__collect_symbols(encoder, !encoder->skip_encoding_vars)) From patchwork Fri Nov 4 23:10:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13032692 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3DA7C433FE for ; Fri, 4 Nov 2022 23:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229511AbiKDXLT (ORCPT ); Fri, 4 Nov 2022 19:11:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiKDXLR (ORCPT ); Fri, 4 Nov 2022 19:11:17 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 901BA45093; Fri, 4 Nov 2022 16:11:16 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4KhqTo032442; Fri, 4 Nov 2022 23:11:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=MZyQaqsBqs8xlx4aeVUe/+ePpT5BKB3GcK2MunKrlYE=; b=WE0htxSRlJsaAs2KfwDOZ19FVrvvJI1a6R9oGlPUYoI59WlSdgB5fpS2ywXkYch4yzcn PXbl0j8+i4RUjLo6t0MhSHzWUjFb5sEpzZIbdYFRlnim1JyD11nDG8DdW6m0lpBK7oU0 qoClB+pB5wEw/JWp4WzgwtWGIVgJQqYV/B+0eS5wIhNklwrpWjMobAhPYb/LqP6Wg0TZ 8G84jcxfn/Jrj4YM0qIv4xDhVkTEGVovCoO/OZcuTLDxuS6ysAoJwpphzZdTjM+I2n4Q PE778gTKXKyPVj1EI4DEjU/jhkfyiHrcHnrgUhZJALpwjEu/u9sMJGMEQaEpe+YvIEDz ZQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgty3980f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:13 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4JDuPV016531; Fri, 4 Nov 2022 23:11:12 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2044.outbound.protection.outlook.com [104.47.73.44]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3kmpr4t3xt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qyvoylcp6kt/krgceP2aLddOi+Up5lYWCMAE5ndrYF4NfxR1ADHCYk/T1iBNfG6rWSh1trWUuq/xCTvWABus/xSWoAYClkJeZXqMy2wTXy5YmN33Igxhi6m7UpvbjQRUOtfXbid8r0u2Jxf9vPS8LihX7yuAY3Cv2ecRfnz160+Z4UNWTifD7JEi9Hw7FHbMQsT9oVcwHXC8kGOKKbNkim/xZywIsNH+MpUPwUQ8oSlFLIjosDCu3Xw2Ea0sF1pDwWeUTYj0M8qD+Glw1hrNXWs4HS552yPNVSGmSuMs21DUcIRCB5xpyOLoUgDHPqjJ8pPzvjXLhu3pRZYXS71jLw== 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=MZyQaqsBqs8xlx4aeVUe/+ePpT5BKB3GcK2MunKrlYE=; b=hut1FgrHfNKPr+l7wRPmT5UTKKGjlqIuUFDc0ubE6FCHBu8qxERaUr9swb87MHKBhqnMSl/EL3LaU4Ifqd91KMcNx91kvpLwubkpb/rrpJrop9M6wwb0ajmHbZGBeyUyXEfAn7oxM8rX+COlY15Lbto+LEimXCE11+WgARTSpp8lkXWz7FQ/m87wjM2EgIBDiY4blUAFJU8EPoNjoUFbclvfvdUWzCYKi0GhcrgPHedTJcE45AnB1G5FBXLZ68eQQbDv+GzMyQRVOyYBdws/HDJ4aB+LB5krxhfbsP7FHHRzZHKbxENsXhN2FeOvICt1cUZrCicvKCxERd4Am+7/mg== 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=MZyQaqsBqs8xlx4aeVUe/+ePpT5BKB3GcK2MunKrlYE=; b=q4+7u2W4NqEBuxGfKpmh6iETZ9krfcAwzWqL/Q3y+vj4j38CHDbxI7ctLlMoeV5g8lfUNmlvPGGzsv69Sme+fICnc67eNV7NVw+yTo27rpFkf0Zy+k1cx4wchDyAM0dNPGEVUnfwWZb2Rev2Rq5YVZivN/lYSUjO7yU1mvI+Bqo= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH0PR10MB4972.namprd10.prod.outlook.com (2603:10b6:610:c0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.23; Fri, 4 Nov 2022 23:11:10 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%8]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 23:11:10 +0000 From: Stephen Brennan To: Stephen Brennan Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org, Arnaldo Carvalho de Melo , alan.maguire@oracle.com, Andrii Nakryiko Subject: [PATCH v2 dwarves 3/9] btf_encoder: cache all ELF section info Date: Fri, 4 Nov 2022 16:10:57 -0700 Message-Id: <20221104231103.752040-4-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104231103.752040-1-stephen.s.brennan@oracle.com> References: <20221104231103.752040-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SJ0PR13CA0022.namprd13.prod.outlook.com (2603:10b6:a03:2c0::27) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|CH0PR10MB4972:EE_ X-MS-Office365-Filtering-Correlation-Id: ae41c101-5aa7-46a1-19e9-08dabeb9dca7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XiGXgkBFNMC4QaRc1LemGbmSpeI0YmJbHask/SpUY7prM1DDREso+aJqIQCx94/feA1Vey+jsRwK+ytOTFVSu4+O6WWUMPb0Xz/GlDO3DdBxiPMPcAeBIzXx9CRYGvxrWVPBj4hbkKnL7yE4r0P9Itp+Z19kFDtf16a2KMkCM0j27nRzCp79A6VNoOl07+i3G4i68GsA/yZuOpBpwnqUnDGl4x5GwPNhRIyeOHqP/ZHi/8Rimynz5+NtH+pyLY3sDhAAKKlTV/ECSVja1IDOfi1IUJm1di8Ucrl5Q2a16sFtfCaxxQXHQ+Qedu+s9rFDmXz0TeEEiTOzYpydBPq01ccVQgRPHs90/ZEMIsqlDE6F+EPp7HHUYMt4h4Iw8CGxzlEYRUL2m6muT2BWDiZZ/8ZjYVFd8MzTJK+czCNlhIprXzTeVdhfznfTUldx5cwngWOCqjSl7yTywOxpXS2xmCwJqAUdeJp3f8XvXs19FaPdbh9qNA4GixECD5WpOQCMAp6KVW1IgiL+bRiwL3YYQCJYgLnhr0g1KrSD60mVR4wsh7E2+Kyj1pMiRNKvI+5rZPHsKYbDcBrIN6dp8H27Z+7ASvvFOpVkNkZ8lRR5tZrRRWQZM+xB4eTJWtM1CsNlnIdxBxK4nZYF0Iuk69pXoK9WKBTGSt0P/l/Hk2usr2nOvwCZNhSACB4KovQ03dowH3ytTGan8fmWu6a4K9aJKQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(396003)(136003)(366004)(376002)(39860400002)(451199015)(36756003)(86362001)(103116003)(41300700001)(4326008)(6862004)(2906002)(5660300002)(83380400001)(478600001)(8936002)(6200100001)(316002)(66476007)(66946007)(66556008)(37006003)(8676002)(54906003)(6486002)(38100700002)(26005)(2616005)(186003)(1076003)(6512007)(6506007)(6666004)(7049001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: W71uJvYeP8ibvcOD7t79IwCFnIF7Gtp5JYF5dRRtShMZq35zId82BMwpnyytVuNS2J/hsYy3i5H24HUDvUwd7eJyfbum/zRcHvddd94lKohk+hF5u3b6b9Lhuj0RODZx8DDMjIc118zNYVZT83bWZfe8WOnRtjXH7t4Tb6/XTkV9rfFoaqL+2AnmxUPucewtIl4B9dXK2ej7ph6SL/GjbJiz0rNp0E+cTNHA3mQw2p8QTJPIymapHBj64zyaaBLcUWyNTeCQel5hZB6oTuDvkrPzHiiUTIobW1roCxYgGrYMgwepWq9bUFxAlCdm0+oyzPFxdLJPhO1CcwWduNbaWt2T7Sb1M5mIQdaGUrOGjyHVNPZ2Q5ORmlLfORyLasW5Jqc60SN5XM5oVjymsytH/JLtmGrAoUikIaWHOjSHMyGXm1YCFUz6BO9pzgav9KL2LNqwgBJtq6Dl7dmeaozT7/0Vd86+XRGHIT5+ZyMhKuFBlHqELmbS9XrqwCbXoYTjqg7i2mKCK+sb0AdmILNEYOyAPyyttGBW5ZVyBjl/kdaS391JYD02xbng4tgL2k0Mif06L80mmKKNkQz8kxbDCCOTBaaJDjzirmNPHuR6AJTDUORFo/WfxYSprczuFi8ClP/3zsE0dhcpwDhc6/oMmpVTN1sZ0TuDwBHi9Jr2sB1bcAmzkbh7il8ICIA3UV2eTxE7iji0X8Xr/o3eVLuayQSMnl7LROXaZvWraJZJzNaOZPaz9TQXkqp4fRFByz38Dm5vsEN40J0FtacM9RL2k11R8KC7jMsvis5r/pL0kzgd9iXuydkhSWuUy4wT5+FtPLTxDobAwFlZLU6mt+4g49hetCjs4V3MVCXkI5nPxUiHyp8fj4MW1ftmsQEm9JSNRGXTZaXpdQfMZKSlWhAwT94DyxUSuRQZ32pbtfTbYwfvRPa6LvHbxmMK9R7jAJNQbo96KBvi7rW3LqWgJIwUc0TpsVswJ68G2yGLPJpmcgciroUjx+UFDCbT8boLXhJyl2SnbtFgol1utMfBHEyq9AD2v2VL3hfnHnoVhEkLEX9X8AJNW9mTqEpgRSyV7OBNfaihVKCOYfR8kQ2XJeXbbdwTM3xGcH4MFFOOFkQ+5dPpCctIUaBX1xHNwFnXh+o+2+3qlgKEQZjxG3IeKQ9gPjZUivdQVIOo8R5XGO45H30EfFTWlpXYjyUzUvU3cZnyGnAvegE87XCZHBNd/+SALhLO/eY28iT/wSufKUqHziT1sospFSf8i/zPWRIlTU36uC+QhUjd9RJmNzxaN6RJx6VUAsulJ4lvHWFgEvs0zwVqxM/88gprLWopZ0VDUhLeJ9ZB2ic4FRLVr/Sm5g3ymcvdnaDLZtetZ1/r2htZM/rEH/5rJJblPQTlih19TnrcZ1XX9EyigEKGYdpdYOljkMjScf3kHdooYneE1ajNNEW0/Q4vIdUEQvtio/zFxWtYMTczchwcMaU/fy+fjCptBTtcrOjeJTfpBdYwCFU2qH9IbqdSvwI9EB8lL8OoNG/I4zZ0GY5TwHpKycPdgbNdHOVNe3yoCboh4OCAN/IhubNxl4wvVUlg2Zx2h5ZADTFkKqQGubDK7WpCsy+H2ro8rQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae41c101-5aa7-46a1-19e9-08dabeb9dca7 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 23:11:10.8869 (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: uVGROONktehqtcAAqvuDxacqSmJ7A4Hnh1rapi0Q9/IerhiWw0XlUd63RDZ8oHFJzXSeGtOCcFf2uhmcmTXXE3JaJOYS3oL+7Vpc7scNvQU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4972 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-04_12,2022-11-03_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211040142 X-Proofpoint-ORIG-GUID: vKzZuDJVf5atiZIRjo5tGeHTh4dsSH9I X-Proofpoint-GUID: vKzZuDJVf5atiZIRjo5tGeHTh4dsSH9I Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org To handle outputting all variables generally, we'll need to store more section data. Create a table of ELF sections so we can refer to all the cached data. Signed-off-by: Stephen Brennan --- btf_encoder.c | 68 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index c914647..e0e038b 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -38,6 +38,7 @@ struct elf_function { }; #define MAX_VAR_CNT 4096 +#define MAX_ELF_SEC_CNT 128 struct var_info { uint64_t addr; @@ -45,6 +46,13 @@ struct var_info { uint32_t sz; }; +struct elf_secinfo { + uint64_t addr; + const char *name; + uint64_t sz; + bool include; +}; + /* * cu: cu being processed. */ @@ -64,12 +72,12 @@ struct btf_encoder { gen_floats, is_rel; uint32_t array_index_id; + struct elf_secinfo secinfo[MAX_ELF_SEC_CNT]; + size_t seccnt; struct { struct var_info vars[MAX_VAR_CNT]; int var_cnt; uint32_t percpu_shndx; - uint64_t percpu_base_addr; - uint64_t percpu_sec_sz; } variables; struct { struct elf_function *entries; @@ -1216,12 +1224,13 @@ static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym if (encoder->verbose) printf("Found per-CPU symbol '%s' at address 0x%" PRIx64 "\n", sym_name, addr); - /* Make sure addr is section-relative. For kernel modules (which are - * ET_REL files) this is already the case. For vmlinux (which is an - * ET_EXEC file) we need to subtract the section address. + /* Make sure addr is absolute, so that we can compare it to DWARF + * absolute addresses. We can compute to section-relative addresses + * when necessary. */ - if (!encoder->is_rel) - addr -= encoder->variables.percpu_base_addr; + if (encoder->is_rel && sym->st_shndx < encoder->seccnt) { + addr += encoder->secinfo[sym->st_shndx].addr; + } if (encoder->variables.var_cnt == MAX_VAR_CNT) { fprintf(stderr, "Reached the limit of per-CPU variables: %d\n", @@ -1288,6 +1297,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ uint32_t core_id; struct tag *pos; int err = -1; + struct elf_secinfo *pcpu_scn = &encoder->secinfo[encoder->variables.percpu_shndx]; if (encoder->variables.percpu_shndx == 0 || !encoder->symtab) return 0; @@ -1315,14 +1325,9 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ addr = var->ip.addr; dwarf_name = variable__name(var); - /* Make sure addr is section-relative. DWARF, unlike ELF, - * always contains virtual symbol addresses, so subtract - * the section address unconditionally. - */ - if (addr < encoder->variables.percpu_base_addr || - addr >= encoder->variables.percpu_base_addr + encoder->variables.percpu_sec_sz) + /* Make sure addr is in the percpu section */ + if (addr < pcpu_scn->addr || addr >= pcpu_scn->addr + pcpu_scn->sz) continue; - addr -= encoder->variables.percpu_base_addr; if (!btf_encoder__percpu_var_exists(encoder, addr, &size, &name)) continue; /* not a per-CPU variable */ @@ -1397,7 +1402,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ * add a BTF_VAR_SECINFO in encoder->percpu_secinfo, which will be added into * encoder->types later when we add BTF_VAR_DATASEC. */ - id = btf_encoder__add_var_secinfo(encoder, id, addr, size); + id = btf_encoder__add_var_secinfo(encoder, id, addr - pcpu_scn->addr, size); if (id < 0) { fprintf(stderr, "error: failed to encode section info for variable '%s' at addr 0x%" PRIx64 "\n", name, addr); @@ -1461,20 +1466,35 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam goto out; } - /* find percpu section's shndx */ + /* index the ELF sections for later lookup */ GElf_Shdr shdr; - Elf_Scn *sec = elf_section_by_name(cu->elf, &shdr, PERCPU_SECTION, NULL); + size_t shndx; + if (elf_getshdrnum(cu->elf, &encoder->seccnt)) + goto out_delete; + if (encoder->seccnt >= MAX_ELF_SEC_CNT) { + fprintf(stderr, "%s: reached limit of ELF sections\n", __func__); + goto out_delete; + } - if (!sec) { - if (encoder->verbose) - printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION); - } else { - encoder->variables.percpu_shndx = elf_ndxscn(sec); - encoder->variables.percpu_base_addr = shdr.sh_addr; - encoder->variables.percpu_sec_sz = shdr.sh_size; + for (shndx = 0; shndx < encoder->seccnt; shndx++) { + const char *secname = NULL; + Elf_Scn *sec = elf_section_by_idx(cu->elf, &shdr, shndx, &secname); + if (!sec) + goto out_delete; + encoder->secinfo[shndx].addr = shdr.sh_addr; + encoder->secinfo[shndx].sz = shdr.sh_size; + encoder->secinfo[shndx].name = secname; + + if (strcmp(secname, PERCPU_SECTION) == 0) { + encoder->variables.percpu_shndx = shndx; + encoder->secinfo[shndx].include = true; + } } + if (!encoder->variables.percpu_shndx && encoder->verbose) + printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION); + if (btf_encoder__collect_symbols(encoder, !encoder->skip_encoding_vars)) goto out_delete; From patchwork Fri Nov 4 23:10:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13032693 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AC34C4321E for ; Fri, 4 Nov 2022 23:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229626AbiKDXLU (ORCPT ); Fri, 4 Nov 2022 19:11:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbiKDXLS (ORCPT ); Fri, 4 Nov 2022 19:11:18 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 592312DA97; Fri, 4 Nov 2022 16:11:18 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4Kj7bw012094; Fri, 4 Nov 2022 23:11:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=9yq7RzDVaOaach9SdztdcML/yFxc9Zoiy0B2WaUD5Sk=; b=cVnKLTP5G8atg4rAxb9GeTCTHNJKkumkJTMhWMtxdn0YvZiUfQTyYmBPTPNSvg1Cwd54 80X2w9L5apfQSyA9qM+Kva5qVfumcWVm3UYJZg2hvPCcheQX8qgOPdOxWHY0k24m1a7F W4NzXdriaSdf3JNxyiL7AfnE55cevlg5EaPmC5txomAaVO8zaRuWGReRb4WBMNBdK2Hw u161WyxC+7ywpTnfTJDauEMnvprRSm6cpq4eP/3Aqj+O7FTEjSnKPscEQOWTqFtl9CmB +v6WUWDnnqKI6lvQcOUeYlg8v4DhfprogvKDmiOL8V4yTDIwS9Baso+jHTvKaAmKVrqb +w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgvqtshkm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:16 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4Lr0n1011892; Fri, 4 Nov 2022 23:11:15 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04lp2045.outbound.protection.outlook.com [104.47.74.45]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kmpwn87fu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j+G8L7+0w+0lfZ3Ga+EyLRNsjs5nA41BXCqCVJMTlNweDuc0kAEJjvismYwGY7B8TysnUNoVhuRgBlI3V4EYsNDHRvLbDZSU8TyPO/YeJ05Sm0/an5abVj64LYmfG2TKdSSH4xKZIGX67v+m1L+m8drkUvW/NXGh5N8j9CD22XC3fMNyT+uZzSSSU4Vs6b6bVQ+veKMF9xN7LgU4X6P71d9qttgPHAH4vYW6P5sn2Utv3Hd09rn6ip7gh3LkvcAhxJ87dH7pKCM8unEyT+y2s1AARtEwpyQ0Dv0ju0NhYXbkM+vu7i9C+s6ako3CIpJXUKa990jbrPvEePYW4Tr/Zg== 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=9yq7RzDVaOaach9SdztdcML/yFxc9Zoiy0B2WaUD5Sk=; b=ghMUW1twdvSkdYRNNCTrWqQ3MY/Fe9n600A+XP5oriq1eyScUVLreNaFBveLACTHUeRusROO0FhRJTvxIffgZ4wJJ1b9Z37g15Jn+pA/fpLtp0vB/cSpMPn8XH1bvFopg7ADYCzBx1b8tTkYrMOkk6tyacFCu99WSkrgx/o+paeOhVY7SazjP4OAoo7+kmhsnTluEWaKMlZ36mwzXT/GOgkZ/Fn+FLXq3tEWWILw2NS4TQLo4ELukYvcoTnAFz+tUuT7zyBBUz1jHxpefTjDJUcVkWQC+iROxDvFYArlARsiN5ZRdg4/T/V3hQ4hrO2S5qSPiAsWs8xM9agOfXWQfg== 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=9yq7RzDVaOaach9SdztdcML/yFxc9Zoiy0B2WaUD5Sk=; b=IVfvU9UQaahtxLiW7P5r7mOrYBbz5Dzjd5/57ODvJApSs6dMjOzXmxkXhKxfKsweAMOJ9wa7GC29p30OkETCPUDCRs9b+O2RuHCA/3Xd5iKhz/LI/PwhxzCT8Cjs0PP+dx7XmQiXck3Y0YgTis4hscJ35eZk3qY0ah8gR7bxok4= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by DM6PR10MB4172.namprd10.prod.outlook.com (2603:10b6:5:220::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.24; Fri, 4 Nov 2022 23:11:13 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%8]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 23:11:13 +0000 From: Stephen Brennan To: Stephen Brennan Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org, Arnaldo Carvalho de Melo , alan.maguire@oracle.com, Andrii Nakryiko Subject: [PATCH v2 dwarves 4/9] btf_encoder: make the variable array dynamic Date: Fri, 4 Nov 2022 16:10:58 -0700 Message-Id: <20221104231103.752040-5-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104231103.752040-1-stephen.s.brennan@oracle.com> References: <20221104231103.752040-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA0PR13CA0006.namprd13.prod.outlook.com (2603:10b6:806:130::11) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|DM6PR10MB4172:EE_ X-MS-Office365-Filtering-Correlation-Id: aad59341-0963-49fe-2310-08dabeb9de20 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I8LJ3nzUBIdVoOfJlsQYJpUzufpSdvuAxmUUNd0SMQTBWnQukBQPPW+iu6RNTxHG8ar9DIFlQwRUlpOb7YyOG3LMRkfk8FEX654wYkPsdhI+Lmisp7HHW4nT2dbojfzR1hYCrLXvJJjVeHfMZX9QWbXOyYux7+EA2/nGjgIzU2VIojCMZim7ewoKADbqfN+2pwj6fc5PahVgvjhiCNKr8SsYkwTDAGPdyK9wnp26Q76gmAU9uIlIOzj1PLpvW/yWNC31ysa4aqdUO3jNLWtG1UPmC2qS4C4iQ4YvNbsjyKfYBQlqaxnknbsHukwtv2ronKTeiArpKsKhLYMNyXOmlW5BdUNMvVlPLmOk+Qk4XK9v+H7V/KQhbKPU+Ww1zWykxFALutuZdjomD1jj4oIDNAn5mdEWGCsgxDnsAkWbwb7rPudq2mDfosYuWqjf32pHK+X11JOgNNic41HsPpw2DfuCMwlDL3Xk7obqZIVrQ0pIT99uu+kCqG0Bbyx3z6J8MH7Jcr6HYb44QHL4r7H9Jue1ezjaRa2tlecCikurVvfBd0qF38U3Kim0i09Zol0J3SkTiaATCAiaXeWlFMU9odZRuk1rlncIjFfdtLLKCPPXlPAbyG7z/KlZMehJKz/84G6bVyuf41N9EEi0tpDI3Kwe+JQ96f8GFLfYL4+112+k8q4n7BShOHUkP17mJHObed10NLpOZWMpNjKNB66Dvw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(366004)(396003)(39860400002)(136003)(346002)(376002)(451199015)(6666004)(316002)(6506007)(6512007)(478600001)(4326008)(8676002)(66476007)(54906003)(37006003)(66946007)(66556008)(6486002)(26005)(8936002)(6862004)(2906002)(1076003)(186003)(5660300002)(2616005)(41300700001)(83380400001)(6200100001)(7049001)(36756003)(38100700002)(103116003)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6bPKA4nXSdMhqolotBLonB08Ex+RxzyuZ9e652F5AQmQRWg8StOW6pVqt0/FNHN3Lavosk+gTf9bN/cp2ehYIEhLH8ohEqRbAMWYznc/eilSIwsme6IIu+RzGHlfCWleiRN/cLdp2mffDNiYL7Wc/8RzomLyIQKhzbwTr18OfKCqLUHLQIY2GeEpWoWuvLMc1WpicuI32Aj2rX9g/QFH/ow9pAlheWXs1XbiJ/3jw+XZTW+lg8aRXCeIqXa3IxMUzaoHh6DMwSL8Ki3vZuK2ESTTSYj6B8/7FgSbMGySzXS6OUA6Wr3n6XUVFwXdGP+9lScF+ZXcSKE7AXGLGVMG6T0It+pSx9rNiQWeT7kHAAbZ7gUUEdHR6g8Rhe7IWZJM/rsT0yf7ZW+lB5quCFdPLEhj9z7fQGNnbW303SFZgwHypiX9THGkrJetU23ne3O1XiQbE5FIgM/o23aPjB0YHelTAkAxPy17R0sl7wF8FLapxISJKyxfwE65iTQSht1b+GW4UfcPZmCB8b3BqaoAFGUH5ndHdph/yWgOiWFloAPS+1KGu/9hFRH+NC6J23PTcvOMMVVhEejFdwE8sdSG4iiE/GYd400G/V2vvT6ZI2hnZtUFWIvPZIytkvw+QedaWN7z92QxSJ6BVlJ3rK+yTmOSvvHpR2ca2WamgNs5wcT2HxVNHWGJ6EK20FOj6Yay3HiKpogVUcAe9gUtiQ2IwSNy9GDRPLRpFr3HzNLWv7wG5PzMgKt9uU01NZo6iNzB7CW3RfvrLpv/H39rnInhAC30E4V8IjR8SPyNlLrTFE8lSyfogPur9VsJbuEcoPP+sa6Ln+sYW1a6bOf8BHRh2q45dJF5ysyL9RQZd/QF0ah4uBsmyuzFrAAnH1mKfgMRk/TEFwkSlZw/nw5FJTML1tJkRdIIIrOjfe3Qf3PIbWsQD4FV4Si//xfkdUgeab0PhT4GpeTu2v35CIgVF3vWgZSAGM8KmqHalt6EcYd8cAMCw8iYpcp/wzWQmWJBERjzzxn7+CVjDV+UtWm9/QEjrrzeU0llohVert6j1a32Ax5vVkfiB2/qxWGvUkf3q8cptHZdKlLhkijaJn3iHHdxyQZCqB3pPwdSBeDyhF0yUldwGySF+1LUfRiI0cJOZSRhbhAuki1PgLUil85uVwjZS1xK7AAEWLlkXymXRppqkgxWWQAAjFG0jlJn6RfADEUX+sr9rmbmPywjen6Zzr74JQ2MuYrhoG/glriswvva6juJrkE9hH1vRTsco5Nl8UtunyCLGHh/h0H8vyb2hgRnICRnNvls7jGvKpH67RoVhdeeco40CNX8U0QlzXJRnqNTPpBWaJX2jB8gg+oOX/JKpZoUCu+FMVq5DaYULw24o3Bdh6F90CBx3L3UKm3Wmfv+lRW+449l4grQP+Z7LFoVfNIv6JVRfmZxxMEVbbkIqgaGkA7/qFAdejVBn0L+jTwt9y0rtuLfuDwunSO3OcU17tHkzfjtymk1KJfeXXTcWYmWk72VwumdT0C1Q+uvr8QPJ7VsEpZdubVRVlP4Lregxeu87GMBZ9r3bDiUPoqpTLuEC317/EuigEDXFf1mV3hKpHsLpUR1kdwRV/spJzAmxw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: aad59341-0963-49fe-2310-08dabeb9de20 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 23:11:13.2471 (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: 4PnlFHsh+0h4EJiVTjWM5FVzXdUHNnst1to29hYtkroglSFIYuvt6rsN9mAJOgxlI1zTwQvMWXvYlI1PKPYIM17MlkXr2s3YabGgqjI80rM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB4172 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-04_12,2022-11-03_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211040142 X-Proofpoint-GUID: FeOcQ52itw36odVkfwOJkv9qxWneq4K_ X-Proofpoint-ORIG-GUID: FeOcQ52itw36odVkfwOJkv9qxWneq4K_ Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org To collect all variables, we need a dynamically allocated array to scale with any amount. Signed-off-by: Stephen Brennan --- btf_encoder.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index e0e038b..5cd247d 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -37,7 +37,6 @@ struct elf_function { bool generated; }; -#define MAX_VAR_CNT 4096 #define MAX_ELF_SEC_CNT 128 struct var_info { @@ -75,8 +74,9 @@ struct btf_encoder { struct elf_secinfo secinfo[MAX_ELF_SEC_CNT]; size_t seccnt; struct { - struct var_info vars[MAX_VAR_CNT]; + struct var_info *vars; int var_cnt; + int var_alloc; uint32_t percpu_shndx; } variables; struct { @@ -1206,6 +1206,15 @@ static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym if (elf_sym__type(sym) != STT_OBJECT) return 0; + if (encoder->variables.var_cnt == encoder->variables.var_alloc) { + struct var_info *new; + encoder->variables.var_alloc = max(1000, encoder->variables.var_alloc * 3 / 2); + new = realloc(encoder->variables.vars, encoder->variables.var_alloc * sizeof(*new)); + if (!new) + return -1; + encoder->variables.vars = new; + } + addr = elf_sym__value(sym); size = elf_sym__size(sym); @@ -1232,11 +1241,6 @@ static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym addr += encoder->secinfo[sym->st_shndx].addr; } - if (encoder->variables.var_cnt == MAX_VAR_CNT) { - fprintf(stderr, "Reached the limit of per-CPU variables: %d\n", - MAX_VAR_CNT); - return -1; - } encoder->variables.vars[encoder->variables.var_cnt].addr = addr; encoder->variables.vars[encoder->variables.var_cnt].sz = size; encoder->variables.vars[encoder->variables.var_cnt].name = sym_name; @@ -1520,6 +1524,10 @@ void btf_encoder__delete(struct btf_encoder *encoder) encoder->btf = NULL; elf_symtab__delete(encoder->symtab); + encoder->variables.var_cnt = encoder->variables.var_alloc = 0; + free(encoder->variables.vars); + encoder->variables.vars = NULL; + encoder->functions.allocated = encoder->functions.cnt = 0; free(encoder->functions.entries); encoder->functions.entries = NULL; From patchwork Fri Nov 4 23:10:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13032694 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A368DC43217 for ; Fri, 4 Nov 2022 23:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229472AbiKDXLV (ORCPT ); Fri, 4 Nov 2022 19:11:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbiKDXLU (ORCPT ); Fri, 4 Nov 2022 19:11:20 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0EA12DA97; Fri, 4 Nov 2022 16:11:19 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4Kj8qx012149; Fri, 4 Nov 2022 23:11:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=qLOdeY1fFim8ihP5Q1df1e0hBCppiSAPmtlDZF6xqiY=; b=qTT5zj/EyswCwE1QIsvWiUzXEZWaHoAh6JzSylxrxTFA3HJv/u18ynt8aToEiv8FYF3N ms/VUiE73LWTyOfCc1zaEGq8AL43An5vcWH03OGQDW9kMA+v4E9yHT+vH+d/cJu2zBvV 5S5+vTjRu5Q7pVdfrtabfq4G+M5LGuOnO5MrlQ2VSSFTlCD/Y942k/AIwQBCwB/OInKp 9oXwLDzaulyh02bIjr8TOd4dNfKU3ln5ZF4zqW6vu8aelAKRV67AHGC2cV90TLZdGZKE c4UT6+pi8gJ2z5I3mldomOl/v5ZuO+tAKPP1V6mxRTX/hZl2NzbsqdocnXoG2Qi1mvGj WA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgvqtshkp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:17 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4MI2DB012011; Fri, 4 Nov 2022 23:11:17 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2044.outbound.protection.outlook.com [104.47.73.44]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kmpwn87g0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BJgtMyrVu02fx+GuXK2aZeqhP3xRsNy67B35Lltzj5/uxwni1FOZFQwMg0OTC8acwnzi8PQywXJcqxvL4+X0dXU1PU8CJDNshnxwCoU3oVmwETIchosspWqVUPpwyJtu9yzkrOl4FrTl62vdoRUuSodlRUMNvDpBHTz5aTjk2YwYHXL0G8tJgI782SA4JsauWpmXz1i4LtNEYCoZwZlxWsdcEFBfJPa0JhRbl2SfRCpYAsZKKHVGxsVIT0dRBvWTNZ2NPBowr/o8hJG4Y65M3qICGts455a+m5JD/gPk9k15PcZ8PMM2CtGnFaw04pqOa2zUB0Tl1QfXCG84t65mkA== 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=qLOdeY1fFim8ihP5Q1df1e0hBCppiSAPmtlDZF6xqiY=; b=ZZlSHn76noLUFhD74vNJMF/DxicKap+OfwPu5ZkQSFLcBK8MGvevjPmJ6Y3NVtTHYrI52HIty4VCdXspgOPohcjqplp8Msa79qRTL02EhH8mLmdIC+P+bTGcF5pHlr2JzJG+5Mc4rJ0/InzYJoEgrPRqRN9rfSQHAQfQa++vf7AQfhYfs+F3gPxiDn76Sc3HKnTdlPORs838EyMw7QRPfGF3FrgYOYyn0M7AT8NICsMAZuO760zqGwxRlJa1+ucvSitqjZAqgpmgtmo+h8IG3jgDTf0TqbKIS4Y8Q5eIymy18YjZUD/bIIv1J+XJAarkD52dGDrelkj2SgLtAvCeBQ== 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=qLOdeY1fFim8ihP5Q1df1e0hBCppiSAPmtlDZF6xqiY=; b=hD3+s54HAR4ow1hl90GBSAK/wkvwr0Z6fda8YrerA2zrvg13ybb964HZIAoRx15zz2GYVk1RQqcXqEBil+Q4O5ykZQpmVR+iJi5/Y0h7Sm2d+WLUwe/SJh5unZmeDRfoBBkIB35gzZjUI7KcUcLHgGc2sFHIOrbchh+a9UIq7JU= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH0PR10MB4972.namprd10.prod.outlook.com (2603:10b6:610:c0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.23; Fri, 4 Nov 2022 23:11:15 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%8]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 23:11:15 +0000 From: Stephen Brennan To: Stephen Brennan Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org, Arnaldo Carvalho de Melo , alan.maguire@oracle.com, Andrii Nakryiko Subject: [PATCH v2 dwarves 5/9] btf_encoder: record ELF section for collected variables Date: Fri, 4 Nov 2022 16:10:59 -0700 Message-Id: <20221104231103.752040-6-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104231103.752040-1-stephen.s.brennan@oracle.com> References: <20221104231103.752040-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA0PR12CA0018.namprd12.prod.outlook.com (2603:10b6:806:6f::23) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|CH0PR10MB4972:EE_ X-MS-Office365-Filtering-Correlation-Id: 619f7005-5941-4c38-bb07-08dabeb9df6d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qavYlu/LRKxsVsOkDWxg42MCk3p7pfmklldLtQE4wAwMXjBv3Z5dbXKkSz5AZM9yj3V4nDGk9lMQ9OsoF1sWBbpBPnqxolQnM0PlPKUUu366wYyeblfUlCqTdyv4D4R1jL+hG1Ha1tadboqYZ3r7v5f2wQOwzeO/hbDytt4MFWPBuXZSBWkcJRmjsBppWuxd9TbMxknUQb4P8JgRTwtZtWWmUa5U9g4x0o/VaYQd12+1IG+EYxfRvqH8DUlF0o8l1oLqzZApJRNNxR0/C4gsWyHGVJ2AzcmbVzExZxauAyBIgvl29l+7LNgOtt5VpNpaP+44QCgBgk40WhaNd6NOXF/uVVz5lKmtN1V6yxTj7Tx911fdO+LafAzf5XlY7ZKrn4bBp2kLSI2bh+tjtffezHtNNiUaaQgb0nE0LepX7HYwX0n5r/gURtfnKvbYb38f6gHaQeVxTv/lrvxpG6cJZJ4qPRwgTYDbe6JYaTQQt5ELtzIeAkY0hTab2bF6qf4k5RxuQSpfx7MqyGqM8wk/RsUasReksMgPExG/EDogSeo73Jf7fWtRTjY0Ns1GJkRfCog6HrwouMjBmJMyZipQj1bJpwOaKNH+k2wK2G+vZLdUWfdSNBkpIA9ASiuKde2K6aSaB6HT+cCCTfpYQ0BfSgrYVGN9ymTOcXXwmF0a9e9tLPOud4ZLUGDqH95MwtXdJ/ND/R4urjTVkZeXHCAAxA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(396003)(136003)(366004)(376002)(39860400002)(451199015)(36756003)(86362001)(103116003)(41300700001)(4326008)(6862004)(2906002)(5660300002)(83380400001)(478600001)(8936002)(6200100001)(316002)(66476007)(66946007)(66556008)(37006003)(8676002)(54906003)(6486002)(38100700002)(26005)(2616005)(186003)(1076003)(6512007)(6506007)(6666004)(7049001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 06vAiVSlfit7WtwOmX/d8sk/zRo7eo1zFhsh7nGeTaxnFvnYPjTmjVAWHQfLriF4tCi4llnPLpJkZtL5zAlrPR0KBYk2gXEWM/4jKAh4E0j7GF2OUVlvizXziRgrh1p+j3A01kOAY/DCNPnqzpHabg0R4G4hXypvpQ1IicrJP1EplDV0WEeaLOzvrOV35QJMmkYcRUSHH6O5uLhU9a6woFasC2EfSbWelSYaMY0QZmDCGa9p7vz+LgeIPVp6vfS8OmE55HRz6evUngGU1Jno0elcuHeY7TvklTDFWubIclDu0UhEmzp0K4u5jsiNV3CfugDVXQO82JLuV39efJYk2WBsNa5MxmM84zg1es3wRVBNEDFTYe82FEf4iuQdjDnP5tGFhM1L/x4owEDb6f8gLZ/6FCEUeqViL3WgbBISvq04ryn+FVnQdTqZ5mYJEMuXIxZvYCNYQgBJY111MhOolwy3R1spA2/4Sk40o9WiiD6JWk0SyJhd+5xbSAJzKEsv0H+YMUT8a2TZJ9mikJa87Hq2Qvw4emBYh8ivRJMKbN/RBMlfeZrrbzsG6Y5SFGm/MGPldVaJK1Lfx1UujvJGkQsKUp7JOyV79rj08J4uX6qXSx7fM3am5+PqHG3/FDMg97OnVK/U3WeUiUbLjCIv43Y/iaArFofImgP2nB1ETCK5XEdxIncGZYT8H4BmnJ5C7BIjQtkV2fHbaIelEIMYdBpTU0ZmBsfFMB05uV/adzV4I4tMF1rF1qAjwTn1H6UloM75tmofLRbYkkzqY7fUOaWLm68rPuhapsDpfrAGvS0tzJiJ1ao/Gw/A//fTTN8QECzwCwcWV5si+oJ6CaFrWJZldnrUeneRJQsUYHnZiEb/PXaMTpP4rGAbJFXsAAI1icFXINEJ+jAyHTzbIVMMXT26TFsQpsXqAZrMpNUY5cqzLaIQd729Brjnug0z0HLvZbfwgXbSMg42nDtKrdCbN2r6RUZM6ty3/iESPDncE+ZQJWU1TiQQ+G9Cb9y8cnQd23WaDGL+Otpqkst3aUNjcRbvphf3EMjlLbkPyNIkimwuDNFlJtxwfNVLjW5ttjSll/8UhDK1fR/Zy0n+1f+e23xwPSKOjKhE/AK4ThnyolwG0LObJioxt7mO0hsGUx5trodYBqbEtx4B3U3Bged6uPvU0Zq1C4uLlE8XWtqPMIRZAZlf4W1BMIdMJJC58MumCRijneZBsL5COeDD4hAcN/ncg266qXgpU6hF2r7x2jm+yAf6pv7A69n/i5HysEEN8rBzVT4vKUSVylgWEz7BJRhW/b0uWlLnL0vhVbO17ebu2iHmlqzihw4Oh1Y2VW1Q+2QrxcNNEzysxccmHa1Yt2A1pAA4zi27n93zpmL4hhkxnoW4aayQm9avaMU9VaKdy/xWehNG+Hq2T37HsTgJm+lYQdeytIf0EoiOquil7ONmGomGuatck3C+v6glqzONZjsyUVtDXqI3r2c+R5KBN9U6SW/iMX+kgGbOutK9PQTMLSm+hboLQuKUzhfZmJN08kWz99WernMLEtHbW7oV/Q6GCfk+ujMXQbEX+pgzhKbIOqg/WXLsj/XLGYDa59m/QIBAef1g1++PKN0J5aP3hw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 619f7005-5941-4c38-bb07-08dabeb9df6d X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 23:11:15.4491 (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: iiCgO0a+EQT176tcokSDuN09mBtVUHPLXInjQ8BG0bcdn+alUokTK2R6F58KJ8uAQfiODdTFePoFMaWUazaennqiGYTdjF9Y/v8FcSemb/w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4972 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-04_12,2022-11-03_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211040142 X-Proofpoint-GUID: oXogAOEffQa49Y93hna1UPV1t9Qr7VyU X-Proofpoint-ORIG-GUID: oXogAOEffQa49Y93hna1UPV1t9Qr7VyU Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Signed-off-by: Stephen Brennan --- btf_encoder.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 5cd247d..d1f2f38 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -43,6 +43,7 @@ struct var_info { uint64_t addr; const char *name; uint32_t sz; + uint32_t shndx; }; struct elf_secinfo { @@ -1194,7 +1195,7 @@ static bool btf_encoder__percpu_var_exists(struct btf_encoder *encoder, uint64_t return true; } -static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym *sym, size_t sym_sec_idx) +static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym *sym, uint32_t sym_sec_idx) { const char *sym_name; uint64_t addr; @@ -1244,6 +1245,7 @@ static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym encoder->variables.vars[encoder->variables.var_cnt].addr = addr; encoder->variables.vars[encoder->variables.var_cnt].sz = size; encoder->variables.vars[encoder->variables.var_cnt].name = sym_name; + encoder->variables.vars[encoder->variables.var_cnt].shndx = sym_sec_idx; encoder->variables.var_cnt++; return 0; @@ -1251,7 +1253,7 @@ static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collect_percpu_vars) { - Elf32_Word sym_sec_idx; + uint32_t sym_sec_idx; uint32_t core_id; GElf_Sym sym; From patchwork Fri Nov 4 23:11:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13032695 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 426E8C4332F for ; Fri, 4 Nov 2022 23:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbiKDXL0 (ORCPT ); Fri, 4 Nov 2022 19:11:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiKDXLY (ORCPT ); Fri, 4 Nov 2022 19:11:24 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54DD53FB87; Fri, 4 Nov 2022 16:11:23 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4KjBAx013373; Fri, 4 Nov 2022 23:11:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=2mDDruQQ3d+FjQLfJs1t6LrB3gnIymPbDk58QYGvWng=; b=PknsttF/L2vWH2rCPFXr7XIZeckJCwfU8UIwVb0ng/XUWXXo9EfT0J3GWV5UyufnT/fd /xxEm6D1R14yF/beJjYbCnKbDbNfSnTJhyiXwK2thFp2y5LnZ10h5nyIei6OzVS3d2Vd OGfiT2rpZZVu3LgnSYfxt/QO1W5p52MWKS0L5IE4IiE7wIlrYT5yvPgubDPezpofGvFl /jfaxHPZ6J4QU+p7g1Nd2JqVEPK5fw4+PI6F4y+HkG5qyNEjYPb+7m1N0BqPS8IeeQzA GnE6AB4p8BMFSj8l1K2L2yqReBg55ngwEkGhj40BxYgGFfrLTYlhZuOBg4xqgsztnxZS jw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgv2as1a8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:20 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4NA3QW013930; Fri, 4 Nov 2022 23:11:19 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2048.outbound.protection.outlook.com [104.47.73.48]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3kmpr4t40u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VgyXH6SO06B/IrkF1L5d27GMgCQkex4yMDzTIBjnGFO3CGforr5Bgxatk6aYrJT8BRkxwT/8EKKAii2b/19FGNhejkGB446x8ss2UAEwjo9gJtqBOGMLim+4sNC+WW9jGdoxLaWYT3jsbtie27QdOC8TvChOsOMsswwmoDL/GlMtE2odsDbDHBC4m4+EHUnJ648w29gRNBclc6mMj3WDUCp7RY9b3y3Ob8bxGfYKIsyKPWKcFdFSm1WwhJW+/TP7jNlxTCZqwENRoJYniIhaiA6kTVkAm1pTTHfKpjPHtaMgGnCh7Byj2dT0Q8JjaB/OhqYspBA8CD1I+4cyE7xp0w== 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=2mDDruQQ3d+FjQLfJs1t6LrB3gnIymPbDk58QYGvWng=; b=Ud98Bpewk/ENr5jOWFAsPnpRyNuIJjrfx+5wAyhCSzAMoZygbnaPpYtK2xjtQlkWVtGXZdF5lsRBPpWvK65tSQlWvSChJ1I9W19eLCRY9KsR4gkXAV6CGKHPhf2L/eshk9W3+A0EVhkK76CKKN25wzKTOKWR2NECVy7DnQmWUWS6CvkHyui62A4owelh6MVKdxZBMdSzHaaaJp/+rZCta3Ltr+R5CWPEmSykNJ3Vq4bdDkFjtXaUUbNPgYa8h+7V6qdiXu18yNO+VbETsCzj8S+8/BZGj8LaHwVA3E40GnCHUH6KNo+RsFK/y8D1WpfxqPcNADHDf7DXEmGTYL77fQ== 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=2mDDruQQ3d+FjQLfJs1t6LrB3gnIymPbDk58QYGvWng=; b=L8iHXIS06JXUF8LXpwMi2N/DZsOMHOtHeD3QtJWoDfta+6XDL1aFGf2WmfKnSxfcRBq6g1us4HFaAzTP8fDmBVNHrvd3FqtthuLaJxuLJN8hSk4FD9J5os41QyBP/wUEQH75m4GZa2Lf5Zm60iuxeDrn/p7qzGfVTLbw32PU6KI= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH0PR10MB4972.namprd10.prod.outlook.com (2603:10b6:610:c0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.23; Fri, 4 Nov 2022 23:11:17 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%8]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 23:11:17 +0000 From: Stephen Brennan To: Stephen Brennan Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org, Arnaldo Carvalho de Melo , alan.maguire@oracle.com, Andrii Nakryiko Subject: [PATCH v2 dwarves 6/9] btf_encoder: collect all variables Date: Fri, 4 Nov 2022 16:11:00 -0700 Message-Id: <20221104231103.752040-7-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104231103.752040-1-stephen.s.brennan@oracle.com> References: <20221104231103.752040-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA0PR12CA0015.namprd12.prod.outlook.com (2603:10b6:806:6f::20) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|CH0PR10MB4972:EE_ X-MS-Office365-Filtering-Correlation-Id: 2869aa9f-fe82-43bf-30f5-08dabeb9e0c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2Wa5SbN/l9oCzAIY3MWx6iQ88dwAT+rtigsH2NPCYCx/FdJBkeau5Xt10Ketk3Gp+RQj+4jpPTTkJT1X1Wtn1mpsOcHxLnQNebxI5AcJ3Xlsn9KMuYRSE6cbHKFK4/ld32yadSKZti0FMmUV5Q1tKsWUGK4bnIXfPEM0Ll4SOb1+wA+YZpi49t73y8Exw1UNEaoywok+ccnoytpahSF6BTVtEX7qaW1lebIulw+1PYhwBfN83fB4xC9zgd4ZrWmZ+dPjg8eo0MkwYFL/ynPNcgdSWE496UarhE/bi+nMGqPLf4mTkVKebxQCve0oL2ZSWkUsssWBIY4yY0yIKEhjdRqVYUubzzVCGrmWKB+uIghECjZDefeOui+jJ4f0PuWwAXXwEIDQuE7mJoaF6IlNnMufZlcMmiQnA/HD1O9nBUezfk03i3U3lziT9YNEB3zys8pqj3quAeE+yhdQEutSbHZCosVP8MHRtl15/+Nqp60luXdLU9Id48f1v0Bo87PXvjC3y+3CAXsHr72kMkAB4HnciIetBI0iylHgEsRKMvTdCqPbuVqxKFwHGnwLByC+RzFK/6TeNw0eZyt4/xSmTEBMCW+D08W7Kjwi+TT7zHdvnr0g7htFMtqc/1XxoLMukFnZYzXM62mfMhT1e88q3lOVKgpgV3iASPOOuQXrun+11fgKX2mRvyFLA9AYYB/w/0E9rxtE8p9qS0ZSmeaBBVlzEDfyWS8E50ziZqtYZBxUgidv6qB70YO8xnLNpxRg X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(396003)(136003)(366004)(376002)(39860400002)(451199015)(36756003)(86362001)(103116003)(41300700001)(4326008)(6862004)(2906002)(5660300002)(83380400001)(478600001)(8936002)(6200100001)(316002)(66476007)(66946007)(66556008)(37006003)(8676002)(54906003)(6486002)(38100700002)(26005)(2616005)(186003)(1076003)(6512007)(6506007)(6666004)(7049001)(21314003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ImpMthO610HE8LCpwtXNvCx40s3Y6cowt6uwgzqv52zLTutZul7FdO6ggxoPWQh4RMC69np1uoFzJkxhVWRPZPg9oNcGq38Fo2f7LiE7s22If72Ybs4wpqpNk3XLPk2t9tKmy+HddAzRiiBE1UzQKEHrp2R/+pczXWkqM2ktoWvsM0UGc8XDiSIsCVtvinBsfcLkspYEjQhrlwMRvugcT+8rZb47GupcR+BAH155CLwvADRVE0XDshu2mEmZbHSgoezuoj1d+0kFfLJ0344JDAalYFy5/TsdBkNANFeIL7lM31JpES7wh3p4FDwVRTekOFwPxR8+qcV4lak6+IDtxq2K3fHLfm112jUY/m7B9GVgVFuiwVKVJC8baB8G1jj5Xb7LwEsWIY+fbEK2wUWZpS96fjyCCDG54pWRabULq6gvuFCCE4mFI14K96WhiPqk53CNKJuae+tWRrEiufOGi/ChsEfF0WHVPkyuIYni3iupz63Jtt0CffotAM1wmzLCscB45QDbnAynNTBIwLy24j07ZXm+dB33yZjjX1Jn10d4zFbF5mCY7mhMDJVJaYC+GSg8LU6NVowXehiDixKBgVlMIYgt9cGkIKLTtisJ5gm+RRskfgEfjsIAXw863p9D3s6q3zPUgseFbNluOTaT3R17cRNVl+I9ZjcOwixWVZJ3uH4lrg4XwlrlIxZH0KnIQVr+s+/hAFzNBMrfHEOZBiyVS+WIUQQvuI25+8lvDSX3VHHTsPTqLbnWu7lrf60XYno31jmxPLoWdUCuVv1fuOiF8cqp4wM2m+hOetaBI7cSPSdEuU9WcvzrMJu928KFe1x160QPZoEETwJxPY2arqmtUygUpaFcl40RJLLX0PtvFmfJohXyOJF1qKod8yD1Uo4cUsBeHRs28HwA8wJi+hx5NWUYtsHCgd7mECIO9LH7WSylxBH+VsPFOU/gDzOBA2+zGN+mhJOofsG7SWFhlURN+nd/UYir3Q6Oc6yFhjSV49BXOzyP4qtMiHEKM5eMzihPXi5k5jlsTqEBwcdn0/RaZDocRZFU6NOa6qvK38afmQNaOlHsOxp0O5nkrcPkfa5MO030u4GiDzpGBh8pofK7Tqy+p6Ijj083cNe64hWztHZBckzIHPRN4k0N3Zc+Z+pGzlqXnehf0woWu6wApe24v8jvtiwXJ6RUtp6ZC4leKQ/BfjE7mLvS0QQ204rRdsYYg/1AcRmlUUB2snB7kGxq8t3jTOe2m9SgcBMwOfsflX23ZER3l1M0WxslpogVSpy8XbK5a1iJ3iNMgRUmLOgaSeGuz7vMcxrDGpwR50srtnTKodOIFJ86lAoNPvwfhjR+TvyOQd2xFvyFAqZGXhdaxHb3+L3mVHEhs+nWu208lit6n7yRqbQMSxcj6iLP5oHjMq5Th1aZyHIi0/bmOAj5pABPRG+eTtTHVJkY9h37wzMjcKG3+wDRV96qgs2iA2BHeitm/U1WZEBjlXaDq694pBnc9mp0ymC8wxKGdcqawF2MKTNyZrmDd5RjZ/GK7GcH6qlDT1K4gam4/89KRwGD+TLtDl1TXxdOI6QYIzME4h92F5dySMcLReV2UVIAmlBIZpKswUv5X/hENqVa+A== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2869aa9f-fe82-43bf-30f5-08dabeb9e0c5 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 23:11:17.7167 (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: lkm080dgP/T6c3Ea2dY1pMyLa3sbLr1bLpkecuf/ZX8ZmnhI2o92Nr4wlg/TocTFRN2+YZyRfPgz8U0yGAthfJ0/PWw7Lr3pILCW+71KvUM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4972 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-04_12,2022-11-03_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211040142 X-Proofpoint-ORIG-GUID: LLb8U3G1t-22v-YZZ_B5cc4fM5vnSJOp X-Proofpoint-GUID: LLb8U3G1t-22v-YZZ_B5cc4fM5vnSJOp Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Prior to this, we only collected ELF symbols which were in the percpu section. Now, collect all ELF symbols of type STT_OBJECT, and rely on the setting of "include" in the elf_secinfo to decide whether to include in the final output. Signed-off-by: Stephen Brennan --- btf_encoder.c | 70 +++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index d1f2f38..f7acc9a 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -1172,7 +1172,7 @@ int btf_encoder__encode(struct btf_encoder *encoder) return err; } -static int percpu_var_cmp(const void *_a, const void *_b) +static int var_cmp(const void *_a, const void *_b) { const struct var_info *a = _a; const struct var_info *b = _b; @@ -1182,28 +1182,24 @@ static int percpu_var_cmp(const void *_a, const void *_b) return a->addr < b->addr ? -1 : 1; } -static bool btf_encoder__percpu_var_exists(struct btf_encoder *encoder, uint64_t addr, uint32_t *sz, const char **name) +static bool btf_encoder__var_exists(struct btf_encoder *encoder, uint64_t addr, struct var_info **info) { struct var_info key = { .addr = addr }; - const struct var_info *p = bsearch(&key, encoder->variables.vars, encoder->variables.var_cnt, - sizeof(encoder->variables.vars[0]), percpu_var_cmp); + struct var_info *p = bsearch(&key, encoder->variables.vars, encoder->variables.var_cnt, + sizeof(encoder->variables.vars[0]), var_cmp); if (!p) return false; - *sz = p->sz; - *name = p->name; + *info = p; return true; } -static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym *sym, uint32_t sym_sec_idx) +static int btf_encoder__collect_var(struct btf_encoder *encoder, GElf_Sym *sym, uint32_t sym_sec_idx) { const char *sym_name; uint64_t addr; uint32_t size; - /* compare a symbol's shndx to determine if it's a percpu variable */ - if (sym_sec_idx != encoder->variables.percpu_shndx) - return 0; if (elf_sym__type(sym) != STT_OBJECT) return 0; @@ -1262,7 +1258,7 @@ static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collec /* search within symtab for percpu variables */ elf_symtab__for_each_symbol_index(encoder->symtab, core_id, sym, sym_sec_idx) { - if (collect_percpu_vars && btf_encoder__collect_percpu_var(encoder, &sym, sym_sec_idx)) + if (collect_percpu_vars && btf_encoder__collect_var(encoder, &sym, sym_sec_idx)) return -1; if (btf_encoder__collect_function(encoder, &sym)) return -1; @@ -1270,7 +1266,7 @@ static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collec if (collect_percpu_vars) { if (encoder->variables.var_cnt) - qsort(encoder->variables.vars, encoder->variables.var_cnt, sizeof(encoder->variables.vars[0]), percpu_var_cmp); + qsort(encoder->variables.vars, encoder->variables.var_cnt, sizeof(encoder->variables.vars[0]), var_cmp); if (encoder->verbose) printf("Found %d per-CPU variables!\n", encoder->variables.var_cnt); @@ -1313,17 +1309,19 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ cu__for_each_variable(cu, core_id, pos) { struct variable *var = tag__variable(pos); - uint32_t size, type, linkage; - const char *name, *dwarf_name; + uint32_t type, linkage; + const char *dwarf_name; struct llvm_annotation *annot; const struct tag *tag; + struct var_info *info; + struct elf_secinfo *sec = NULL; uint64_t addr; int id; if (var->declaration && !var->spec) continue; - /* percpu variables are allocated in global space */ + /* we want global variables, or those with a definition */ if (variable__scope(var) != VSCOPE_GLOBAL && !var->spec) continue; @@ -1331,13 +1329,16 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ addr = var->ip.addr; dwarf_name = variable__name(var); - /* Make sure addr is in the percpu section */ - if (addr < pcpu_scn->addr || addr >= pcpu_scn->addr + pcpu_scn->sz) - continue; - - if (!btf_encoder__percpu_var_exists(encoder, addr, &size, &name)) + if (!btf_encoder__var_exists(encoder, addr, &info)) continue; /* not a per-CPU variable */ + /* Get the ELF section info */ + if (info->shndx && info->shndx < encoder->seccnt) + sec = &encoder->secinfo[info->shndx]; + /* Only continue if the section is to be included */ + if (!sec || !sec->include) + continue; + /* A lot of "special" DWARF variables (e.g, __UNIQUE_ID___xxx) * have addr == 0, which is the same as, say, valid * fixed_percpu_data per-CPU variable. To distinguish between @@ -1356,7 +1357,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ * per-CPU symbols have non-zero values. */ if (var->ip.addr == 0) { - if (!dwarf_name || strcmp(dwarf_name, name)) + if (!dwarf_name || strcmp(dwarf_name, info->name)) continue; } @@ -1365,7 +1366,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ if (var->ip.tag.type == 0) { fprintf(stderr, "error: found variable '%s' in CU '%s' that has void type\n", - name, cu->name); + info->name, cu->name); if (encoder->force) continue; err = -1; @@ -1375,7 +1376,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ tag = cu__type(cu, var->ip.tag.type); if (tag__size(tag, cu) == 0) { if (encoder->verbose) - fprintf(stderr, "Ignoring zero-sized per-CPU variable '%s'...\n", dwarf_name ?: ""); + fprintf(stderr, "Ignoring zero-sized variable '%s'...\n", dwarf_name ?: ""); continue; } @@ -1384,14 +1385,14 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ if (encoder->verbose) { printf("Variable '%s' from CU '%s' at address 0x%" PRIx64 " encoded\n", - name, cu->name, addr); + info->name, cu->name, addr); } /* add a BTF_KIND_VAR in encoder->types */ - id = btf_encoder__add_var(encoder, type, name, linkage); + id = btf_encoder__add_var(encoder, type, info->name, linkage); if (id < 0) { fprintf(stderr, "error: failed to encode variable '%s' at addr 0x%" PRIx64 "\n", - name, addr); + info->name, addr); goto out; } @@ -1399,20 +1400,23 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, uint32_ int tag_type_id = btf_encoder__add_decl_tag(encoder, annot->value, id, annot->component_idx); if (tag_type_id < 0) { fprintf(stderr, "error: failed to encode tag '%s' to variable '%s' with component_idx %d\n", - annot->value, name, annot->component_idx); + annot->value, info->name, annot->component_idx); goto out; } } /* - * add a BTF_VAR_SECINFO in encoder->percpu_secinfo, which will be added into + * For percpu variables, add a BTF_VAR_SECINFO in + * encoder->percpu_secinfo, which will be added into * encoder->types later when we add BTF_VAR_DATASEC. */ - id = btf_encoder__add_var_secinfo(encoder, id, addr - pcpu_scn->addr, size); - if (id < 0) { - fprintf(stderr, "error: failed to encode section info for variable '%s' at addr 0x%" PRIx64 "\n", - name, addr); - goto out; + if (info->shndx == encoder->variables.percpu_shndx) { + id = btf_encoder__add_var_secinfo(encoder, id, addr - pcpu_scn->addr, info->sz); + if (id < 0) { + fprintf(stderr, "error: failed to encode section info for variable '%s' at addr 0x%" PRIx64 "\n", + info->name, addr); + goto out; + } } } From patchwork Fri Nov 4 23:11:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13032699 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8BF0C43217 for ; Fri, 4 Nov 2022 23:11:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229833AbiKDXLt (ORCPT ); Fri, 4 Nov 2022 19:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbiKDXL2 (ORCPT ); Fri, 4 Nov 2022 19:11:28 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E7863FB85; Fri, 4 Nov 2022 16:11:27 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4Kj7ca014044; Fri, 4 Nov 2022 23:11:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=500kHVvNpjLERXwFHkww0pUF7hsApnR2IlUPDBUZMaM=; b=DZUZY56V+OIgyfZ3Ol1w/us2hCTIckDDRqwozb8yrTK2Is8q7UOzZhSCCbIw0Tzf10xF S4CXqe+XokBJ0SXFCaY02x1N5SBOOMbpoW+RL+tezRx21xRw6/BVg2RSUCfayJpZIP52 mVWi8Pay0nksYhIiQdKPWXDT7kVBQC+GDiD63dPfZshABvsZyAH2oM39J+XhFyMvz0jT Ae6IBKPaXKTqviS4KswEd1UTPYpy1UVt6nYHNJgKARfLAPPVaiTPT1cXiF1VNdVluJct HTPdZFjYVRpRZwFVGm5zWnwZVTuvSLDN3/WgzWZJdABrBR+MjGyfkmdWx6fEZ0sgmNA+ 4w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgts1hgp5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:22 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4LATDI031957; Fri, 4 Nov 2022 23:11:22 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2048.outbound.protection.outlook.com [104.47.73.48]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kmqb6r51m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LHQVmePMbY+T96moRLdUs/QBBz8kT8zwQj2WD+7xex6oyGccy7/w8CO+5u+UyyRhDyd+TwFl23qpRyeDwaspS3u22+4ezTqEqTiLhZ8HVGTCsxuVeTmvZJ83gESHoSyfA/LaxX/3WwAaBcniOHN2o9TMGje/axgG0YEo8w6jaMUjKW/MzjA4fip6yELG+G2ix3VJ1LNJwsO6W8eYXZVGtNXkLreOthWsmsMwm4IPW1XNKNhwDDCqdpkawvfojTGgLxfYp3sQGWb+0HjS1vJ4XxiIAyFg/42CqBDNUkbdQope8LpOMAQyAK4nb3POI5eKqgYxPT46DIsuDxKftJndSQ== 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=500kHVvNpjLERXwFHkww0pUF7hsApnR2IlUPDBUZMaM=; b=YNPemdxn6k4KyaIXWp2eo11mfvTEP842J4zwa/HyYCt4gEzGEi5YhZkT9LUHjOnf6818YLZ3BJwtNs78RHfjv134ZMd5T3cgiKLIVoBqDLkAghwM9739Yoch9qKe37S8A78zHH8pFmQdLefvAMb/Ilx+dGZR4/4m7vIUJs/2CV88vdczXtqXmOm7QAL5m4SmPfzkzUnxNuYPH6MkW4Py1lMv8B1OGuMdBMPqozyVay3Jup9Mz3Y0/jrXwDaEx1lO1SZpADCmfdHGeXM7afGJ5OKzQMPcKZBKDCnyaL8jdCO4LkbOj+711qfhAGMhddADrcBdoyt5yFvWY+wNq62CkQ== 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=500kHVvNpjLERXwFHkww0pUF7hsApnR2IlUPDBUZMaM=; b=CwBUSrhwojAyAjl0Yc50/pfxRFQjt+s4yE3finfm0FWD902hf/wN9MuLphAieM4zZvssOPwktSUHfLus7v/TW2D4hR4bZcWcfK2SiZ76wQZmLubuo/WQVjwXyAm8BTKOSYDSm5Z4rQYIfw69e4LvuenjQL1a/6DFfYtHp3/GC7M= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH0PR10MB4972.namprd10.prod.outlook.com (2603:10b6:610:c0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.23; Fri, 4 Nov 2022 23:11:20 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%8]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 23:11:20 +0000 From: Stephen Brennan To: Stephen Brennan Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org, Arnaldo Carvalho de Melo , alan.maguire@oracle.com, Andrii Nakryiko Subject: [PATCH v2 dwarves 7/9] btf_encoder: allow encoding all variables Date: Fri, 4 Nov 2022 16:11:01 -0700 Message-Id: <20221104231103.752040-8-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104231103.752040-1-stephen.s.brennan@oracle.com> References: <20221104231103.752040-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA0PR12CA0008.namprd12.prod.outlook.com (2603:10b6:806:6f::13) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|CH0PR10MB4972:EE_ X-MS-Office365-Filtering-Correlation-Id: ce4e1d1a-2981-46f4-cc73-08dabeb9e22a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Z2oJbnQYcTd/M1TfHe98/kGNwl9UzM3V3sB8xWcf8VENN3unMZ1wYBgstnX0PzBbmUL4vrQ3Z/xikwH/v5/5hr6kPGoGJGp2iFEt3jTtGM1RO6Mb+94mTkbK+7lD6fNprSJTSMtZM0PrxqmPVs4Olwh303gYQ3O3Zs1/+vPPknSwOWIh2nZQG6qUiLOtPLnTdPhjnrFtMIyzpGPgaVnMnXQ/bPipdqN6PNyDaXbOsWCSP7wfwgO9sPmxMWWP1JcH+hk1W/8e3vMUlLNNfJrhV4KgureybZx/ItZ0l2RxsL8u8b1tNUBTHdXbCRSbvQ+mq4SL+4TaF3L0Y6+3Mh2y4osfFoiYmFH7i0lOhHbRnOJVsFjfLqaH3ipQZ7yYnaoeOe558Zju+V7y3FArSxwgjnKLpe6HUrLwc37641Nz+DrMNIVrA4k6GQqptXpmlAvSyfwnghT73xQs7o8TStIucl1+FXSwBQT51ZDaQYMnJSy5/kQ6UDbrYk1bGWvTNHdsFFPm2cca6bbLVW8gH6//IgOEQn0Vp+ddheTtc2Uv4PxV8j5m5OA6cQuCbbL5EBraAKWbYQn4Zkrs2D38XyE+3+eeekbGQ2pRnACN95O+PWKDM1Pnmd5hBJ3K7ATEoR0yM53QqTzGBhv5qi8wfrghIJpbL9KyoyJZqJxL+t97yI7eSRFhO2OzB3eE2LZt/W+rQVy6yWEtNj/rB37DYXe63A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(396003)(136003)(366004)(376002)(39860400002)(451199015)(36756003)(86362001)(103116003)(41300700001)(4326008)(6862004)(2906002)(5660300002)(83380400001)(478600001)(8936002)(6200100001)(316002)(66476007)(66946007)(66556008)(37006003)(8676002)(54906003)(6486002)(38100700002)(26005)(2616005)(186003)(1076003)(6512007)(6506007)(6666004)(7049001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sP7dLj6VNMAeo5z+YlnHyr4bwInFEhwurohZkGquko5vTOrtqpUdzqB0dV3uWmT5L6b1Rp4bqdaIpj/6sYsgOsPMM1NXygMEd54mJnCJFFqFulzniUETe4QCIgXxYCl6Ty9Iej537A+gwBTrOnf5IHIpJW7qKbO5T30M+b/nYndAbjzFGws8knKi9Y+Q5VLx5QeHydzF8oKqF1a+rhc6/dNP0EEaNoVWk/hbJXpkfeYFcaDb3B5ZYX4vfOO6O/PHyldoZf8oB6H+LkcIiJ9BHQTAVZkMISjc+dg/afvnkDUVxuNO2NrkjerO83I4YHmVypXykvwyXo5u9Z35FtNyX9dJgZwLm6ZJQRlo7ivMtOhbT7MPM+ITcEeACZflklDFsRlSYBHIwjgR3Z82r0KvnwJJHZ7ox2S4Z9C49dUaE8Sl4l2pRJdGU+2QXcrOt6qAzkyHqH5HHH28fb661pTj6vb3R/XevOw1nRMrl/oJuvhv2cGWaHiTUkyGPnKkjE9NL2nDTzNgqqw9mYjdt27HZwdimLOoPoqCOujQ+gAjuQRgr9rFkDRY9Ahd3sOqHe1FQAoSw/sptKDrdN+XIrrBJQuQ9Um/2taUnWm+n+kW6QKCvJFA6orqbWZYFkD5zGMOVJA57oehU4NvAYt9RP6f8mz7ZW6v3k19Ks0GzngWaiK3yuTobNUeBa4m/2Cf6OzrzCsLoGkSS77iQVxAGwDt9wkuUOxZ29ZG+vlnpV/bCHO87sF/qo7fHvfybBGV95nEquU0Gm9IoFsnKEQJCZ6jOf/eN5ufAuwrXdSKs0sy3LZWCwmJXsEn7riTZWAO6wo3juIWSZ/jmjqWjQIOm0O7Kn+JaUrlS1F306TlM62M0eqVHBXj5jhJgSZR3/9sQdlTOgrcdckQA5HMxgAdyksGQk66GxKseD3GWooQyRpMvZhcVtH794OEXFfDNAI6BMIziWw2rVnndZvcWdXaAXFFBAbjGin7XC0ZjIhgKL3s0JC0/yYcK8OlNVHOxOvUh3K7Mn/3ONSqPdbsPBaA1Mk5YkxjoE1C/ajrf86amBVnBV3/VJkCu+KdujkYaSK6CNJ1bedVDeFenfcQCY3iKKstE4gfbzZoIB7QsZQoC3FZAyYOINo6tHPKbSW4CbBYdJ11rF8b7MVscn+6341TyPdt+DcEjVCEevcOwYi54DQJ7y58xnLUHqxwL8Ko5n/jpaXHN3XEfvmZePhQsFZLjObmK/ukFjd1SkVYDenm3/NYiEQBXR804qyyJwN1NQ5k4BGEcf6CtcudPBA64RcVU2/ZjsrRGSUjaxPK0xf2xp9W/B9ECaJnBBXXvRWy4Xi1iUjj9BB5ulyPo3ufrYVKBR5c9mBz8XCKvYobhx4NOINkK/4+UozCMASe/DIwNfYwq0bOMaSMhe2TOOXINaHBoiwdQ0BisPtX7uhptDV6V9Xr2tnVLuIsWdp25x0wZc5BqUIwcVglDk6fNKXoow1WaIn8hWJIe97EhlOhEXvLxVVBngoH6gDLgP/oBLrefqLmoYHQWsPwvfPeQkWKN8tOCtL264qsuqFo0pdpe001SyqjZKi+YSMfXjIfsWgHUwP+tadmWmk+OGLxKpQGp+rqcGABvA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce4e1d1a-2981-46f4-cc73-08dabeb9e22a X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 23:11:20.0435 (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: 1Zi15OSaSniD9Bc75KsvJKgEU2sFPGLr0oN3AmazQF8n1SeQk1nW9JF82rTVYE6YXJMmn+80SfzBPUKUlZjatxtFmcTYifdkqlikZwEuMBI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4972 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-04_12,2022-11-03_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211040142 X-Proofpoint-GUID: a8WHorO9N_zXDyPs29VXZcBOWXVHSW6O X-Proofpoint-ORIG-GUID: a8WHorO9N_zXDyPs29VXZcBOWXVHSW6O Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Add the --encode_all_btf_vars option, which conflicts with --skip_encoding_btf_vars, and will enable encoding all variables which have a corresponding STT_OBJECT match in the ELF symbol table. Rework the btf_encoder_new() signature to include a single enum to specify which kinds of variables are allowed, and add the necessary logic to select variables. Signed-off-by: Stephen Brennan --- btf_encoder.c | 22 +++++++++++++--------- btf_encoder.h | 8 +++++++- man-pages/pahole.1 | 6 +++++- pahole.c | 30 ++++++++++++++++++++++++------ 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index f7acc9a..b3ede15 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -65,7 +65,6 @@ struct btf_encoder { struct elf_symtab *symtab; bool has_index_type, need_index_type, - skip_encoding_vars, raw_output, verbose, force, @@ -74,6 +73,7 @@ struct btf_encoder { uint32_t array_index_id; struct elf_secinfo secinfo[MAX_ELF_SEC_CNT]; size_t seccnt; + enum btf_var_option encode_vars; struct { struct var_info *vars; int var_cnt; @@ -1247,24 +1247,25 @@ static int btf_encoder__collect_var(struct btf_encoder *encoder, GElf_Sym *sym, return 0; } -static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collect_percpu_vars) +static int btf_encoder__collect_symbols(struct btf_encoder *encoder) { uint32_t sym_sec_idx; uint32_t core_id; GElf_Sym sym; + bool collect_vars = (encoder->encode_vars != BTF_VAR_NONE); /* cache variables' addresses, preparing for searching in symtab. */ encoder->variables.var_cnt = 0; /* search within symtab for percpu variables */ elf_symtab__for_each_symbol_index(encoder->symtab, core_id, sym, sym_sec_idx) { - if (collect_percpu_vars && btf_encoder__collect_var(encoder, &sym, sym_sec_idx)) + if (collect_vars && btf_encoder__collect_var(encoder, &sym, sym_sec_idx)) return -1; if (btf_encoder__collect_function(encoder, &sym)) return -1; } - if (collect_percpu_vars) { + if (collect_vars) { if (encoder->variables.var_cnt) qsort(encoder->variables.vars, encoder->variables.var_cnt, sizeof(encoder->variables.vars[0]), var_cmp); @@ -1425,7 +1426,7 @@ out: return err; } -struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, bool skip_encoding_vars, bool force, bool gen_floats, bool verbose) +struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, enum btf_var_option vars, bool force, bool gen_floats, bool verbose) { struct btf_encoder *encoder = zalloc(sizeof(*encoder)); @@ -1441,11 +1442,11 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->force = force; encoder->gen_floats = gen_floats; - encoder->skip_encoding_vars = skip_encoding_vars; encoder->verbose = verbose; encoder->has_index_type = false; encoder->need_index_type = false; encoder->array_index_id = 0; + encoder->encode_vars = vars; GElf_Ehdr ehdr; @@ -1495,17 +1496,20 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->secinfo[shndx].addr = shdr.sh_addr; encoder->secinfo[shndx].sz = shdr.sh_size; encoder->secinfo[shndx].name = secname; + if (encoder->encode_vars == BTF_VAR_ALL) + encoder->secinfo[shndx].include = true; if (strcmp(secname, PERCPU_SECTION) == 0) { encoder->variables.percpu_shndx = shndx; - encoder->secinfo[shndx].include = true; + if (encoder->encode_vars != BTF_VAR_NONE) + encoder->secinfo[shndx].include = true; } } if (!encoder->variables.percpu_shndx && encoder->verbose) printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION); - if (btf_encoder__collect_symbols(encoder, !encoder->skip_encoding_vars)) + if (btf_encoder__collect_symbols(encoder)) goto out_delete; if (encoder->verbose) @@ -1671,7 +1675,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, struct co } } - if (!encoder->skip_encoding_vars) + if (encoder->encode_vars != BTF_VAR_NONE) err = btf_encoder__encode_cu_variables(encoder, type_id_off); out: encoder->cu = NULL; diff --git a/btf_encoder.h b/btf_encoder.h index a65120c..e03c7cc 100644 --- a/btf_encoder.h +++ b/btf_encoder.h @@ -16,7 +16,13 @@ struct btf; struct cu; struct list_head; -struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, bool skip_encoding_vars, bool force, bool gen_floats, bool verbose); +enum btf_var_option { + BTF_VAR_NONE, + BTF_VAR_PERCPU, + BTF_VAR_ALL, +}; + +struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, enum btf_var_option vars, bool force, bool gen_floats, bool verbose); void btf_encoder__delete(struct btf_encoder *encoder); int btf_encoder__encode(struct btf_encoder *encoder); diff --git a/man-pages/pahole.1 b/man-pages/pahole.1 index 7460104..e7f5ab5 100644 --- a/man-pages/pahole.1 +++ b/man-pages/pahole.1 @@ -215,7 +215,11 @@ the debugging information. .TP .B \-\-skip_encoding_btf_vars -Do not encode VARs in BTF. +TQ +.B \-\-encode_all_btf_vars +By default, VARs are encoded only for percpu variables. These options allow +to skip encoding them, or to encode all variables regardless of whether they are +percpu. These options are mutually exclusive. .TP .B \-\-skip_encoding_btf_decl_tag diff --git a/pahole.c b/pahole.c index 4ddf21f..6ff4e22 100644 --- a/pahole.c +++ b/pahole.c @@ -37,7 +37,7 @@ static bool ctf_encode; static bool sort_output; static bool need_resort; static bool first_obj_only; -static bool skip_encoding_btf_vars; +static enum btf_var_option encode_btf_vars = BTF_VAR_PERCPU; static bool btf_encode_force; static const char *base_btf_file; @@ -1222,6 +1222,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version; #define ARGP_languages_exclude 336 #define ARGP_skip_encoding_btf_enum64 337 #define ARGP_skip_emitting_atomic_typedefs 338 +#define ARGP_encode_all_btf_vars 339 static const struct argp_option pahole__options[] = { { @@ -1533,7 +1534,12 @@ static const struct argp_option pahole__options[] = { { .name = "skip_encoding_btf_vars", .key = ARGP_skip_encoding_btf_vars, - .doc = "Do not encode VARs in BTF." + .doc = "Do not encode any VARs in BTF (default: only percpu)." + }, + { + .name = "encode_all_btf_vars", + .key = ARGP_encode_all_btf_vars, + .doc = "Encode all VARs in BTF (default: only percpu)." }, { .name = "btf_encode_force", @@ -1763,8 +1769,6 @@ static error_t pahole__options_parser(int key, char *arg, conf.range = arg; break; case ARGP_header_type: conf.header_type = arg; break; - case ARGP_skip_encoding_btf_vars: - skip_encoding_btf_vars = true; break; case ARGP_btf_encode_force: btf_encode_force = true; break; case ARGP_btf_base: @@ -1803,6 +1807,20 @@ static error_t pahole__options_parser(int key, char *arg, conf_load.skip_encoding_btf_enum64 = true; break; case ARGP_skip_emitting_atomic_typedefs: conf.skip_emitting_atomic_typedefs = true; break; + case ARGP_skip_encoding_btf_vars: + if (encode_btf_vars != BTF_VAR_PERCPU) { + fprintf(stderr, "error: --encode_all_btf_vars and --skip_encoding_btf_vars are mutually exclusive\n"); + return ARGP_HELP_SEE; + } + encode_btf_vars = BTF_VAR_NONE; + break; + case ARGP_encode_all_btf_vars: + if (encode_btf_vars != BTF_VAR_PERCPU) { + fprintf(stderr, "error: --encode_all_btf_vars and --skip_encoding_btf_vars are mutually exclusive\n"); + return ARGP_HELP_SEE; + } + encode_btf_vars = BTF_VAR_ALL; + break; default: return ARGP_ERR_UNKNOWN; } @@ -3037,7 +3055,7 @@ static enum load_steal_kind pahole_stealer(struct cu *cu, * And, it is used by the thread * create it. */ - btf_encoder = btf_encoder__new(cu, detached_btf_filename, conf_load->base_btf, skip_encoding_btf_vars, + btf_encoder = btf_encoder__new(cu, detached_btf_filename, conf_load->base_btf, encode_btf_vars, btf_encode_force, btf_gen_floats, global_verbose); if (btf_encoder && thr_data) { struct thread_data *thread = thr_data; @@ -3067,7 +3085,7 @@ static enum load_steal_kind pahole_stealer(struct cu *cu, thread->encoder = btf_encoder__new(cu, detached_btf_filename, NULL, - skip_encoding_btf_vars, + encode_btf_vars, btf_encode_force, btf_gen_floats, global_verbose); From patchwork Fri Nov 4 23:11:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13032701 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46B51C433FE for ; Fri, 4 Nov 2022 23:11:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbiKDXLz (ORCPT ); Fri, 4 Nov 2022 19:11:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbiKDXLa (ORCPT ); Fri, 4 Nov 2022 19:11:30 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C23B3FB88; Fri, 4 Nov 2022 16:11:29 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4Kj8Xq014047; Fri, 4 Nov 2022 23:11:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=d5T6UaBB2if/Vn7ZczP5UcjhJSksdGIh+yyY/t+UW6k=; b=UVzIm9OCBDQ806HN/rNFWXriwxTTaeaG/r8m635tNfFVv6GMjG0Ig4dO2bCzb8eJAfYq raUbaqVTQBzbyl8DJpIIFBFa+7BhrROyjGP7Xx4SNepfs2xiBGoUadjOkJY4ya6lSdMD pVd6NERQNXSYT8XdFPo/n5X7g337vtkIrSAbEQYNfxsXMF5wd914N8FupJ6xJz32TJOs Bk+kswy/1+21z/MQ8FBUeWLKMfZX3QtcC18KSyL0CeTPGRx/8l7+Room+Bnx9nJFPWTb x5fiNiJns2m1JVPqiMoHRYPaaIa16R1pozWWzldtfIMl6eEdvEfQKGlNbgtGOhg+t9O+ 7Q== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgts1hgp6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:25 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4NB3i3029674; Fri, 4 Nov 2022 23:11:24 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2043.outbound.protection.outlook.com [104.47.73.43]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3kmpr9a2xp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B5srHPXmoMDKnuOXCPa1864bsuR8nUPxptgPcOdlJ7UVKfjiMxlKd6FZD4aPSscoF0yliXb2VELHSP3/YJ8LMY/NrMTaMDY1DV24iTVbm2E/c7fTelL96G4uhz9obKR89RX+DMfOPTPfsCmXErow2vg66YEy2Fi4yjt67S+kXa67WLZ8wTjCE/y1vIgde/uYIYJempcS7e7f8wXeMftN5HOfEc74E5dN5s5fLpVVEqQw1ULVCO1zJowRWK0lxtjOXh8RkrN5+t9MbHadFg3OylKIn7c6v//2gOduJJz77mH7jREVVKeeg3O5MblbO5XtK473nxLiK483TjPoqFSZrg== 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=d5T6UaBB2if/Vn7ZczP5UcjhJSksdGIh+yyY/t+UW6k=; b=LFaGr8aBPxNqQ8vPq7OUi4p5VFx2a/B18qirpcTCoizTz/pJ+ajN7y4jL8S3DvNTJAxsNfFhcEGON3BUFJrPeKl56tkjytFNraoBKvUbejPl8jxf8uEa6gf+Ft21NqiA+vM97g8Rhc+PNNQ9f3BlO10WZCRkvKg97b+rsqc6HxFyAxGO5G2uB9mCR3yejFHkWSBOj9yoRNMvsZtyx2dskZEizhe/18OMgcMTJlX+X+hBWlk2NgLV4CXq6f+npNGF9m6ui4G5Xiokb9ABnwziQidCMXx6Dx9U47RzWB5hSq0RSDl+f3ucPYvgu0me3al9iSn9jc7wtvk3OEPisfiv2g== 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=d5T6UaBB2if/Vn7ZczP5UcjhJSksdGIh+yyY/t+UW6k=; b=zTHvNReQaLC/kJCliOSkKE9d57Aav3uE+NRIFi4c3SImka1Rvm1fMUdyIoic/adOOSnPIFXIXUbBbF31DM0BPx4ozZJ4TM4yzmKzmC9Le4qHEkse+6N+cEjTiQv0wcVFbLiuQeXvDGCWVAS944ph3VCw+11zC3v9uwwIZ8p0vSc= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH0PR10MB4972.namprd10.prod.outlook.com (2603:10b6:610:c0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.23; Fri, 4 Nov 2022 23:11:22 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%8]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 23:11:22 +0000 From: Stephen Brennan To: Stephen Brennan Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org, Arnaldo Carvalho de Melo , alan.maguire@oracle.com, Andrii Nakryiko Subject: [PATCH v2 bpf 8/9] libbpf: btf dedup identical struct test needs check for nested structs/arrays Date: Fri, 4 Nov 2022 16:11:02 -0700 Message-Id: <20221104231103.752040-9-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104231103.752040-1-stephen.s.brennan@oracle.com> References: <20221104231103.752040-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SN7PR04CA0101.namprd04.prod.outlook.com (2603:10b6:806:122::16) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|CH0PR10MB4972:EE_ X-MS-Office365-Filtering-Correlation-Id: 4df145c2-f491-4a13-7292-08dabeb9e382 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xrWVuojUGG+J63aKcA1cnx86lMYvvejHtbsBMYTAFexpx0sS7ryZX0cC9gwj5wixDPE4WnEdmE8E6ONov/Y2VTEPmt7Uvh3VcnklVpr0a4bOhYC4Gdd5M6KxYc6NOyjkeo0Tza3iNTd5ET55Krfw1ttNj6wl4iSRbpLSpc0yc69wrWIAyBcjOCwHU2+nRlcOxd93pDHxt8VN1pINn2+TVwFyCcCHOrLRX6lzUYV4uqFGz6y8lO1+T0CcExuksd5yRLgCfWqeKk1USKc878oZu2kOWt3G00UmX0s+BvcqPAWwGJqnS0gWRPyx8V3bp/xAdlIDra7v+d6vHl8bkrw/gDNyfVRgJjhHgZTJBFHvHSaynOyTI9NY/HHonNvUq99v5P3hzvWWqwgPh7gGTszSMr4c5Ghud942AdOg4OD9+RGCcPTzHSw6j1wYU/67mkY+MVdkskc+fk1nArEZ4F1Fc5i2nsMmdy1C/NyLq3HJolkJw174USo4Xq2jDurqlJGi1KbtJ93QXJ2oauVOh3PuvlCxUzFmaA7lPB7c1FngS1ze+JT3ffcJ9dA+Dq6UpLyQInzeMCMgtQQO0gkEPP1cN7JYl3qWyOyiq1bpUxUo5F1U8ejjSoQc2+0knzRPJEbIurrKNLMWxoQCHs1fNx5Lus/NmidpF67f79okE09ikr5qz4yotHqv9GRst02dZ//438Hb79MAxlcb3NVid4RIvvcPU7ve5TtDGGf3sYGcSyQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(396003)(136003)(366004)(376002)(39860400002)(451199015)(36756003)(86362001)(103116003)(41300700001)(4326008)(6862004)(2906002)(5660300002)(83380400001)(478600001)(8936002)(6200100001)(316002)(966005)(66476007)(66946007)(66556008)(37006003)(8676002)(54906003)(6486002)(38100700002)(26005)(2616005)(186003)(1076003)(6512007)(6506007)(6666004)(7049001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ypIb14hE0xh2q+4ZLVxr6If2RU8t78hudD1OPTpa1NygNgGi7oeZ05QODTESVzrh3JT0NEiaA0C6C8yd2txM0iyArD4NJiUdzirGb/FPjXkFM8NjqtpNo07jntunlO3WpKolJ+ANEnMeyesxFcq+qBr2EZ2Dc1mhfFpeF7ZDNAjh8GjNY8aQGZZS32Vmzvq6fqNjyQLDF8Q48BEwTGDHvfpd3NwnOVl7OjNR3TEFybq4I0Aa5RKPID+lA/dcJIL0jzWj7pHaesGOVuAucIXTAyRWkIFV+bQ3GZS1BpSrjekpZAXHoL9hPC7GmVjX5no3e15ZQ3o6nxObbTpPFOw4uMg938rhDNZg37vyXHE2lZuReZN3d1EhFSdHLPf/U2HTmPE5OPaNHognt7U//Q8L1DdnbO7KPjBdZrZjuzmmj49I5H4lUfiHTELaE7cuf8fCCkzFIWotwp77JdLcbH41QvHuJ5nWzZKqQOk2li9Ne0DaBmTUukm/KsRT8Jgrym67vugIuTsJ7FeNTa0QNnoNFUr2bexqPynZmeWPVj6YbPSJRfp1WbNGuKjJu5BmVbmHEZth9FPIsS9+JdOvwCAUmIMiQ65RV744/oNkcH8tUwMg1PS+xuFCzREyfX++cscOtJFyi1IxioAZb9ZmLuFztfmbVy7oUbYSpfFOFeEHBSi0jU1hm7Zu8TyzfJuIMSwSZK6KxoT3j5tZW3+yh1STjqGgOrHB9PYQM/0VLv0jRYkhQn/lEXMsZgz+fnqeaiwDLkE4BkF2sBIiQm/DgLnrbFJ1ksWPe4eUs2A99Cer2JWKJxkGtoMi6e6MK6YS3FQSi8x170NH6VSar7uWxDuuLCucAuqA3l+QmUyFAZQaN5EllgC0K1XKUipwDe+H1+qhfcee9YcmMV71du0bDAq13tC9dqS3MHZduc7MWvvUQROQacu6/16X5eMmmulid8JiM1l8yWt1kzDGvatFbAEtq8z+LLiQkiRjmXnFzXyQaiv0VAZ6C1txCHQ2cIG8O+BqK0PYGaqE3wc4hl11Jhoknzo44BJ1h0bDWgoFsGETcTO9WC0BGcDwqr5KiPPMOfd96BHklYnzZwO9mGWfiSOaps/TjRIrEB74RcUT65Ky5rzrZQLq7lxZGA7+Q+0Kfg+wYr8FuRH70i7uCQZ9m6F7r5Y9FiaNpaBySqxYBgP7+uJ7GiXa//EnxpCJw+BmjLFneKrzvd1CXH36jxm/s0Axs6AWrfRpFxyTqJUBLtUM0kNzUUhunLgCRIkBezVq26Sm9xGc+hRVhjTQfnmiTB73uYtY8EVQRcZmabA7AeNybYrj7dpt1tW4Hnj8WhijfLJwHKo22Gi6VYbBfMfg/LL2EHP4ZQTHb+EVC0KCRNJUXSem09QfEd1v8U6d3iL7cjZ748Nn1lAnVOYsMa8c7PkqlFcVTxyh+JPJ5a+qrn5x2shohJS40ZSnnnMk0uvfGWcp+MqgXziqxgKLQAciPMIL+vaJis1mq69XLuU2WkNgMyfMdNZyYRJFf+jGE5yDPt5V3pTh0IfM0uMJAy5Kxxovh4exjS4T8oK8c15P+3+In1Old8hbQR0eiayPYwksWhYrDJlBH1PYeImxrRqtrdn99w== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4df145c2-f491-4a13-7292-08dabeb9e382 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 23:11:22.2956 (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: /eBcA0SN9tb4dN8Ev4J0V6at0S42wC0F+/uzujXlw7/3J6aQHppZGzk5l/4SxTvrcs1HCs1xOdYofb/TSj6kuqSLpHOTfke5/mrhGxIcKn0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4972 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-04_12,2022-11-03_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 suspectscore=0 adultscore=0 phishscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211040142 X-Proofpoint-GUID: XjoDO7VkIBDoXq20HcojOqPJ1TRaFLKC X-Proofpoint-ORIG-GUID: XjoDO7VkIBDoXq20HcojOqPJ1TRaFLKC Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Alan Maguire When examining module BTF, it is common to see core kernel structures such as sk_buff, net_device duplicated in the module. After adding debug messaging to BTF it turned out that much of the problem was down to the identical struct test failing during deduplication; sometimes the compiler adds identical structs. However it turns out sometimes that type ids of identical struct members can also differ, even when the containing structs are still identical. To take an example, for struct sk_buff, debug messaging revealed that the identical struct matching was failing for the anon struct "headers"; specifically for the first field: __u8 __pkt_type_offset[0]; /* 128 0 */ Looking at the code in BTF deduplication, we have code that guards against the possibility of identical struct definitions, down to type ids, and identical array definitions. However in this case we have a struct which is being defined twice but does not have identical type ids since each duplicate struct has separate type ids for the above array member. A similar problem (though not observed) could occur for struct-in-struct. The solution is to make the "identical struct" test check members not just for matching ids, but to also check if they in turn are identical structs or arrays. The results of doing this are quite dramatic (for some modules at least); I see the number of type ids drop from around 10000 to just over 1000 in one module for example. For testing use latest pahole or apply [1], otherwise dedups can fail for the reasons described there. Also fix return type of btf_dedup_identical_arrays() as suggested by Andrii to match boolean return type used elsewhere. Fixes: efdd3eb8015e ("libbpf: Accommodate DWARF/compiler bug with duplicated structs") Signed-off-by: Alan Maguire [1] https://lore.kernel.org/bpf/1666364523-9648-1-git-send-email-alan.maguire --- tools/lib/bpf/btf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index d88647d..675a0df 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -3887,14 +3887,14 @@ static inline __u16 btf_fwd_kind(struct btf_type *t) } /* Check if given two types are identical ARRAY definitions */ -static int btf_dedup_identical_arrays(struct btf_dedup *d, __u32 id1, __u32 id2) +static bool btf_dedup_identical_arrays(struct btf_dedup *d, __u32 id1, __u32 id2) { struct btf_type *t1, *t2; t1 = btf_type_by_id(d->btf, id1); t2 = btf_type_by_id(d->btf, id2); if (!btf_is_array(t1) || !btf_is_array(t2)) - return 0; + return false; return btf_equal_array(t1, t2); } @@ -3918,7 +3918,9 @@ static bool btf_dedup_identical_structs(struct btf_dedup *d, __u32 id1, __u32 id m1 = btf_members(t1); m2 = btf_members(t2); for (i = 0, n = btf_vlen(t1); i < n; i++, m1++, m2++) { - if (m1->type != m2->type) + if (m1->type != m2->type && + !btf_dedup_identical_arrays(d, m1->type, m2->type) && + !btf_dedup_identical_structs(d, m1->type, m2->type)) return false; } return true; From patchwork Fri Nov 4 23:11:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13032700 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F709C4167B for ; Fri, 4 Nov 2022 23:11:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229517AbiKDXLy (ORCPT ); Fri, 4 Nov 2022 19:11:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbiKDXLa (ORCPT ); Fri, 4 Nov 2022 19:11:30 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9616745091; Fri, 4 Nov 2022 16:11:29 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4Kj7c0012094; Fri, 4 Nov 2022 23:11:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=YW5FZ/CC/9qXBOExze1onAUh3IpyArNQEzcHTnOE9rE=; b=0w36f1EFlfbuhOAVZNSeVnz61zS/74E6/iVTNOkPpdy5HU2ZnEnwspYN9bJ2K4fud2P4 o4DLh1ZTodbYU9EY+Z+vl13/apHuPoqnjo54i3+Vwp5MzOkzWwaFV1nfO8qASZKBZbjO XdkOe5urd1MozgCJZrfpi1xQTera4gy4PAk2L+S7hF/sCVzXmlkunpSbXoJ9Ix5Fh9FN vcYQJHjC0R6d/Ypraoco7akUnidQO++wTczkYUldwkufVYeVrE9gGytf53xe6N2RZqG1 O3VUBxmyBPGbVKxY5rRzI3VtJt6rD/iofdVswIrE5bY1x/UqqQHTssHXr0xVVNXuWZgR nA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgvqtshkv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:27 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A4M1oEM012041; Fri, 4 Nov 2022 23:11:26 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2049.outbound.protection.outlook.com [104.47.73.49]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kmpwn87jd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Nov 2022 23:11:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mfsVMtU+JXk0OKWdUDfkVPpRg7izgOdC8s1daFkY2/YSgolH5DjGfKFPFcX20aCp4TU9q8Pf4McpecqKY5BEe/mrQa7YLaeWpz9frPuR1lAd8bXZYyjAzDXt9rYmhwFsUCDRsxfTlUHCTx594cLwv6jgCyTaEZ3Jb4ezuAATS1gkl2fOUndq8buL1RnVw7muu05n12wNZn/JdHdoYF+OcTW2lXTTRsKGkX2uTlL7sj9g+l49tU/q4wsuoCAcTq0NqinArWQ6ZJFKi6WtlyR5xZUbBvZZbpb/11CWPBRlzMd9FUKmf9ixV8L6STokDSYkCqJysXlpFAFK6fssptR+Ow== 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=YW5FZ/CC/9qXBOExze1onAUh3IpyArNQEzcHTnOE9rE=; b=bBigWxvTJvmq3cfogu2Gj8TCcBdWPa8ofcAJacc+o/tjrBEDlSPoIDSBqWTaVQ1I49oPlzIIJ6gMqIijVkZkgnsHai9+fKNwKR8ixavmHoE6HQSfGxATn7lDTGUgjUF2sQnjRHwy/c+N1u0iknHyRdxVuB3Ao+STSMm+4WdaMhavQSALArbTFWNv5GlzhkpmRtNR7nNIA4O7B8Cfhcb4+aP7xmTtFK4l8izFnn5a+PjkzcXQGE0RExKLhzsitC0+BZuffFq483bmiw3B0AFC/sSid/1c2+zX3fiGagrrvL876zvMUl5ltX1lbwyPhcfqgF/2ZEnUYO0Zdlj7fSL1TQ== 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=YW5FZ/CC/9qXBOExze1onAUh3IpyArNQEzcHTnOE9rE=; b=JSllnHO4yIJLtkYnTgUEd1+AWUstxUbhO+mK1lQ2vLU1Cpct5kQmV6iwYAXSVT9FZKOx/8F0gge/ay+tuxXU63v6WYKWX2en8GYGOcZWci9PYO+tLUcZFjX0J/svG9RxpjCyCvueNOxRb/nYxBXgMLm5O3XVQSUtG7hRclBnqDI= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH0PR10MB4972.namprd10.prod.outlook.com (2603:10b6:610:c0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.23; Fri, 4 Nov 2022 23:11:24 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%8]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 23:11:24 +0000 From: Stephen Brennan To: Stephen Brennan Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org, Arnaldo Carvalho de Melo , alan.maguire@oracle.com, Andrii Nakryiko Subject: [PATCH v2 kernel 9/9] bpf: add support for CONFIG_DEBUG_INFO_BTF_VARS Date: Fri, 4 Nov 2022 16:11:03 -0700 Message-Id: <20221104231103.752040-10-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104231103.752040-1-stephen.s.brennan@oracle.com> References: <20221104231103.752040-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA0PR13CA0011.namprd13.prod.outlook.com (2603:10b6:806:130::16) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|CH0PR10MB4972:EE_ X-MS-Office365-Filtering-Correlation-Id: f97cfe89-6bfd-4aec-daf6-08dabeb9e4c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KO2d34bbrbMvxprBqJkhCYMxl97yqmFCYqNLIe7BS+e0IXo0HmS9b2P8jgMOaRQx+urMVPp5KfJoT9fzYTqOSx+6JqYPhL0Z7O7pWTfs6/ToD5aAjvLyfqNPSvauqfdj3L5IidLQVQmXJodORdOxzoAivqoueNFy2d0QeWoj9QnW6pl5YJLd7blvVpIiTvbR93gFvopc0GJGLxeGkkq0zj6t7M167Q53ZRtbv1VBavV4zJy8NnfC57Cd6qMpq8cQNvu/pcJlUiOCygFgd2mLJ6uovAB2fS3EjbozlfjpnD2yNAekOUPD1nhFm/1yxjdhpEX4E/IH28w0FC34Zxk2SasHwNjhbm4M7j8V6uF9WkE1TxNy5Dt8ixMozkL67U9PY0JjkwpEoaS7CWHyP/F2zp30r8LJ9aywsCFFF3bm7OODCa9c7NpgIl3vnfDSKcZEyyat3fHjU2+HGBcNNXhkOA4HBRN+WE2Lx8V4Jxe5wmuPBwbUXrBdmMJuYjUA5cLKEDRX4YE6UeV1Xtd9IULaHkcBwqCRgj0hHeFbiyhhAlsDtvN8cZG+VrzqMRN4nyCW2eIzOew7iIs5Drl5O4SFV80azpyXGSM412u8ljjqAN1I0WBH79vNyX/8ME+aQK+0SccVeQvWf7fksY8IURAKg9kRd2arDkKrcfxyT5fJQj4+hpxNQCcVuMq0aBsYKKa+grwYH3hSFhlUBbClMApNRiWs+45i0pcTB7WXl4h/tuBtLbJQlgYhAbM2R6Fv5LEhEwYOWebayUfb3KXPCgy9WA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(396003)(136003)(366004)(376002)(39860400002)(451199015)(36756003)(86362001)(103116003)(41300700001)(4326008)(6862004)(2906002)(5660300002)(83380400001)(478600001)(8936002)(6200100001)(316002)(966005)(66476007)(66946007)(66556008)(37006003)(8676002)(54906003)(6486002)(38100700002)(26005)(2616005)(186003)(1076003)(6512007)(6506007)(6666004)(7049001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wrScGp20KRxx0bwEzZKkyF4483kVSdhQMJw0Qp2YyseKvQP8kBKStwtVn+sNy+mJztSuBn8PhW71Ri1u1AdaIhCHyBrnB4wFYbCc/FteEAzGWLkQfJBjT9Bb2HEYwMW7W6gi5NE0vhWEe+9c92tkSb06q3F2ZYlSBXlF7xt+8kezod/wZnNd2zHlyB/1MNprWFy+xcwj0Dmn1pKURTARdK+zyLs+gmf9ISIrfgjmEIRVaXX35SvKxzJEUcBFl1InDb0v6gcepuixZY84i0/u/Rp5d/ZR9AixWDPbRHCBbKMlvpb4fqBGr2uzwwe98wkToU4OA9HZOP4zEP7Tdd/G98Gl1tN4q8G5I+PgZDYfgEmszju2aJFFXn1AtUN7jbuHvlikrifDWF83n4NII8NUPLOJBNHT9NCKRzaOJYpljtxG5nDEH9ZSVL3BSBbTm3PbcFviBxd2JwcelQnfvj/LTGmS+LLebLkQaXkiqW24r3f9Dsn3GJjX2zd3X4Iu6nFb6uGtjo0hrxl/rVycvCwNCgMwDmJ/JO9FWMO7n8QWMDCm+qmm4ogQVsbkNjdIeKcdJ+15IZjyINdYJvMc0aVorpkDSa6CiJQ6W1OjxYF1QHOB1pgjcPKMhISt2vI1oYCIAzc93dv/jTQg06x+9bJeZlyZBwk3cP/JoTx8CxQWwu3WltRAI7FPvEFD15r5dLrkSbeqg02ZRPZ/zIYMZ0asAUhNPMgz3GYShsiAHlixE8ZNtKD8o2RirgJFtPELcZWo0hoaXP/ic7/wQ7jPCyLCJlmExhPgIA4OylgWl4Ybmoa9cz5Ag5p1hO4aYrRZuwLncqj8r6jLPxrFLnwttiYjSo5+8RJNG0nkXkfdyxl18l3BnyfHjy2a93UpTJq1emlQd8EaZuYK6wzlCs9m3IdQv1xLqTn+mrefEZVXCPIvt2prlwgqp8qYQqonr3Meo1AOrc2EhVGWC1cUMCaVau8pm8hOooG/LA+h3zXja7acVIpnn+60Lc9repXECNlWOz3roH04q9drCn0DdyUh+YTkvaCKqrnc5gsp/V10qF2f0OLvI25NwV/n9Ip4M4+uIbmElOdJWiJsJstSqQhFI805066yEmYEBYmg84nyX6v6WIshMW3spTbukfKF5kE46jGb/8U7vzvQvh30FSRfcuHxElWRPNM4I95OD01t5eYCJrA/XcZLLBQeSrQ8x7zku5VJ1LUMxsKVbIDqSBVuTwFr0hzZnTyRcBll0fotCaIln3WvDRxGo4kUGT5mBWZmoIuOs4DTLfCDCTDBArhxJIDG/3TIN1VRKZEfJCeoEOTyMOA+1JkmHQEHUC4kOm0VrGKY/u+VuaB19EvPcj2Bt1yFdyra8b/U3CqQPurYpWSemMa0Zw7ilhaDgP7BRpiyB8UDh4UDg75XSqicSqNqazqeyJqPxk0x2FPaFcAoE9eufmL3PapFOkuzdzUaeBW44GwDiCq2JPOcg5vM71HJYJDsl0kry9RMgiZbPfBiieyJ/2ma6zbop9KXXgfm8tJQajxDAi50w+bj0kTqi6sAJAQ5MFinPKI9jjhuuVxV0qWhIn7rRhhIxEQZZ8rmbho6jiGcaTuiaqTKTI8g91cYA7Xt3w== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f97cfe89-6bfd-4aec-daf6-08dabeb9e4c6 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 23:11:24.4529 (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: xFcH6gKQYduWl5ILueND12A27IFASrja3THQGCGZt5h1R8kUwe5CwG4y/XnrwFXnnygtP4YP0NyCpOdAQH5AN1f60fAMq8cKXKdvaRBdDo0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4972 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-04_12,2022-11-03_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211040142 X-Proofpoint-GUID: JSFpNYatYaixuutYDGF8sPTbY__Xu408 X-Proofpoint-ORIG-GUID: JSFpNYatYaixuutYDGF8sPTbY__Xu408 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Alan Maguire This patch implements a proof-of-concept of the kernel side of global variable support discussed in [1]. Add new tristate CONFIG_DEBUG_INFO_BTF_VARS; when it is 'y' both per-CPU and global variables are added to vmlinux BTF. When set to 'm', variable BTF is added to module kernel/bpf/vmlinux_btf_extra.ko; as a result, global variables will be available in /sys/kernel/btf/vmlinux_btf_extra using split BTF to store variables. To achieve this, we add a "target" option to scripts/pahole-flags.sh which - if set to "extra" - gives us the flags to be used for extra vmlinux BTF generation. Module building and BTF generation are skipped if CONFIG_DEBUG_INFO_BTF_VARS is 'y' or 'n'. Depends on having a v1.24 of dwarves which provides support for encoding all variables as per patch 1-7 of [1]. To put the pieces together, apply those patches to pahole. Eventually, like other functionality it would likely require dependending on a newer version of pahole like v1.25. CMakeLists.txt before building so that the pahole version can be a proxy for detecting the "encode all variables" feature. Prior to fixes [2] and [3] dedup failed and was highly redundant, but with those fixes in pahole and libbpf we see that in the module case, vmlinux_btf_extra.ko only defines two non-VAR kinds; one for the percpu DATASEC and one for the 'double' type: $ bpftool btf dump -B ~/src/bpf/vmlinux file ~/src/bpf/kernel/bpf/vmlinux_btf_extra.ko|egrep -v VAR [115981] INT 'double' size=8 bits_offset=0 nr_bits=64 encoding=(none) [159904] DATASEC '.data..percpu' size=209156 vlen=378 Signed-off-by: Alan Maguire [1] TBD (requires resyncing patches with dwarves) [2] https://lore.kernel.org/bpf/1666364523-9648-1-git-send-email-alan.maguire@oracle.com/ [3] https://lore.kernel.org/bpf/1666622309-22289-1-git-send-email-alan.maguire@oracle.com/ --- Makefile | 3 ++- kernel/bpf/Makefile | 4 ++++ kernel/bpf/vmlinux_btf_extra.c | 22 ++++++++++++++++++++ lib/Kconfig.debug | 9 ++++++++ scripts/Makefile.modfinal | 6 ++++++ scripts/pahole-flags.sh | 38 ++++++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 kernel/bpf/vmlinux_btf_extra.c diff --git a/Makefile b/Makefile index f659d3085121..7cc99a424a85 100644 --- a/Makefile +++ b/Makefile @@ -527,6 +527,7 @@ XZ = xz ZSTD = zstd PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh) +EXTRA_PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh extra) CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) @@ -614,7 +615,7 @@ export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL -export PAHOLE_FLAGS +export PAHOLE_FLAGS EXTRA_PAHOLE_FLAGS # Files to ignore in find ... statements diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile index 341c94f208f4..8e3ee5c98f23 100644 --- a/kernel/bpf/Makefile +++ b/kernel/bpf/Makefile @@ -43,3 +43,7 @@ obj-$(CONFIG_BPF_PRELOAD) += preload/ obj-$(CONFIG_BPF_SYSCALL) += relo_core.o $(obj)/relo_core.o: $(srctree)/tools/lib/bpf/relo_core.c FORCE $(call if_changed_rule,cc_o_c) + +ifeq ($(CONFIG_DEBUG_INFO_BTF_VARS),m) +obj-m = vmlinux_btf_extra.o +endif diff --git a/kernel/bpf/vmlinux_btf_extra.c b/kernel/bpf/vmlinux_btf_extra.c new file mode 100644 index 000000000000..9aa682287a1e --- /dev/null +++ b/kernel/bpf/vmlinux_btf_extra.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2022, Oracle and/or its affiliates. */ + +#include +#include + +/* Dummy module used as a container for extra vmlinux BTF information; + * to be used if vmlinux BTF size is a concern. + */ +static int __init vmlinux_btf_extra_init(void) +{ + return 0; +} +module_init(vmlinux_btf_extra_init); + +static void __exit vmlinux_btf_extra_exit(void) +{ + return; +} +module_exit(vmlinux_btf_extra_exit); + +MODULE_LICENSE("GPL v2"); diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index f473f7d8a0a2..3c7df82a37db 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -364,6 +364,15 @@ config DEBUG_INFO_BTF_MODULES help Generate compact split BTF type information for kernel modules. +config DEBUG_INFO_BTF_VARS + tristate "Encode kernel variables in BTF" + depends on DEBUG_INFO_BTF && PAHOLE_VERSION >= 124 + help + Decide whether pahole emits variable definitions for all + variables. If 'm', variables are stored in vmlinux-btf-extra + module, which has BTF for variables only (it is deduplicated + with vmlinux BTF). + config MODULE_ALLOW_BTF_MISMATCH bool "Allow loading modules with non-matching BTF type info" depends on DEBUG_INFO_BTF_MODULES diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 9a1fa6aa30fe..210d7869c14f 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -43,6 +43,12 @@ quiet_cmd_btf_ko = BTF [M] $@ printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \ elif [ -n "$(CONFIG_RUST)" ] && $(srctree)/scripts/is_rust_module.sh $@; then \ printf "Skipping BTF generation for %s because it's a Rust module\n" $@ 1>&2; \ + elif [ $@ == "kernel/bpf/vmlinux_btf_extra.ko" ]; then \ + LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J \ + --btf_encode_detached=$@.btf --btf_base vmlinux \ + $(EXTRA_PAHOLE_FLAGS) vmlinux; \ + $(OBJCOPY) --add-section .BTF=$(@).btf \ + --set-section-flags .BTF=alloc,readonly $(@); \ else \ LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \ $(RESOLVE_BTFIDS) -b vmlinux $@; \ diff --git a/scripts/pahole-flags.sh b/scripts/pahole-flags.sh index 0d99ef17e4a5..44bc714fe926 100755 --- a/scripts/pahole-flags.sh +++ b/scripts/pahole-flags.sh @@ -1,6 +1,16 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +config_value() { + awk -v name=$1 -F '=' '$1 == name { print $2 }' include/config/auto.conf +} + +# target is set to "extra" for vmlinux_btf_extra module encoding flags. +# If CONFIG_DEBUG_INFO_BTF_VARS is 'm', we encode variables in +# the module, otherwise if 'y' encode them in vmlinux BTF directly. + +target=$1 + extra_paholeopt= if ! [ -x "$(command -v ${PAHOLE})" ]; then @@ -20,4 +30,32 @@ if [ "${pahole_ver}" -ge "122" ]; then extra_paholeopt="${extra_paholeopt} -j" fi +case $(config_value CONFIG_DEBUG_INFO_BTF_VARS) in +y) + # variables are encoded in core vmlinux BTF; nothing is encoded + # in vmlinux_btf_extra module BTF. + if [[ $target == "extra" ]]; then + extra_paholeopt="" + else + extra_paholeopt="${extra_paholeopt} --encode_all_btf_vars" + fi + ;; +m) + # global variables are encoded in vmlinux_btf_extra; per-CPU + # variables are still found in vmlinux BTF. + if [[ $target == "extra" ]]; then + extra_paholeopt="--encode_all_btf_vars" + else + extra_paholeopt="${extra_paholeopt}" + fi + ;; +*) + # nothing is encoded in vmlinux_btf_extra; no global variables + # are encoded in core vmlinux BTF. + if [[ $target == "extra" ]]; then + extra_paholeopt="" + fi + ;; +esac + echo ${extra_paholeopt}