From patchwork Fri Aug 26 18:49:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12956511 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 0D474ECAADA for ; Fri, 26 Aug 2022 18:53:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344934AbiHZSx5 (ORCPT ); Fri, 26 Aug 2022 14:53:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345376AbiHZSx1 (ORCPT ); Fri, 26 Aug 2022 14:53:27 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0108FF23F8; Fri, 26 Aug 2022 11:49:23 -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 27QIEuOX020114; Fri, 26 Aug 2022 18:49:19 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=CrThpEzg4BRhP5LveZJCjkZlGI9SHTu/3+Y2iSRdA4o=; b=jhJ1nAugxeFu6bWu62+auxfY+mPCq9XpRLhDfmVEB9G9wkkRwnf7ywusdeGg+kH8DRjU SgOimjSzr38wSIxhdZFhdRj7ajAh7jnV8fWqJ29Nk+h6P4Y6yxcfRthXHdTr1gOmEo6F oLPhR3TsZAkw2CiRjoA9WqSJeb0bwUSEfXQwrN1CM/KAQJ51l9gcTqvBtRFElsz+LMN8 MftlmJLSHYBEuXIHvyj27ZHCXNND/t3rGoOl9EBwZbDOXlJSmtPBodpeB2dv5IXrKwrK xZPQDb2Q4JUpW9BiacjYj2+bl2sfWdA53DQbA2FQZmqq79/XutbUOCWyepM4YgSEmSD9 IA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3j55nygptj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:19 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 27QGm6OO033589; Fri, 26 Aug 2022 18:49:18 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3j5n6r8kd8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XEVdyeRGKxDYqVTrT+lr0/eATz81wnUOf2xs8i37nUHQ+p1/rKTYDJGEM4YytoydMLzVoHAux4ovzezUE12S/3rf6XMvj5xYrOkpZL0V1Ea8/USVXLUasAc4xmeLenqOXXGp1uMZPN4wViunQ0K7nR+Ky7XYoays0q0BdO4edAEehkO1B3JZ7rRn93NpmdbT4ejedCXUS+3sNEE+ZQ9rmwBWn7OeK/lzmDVripaZF8YJBYQtdvJgiyyUQhv7si9Hz69or221O/0hcGWhQamRKEaWWL8izRmncWuzw8kzTG58/E4pd7B8vUnsuvjDlIl0TKKGhiu5rCXgYEsmASZ8nQ== 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=CrThpEzg4BRhP5LveZJCjkZlGI9SHTu/3+Y2iSRdA4o=; b=lz1+sfIW8dLB/6zoBPG4RwL5J3RXGcqGO51JYMyb7Lg/F841CNuu8CIyLMQOgmJtYQuFMfQAOAo+mG5lYr4IDKTfNHnEgEpItLi1ha/pwJlAnHziZlecHy2HFimdvVxKH6VYeylRhI2rZMMtjh18lM/znYc6vz0OibDmXJbgsuy6uFmmgneZdh60VR+rmEEeShRhPbcEUs83982+eBMHo8hg801ZDl3rPd7VzghIcWwkPF98lVmRANocRy+OtlM7+I2u/IxxArZIIW6C47aJqGq5f4y9MFoG24viWaI8LPS5QTFI/amyE5NReZoPG0RxSAJFkUygFQXPR5mtMEK6kQ== 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=CrThpEzg4BRhP5LveZJCjkZlGI9SHTu/3+Y2iSRdA4o=; b=QxWKVhkpDs1Q2ux4vb7qVoAilyUaoRPsYQNCngDzKNzQxbBg7aVi35Ahz+cz6yHmWTDQ/zy65iEkGRHLBx6FeBDrIj6ZuI37LzcWHBU1On1JNQeVyyxgsHieRAQT97rPt7uURIO6AJhN8sgfZHKdGKTEkKpdV/e27X7IaE0b9oU= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by SN7PR10MB6331.namprd10.prod.outlook.com (2603:10b6:806:271::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Fri, 26 Aug 2022 18:49:16 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5%6]) with mapi id 15.20.5566.016; Fri, 26 Aug 2022 18:49:16 +0000 From: Stephen Brennan To: dwarves@vger.kernel.org Cc: bpf@vger.kernel.org, Arnaldo Carvalho de Melo , stephen.s.brennan@oracle.com, alan.maguire@oracle.com Subject: [PATCH dwarves 1/7] dutil: return ELF section name when looked up by index Date: Fri, 26 Aug 2022 11:49:05 -0700 Message-Id: <20220826184911.168442-2-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826184911.168442-1-stephen.s.brennan@oracle.com> References: <20220826184911.168442-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SN7P222CA0012.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::26) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1dbac266-6e0e-4c98-e1a0-08da8793acf2 X-MS-TrafficTypeDiagnostic: SN7PR10MB6331:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j3ovlRjoqOkpzdn1jPSsCrot68srljQXUu1Cpbh2PeNtwbgZYsc/hAEH3B/Dnqud0adZ9nZEMKrQOrPR7yaKun9wGs3ONSNkjPiEtfDPMi5aoZU4U1m/HRof+3Ddyb6FpCjQX5tRW10sehF9YtcRCthw82/Qz5NReTy1A+u2NItet7fDHCYqxi9u7HKhHFmt2CSdn8z1tjbdx6jnhe9RctrnkBmvZOaOv2qwctAID9z1bFygSZQUByFUWJ/153zljEo+ofTJ1sFZeiD6xYT7foWlXVsSaUgcgKjANjS2wkjTRuNZWwXrUP3taZVnzuARQJlkLAW9hF1uxLrA/X+Tm92TmxYmBPQgiJ/RFSG76aO1iu5KvW6c2UAz+k71RGPcyhs3pMxo6RLJ6/+Fg+BMEaa4PkWhexCVsmn72LFl6p6nec1kGY6XKYDM02Fn/q7c7m7bwTiKQs0M6+mX+6oyXcoohmv19l8u4Efkb5oxAv2ai4BXtPuVlBL+nkjKCn9FkCsacnLF5Z8Wt+qyqMIoE5O5L5ydTiJv/8RNw0CKpCEL8o8w3iBWQtWTJjEAN/rLUcjBAvmwxfFgNE1aWGUUU7QvkW0HgWdImjgGfNeh2Mn1QpMkaUVI/ZFdYT7QIeRHbnwgzspq250H8kRNNdY8vUOry3I7m4q7c0sFVRBtgQ2EPBQsuaxSpx77zH1dpaM1wJjncxnopeZzj3RczRgH4A== 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:(13230016)(366004)(396003)(39860400002)(346002)(136003)(376002)(107886003)(6506007)(478600001)(26005)(6486002)(41300700001)(6666004)(83380400001)(2616005)(2906002)(186003)(1076003)(5660300002)(8936002)(316002)(6512007)(6916009)(4326008)(8676002)(103116003)(66946007)(66476007)(66556008)(38100700002)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xqSqicF9399UAaEcIwJccm4GoPjnxj1QCxyXYhrIhUcbZ8kkuY00B1AQ3ciH/vX3pfYADcyc6S0sdmrRC3do52zDAbsKk1BtvaB3yGnNmO95yS3B1tsCKYia+4C5ME3XIOQ5c5T6en8LLbOH19V4TXfflhPXabJJ9TecM+TJowywQNI+DsWh6KpdPbUXwDe+D9rdZNeV658GjBLXeqK/vw0SJqCfzLDcRNqlDXe/z8fDOpyIfmhY+FZDHtxAd9K8FWJn1EnJ9N4pTor54RJhzATQ0HzCC668qNz7GIOrlWB6vUOAv84wRPhNGFqkmWA94t7bK9AQA0q1iH8uU19MLCDlViZs4Y8RWcrqU2QEc3T9N54esLOk+T+QR1WsiqKTPdLNawkHekYpY+lY73fP1wieKOFw0EoaisGCEpCSRmrFKRme9whmvEV+5MOgnI2MlYO0jih1clOw70E8eBfQ/9NpEsB4SplI+d+wrFo3op6iY753r0SXsCn2WkLuyI+xlENjoQru3/I4EpjKRSdSkDuWVYm96RYzOfjin4HZ7UfrycFF4oFuTAL0zfZrnmTLYtWwP2T9ACgVU7qcDUM7qprkHRIqQXo+J7etlVaffphATUThAJDc32CSrZZ7asL0fBc7LrJkfXW6ms8IsM867Tvj1kyNgnPrwuI5hIKCwEEazzrkECFN9eLRISPbllx26yCn0OIrJRtmXia8igC092A/maawkpGdVn4oB7rQN3sUTstSa/h68loqGK2cvXAr5audL0hHRqT2QvBe4GnwIY0zm+anMPi0oahj+eHKrSynwQzlT6dh5/nZcsntGzgaB3QJdmMZpbN4OD24SwdvoF2QHxMtkkzCd4xpgiTQEKXJy6vkdal0mPVG13H48aVE61j7rCqn3/kF4+/So/SXCy9ch8Pha6PuMc6xA0IJUdOMG+BQapn/hHt+XsYGArziZTGGO6Txxc4s02bcnI20l/X7wGHsfRu8qHcm+l8kehKhQToYYrHvePkTbzA+asvLr3lV1eX5UJWn+cgSIc6DCzV/XxP7W7fFxsyVwj++2h3GijJxLNElhsJpCiYwthVtwVgj4tvrVR6FwMbLQHJ2Oh1n0DBaABwtYMWZOA69621zhtI0FO8gnTY0GRYMcYonA4CoWpHRf0zMRDETFnoHrYPhax3HadDdt9t8AkqPR/gKIAdDj7zJdPQ7YKeOghG8Mp7sjY8HL39bKKWRDTP6LfNeQnvjXp00SiMBBXE9CQOed6emyLcUnc92z3iVbrpK4QwQ/rSLoHMA+OBaxM1TvKhirknxnGU/EhPrGj1uRYrFahaqmZZYGHlEquJotoXC16OdHzNGYb3o2bmF+AfymZhBDgkjqN9Gq9qlD7EzZyowEBExnJB+Hqlsf2mzR+qJ+vMtAR09pj9oIp1EDNVjPlmBBVKLjtnwup+Qjqc3Ea6FapiXNbzLq6vGfJCZrKNQwBIxWcH2LuHfi1Mc0mfiVv5Rw9IR+/bHke0QUxWcONdNS5LYEekBbEIfxJe935DDsZi8e9EefoX1Dw+/wM2dKW+BskqsFI0IFUw1em1NlIIdzxd0MwByxHzWlAEFvu/7hSCMIes+3ON7QXm6v8AweA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1dbac266-6e0e-4c98-e1a0-08da8793acf2 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2022 18:49:15.9137 (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: bqw8bZ+yS06r+hw2y3AgRa1MMCdzmL8dgC47V5AXydOLRy7ynyWkBGe4eii84h3RywHqkQbZJ7SdTQgkFlKVHFwNa/JKlwBH5g/H5ivTRl4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6331 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-26_10,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208260075 X-Proofpoint-ORIG-GUID: iS6g_935DJecx2sZm92w7Uf9zKz5ib8q X-Proofpoint-GUID: iS6g_935DJecx2sZm92w7Uf9zKz5ib8q 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 e45bba0..2dcf986 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 Aug 26 18:49:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12956510 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 87D10ECAAD9 for ; Fri, 26 Aug 2022 18:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345370AbiHZSx4 (ORCPT ); Fri, 26 Aug 2022 14:53:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345339AbiHZSxZ (ORCPT ); Fri, 26 Aug 2022 14:53:25 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D686F2401; Fri, 26 Aug 2022 11:49:26 -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 27QIDva5006723; Fri, 26 Aug 2022 18:49: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=Go/210amZQ/jHvLyg4x0RO+A2enJkjN6+7/5kX6WJzw=; b=FTrAv+9MKAniSZjL8X9tKK7L4SuwwKMa7u3fqJorpJih3z3KygqH1YLhQUD+frm74/Ib Sf5SnlGahOTJ2fth5rUpjwu1LMjHAOUCuYNFhacym4Cuch7f6azeobTbOZj2qlHyOs88 m50jOqLiaGadGMN+6hpkUcaXMtcYTwFXYo58g2yxaxOjAFI09gPD3VAou8l7apS+8J0R qOr8XrsKkJkeXc1Utr2dxGfr3J6GGtq4AWfyRe7arl9Y7T0zfWBGT2kOZ2XDg1odf+05 qD9y4p4Id7cZkKuJHWHp1MQh+wQDPWMmQn3ApUFFJGA3Dfu+Q53SMrTO4MRDYrhG1AzE mA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3j55p28j6m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:22 +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 27QGnShr036168; Fri, 26 Aug 2022 18:49:20 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3j5n6prgx7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yyd+amuSVqC4s1uAwoUWUZ01Uo+2RR+KUH/GL+4nxGprFqkptgGESgIPipwd0ShmdDrkojI3K7ZC+eXdVL0fvQbhSKkPm3bN1L9pxAiuJ6Xg6Qs9c9lFMIFG+QKow33xC8mPq9KmgTu2e3U0XoOkOs5xc0RYO03B+7PDHqL/VseUlpcCI6cgVye5UAas8cuUt41MPYPZgLmHOCSNp9RHLQsXQpRb6EqIw9Y1q8e7uGqXLxzgc3G7jfzo8er3kL83AcVrb7x/uFkuSZVbWa+7h8vmPiJuj3lrkMJEljsPq+HSbNKCC98sggg9i/R36sjwzaeX53YNCb89Vnu4Duo6tw== 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=Go/210amZQ/jHvLyg4x0RO+A2enJkjN6+7/5kX6WJzw=; b=iWlP1cEwZJI+MNpnNo+Lfr+VD5C4mG1NrL36jxkO0H7wwjHoaRkWnf+7WJ283T5PyX9LwRsg2XtV+gzbeNZVfzcTX5S4kN5Qw3Au/wGjMolyyKw65Jy4jeukOq6FtGnMFkauvga1ZAXpWYR2tdX3YZcwhDpvXwvxh0kg1wG3JoFmHafs/FRGI/NoTv18f4Sd3mxFmBGhcSdePxydqP8027Ks+9D3Hf4GXDNEMW3zpZQR9oMJJBG8bbQnlT+KiKsIvZmZzrgY4dbcOqh/+GBusnw/MnpefWml06rdpcUTNLC7kIR7xGO8t46huCGuyP7tAg+F+4xFmXPNpJVd4uSDrQ== 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=Go/210amZQ/jHvLyg4x0RO+A2enJkjN6+7/5kX6WJzw=; b=Ht3vaZ78PmXlhj3AGEcxISsrBZpeuPL1bXOmJo10h4xt+NVp+Slk6coBNkPbPJVbLt8wvCJysN4Pco9h/eR90rF6IQn/8aDY/OTjEZtaoFUxkv/st7I7xn5KzYRkXBas2Qxjh1BxvHpboC6EnqobJXdBHbhcuo4ZhFeNFzjwTf8= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by SN7PR10MB6331.namprd10.prod.outlook.com (2603:10b6:806:271::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Fri, 26 Aug 2022 18:49:17 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5%6]) with mapi id 15.20.5566.016; Fri, 26 Aug 2022 18:49:17 +0000 From: Stephen Brennan To: dwarves@vger.kernel.org Cc: bpf@vger.kernel.org, Arnaldo Carvalho de Melo , stephen.s.brennan@oracle.com, alan.maguire@oracle.com Subject: [PATCH dwarves 2/7] btf_encoder: Rename percpu structures to variables Date: Fri, 26 Aug 2022 11:49:06 -0700 Message-Id: <20220826184911.168442-3-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826184911.168442-1-stephen.s.brennan@oracle.com> References: <20220826184911.168442-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: DS7PR05CA0028.namprd05.prod.outlook.com (2603:10b6:5:3b9::33) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8dab9bc8-e450-4726-6bce-08da8793ae07 X-MS-TrafficTypeDiagnostic: SN7PR10MB6331:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E48kYKM6cK1DDIKwAffH7vfV9xbDcMpLXxX5k1Rtb2AlFaZG2HHj5xuWv387VuK6ZwwTxa+NHQqkXmjlalaGQBzXgLmXgo+Fqgf7y+DuNIIeDWOt0P6RqrLoGIWCr4JlPRRvO76nEEf60g9QudvGqHnl+FbYQI4gIpYHs1+1xB0DgREBMu9Oy0eGNXOPCafj20dtArSS+XPzkPGHE4u1UB9c335p0Lc81JKBjF9/xWdNpBxUistxVn1+XD3bf9OZ/uaGAOl2++abTGMT8U6md92O17Sjohj/8Vj0HS9/KbIC0TUBTvLABkLl4K6KOhCh0fJs/jdZ3x2rjQA7q+bdexi8cE/NrUjxdHNx9ZVkuS0SZZSHEtNNiuakptTJTinBkKtVYmo2eZVhMotDD2KxH3Kto0u0ao/yRKUiUDrwSXcfgaumnWbLRKdNYOtCjJJ+qJyW0RB9zFKlr+XlaulwuwkLCJDXpBpmKf7phv55LkHq9bGlHD65aLQvMrNt/1qeNp+P5yB7eSCgld6Hn7odS37so3nUGuGHYQXQLGCBnc/KkLKCdiHUiVsmcnHvKbRW/yGTeyrYCpyJakMYQhm9+b6p2O7zFF3mT+wo11XH1hXyS5QlePuFju+UPIeUWNJFyzzyWRqeWfMNkng0DYftAWO13Qvf2YWHyss34v+4LT8fYypKolyF1yt96dN9iu5Ljqe3eAJgKBJ2W0l7s5FGNw== 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:(13230016)(366004)(396003)(39860400002)(346002)(136003)(376002)(107886003)(6506007)(478600001)(26005)(6486002)(41300700001)(6666004)(83380400001)(2616005)(2906002)(186003)(1076003)(5660300002)(8936002)(316002)(6512007)(6916009)(4326008)(8676002)(103116003)(66946007)(66476007)(66556008)(38100700002)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ekfsYNm7sZ7Qm2PU62L4L0HG4FgWzNdVf3pYOKxpIhSTVAE/93lXxTrgotPBL5zmiPY/zfi3cdKJvGeBQmUpjt+rm09hTLe0zx8xX0esLcYloxdpmT7Sr/P/WnVVpPY31v+zmjzGrhPN3lQgi9rmsTWQHPTpzWH/CKuLnfUxM9mVXuD9ctrm9jOu00/1813Mdxa0cQAjUmP1vgSN/iA57tu39rOrrKL5jzfTzZqbnqQnwbkBHurkSlOyGg3zZ3Cqs7QD9kRFY7kfzhkxJQq9goTrLkr/dP8kt7iyhz/ghHTJ/BNuFQZKqRCVbCxwqFEcqhuIGrp97Yiek1S5jv6HREYpZKhjFHwovXig6R45EKLYlOFsK7o+2vLtYmCq+S9Nb/n42xQmAFaQ/3EhNUIoLSqQhQ4pSql24YtU6hEl17qoHGSgwbrkmtL1yUHurgxufkaoU70v1mVyMB51N5wXAspuMJCRaXvdhhFMOOwMJqmj4G7ntUfLHhkioTKF2JMT6DQK4ZaT7xPsNYnHREkVJYuxOEgqkP6dkshMNyCKzyD+o2eSMuIDdlcVMX9U3ZaRRDHV9EdbxQBE27lbSbTtJ1+KSY5vYTxoUvfaP9OKQ8Rg8+YcncBsHBGiZ1/mdBjC75PjYLQyGPLfXZ98Vv7W1xgj1obOGxz6zI5jMZhtqevIJIkQmRg91hUylE4chWxf4Mo4gDfVJmjiW2ilCAL+N5KgA0ktC6xi58mlfMxi83grLmz2E86bMWLuKogDjCvn5B/XINUT8CvryDPro6tCf9034DScDmwguzOZIlUgaY8QyBVbEuBSMricVXiG8od6yX3S5JxFz4TONhdqWIaKK14R4yC1k43BNq6hHC6XfE1JUASKXJMkWNPZFo0aANNZdFjRVD6LhkrPx5fMZLVKNd2KYvPxckMMork0qQZnGbmnjIhS2Z6zuAnK1D2bq7ZBwKYEaPiu0gh48IdhfCB9q1nh1vXodDKt5WV8XUGL37rUu5dFKP4YVLW9l0Cq6OZh2yPwDnmS22ZbCmv/B6ZWRMo8gXN2OJD27WswL2uxfb5B0cEW78uTSyWDvo8NDwKdjyACDtGSKt+RjS3L/aOuL/Li+GdLM0WOUwbLVVhUk6erd5+rVx+BKkZco4t6lnZAIm/CnUS9lWcTdu23pNI4LSMcnntbT+Bk+4p1C69Ltf+rrVYOSXkE8BzTHWYLyPEai7f6RRMok1b5mw/Egt8Yi1j3TrJVPjr0QZQyt5LWnh9sNJLwAURWvpOXLsv2sfN94A5eMRUW0K6ZQRt4NBGsBdqSbVeJUdwAs54SO+ZC4uCMgsF6kmGZbLqyZ5YTnDj9wYzf0gybqB1OrauOjAHZ1npaBIw9ayGvRg1duPd6YYpWVNHG95nfroX9HTa6t6+Zt7EBakQ4H7WfFrlUH652nHP39PCTRhFH6E9+3PmQh1Rb94Qsu/FzBJFJzc8MQmw6X/dLLXFz1HzWGqbhDuuxxbwakkxnrriyh1hcTOc/S3atSOOM7weJiO9T34ThtIcf4uBN9W+ui4RKCQGesELIq8McL/ozsMRvewCAsZnFS5ytw6FaZAk1awbyPHX0U2QLGWaBxTCfHcWNuE/yjsYqfQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8dab9bc8-e450-4726-6bce-08da8793ae07 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2022 18:49:17.7729 (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: 73UnG2X4V3LUtEqKhzqCkApMac6Egem2eWI5eDRBhwuHo6uL4v7BD2OYWZsVwHAWxvXhOogWCEaq22THjFwvzrCMcV7XMnkTWk6xtTOCXoM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6331 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-26_10,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208260075 X-Proofpoint-ORIG-GUID: Wrp2ek99jKENJQYVsdsxVuOq3ZJoRVo2 X-Proofpoint-GUID: Wrp2ek99jKENJQYVsdsxVuOq3ZJoRVo2 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 daa8e3b..bf59962 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; @@ -60,12 +61,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; @@ -1126,8 +1127,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; @@ -1143,7 +1144,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; @@ -1171,17 +1172,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; } @@ -1193,7 +1194,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) { @@ -1204,11 +1205,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) { @@ -1238,7 +1239,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct 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) @@ -1268,9 +1269,10 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct * 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 */ @@ -1418,9 +1420,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 Aug 26 18:49:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12956514 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 8FA47ECAAD7 for ; Fri, 26 Aug 2022 18:54:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345292AbiHZSyI (ORCPT ); Fri, 26 Aug 2022 14:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345315AbiHZSxu (ORCPT ); Fri, 26 Aug 2022 14:53:50 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2FC5E8689; Fri, 26 Aug 2022 11:49:26 -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 27QIDu0O006711; Fri, 26 Aug 2022 18:49:23 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=MiBn9Rg/Wt0I5XMvmyEXs0xBCJsWWOGWqe4hTbmDj/g=; b=DQrekDFl37q2cRrj8ch1aCPP9GiqPdHFdtRy9zYQLdEhv4ludc5PSJ5v8TsC+eDlu2k2 SV4uf1COI+ljxt0DuqL6o2C3TzCWvmr0Xp374vy+c843gF27oQ91wgyOzr8GyBA1U9F8 WhL0zrNil+rzwrwQ0NxYwiMclfFACb75BqEJzdSmFYpmhmILwafpz/5zPvQ8Ot0Sjzkr 2cUINq5+5X8zLSOH/Ilmj6ETJgw03sDhAUxu8qr16lS86g+qqg9LqdtvUND86BFV2qek Kwchx+dmdFXchB8ub2jYd4+NvoLiHyBs64wUcUtPnwMrz1sCbzipWTJkh1IshZCACwYp SQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3j55p28j6n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:23 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 27QGohKi033607; Fri, 26 Aug 2022 18:49:21 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3j5n6r8kft-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f17KRdz68/mdjbQ2RinoI945KnsF46PAFcCnADB4xNoYGVg86dD6oPrqiUJmgF7GN1XvpXpttQgAbLmHt4GMwkAXUma1fvb0qOU2j12QaadrG4ChecOhMakvgROa45SZ5ErCKI6Rdc/UGOZxisk+eIzCDRqiist4ax1H/VeRjxhcsAK0Jg+iEXr1CZpxlmiFb0He3Q9LSjwpHhvF2YV/oz0TOE9cxGwdysYRupviSw9u/Y4vNF9//kPArZizyD9cZCSHxiNDj5/wrsJBwXhbBm/tcbPpk90S3qWOpMFU10sAxxsrsdT/VlL73StOUsT0JG1at9fByZj0PYbHG7p+jA== 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=MiBn9Rg/Wt0I5XMvmyEXs0xBCJsWWOGWqe4hTbmDj/g=; b=CY9Lz6eWqcAorpDFo9B5M15TV2yEMl10EX365Kzz1G2/hu5C+2srR4fBy2AlvETSUHXasaaCnmVnnSSQTuscse6I6SBJQTHBp2QOYKGI1mA533J79WA6MT96afbAfa3qB/vT2koDTCnn7Msxkc2q+pR47e4qfXTgLN9g8Zo7CoLTpEah30mHcTDLCIGopzYUH2Lo2qc0eYWgiComjTHB9dq5s6hEblSTR+eNSIm0bhqKT6+Zqf8AQ8d/KvegzVv8vwLtPxLIQddlujspZpGlBdXB46/mFzxqd2DvpB7g08BNiFx/y3Yy1BI9qagT8LEih0n7IpFI9lQaPwnftAoPbw== 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=MiBn9Rg/Wt0I5XMvmyEXs0xBCJsWWOGWqe4hTbmDj/g=; b=VEuTRmE6aR+ENDqs9g3h6rWpuEv20eRCHVLcP/gG5uTJzmPWH55nh2eZrO7J9tAfJ9UhEVKYQR4B686IgtEl6M8nq9D1FucZcwgRoTX79o3kldbtBHkSEbWNK77hKEtB1wN7aEV8k2VvsfkiCL4urqLlVnc6H5ld21aLcALWyjo= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by SN7PR10MB6331.namprd10.prod.outlook.com (2603:10b6:806:271::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Fri, 26 Aug 2022 18:49:19 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5%6]) with mapi id 15.20.5566.016; Fri, 26 Aug 2022 18:49:19 +0000 From: Stephen Brennan To: dwarves@vger.kernel.org Cc: bpf@vger.kernel.org, Arnaldo Carvalho de Melo , stephen.s.brennan@oracle.com, alan.maguire@oracle.com Subject: [PATCH dwarves 3/7] btf_encoder: cache all ELF section info Date: Fri, 26 Aug 2022 11:49:07 -0700 Message-Id: <20220826184911.168442-4-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826184911.168442-1-stephen.s.brennan@oracle.com> References: <20220826184911.168442-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: DM6PR13CA0064.namprd13.prod.outlook.com (2603:10b6:5:134::41) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 83aa6262-d75b-46ab-98d2-08da8793af31 X-MS-TrafficTypeDiagnostic: SN7PR10MB6331:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uwEBc67Haj1e5AOgO+tsagRG0fFgoVUll8I64yHNgVGXtjcQrwSCIV6c8uri2VdZAvS3yUdoFOYbgOKVUYAFkgOH90ak6SZKQpv9A+oBCVgiO6Bw4lwz5MbglkwUFXo7lDmxezAXTlvLMaxNE2kmwcVEzYvaRjPtlLfF+gA1HsbIEdOh1s5u85j69hpAs3q1jgk+wgH2itBe5QBCnkIdB1F+fVY0LWvOEmSlO7zOcjJsB6ZxD/lziKZh8goE5pNulKOcUkYH+TnoKwbA73/3ioTvBrs3xDODHrVj8CjCtDeMK0Wx7OXAg+J0wRoAuYF5dVfaUBm+53JQiAuAVcBEaWv/sKS0w1QoNAygTtJuxf7WptDAetNU5Mo0IbO6YmyGrpCQHpkn1msRo7j2AsQWE/ujsyaQM10TFJCN00fbFYG1EZo4YqlQRmYktt7mQTJUN/ptugEiiv4CzvCWoDKNu0pROwVfITdQFlIvjwj7fkeGtO86MevjvARY844PXxmeoqovIgUXiYIWsbtWoxCjybIUyC+xYtkhyvPt/kR8FUSd0SNJTCiyj6HxQOMCRxy63v/nByeMfpvu+f0764dCipNdW28US9p03n2lqz0t4s2mB6ezQ9p32AfzLALXrGy/gUaetpOD2rAmvN8op2+VAe1BvAVAU/yGBTUUUKSd/VEMN3QreqRBb/G7c/qD4FYizQy3OV8sWtn2/laMMravFA== 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:(13230016)(366004)(396003)(39860400002)(346002)(136003)(376002)(107886003)(6506007)(478600001)(26005)(6486002)(41300700001)(6666004)(83380400001)(2616005)(2906002)(186003)(1076003)(5660300002)(8936002)(316002)(6512007)(6916009)(4326008)(8676002)(103116003)(66946007)(66476007)(66556008)(38100700002)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: b6sFVo8TmRPeOt1Y4uxcJZM4WgSmFH8aX2vDOnhTjKL1usJASaeH3NRFtKuBi/NQDZF0Ezap1ordFljXtnXJcWbd5sayAf7XNl3+oWW63cYxeVTyVMSiF4INa+Ts4ufrx/7pxCm0l98Psope5V/eSBItDcmzFTnKAILBZ7ivJQWBeh6tz/q/nMBnVNJRF8dSt2aK2TVuccM849ojZ9NJc6Pz/rDuF+VP9sHKxdeB7cPJnlE+bCJfJlXu6W26h3ouRyiIZUaDVGr/LZaLENz9Gi4e4BrBeVU19GvMjmro8aUBuPf4hsem9d86WADbhgjEH4rK74P3Lcxu6yxEDPzMf4LpOc13Y8PDWpYt0+/ii4i7RReEKkmc7pLnm3YGn1g6ImHbN6tynFR5FXEHciBJGy1Rg6xTzjep56X4WJB/ZVFpMBPyN8kwp1euGVAg/yFmAnosVP3A9F0XaZ9vSGKca7UxhWGiQYYJ0f3tRIOcnWf0VQRmznw3OU5ZCwriGCmcPKN7PCHUYA+300+prgV8Ca1BzC6/PQivCSHabavOqLPWVgATunNETGh048S91MBfiAq3hEPRxjLX9CfX5Zl8/eRVUrindPNrxL4P1Ct+PsGHRzekz94t+qR1NEAYre0W+uLEPXLyCmaM9ttuAps635P0RzYvFpDaT+kTOYrPwOsBIJN5w2gPy2RJ/H3as+bGdNaPOTtrr9e7a3QBks5GIr7GbwoYRinNzPlMBrKK2EfMnaUUlZeOZ5LYqwFi4dQDXqywI/07JYqwf9j5HFCTfmOXwtjyzq5X+Lc7GcoctWzypzwglLeA0CHUYWXMiLiYTZUomXrYNwBgzr3x4oNGew+4QZPMy1hvcUwZlgsXwaOTyV8pA/OeFp5uVaieldCXyKly+gDkLh6Ax7Iv9O/20jUcFts5m9mJq6NI7qNOb7xTM2Jz75FJGcpxpW7jIdPEB1/g0yyYEE8zgrfQ+gwdQMIirdTX28QER0fxkbPqV00VyTSN+Q9ULgh7NB64ToENImaWphuaifb7mH/qU8zPHO2e1fqM1O4nSatMzCiNhrRQLnHyOuthH0WsIxI/SnYYjNZaVf9VP7WtFXQH79iabKXqLz5zYKCVta2Vl0LXiCoxhh0G8GH/yAuiig7QiB5Qe26Kd4eOV7Dx+40fUbgpNxevxgsaFUnZk3pxz872TcmFGelGVRc2OSE7yHECgyEORqwpf6SW8qF1gVO+EDOic2BrqDi2n/72YZt7VFEz9liLC4rV20Ak4k+SB+KCX9aivQWmVPb4k2SgXLyhLowW4ZbU4mjkLAq0/YfdJhi4I9F2ibnMs1e0FomCbxF81+TMMqrjU1IVgaHZVqYsc5LUDa1BBZgmxqMzvdS2peUQGStA7TKY/U7j/cn6mad3RT2E+ESXPNKQpB4g/sKXVispJ3AnxROWlgJ+vl/AiP3U8a3Kwhu08IQvBqkdT2BSJSHFf92UF1OANRupQtCnLH4STqDNpnhHWN/p6W0VgIJcnaDv/yJPW66IGXDOwKfrEUkKMsLZ7xdy0Ef4eM7STSZsdX3QubB7UD3xDDvD/BgAfo+MQAW/3I64YtLCMoSK4UMn136oB8jutluXy+nvMGrm1g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83aa6262-d75b-46ab-98d2-08da8793af31 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2022 18:49:19.6645 (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: IYkQA4XxP2FV3r7LLBHKhhygrCx5VoZHhULg04PTsi0NN2ZrurDHKnwwd6eteXU62E5LlPP9CvlHcWUjIfM0zi49Q4WpD0gtAVrQUyQz4YA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6331 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-26_10,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208260075 X-Proofpoint-ORIG-GUID: LulBbNsz_oGTeN82gs023lg6NWHdij5V X-Proofpoint-GUID: LulBbNsz_oGTeN82gs023lg6NWHdij5V 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 bf59962..f67738a 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; +}; + struct btf_encoder { struct list_head node; struct btf *btf; @@ -60,12 +68,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; @@ -1167,12 +1175,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", @@ -1238,6 +1247,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct 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; @@ -1265,14 +1275,9 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct 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 */ @@ -1347,7 +1352,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct * 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); @@ -1411,20 +1416,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 Aug 26 18:49:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12956512 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 6A51DECAAA3 for ; Fri, 26 Aug 2022 18:54:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345025AbiHZSx6 (ORCPT ); Fri, 26 Aug 2022 14:53:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238115AbiHZSx1 (ORCPT ); Fri, 26 Aug 2022 14:53:27 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC02DE9927; Fri, 26 Aug 2022 11:49:27 -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 27QIDohs010635; Fri, 26 Aug 2022 18:49:24 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=pTvj7L2x7IRjDdFH7Z9M/bRmJvetzjp8NUWrLkP5TvY=; b=EvZ/XnIrnY5dDULR/eJvE4MSIYWzhkagwYapgCE6bfLm+1EF5FHeRw2rFpEIPg4gwVcS 93QIioS0Xxr+PyVcLWrPqKBU8p1DFlTJ9asnZD9Yo/ZY3ZBjSJUvALuF4021OS1iBjQG XOTZEgpIqJXeLImua5lmhUHV0XC3BqtCcMyTmSF/uoW1yBKTR5fmE9dVBiZe4WG/vq5R FttlOrx3yq7ZptLuf/k61ipMoGZowdzHgAcK6kuy6pJKtgdVyU7XZS/x1YKbxkM2xaan QvuvOFVMuWSoT53oGuZNbvW61qqQuAYywUg1lVkP2thHI9J7DeZ78A41QfV62BPD8wvD 4A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3j4w242e04-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:24 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 27QGIxYO033694; Fri, 26 Aug 2022 18:49:23 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3j5n6r8kgx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AEhwcSJoCBPSqgyjyJfAhy0OlJ5QAlo1g/VdOuIF+dAQZ7w/zvgw9AKeaUQNKUtGZs40sWi3uFWB6Nr7MRxNcR0EhKnlKf5a841/i08hE9z7qbaKj4XloJoyEDb5MSY3ScWxv4QXUNiEeF/SKQLQMIjuZUvjbY94E+SvcLTIPwpRZpPeoonfKG6lz7YRMO7ILGO09lNfMJOB8lZvxtovHZiV6cd1kfaBL7T//5ojItf9O+gtYrskl1T7JzhivEvWjAj3p4Yvex81Mm6YZO2Ww9BAKjWXTk0iwYvx+HbguTm9474J/qArE9swEEDWVM0c4ER81OdyMZY9Nv25fzQs6w== 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=pTvj7L2x7IRjDdFH7Z9M/bRmJvetzjp8NUWrLkP5TvY=; b=O+6ObNRLF8W6yNEl7L9GPWvlqCxYYFFGz3+pyIpiV7xONsZA5784cHe+1HUQuuaBwfou/KP2AgkqrOQgiPnsFImr8GY645DRYwFf6AUu0jzZwJPVqG6RWskWIDpZFH5pdU0mvtUlGoeUVs+FnTMMbwXcnji11H+gq7ciWYGGvo6v1sbzB6XHTeEq5Y9ASGZlPd8KU00mSlbLtZlSl9d14TSAdLnC0ghfpQOB4pPu4pdstdY9HX+5tE9UP/tp0YCore3fMY6a1YpfviVnmGEUJPf/zFfrqDJvch0hXH7hoEWe6IMSvZIeVQVdRz3wDLJGi+c4VrQHYczt1KuKfu/lzQ== 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=pTvj7L2x7IRjDdFH7Z9M/bRmJvetzjp8NUWrLkP5TvY=; b=WykZ3hRLmMW5QCJQF+sVUNYeOPLi7pMoQJBPRKwHOYyr4vjY3QqYV/kGYbKczUZ27lXaz+3xyP9KfVb6BXHmZIYL3f578K2xshDKke0sw197O6T5azu4Brp3rdwKg5/I5rwsBT/3+WG1vbpNv/ec2FNKmNMoycFvQ3ZQyp/0tGI= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by SN7PR10MB6331.namprd10.prod.outlook.com (2603:10b6:806:271::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Fri, 26 Aug 2022 18:49:21 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5%6]) with mapi id 15.20.5566.016; Fri, 26 Aug 2022 18:49:21 +0000 From: Stephen Brennan To: dwarves@vger.kernel.org Cc: bpf@vger.kernel.org, Arnaldo Carvalho de Melo , stephen.s.brennan@oracle.com, alan.maguire@oracle.com Subject: [PATCH dwarves 4/7] btf_encoder: make the variable array dynamic Date: Fri, 26 Aug 2022 11:49:08 -0700 Message-Id: <20220826184911.168442-5-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826184911.168442-1-stephen.s.brennan@oracle.com> References: <20220826184911.168442-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: DM6PR07CA0088.namprd07.prod.outlook.com (2603:10b6:5:337::21) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 15d89b06-a0e2-478a-2a62-08da8793b04b X-MS-TrafficTypeDiagnostic: SN7PR10MB6331:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Klf+bxZUwOpsUirj+tzoaoc+9pxJiggMJjePpCt9KZY/Fs+k6xVJ2LpVw9ZngLClibxy+DWZAD/XD2/3CsVxtSBpQzABz5M9l0AWBybIFfJV/zD06m9H2JRyPm9WRXQeVU84j79a/xwSdK54hhlM8eKXcFqUc0XgJ+ZwQ/plSJemusUmh50Q1eeWRxPxIbIW5e032ltB/nHGR+X6/yOi0Ns9LWgf4VviS+GJ7dIfHGTlvZ/whqhoQy3e5V6dDY8HvRHBLhpHuG0UAolaYpIXikvRNlgGJe7yfpv4P9+XX9nBsRtPJV/Y4RaGp7dNsFC1gbksQZukscf2fMDeVbSBXgze0RWI67VoWCC3DoqS1SmNZeGTFJNvFxIK3HpWlTB5S/JhN4rUL2CaBKxVACNRtVMItLELWpyfq99dXAYVGE442rjvo4vyEEU0IQKqw3RmmXHjordBNX6A21UVXWE8QdbHx1Cugx51Ul/jhnlAQ394nwLcXwkrOlEGA+IUh8/eq7S2chF8PFKp7OkVj7wKLo2WlrWbPifwnNPQV56QEY692JQTm2Zc7pDMYaygH6cdVTI2BGiPUi5Qfg/V2cdCtkyXcV2RDsshK1p/BYE72Q0yam2MrPA2HQDGPInNvM2P+5vTThHNYHRi7BsM+dHE7Z2yq3i+vrZYiWpaI/CCD1BpCC1nZFCfkUR0zzHHhIOtDNIxHC4DZ/zuhyLBJVU9kg== 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:(13230016)(366004)(396003)(39860400002)(346002)(136003)(376002)(107886003)(6506007)(478600001)(26005)(6486002)(41300700001)(6666004)(83380400001)(2616005)(2906002)(186003)(1076003)(5660300002)(8936002)(316002)(6512007)(6916009)(4326008)(8676002)(103116003)(66946007)(66476007)(66556008)(38100700002)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: c3bJignZ7hiURKkIhciJdbx+q3MbHUE5filHUCQOWQ3xDcbPdqJr7/tYonbbWE25qXjldRZFsQ39VjZUpB2v5JKE8XCmVa+LkaXA1mjrA7rr51dolVIxHzATPx0qjB+GveQ7Kior5u0RBs/kanANe409kogwAk3KBrXqwaKj09By0OT63rcDGbC3b+icTKW68VZkVkSdW9ARAR2v+ZSxPrVjJOX7PYymLbzGw93tYCcd2U6Xv2BdRRXTN/4SlUz/hcMtcyyaYdDd+P0e6FJDb9OIRKSD9n7tXBRAHjzKQ6uZTVG0Th9nd46MrjaNAvqQBvBHsPzTOTyQnpf4f8n/QhghNcg/ZdH+ohIaGbKJZRtjkKVY+F6hkG7m4ZKyvpkSr+xNDW8esl6sMAToEbsdZcY/I4wHpJkU46zhMSi5JRlpJW6suxmtHejnUJ/cyZu0dQa9V4XHTcM8cvK+aSGLGGIDURvCmZhL8mMNpM7/PcUi5bSGt2VQud9tN8ABEh2ekofczMnneGONCr+ngeqLsMhDJQZc+ECfa4Ku6z5aWOXwy+/d91oMGQZlSsHyQzoAsxhgBAg71/6CqMZn9juqkjQYhYNa47cwi7wlJpelBLnrFZgkbVuuvYjTOofIKOKbEiWNPK/u7o6HmbU13JqSwulNj8GfEk6d0OWyhPf/48g7pupH2Hll98+CYpBO0ILmRmvczGfewJpTlY0Fgw++5gX+2mE5N55KeQHWZ23G5E17orfnQn9DnFkPf//x2Y1cLBXb1r1X2eYqQKFyN5+dVFr1dzCbCDL5MzXV81rDyxts7cExD8t7IAO6jQqOOTsBmHfjvEVhGugc0WeBLbOQhgE+bl/gPeqn0qkidXFciOdcwRYzFH0L9YrFBZ206jKZks3sl+zxElDGzoranT64c8FadMhb7T/I5mPhzTTAHDJyZe39zNj0BJxy29vPKy32roYkV2/KivYcdzurXyO8DLSnh+SzJCYnHO2mUQEtdeQJEzaGtAIKqi6tnh8cYzFIjkWy5EtrO1hldtohaF9h14qENEq4oXYAED60EYxddMnkZCEEu38PiI8+NTIpVvrODlTm651K9fcuR447fWvwApCyy78pZZFG2OI+Dc2QM3vM1YopQiaMB6QuOvDKQBvABJRqsfGfUG0bLX1ovbxPnqybBJIn0r3BfxRIsJQouXfLAgFRXUwULj6qfL74wjJGmilXViEr4RPPggdtnjUZEM5gzHVSdtL2KeUzOKCF3dTgl4WOmEWUy/UI920v5lX4JNwBzmJOFAWkaBejZVFgq5ww6LOWwqyBblzIYQitDe2l51mRMeVKbhOoTR0vTycPEd3WK7dKUr8QUN8h7U+nAtz8tVNOOxwPprmRWBc0yuKSy3blIF6gXu93X1ZhpSvlSyBTvP6sIw5flUExY1omqWGhdUN69c58v63iVtkU3Ptd4+cCr6cok9A4Gakalx7VE0ldrYQU9GTtnJYAkHL2x0lvLWjt4QFhaSjOwrgTtQfcmdYAF5gu2ClmqYcOqpmUxZaGATlUlWKJvBu2vM9urgpz3vOHa1juzWRs3E06lAiJVnOZ6/4XGg7nx1QGCk5bSOGNbHPINkT+REuM3FjJYA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15d89b06-a0e2-478a-2a62-08da8793b04b X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2022 18:49:21.5567 (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: 2/vWXDXE0ZTK3fnjoomdWuqEZ5vjl1Zkxo80oyKs1EZi3zSg11a7Z6w+41ub8wjw/cMcktxcgNPNOPZegaYkb0oZPGQGy/ha5Y0pi7vGw6Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6331 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-26_10,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208260075 X-Proofpoint-ORIG-GUID: 5OpfzfSqeUXxKV_YmjO0SL0D2tAy7Yhr X-Proofpoint-GUID: 5OpfzfSqeUXxKV_YmjO0SL0D2tAy7Yhr 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 f67738a..ddc9d00 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 { @@ -71,8 +70,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 { @@ -1157,6 +1157,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); @@ -1183,11 +1192,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; @@ -1470,6 +1474,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 Aug 26 18:49:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12956513 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 42D70ECAAD8 for ; Fri, 26 Aug 2022 18:54:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345389AbiHZSyA (ORCPT ); Fri, 26 Aug 2022 14:54:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345051AbiHZSx3 (ORCPT ); Fri, 26 Aug 2022 14:53:29 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B91AAF2423; Fri, 26 Aug 2022 11:49:31 -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 27QIDtJM006700; Fri, 26 Aug 2022 18:49:26 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=0ruRXZ7WRJP9qd5Z3A0KR2iyc2JhvqKbSEvMz0I7AlE=; b=j1SzLn75FOmjfa/33IxGzyNOGhJNchAmQMvecUTAhbqwxQrNZYFieqRpxJC2eBguLiRz OGw8KXJgAG5QElAxmKtsPWYKy2uNmhrEQS1Cs0pyKd0OvNuPK5YDfLcJyWlv6sK27oWS VSYZnWg4/t/C6Xc7SLuMFLsGGiszCDiArlnd62V2yVXmWLJ6/TIKaY7vx4bLa4XKFm15 DS+OovTnGBJbH21N4yjol70j13S+ueKDyRYIubbRmruYTJ4cSKoyQTkZnJQJOINNU83c GbAdVLexsuPP2DcQR91yPxKqAvuT90SkMPcDhCLHHSD5RQc+P/+TiDntvT1oB+AXraOS 4g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3j55p28j6u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:26 +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 27QGopL4028138; Fri, 26 Aug 2022 18:49:25 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3j5n4p7m7p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k6tOBXWO6hjAGmLmt+nNYu38RHBGUAHAzUDcczRPe1co0TMGNFICvFPAbPu2p5ZCNmXPF6alpI7BZHyDddAJ0rqyXsZHjhDcRTob3zps6wmgoMQWiZaz1G8aWTEA1vaqJQeqlt35vRG+pT/u95DsM5L5EIaYTNMYOGdf73Or6qCcJFi3qWdbHhkVzmidauZcUVEWBiPqXeZRlOBf25pZxDqrFk5mwZr1y+hrJBL4VKIlyPNADasCIkMBHIEvdtQ282vT95Dfa3GcWz45QDFI7O2VFpo4sNBZ+3/KXiyQnz++aMotF1TErvrCz0Bui6GW0/aWLgS9wbTNRZ2Vq2mR5g== 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=0ruRXZ7WRJP9qd5Z3A0KR2iyc2JhvqKbSEvMz0I7AlE=; b=dGcgd3YjeZtGl20qi7n8hLqZr8lGWg+34DEyu5rjEWVw3nX2s9eeB2nnk6iPRW23q0qydrlvvQ1u643FjP773HPdFSc3l21nKaSlB8QYBd7384SDtkg3F+hNv1gLQM9x8KE64pa8O+kdtm+/moFPfCOmdb2EZxoW36BBSu3BuZrY8yPsrogrXMu2gEHMSHs81zJtLno+bu9UTjbpbaYwcZVob6xoQ8vudmki1s+pJSIvcSr0BFj1SNjQw9renQ2y1/IDEKigJASx4kLWLGHdW26uWluEa2DKR7Lb5xRtP53abWoUtBm1jPt2YynOwzmWieO/Xh9pDzcpiFrtHHmzgg== 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=0ruRXZ7WRJP9qd5Z3A0KR2iyc2JhvqKbSEvMz0I7AlE=; b=eJwX+9ZqlwlpvVkpZrZ2chcFFbS62So27wL3YzTxmJcqW+DHnMn15maPNJzzoDVTJAKZ6rp7hyimEZYl9j6IHcPTWEYlXQHzjfY7ouBnIoeNm3HNjc5Ai7etBLmfhpQKEz01k/56eDOKeHirOFRYDqLiC6bMICiS15K4fbEEtVE= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by SN7PR10MB6331.namprd10.prod.outlook.com (2603:10b6:806:271::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Fri, 26 Aug 2022 18:49:23 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5%6]) with mapi id 15.20.5566.016; Fri, 26 Aug 2022 18:49:23 +0000 From: Stephen Brennan To: dwarves@vger.kernel.org Cc: bpf@vger.kernel.org, Arnaldo Carvalho de Melo , stephen.s.brennan@oracle.com, alan.maguire@oracle.com Subject: [PATCH dwarves 5/7] btf_encoder: record ELF section for collected variables Date: Fri, 26 Aug 2022 11:49:09 -0700 Message-Id: <20220826184911.168442-6-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826184911.168442-1-stephen.s.brennan@oracle.com> References: <20220826184911.168442-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:806:130::23) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b167d098-3916-4ee0-141b-08da8793b199 X-MS-TrafficTypeDiagnostic: SN7PR10MB6331:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ORDN2Gz72Yi/eaOU/goVGIHIvg1JQRkrrV0R3jzPLdfvrfKnUKAuQrg51S9SFOUTMkh8Zkjijrd5YQOga3B6tVGhts4e1Eh6xHPjKnK6JbkI35eqJzStJaDvABYkcArjsFhv0rqdqGKXajmsz4QebOD58qTiHXanD0HwiRzHtSUS3dQBPE7cxfzLHAYzndvpnRNoqZFicVbhFs/mcf8jxm54EATVCGy0JnPYSSYS7w3NPrHsOVtMVYd3crzzJ1xZHHUcd8mhgZitkAMYEO/+Ikt07Z4rU7TZXT3vSzasdu+1gaGczPrbO7UisJO7hco5Vt8tvp07UtRgoktRuKWAgLYrZR0IGRlxpMVJcAf4K55ZymHKf7X9zhLqbPlb7rk8Dr0/JxVRmvc8R0tyf0A1iqD/A2qAL4cFivJnGk7tmK4W/g7wsSNeoGef0cAYpQAC4EZcuWxeijswfRD52D+aqbPrk/N+e+Uy9U+gmZYCgfw6JCbkyBu+HOFZDdOB68nKhszuKPBcpoIZ/Y2vx9eFR38B6h9GmoA2gyG61ZYzCXxskrVIb2H/jpK8HOhSHBZErDfsJGjuHj/WYK18eH08WJVfAIlKZkzZZIQMOwIPRJxBne67zSn/FXKWgwtB+GN32tcu6bpMkLAh+btiwfOb90hOzz+3AD3wDJw6KBISuIxHhw8DNATkMXls21+A9GqeFH2lIxc7e2RsXBcjmv4wvw== 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:(13230016)(366004)(396003)(39860400002)(346002)(136003)(376002)(107886003)(6506007)(478600001)(26005)(6486002)(41300700001)(6666004)(83380400001)(2616005)(2906002)(186003)(1076003)(5660300002)(8936002)(316002)(6512007)(6916009)(4326008)(8676002)(103116003)(66946007)(66476007)(66556008)(38100700002)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UW4vcQlfQe4HtAPlmsZjOM0YvOT5zOv/rYW1aESV13hyzZ3tEdd6L6AYqOPC5wZAJquWL4j+3AbwH1TXZNxh/1+m9uA7UV/m5mkQbis7wBMCIpDP2QS9j7Vt87cJGTsEy0KhfUBApQZgZ1RoozsS3GDora1Mox0/Kplg38I6qaaQRtSsBR/lkmLiL895/jZXFlNLq5m1+DNevY3m6WPCniEm+vGkPeJnMkaKN0fNpxm0v/knvOZPZnQCpWHUY1Gco1HWTUY8T4R1p55bsaBitpubs9l8CIPsa0iVCGEWmGZkPJ3EmLcs3hCcuSIBBfMbwgTHRemLs3Ezsr6YRqGxIyXAF2KPSYjR1kkLA4+Okh/099yXrfPzEzyMsHRksBZqiPvZ9Il8ogLAyrpj8qsMxDgiVYtu0yT0Dx5E/bNPZJcat498UMR3+/7tz0aTU6nQ2Bcw3h2Jdz4UDka5+L+Aajw8SKT36qMmxIlYbHy5TFDXg195IMAvnBT3h/uukaD1Jdsrwse7/6x6gm2ZsLWbKINaIcxWcvVKIZ8ahspu2p/dlwTOYuT9sZ/Q8sT63u2aZCCCotr2SRspV2pTTfjeFFhf4f1ivUxxvK1lTp7QVn0AbGALVKbK+N5lsw0p3u4ctVoCGOFdeXm7+ueSPwd1nVn3iiRrwmbxsF2HYk1vEvXwjbKYd6kFYk4FHms4I3td7BJAQoo2Kqq9LMCK8OIp0Ar+LLKZabiL3epKIOrMAsUtsIuTl84/mOfdt4+9lD1pnloZDrJIxKBliky4/f8F2vfk5vzl+Qd2HdblyDLlNDQAqRPJQ2bP/KrWN9/tpH4eIqqc1PcfyFg99Ez2vqe0JTbGeYdUbckHyaryJCu4o1WCkWxX6m7VlJ9Z3EUi2dRIJrBVXZu8t50DR6pVSf7qp4H6+9O6199rAUAIjS7X8ZlnzigoKtqWm5RGtZinsw7cWk1U+4NS0oPh4h8zixZPw5U6JGmTZc2wxK+FWffIpUPM1itZEcgYslvqJrnXds2XDrDOXt3L2Qxc6dz5zGQ8Msr8JSjKsRaAUVIlsXvB1rcWOl3Gkj+O8M5TjDly0zAkGyIqxEc32SeHLIYPBLAJ/WekfRfPpd7Pv0e1i8Fpp7JPolic5s/bbzzqKPDLBN3qbqt37mWnYUh0jOhHRCmMDPZOOz12D7C/Ct5lOmKjdkeS7LU4YQ3BOEq6uOkVBYdJEl3X3c0OVjpLXSawqlX/juFmHjJCFgzJ+Paswe+P1zbx9MbVqVxTwPLr9SfDIYAXc5AQHEz0Y9FYqWD0GxQrVg3tIBP3oIn8YqXeP696sdy/4YX+2b3l8K5ylMbhO+YFWlfwpNxHIj0Exxopm8PEVXTRUDKEPs4nQJTkRqTb8DwvBtP4e8qkM0pfCed3EPvLbjxVdjjd894Gg/9oNtB05SaE7zekwmpmFaI4KE4CI0eL8Wgh1uGnwdr39SUp273sSE0iEjR58VZIuP81Ut/knOnjnkYIqcrWERlKZlPAkrh0Y6S2nqXPJAVMKvuCJ9Z1j2/NvwkX/G/5dsD48aFj/V/fOM37s97tQLW1A3+q2Lakv3oy+CvzwdtpSKMchm6dxlzwk2rT6/GzopWb4qRwVw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b167d098-3916-4ee0-141b-08da8793b199 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2022 18:49:23.7450 (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: koj8o/rIdP8EWInaRpW3fwhEUHFjY/HKMDWzAinwxGseQpPZb/wvPrzFabCs5M2d8Nsq+F9rLZKSP6l8NhDtqzeGV3oO+ZIByusjYZVdRZE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6331 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-26_10,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 phishscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208260075 X-Proofpoint-ORIG-GUID: sKJLwbDvcM8dad_Gqz-e1aTdkEzw0J_z X-Proofpoint-GUID: sKJLwbDvcM8dad_Gqz-e1aTdkEzw0J_z 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 ddc9d00..83aca61 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 { @@ -1145,7 +1146,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; @@ -1195,6 +1196,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; @@ -1202,7 +1204,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 Aug 26 18:49:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12956516 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 D00DAECAAD6 for ; Fri, 26 Aug 2022 18:54:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345374AbiHZSyR (ORCPT ); Fri, 26 Aug 2022 14:54:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345376AbiHZSx6 (ORCPT ); Fri, 26 Aug 2022 14:53:58 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 240ECF23D3; Fri, 26 Aug 2022 11:49:33 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27QIDjnV025971; Fri, 26 Aug 2022 18:49:29 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=EyFffKxsdeN6S4XpBB/c6UZ4vE2Hcpetzy/SXDuzkrA=; b=3GTSRzuLYLuC9r0nCGhL3V17iLdlZw5EKroB43q+oCUUQT/2Ahoe1KcigVFJ597mDQ/q h6kMe0QNrk3o8uUcXaHW4sMT66DOLbyWCUVyR/K4JUV6m0LTVXs+NKjRxdZxTihRw/TH vJ0gFW9TLIKfwA0RVaJ5+SyqSFP6F20++TL6niF9VEXsyHhEhjhS39ZCpZF/yEgaHutM 75nzVJz0c0uR4mJW2WnD6e3gEu/4HSVeiynCNIsHQxbpocwoXggQLCDp59Y54jYgkZTL +7NmMyIFcHSth/ncTuw+Rnc3BuUh7syfFgPDjjWf5U6SeqmH+81QNmX8262NduiR8Wgv zw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3j4w25t7gv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:29 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 27QGQVK1029811; Fri, 26 Aug 2022 18:49:28 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3j5n5r73mu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hBxb2GoIiu4KuGurHfVCzgSZwPuXbGlVmmmYiij5+OFWbSDKXie1UBTYpAR6Fm9deWiCO8X6j50636IBH5gs64opTPxbkbJvDyWRFWhcEOHtuovXFTGbio4dYhgTABaB3N9x29qdxXAQb0INpVmEqxaphZWJl8lVRnkVmIVaqE3hvIzahpck1cPOSCAO8DcVdIKycB6TFVYSDkxBePReQQGYf2BeeILAWSe/vK9snjFozWeLfDMO7sYM6kkxWtdTflO2xqLtQSWPmXpcw0dnfWngVfCOwikpF3+MeuOcWzRuc6kKLzUkDb3wcTYMa8DF0sNGdbs2We8bcf5s5PaY7g== 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=EyFffKxsdeN6S4XpBB/c6UZ4vE2Hcpetzy/SXDuzkrA=; b=PNznUdw8C0w/t65SZNdcNMCQVZZRJSkQQhak8OgxKh3VpFg/5ygWKWr9dnjq/i6v/6HcAzxFF+PoT5IOTkLtAk0JEYamR8ngr6rz7ZauDkEh109vyvZbtToZBQEnDwRompoxFtAjEQE1omtgdl8DdxV5h/U4IAkyqZU+Ln8hjBhlfka1vUZ+bDSJFGru8wyukCWBeWAPxy1C5hR1gbW44kqUyAWgj22Zo2Sy7GkjSKeVSLxH6TZ276kHwJY/7EXIQBvx9szG7OsQj2ixlECHtjVvofxOTlYLUb/fHfP69RRuJIoyuipWjbnBnVu3MWCMwSLh3fqcf0d7iwrD3S0Mrg== 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=EyFffKxsdeN6S4XpBB/c6UZ4vE2Hcpetzy/SXDuzkrA=; b=D4iwRwC2x5LNQWcS9ZZ2Es64C8n8P6win/arYBtySdJLvEttIOZai3wewZbzWmtfyk8WdjPs6b+aWMSHZdG6RUQOXX3dGhSrGC11e7HRRbcYyV5i3YA5ONYvfIN9B+PjXKgEKbsB1PiRsDAx+FF2E4EXAEp8y9kucXouWe36IW0= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by SN7PR10MB6331.namprd10.prod.outlook.com (2603:10b6:806:271::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Fri, 26 Aug 2022 18:49:26 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5%6]) with mapi id 15.20.5566.016; Fri, 26 Aug 2022 18:49:26 +0000 From: Stephen Brennan To: dwarves@vger.kernel.org Cc: bpf@vger.kernel.org, Arnaldo Carvalho de Melo , stephen.s.brennan@oracle.com, alan.maguire@oracle.com Subject: [PATCH dwarves 6/7] btf_encoder: collect all variables Date: Fri, 26 Aug 2022 11:49:10 -0700 Message-Id: <20220826184911.168442-7-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826184911.168442-1-stephen.s.brennan@oracle.com> References: <20220826184911.168442-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SN7PR04CA0081.namprd04.prod.outlook.com (2603:10b6:806:121::26) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e5babb86-edf2-48e9-61dc-08da8793b2e9 X-MS-TrafficTypeDiagnostic: SN7PR10MB6331:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hi2DAX0ImMUYDnGLfidjBRQT7BV/3rspEFG0JVP732uvN9HSOBzOuSdyfmUXojiFeoWZMpPNDwqCIltyC2MbJMQJvrRFDJHoeHxR545m7R/iXuZ8DWostL2ZBBss3lrnn0tBImEJUMXQFhdtz7Fr5I2Z2RHVQO5bQmXbiU2H8vBfC6vm0uuqSsmQEgfNwRSZHLcxxK+mCy4uXs4uFp5KR0jcu2yr0sImfCGSTZvEXBYpkwozdtP9s1lzZxVJGLSEHKgwSD1Zk9QvuoDax0R96BQ5x2Cpylu755qFVnrtysICzMaFYZtSD3jcU2jcIukbZGJVTDLgbIjKFIqQUmUmjzcak0mv7ICcoisugatzt6r3Yh0XBYjrCSAlUPp8CE+pjVHxBCw/f8Rqdmxp8+qBK4STp01dwoL/bWX6RX8twJdaT9VghzYjPAkgFek+1ETfNGsUJx7rEnwe4VXAsaITbvfEHOMoNDE3QF7nKkMVQicZy6Z3uA4h/WdDrDwX0jeOJGqYP8RJKsQEfI5Psp3hLWqGLBmlwgOMvwJvRycCvK/Dj4Sqjiq1Wuyfc0tFGYJT50cdKh+tmGr3UeVK7e+TVg5a9DtLBl7TL1rJuoPbPwX3gbEMp18y06+P2iSE0cbMiH2Qh9m4KgCf4DRHrrjFA9JaMEU+W/jvYPEFOuSM1W8zxAq+GUjXgf8ttrcRFUEcPKwZNjWG3grHCSNcGCbUOWVUxDY+xAz4l5ZDbG2UyaNa96CqL2eofvQwFK8A6u8d 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:(13230016)(366004)(396003)(39860400002)(346002)(136003)(376002)(107886003)(6506007)(478600001)(26005)(6486002)(41300700001)(6666004)(83380400001)(2616005)(2906002)(186003)(1076003)(5660300002)(8936002)(316002)(6512007)(6916009)(4326008)(8676002)(103116003)(66946007)(66476007)(66556008)(38100700002)(86362001)(36756003)(21314003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fgOzG3RkITQRb0IkMDcfZmfrt0sMYktA5Ise2rBRGhOgk15doAyixn+V9U9q4GJ+wFSspmKR1Yvnp37E2otLNmnW6JcgUUXmDq01OCUfNByU/bDhTnhRrKws81mSnehuPustAEn8bHGc8+H/iLb69IbWz6drvBsXIP3EfyxXWVmmuGyWA5F07uZ1BdGSYWjoimUXf+5XIvBZhgGBQI+5wMLIGOdMkOe+aDlQq75U/kqJzi6LpRogbBkCTWD+48HtM+DN0g8/qaVNy5we+3NJFguYWF9f0PsFIo+HAN7aJn2iL8eERpzY2nyTHJJesZhX0eWZtzfdUsEX9SCSo4HzEg3GXsLjkwkg37qZ/O24o7kchEgzanzNYkahDCL8nXGpgbvvPgfhdJTj+IbZDYoHG5friW4XqF+2S2IbAFc6TDR6KiF00DDM2EGFnJorv6Obe8o3qOrvve/rCJBR+CflhuJtwylP22NeuEOuYolywXPqr7rsA7fgqr3H32GChEuUbaQ7N3c+Lq97a74b5FxF4U8e1jD0XmeqBqBP84DqtToRWVB54JhWOVxl8VjLnuaZcPFRrZv2xcp0vuzdxf9WFi40ZcS+QBsTrUaQdHhp7XNf75Wed+lEPWA+Q3a7m8sw2f+3amawyL/4oBbmBEjjWZzf+QTQxTUvwm7n4KLf/CQEidG+KWQ2oDJ6/BF4VBhRQiSwiMgIBqACJkUaZsrpdfA5+iM+ILCxA0qEjmuQHVEg1j6/o3YD3FeIa3nmdguF1IrCY4cHJ1Kn7w0mlFSnKjjMnb4xDEqG99NbSlJ/sf33jJ0Sme+OvCyOWdTO5UrNNTfiCoDQIUuWy+9U1Veo/cQZ4FChCgVZs3xFM3t0LMMaC469xC6edMNT4uxG5CIcOWGNk4YenecTNGXqgfzuJqNbU2zaCto8jLHyRvR7v5JBQBuSjk2BCqXWWMplF41s3iZN4tzAhXzBJG/PiihNTLdLI0cCZy4cblEozcQ55LdRWdLfX8Iq4lDE/raZNkFskk3gyaFr8nx1rcvVc6Ol7zrW3ls0Yq10VpYFhj24VrgANQKu8t/X3hiyas/0dzsKHmON9LdH+B/2cWi061bmFHexxVJ9+4+rqgKtFPz3ID0k4DyRh1pnA3ibHFzBfXIfcS0NQywGFiIbZdjQlJSv3KT8Jfa503sfVLzWp8diO7r+7KLwkZ3YZUrkf37Mxwt3p4MgLA59OyCkK428EEo8U4GzuHC+K+zD4RcvaVT+zssVJHbaUbBsmIK+fTCg7WMSFno5FXC16iQkSzbA5uV/EqQigzmxK1GfsdiVFP7a42+R4F7w6YEIU+DD2yWVd5sAW5qrQvTEJt+lW+YjeJVyNakb9DOOOEx9zReOj9bQixFYWHp0ciAAVS/7Z93C9cOsuCQFab5IVt3XKOVRnq45kby3OyX0uRgyNgO94Tr2FbG77B8VmlUhh/sW4vBVPjS059SxzaKII9rPpz7rFLceBdWc1c3bE+Re/kb1FOZlhWoWDVlkaVKYoW0mTsfESqmniROdOilkIoYVRoBVM+BAQLma94HhkLDG6Bkb1K9Vbth64m36+XZwV52baC8ImStVbRilDDH0iMnvV6tBQQM4rg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5babb86-edf2-48e9-61dc-08da8793b2e9 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2022 18:49:25.9646 (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: zlphJn2oBW8C1PWuYUThuTFSjbHPYmIA3slAfw7LW0F6QiA2601dYYr/IZvEpooOnlm/Zv06Ld+EjXHnySeAnjGGg3jmGJRFRXkuaofHjII= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6331 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-26_10,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 phishscore=0 adultscore=0 mlxscore=0 bulkscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208260075 X-Proofpoint-ORIG-GUID: 6gXfDsP67k3Xzg0m7XzhbFBAvR1oZuWc X-Proofpoint-GUID: 6gXfDsP67k3Xzg0m7XzhbFBAvR1oZuWc 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 83aca61..1804500 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -1123,7 +1123,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; @@ -1133,28 +1133,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; @@ -1213,7 +1209,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; @@ -1221,7 +1217,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); @@ -1263,17 +1259,19 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct 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; @@ -1281,13 +1279,16 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct 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 @@ -1306,7 +1307,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct * 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; } @@ -1315,7 +1316,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct 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; @@ -1325,7 +1326,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct 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; } @@ -1334,14 +1335,14 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct 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; } @@ -1349,20 +1350,23 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct 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 Aug 26 18:49:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12956515 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 B68A1ECAAD7 for ; Fri, 26 Aug 2022 18:54:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345358AbiHZSyP (ORCPT ); Fri, 26 Aug 2022 14:54:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345378AbiHZSx5 (ORCPT ); Fri, 26 Aug 2022 14:53:57 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E2AEF2C82; Fri, 26 Aug 2022 11:49:35 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27QIDjs8025982; Fri, 26 Aug 2022 18:49:31 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=2CC2vTW+p33cEfrXC9oOJ4lF/EDb7hgO9hM1oeIz/1I=; b=RRzBLKfYx/LJCnnYT2dIltMRIC5QQeRcHPpW2g5b2O+DEkoTQQvbtXqobvcUIF4oVAYp GAsqhsDEoCbA5mTrpQUdiK645Gjsz2QkcRdu/koCaYJqJSo4mboQFGXlAD3TAVIVz65W SCJITA4cVmtN39ol2QQF83U0goNeYNFbq0VFpxMe1AelDL8s9ahydXAdm6+yD+PE3pnh q74XmgbljvgxnKFIAg7lKKYaYeZ5jNzv1r4hjw2ti/ChduMDxITgoQjh/DUZB7PF4y1X QnrmheVv9KfEECUjoRyBy1EpjpPFMNHbMQvWFEBC/EOtiYnLkY8ldw5px47laZkrSpJT 8A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3j4w25t7gx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:31 +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 27QGYPpU018831; Fri, 26 Aug 2022 18:49:30 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2176.outbound.protection.outlook.com [104.47.59.176]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3j5n59fb1e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 18:49:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gWrAMNK7Yh8Abmk1YflRqhWTKUNu7n9OUeq9oKdIGt+//7fAEUGA+h4eKSIRjjkKSa+bYfuq1YenCO8BCpL7xu7aaNh7phORroPlJxOEQqydo9zrKtH9s7C3Wxss290FoUvmFkRyDAwnSdd5vXsrofNeliBvKQMjcBJO8+XF0kn7SCGx81kwQu/GAO3pfHDyBTZC3V+iOWd5Wefi1APn3assuoy5OlWvddvVw1oDThu2fT+DKJK23WjhRvAarSkxokzUycpOo4o99FfCNCyhq3zToijItWYGZ03u67+pQbDM9IFTLAO1Y9ShWhnwrxgSvCq2Gxmc0EI1hBcULlNj4g== 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=2CC2vTW+p33cEfrXC9oOJ4lF/EDb7hgO9hM1oeIz/1I=; b=emJoaWLehMIU0OP5iqlvI1fhLbs6K4AXgE8WUXyIFC6UG/RS+1MAOsvmHCethPjFRWY8xY6DcTZZ8jWUwwurdUJ4o/3lwoFvLgb4c+v9o4SBP0Y3ZCRVLFkRh8ImceNKc2lG38qSTnBC+LI4njqI/Ptl/Gqtoh+Pk5iFl3KsjOGuOTb2n2Mx3I5JjqD0xuymGX8D2lf2v+qST3kD96fK2e4Y8hzF6TcjdeYmQlI+Jxm6R3rsDuQsItaHTM7CGJzn83hir9TcbCgVShOpUc+fiDi33jmaQS5HlgoKQb+EYFMN/bSHX6biu5Eo1Vi6Mrs+NH9Ie4OcMq+AeM31nQZUtA== 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=2CC2vTW+p33cEfrXC9oOJ4lF/EDb7hgO9hM1oeIz/1I=; b=ReVFVhRO8DcS4efv+Bj5rxpdvnj35VQ/yc7PCT3bwLve11lvOt0FWWlFm92xV2HkKWe8W5jDh9N30RNqxXCl0qYC7Ch3NHKlx01drPIyjqgbuFAxA/gHRk2eklIOJSDs98xeMNq4b/ioYpVAatjk1GGc2ZA6ERgcqQaAaT4mMTE= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by SN6PR10MB2558.namprd10.prod.outlook.com (2603:10b6:805:48::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Fri, 26 Aug 2022 18:49:28 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::44ed:9862:9a69:6da5%6]) with mapi id 15.20.5566.016; Fri, 26 Aug 2022 18:49:28 +0000 From: Stephen Brennan To: dwarves@vger.kernel.org Cc: bpf@vger.kernel.org, Arnaldo Carvalho de Melo , stephen.s.brennan@oracle.com, alan.maguire@oracle.com Subject: [PATCH dwarves 7/7] btf_encoder: allow encoding all variables Date: Fri, 26 Aug 2022 11:49:11 -0700 Message-Id: <20220826184911.168442-8-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826184911.168442-1-stephen.s.brennan@oracle.com> References: <20220826184911.168442-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA9PR11CA0003.namprd11.prod.outlook.com (2603:10b6:806:6e::8) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3d4f2229-12d5-4fbb-e3a0-08da8793b43b X-MS-TrafficTypeDiagnostic: SN6PR10MB2558:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OtfP3KdYskNPLbzL5FB5aIdtd/88GSlqYOJ/iirIk/0AMNt7ogg0OZ08iu12OYcfYC5RAAbJzxPe2FmYScXeOBzLlu3Z6PDy6h0b/vhmTJp9pXHKX4Gjw0x7fsY3dMyrc7pvHPFP8eTRdXOkKaTSfkmU4isAIlLa3zOxD4Jt2UZ13BDuCVNYh7AhwaoVBOCgkccdvgnczeThBtma+9k3PYiPJyFzNvfTnO6Cm7yBAQ34tO0b5NvpBD82AKjenmulTfIbrOjPmiqRhnDQ15kjX6tC0N6xh7xrOMx92gRI/Qodb9RddDoWIj/IkgHwLHdw5pC1I/r2rsnWwG+9frYJcmFsKdxoVoPd5jGZsAUMWlxGiiYzyGTTxTvFgHZb7LWjGZUyL1vXOPgqWFULHXTjigkQY6/KP12iUU3x7YqYPQQDO1h2jTrKbqePAS79gAGHRjRtWShvtN1j1G5gBHWAdTVUa/zu1dBdSEZWXbFklQdFXHCkq5uhKZui5ehl/PA2tqN2mMFISZp1fdRQJlvoxzJaazTxzEzluFvFWO75Jn5yG9hV/eCOPpxKFse4/JJ8uF6XowwaUIW3JJHsZH95s2ygyrS61aq7QnHIHVRH7qWsR2DeycS5xI09PivfLwLXXzmevYpftNBeotGEe1J3V3KB69YMAUxB/K3ETUNx9jz6rTVT++QTJfrMxSt208zUzspyFY1ZQ4TfwlSYpoZ8xg== 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:(13230016)(346002)(396003)(39860400002)(376002)(366004)(136003)(316002)(41300700001)(6916009)(6506007)(6666004)(6512007)(26005)(478600001)(6486002)(66946007)(8676002)(66476007)(4326008)(66556008)(8936002)(5660300002)(2906002)(38100700002)(36756003)(86362001)(103116003)(1076003)(2616005)(186003)(83380400001)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7DnVPxIn1SkAouOpBaaGIO2ikROSq7kIzJmz2KDlMk7yWb2nyumcMzwlgFuBONjECpMtbAId0QSgADExt3U3DCkspR770/yRVsTT0K3tGmYQxcWvlAtMXtc7Y8/4GbBi6ptPc08QZCl0VV0yKDEQZhpnXuOOELFODXKoUKat9XNpqu45B9uITbv6eBALcBz++2IzElSOuEcj3QSbnkNzlkqQQRvoZZw0In4/h5EnvDA2HWnt3B235AzlNEX7BjQ5gffPWElW2pGGRgMsnQC+K//2Q73mFdwEU5WU9nfnas8TdxefKx1JACu3ekYjhIEJ2jmmTy+0/w092qQPuYxGvzDJAAvVfkvL3vYAiY81UiD1f5JcuJXEALNB4mPi52gX738xRYO9qGN4Cb9lwH3RT8S7aPhcXmM/9zwksFqRMJPxMCT+Ph/h2x7YtxPHIOyueV1Uj1rTBUZ28ytNLOB2KLkTxD3Xd+2T3/dEDnyToRMQ0XCQAXYIK+cab7LbRGdtDMyvpUrQ/wOjeDughasf4V93rjYUt49We6WJOsi8M5hp9CiXSlf78b+YQ+A/I18GVUs/yFN4wRsQYysNfbQyY5e9CvCkIeRM3DP/EBENk0wVKr//9JhLxe4KnLzIhkfLfBLXtTZODIOmMr3wnuBVvqvzMsvfgmKNVzk7q8mVVYFiJtGGn6EEZUnwJ4SngJcf4oH5GXvcRxOV/lUDvZqr2tSC1kzzp6e8iNBotnxkyXS+qli/X6msFZTZ0hU1Hn9DKewP0/3NQURBMavHksmgdvKIjzF/FuFDzX41rhJWnLne1Hd+35iIVNG8WeHGMIzI+pjJHVMEct+6wsevzOBPHG6ZEpA5WkX1CkOBBHoSpUfnPpnnTfyggmhyQQlMBIDg7SvsPmiu5JLRTHTkNrMRMmWVcr8SikhOp2M7ACp3NykN1cIykirf/a/VBYUcG/Es/lq3ZXAXA1RTF+sOd2koeMRFXMZv2S3RtB/rKLGdCDQFdJw8bw6/Ma8jD7l5KQLbr2rKGUDeBbtu7bA1duQKWDzuxbWkw0KQdTEz3PYapN3Yj3tiMaCzUawtoKOhCiU7OxRX7gF/nNp58kljgiR8JeXno8c5E4r0fvqWyb2ALa52evwKgj3VGZPMw98cEmIepxhPYLRlAyqE8Axy2CASfPo/weoGsAQKYl4hduvb/kI7G2Jwd+q0LtLEDqJcfRZMCw7gxgIKZYnxjbiqwPO24a2P5irvvRnlIK/gtNq1Qt0ld5q1WvxypZbcFKrx7oXmNTWe+oESDCqwl5t61wzqAueP7azM1scRNZZLW5mEVc3oIEbEZeYquhokeYhWWtcrCrMKenoRJbdRkKsnGQEsGtVaxCHFWrYGVACShDBuYYci/ZknQYbWBeMIvCfOGb5ZMgNnyqpvMNcOhKrwNkfPbFfZ/5joWByj188n/8uwF1i9eNfMC9S6VYcoU4ot1MVgQAmIflM5lfkDoinaoNjdLZo7UHk78orC7F2qWdvHS0ZnlhDwd8WTKbvwiTCCAF+OhtmYcPsJHAwOni1pmrvOAgMlUMvV0Rl04UfTDi4TgYZTvBx+yiEh3HDI2TuBVs0mQfRBqFvIsfHBTF4OQ1lg+w== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3d4f2229-12d5-4fbb-e3a0-08da8793b43b X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2022 18:49:28.1987 (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: dw6vGimUT4eDFOxXDdomMfMSvXIqoXSEfQ7tvohSp3qfMa234pyaD+K9Jes4jdxi9yq188kLLpe0AFnFRD1RXZadi9BBJgpW1/GiY0MKiEk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB2558 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-26_10,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208260075 X-Proofpoint-ORIG-GUID: dP31m1Wq5nuoRTMZmLvSq4wlZPaooyYI X-Proofpoint-GUID: dP31m1Wq5nuoRTMZmLvSq4wlZPaooyYI 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 | 31 +++++++++++++++++++++++++------ 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 1804500..eabc8d2 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -61,7 +61,6 @@ struct btf_encoder { struct elf_symtab *symtab; bool has_index_type, need_index_type, - skip_encoding_vars, raw_output, verbose, force, @@ -70,6 +69,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; @@ -1198,24 +1198,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); @@ -1375,7 +1376,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)); @@ -1391,11 +1392,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; @@ -1445,17 +1446,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) @@ -1615,7 +1619,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, cu, type_id_off); out: return err; 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 bb88e2f..d21af0a 100644 --- a/man-pages/pahole.1 +++ b/man-pages/pahole.1 @@ -207,7 +207,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 e87d9a4..1f86ffb 100644 --- a/pahole.c +++ b/pahole.c @@ -4,6 +4,7 @@ Copyright (C) 2006 Mandriva Conectiva S.A. Copyright (C) 2006 Arnaldo Carvalho de Melo Copyright (C) 2007- Arnaldo Carvalho de Melo + Copyright (c) 2022 Oracle and/or its affiliates. */ #include @@ -37,7 +38,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; @@ -1221,6 +1222,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version; #define ARGP_languages 335 #define ARGP_languages_exclude 336 #define ARGP_skip_encoding_btf_enum64 337 +#define ARGP_encode_all_btf_vars 338 static const struct argp_option pahole__options[] = { { @@ -1532,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", @@ -1757,8 +1764,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: @@ -1795,6 +1800,20 @@ static error_t pahole__options_parser(int key, char *arg, languages.str = arg; break; case ARGP_skip_encoding_btf_enum64: conf_load.skip_encoding_btf_enum64 = 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; } @@ -3034,7 +3053,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; @@ -3064,7 +3083,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);