From patchwork Fri Sep 20 08:18:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13808243 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7596D6F2FE; Fri, 20 Sep 2024 08:19:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820359; cv=fail; b=ddBotpTyvh488qEzn4XQ5I8jQg8akEthdMTx/9rbDkLZbg0gkfWY7+40ycebjmtqRNFGMw+kqQRJA8iF1b3l9l9WRxwnAHcFMWFhJqtfvBW/3yFp77fQEOtCXAM5cVz7Uwtf4hpj0U9/FBRX21PjItc33dTTQzAAFwNkBEaafeI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820359; c=relaxed/simple; bh=6EZ2luigtO88K4R5Op/3rpy0CT8BTVs94pxIvz41LGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=WQaHbDpW3NPnYxbjKOKmZSWZ9n2JAlv8ICpbrLIexDI4zrHzRA8XTrT0f7K5bd5vrF7RglovXdnnMi2TbvHi8EUoa89pQMfNUN0pgME8mYCbXHHT7YML7Du9rpGl3Be2TYCW6Vgx24fAiG/jYOKYdquyxoJG9+uIKQWohhQ0l9M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=i7ZA30FI; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=vR4zkkOn; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="i7ZA30FI"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="vR4zkkOn" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48K7u3gr029014; Fri, 20 Sep 2024 08:19:15 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-2023-11-20; bh=mwl5gp7wqfaZGY7yQqD5/hsyLm8D/edNP5UlFYcrpA4=; b= i7ZA30FI76UPfVT53sPpo/ffrCeQcH0IowZmVCo48iu2+ag8gbR1vwZJAjqu6aeT +gkiQLC+rF8mYGuQ3ey3kKN3RWLfu1Y0YWjQ0wSJXOkGg6EFPzxK02P8sMMrjaUf D2p5y0qXR8eGc7jdQPozUEgFky55SCPtUxj6UJqU6Uwh/28fHWSUOhW7WojbCF/m w/LLDHF+YsbApJ/0XWRknJnAH49NMgoEUg+Et7jjbze7kzP5gG13caSWwDT6U1A/ cb+NaLfKAMTBnEt5/4odJmpeMCbgkhOC4CqQvyvSgQYORU4B9VDLyx2PvJtd+Ehj H0ahLkCMVCcA/lVNBrlsFQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41n3sfx55y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Sep 2024 08:19:14 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48K6MuPo000430; Fri, 20 Sep 2024 08:19:13 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2175.outbound.protection.outlook.com [104.47.56.175]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41nye05935-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Sep 2024 08:19:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=U3ufcaAkODkQxnVIr+NgZTjoviKw8/eAdsNyt9N1gW2YYMfaYwQuoliBSLoioQCzxXeb7HySWPvk41RIF7lO98fdTPAC6bm94tAC5kZOf5kRqgIDvEt9TN15r826eJjJph48G1v2CAnzJVLZCsTgM5/dYqIsaoa5W1Zch5MwDRU14BU/niskOBA/iNSY0OrObmVAmfunHiIZQlbWnQX6ZSnwUHAebb879J6VxSCgAiAjyyoMjpkiHHSQLT0n8MBT3VcAgvjiSKWxDXOoikDdX0yb6ZrXjd8gsQ/wEN2WQRcsbPIjFk3VNSaP/LcdrruichVxkZL4QornxAEQOnVSMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mwl5gp7wqfaZGY7yQqD5/hsyLm8D/edNP5UlFYcrpA4=; b=raZ7hH6oaE2XgMt5ixdyHDBqRbdYyH3J4zHkPCf2edrBKDVkBfrQ34UTFPHLgbuVjmMLoxqjgpkr7XYwFNX9rLsUKkyZysLJp3PxMdQRVCdlkn9Smr0hvroJNubGjqu061SgNMyzIsaD43gIh8vXaJUKpXg0nlcuP2WOEldsZFE0qY904VRb1762VZGyZN0i0Arv9jivZjKEthqEPLbQABs8RGXrYbDIqAWbpg3wjiQfgLQuj21uLbpDmmlGGmfz8KIoBjpwIl5jx/u0cxoMvWqA1eGhX2xS41WIRfcQDqwIzbvf+BwAQfHODE38CiSread3/V17Ze1TsnNPnysNCw== 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=mwl5gp7wqfaZGY7yQqD5/hsyLm8D/edNP5UlFYcrpA4=; b=vR4zkkOnHwNIGYeiKq+QF5vqtxaW1PWzoveRfV6Zgs257J67NJM74zd3dGtkuSVQiLrJOmE6attmPxO1+T/Gh0VjUtQS61l/z4hNm4k2bkVgcUxkScQylW2OWt+9Cyrpa6PR05FhgNhYo6cMhHpFutD29NhWDQA4PosW22mwOy0= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by DM4PR10MB6037.namprd10.prod.outlook.com (2603:10b6:8:bb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.9; Fri, 20 Sep 2024 08:19:10 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8005.006; Fri, 20 Sep 2024 08:19:10 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v2 1/4] dutil: return ELF section name when looked up by index Date: Fri, 20 Sep 2024 01:18:58 -0700 Message-ID: <20240920081903.13473-2-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240920081903.13473-1-stephen.s.brennan@oracle.com> References: <20240920081903.13473-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: VI1P194CA0042.EURP194.PROD.OUTLOOK.COM (2603:10a6:803:3c::31) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|DM4PR10MB6037:EE_ X-MS-Office365-Filtering-Correlation-Id: 57de1ac0-6172-44bd-4f44-08dcd94ce78c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: xdLAm3apnZNmSZuJ4HYGYylX2lf42wAno7WnxzEQxf6Z6wZShLoLUiUgejFrpWDPR/FPtiP+POoRvqWpVMxnx6hR8f0+1/a73N3SVDswGS21Sxlppg37SE9XGx2Bw8PPZ6DQskaYyvwNvCqka8R1/HRbhImNcffAHtkBmCZAdthgtB6mxAehyt4hUfMqoCXbv8SGDOrjjtEcD0T5VaOMx7b275j6dWqXKgCbdpxMZpl1NpXx4b5jsjZBMKSr2Kx4rvLsWs90UWlSAQcA0g0kql1nRhQ2ng/uLadVyzM/TG1NLLbX1f0dRd4ejRc04f/Zxcry0wAL/UVMlcmYJqjnv6eH8WtCvsLIZJDtmZPfvRgWOIF3npfYsaAw68Gwz0ciDBUfDDF4Z9nqN5bC8QR4hS5TXnWgQ1We8OKV9ajK6hwUyfKDHx/eVSKntUXichvqFOItvtG3VzWlu3d+xnE4Zif+F7t0zfPQf6IiZPEwmCdcjGSuqe+axQ9iXhC0wNCReMwfKdmEyMVL5vw2JnBEN9L6YmDMCOblvpU92W/DGEAcBVDmJyQ0QOYQCRNm4VYRp2Jp2PNDp779lMD+4VjpwbDxD0hxtF8j7TTrWZenbqAqnxfD1vp6Xi3Kfscn2BcrtRnhD20TFdUH80lRN9zJuJqwKg43Wss+KoWihGbrZtszNgdr7/Bcew6P7eMZZ93RPPG+BM3qLbrvpWUVzq6GXevM4+U+5B63LbRe9KRWPqmBJ34uG5uk3a99h0z3YYvoGbksyyFWBH57Zj5EjhtXDbOWb9CafuiR5dRRDo4fCpw5Fiw2TNpscQ3cXW7COYH2XGxGExYxX44ZdTAOAwhoG+dwLuYlLiEvgsEZl7zsMw3rD2Vtrz3mUw5E08BTkdf1JIk635+QVpje6GsS+L/eCi6hqnTfipUXo6wEMtRlY/G3VQ6NWLi3KRNNO896ynE1M1D0UrByzdEG6Yvxo47VllsdUYjvKGVYhHJfT/Q+qYPpVJI+SQPmjRcexibnbH0LinO7S6EeKZ/l/tPO9SZJNm2ZjqSHzNxOk6PQIJufFAK29cFoMRkNl2xJzN9ixQj/MIgWdka2bMiyzlOK2IC1IdP/NYqFtgIOJonxG5Q1cwM042SJuCwXfBY9en2LJ/14QjgMdKnUCwDC7TBm19q6VhPggaeziuSdxPGQgiQa2ltu1HdXVnxBxsukdvOQcyhKS1IH3mMBCSO0qRhjcu9DEb6kdL7v8IP2RgM/BR02lFwLLvBvtHns6XKc62DWOmaMwygkVfk+iX1iI9T6KI5xnw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: m/1DWlky8UAXC+D/i3gUBEsklwAAI1rJzUpypN7tE9ksPwQ16YkPF9wGfLC57mGT3O9zT3HJVCzwUCgupE0FobK4DeEK9CQL6I0E5VPDhSzXpzo+jmrGdltZ08B16/zijhvVJAsj3FFjYKypf5OhGzubv3MPeYmxsjfCEwEjzcFbHzEhx4fDhrOcmyzGsItPRgv7A00XrT0A5hKCxBT+nSlv8cQsVsjKnOE4TRyT4i8EuM+A8cuM2XwczCtcfxrePdKOxQRlw7EzZE7RFo0nnM0hs9zra82TLiGtAbzQcacHEpl4ey2MLMxZxiyQTEa9knXSVOZ9eZMj5u6CuVemPSAd+1tIHojLJuwK0ejzJBnFpKSVun+Fhdy+3DhNkYYg4PG1zzRvzdN8vkhbnbecX4b0zL0YbJiUU9zLsbZXkhXMEQ4L2TdA5Z1Dex06oxH0TAzzmqT+QLaLv1Elgc0kcrqbVIOPgj+vaDmy33GtZfrK8aRe07jq/aSVWFLTJ4G7TPM8Alrok7yli0C7Y7Wld7cCBQtYhHKIEqrEwjpEPHYYhzlqQKsyJO23Pu8RVg1ZCJao5tYUUOUB3AUApRVfBnbw6u9dzspBBMvgbCiuuN08x8bzIwkZwTO/jBZ1s5QaKFEfpxjaXlQSqwlRPdo/Joaxo9V4DAhJtHcMuEQVWeV/IWuDShIMmzX7qsFpvFTMVFbPo+tiQ9kzhhcjLbIYcpNMD9mZv1+4YMOEj0kHxEfmUV0L78SWGkvgb8f7EavxHviUZcWIDJTHjYsRFsWdWIGtWW5ZqG79yoAeAcP7wvPTRXU9MYLoAWs5pFu8sRCRXq9TC8a0Zjxl9y2ejWrhdVY2kU/H4x4pugdzYanScYxen71n8Y6UTn/n7J+apmCR28V9gcNCsax9g6ouz1lbOE3MqrVu5WxSaV/WAWwBwDq4yi3DU1hTzKJNrM+j63AxfZdtnZqfoLOicgZtAWzokQzpY/ORH6hDa+nqhHHA2YVyA0LXnmUYIo9E41yEGaE+oGyK4c4xEP03JtWFyms0ugx2xTa9+LF6EDTemXO5WOK6qIFJatN9XFJQsx29gwOnCJYdv60DVHE/EekBq66g1huGfmRB+nYSKcanbfGS1Yuw1hbGXUqBg0FDB3iLemoHlu2+Zjzjef6mMljztHkGW+HHqkMkWGFV+0bkJTgXjeq0/+e5rDhdxxdUlv2BspIKjbpQhJrbL+tXDSsYArzvYmMl9VKKM94MJR1Qms6PBnEkq4+EGxeoRRievU4436tilQ5amFgs//hRdL8dq86n7XWZz4ZVEEGOG1T/vUmddrtq3tvqIVNeEAPP0LOCA3lEwyuxUe5MJROIm0GhHDYgJeGmiwupmRexWEILc3ClVrz9B5IjsXxuvrYzIwaObWWmqsZs40QwrNwYz8ri21PKhWtB9DCfeaGT/6/5LiBAUUI79S+sUXjXqng8BpeSdI6OXDOUwAlP8oYDTjWbxmafke+ZvAwN5SiN+/QbSrJLiM7W77bQYcIS4Ml9h5bqtwhfCu7OzluxorKPtLSP7QaxwOFN8V+ZViZik5ckNS2l2HlPUTFwprf6gBC9JI+lOwYgif+gG1K58IkDKfMnL4rOdA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 3FTOX6WnAzbn31LInFBZH41q24PD6AS9WDee/D9ds3a6koOU5HoLKK4qbXCkGzdjonLWNdpnNTbIjgRsbQrJtk8JCzfZj62zGyWL0NJDK6CJTnhGf50YRMQR10F2lv8S4QxaA6cbl2gqXJO5vahPulVJs8i7+lsjFUsNvHePMGIfkxGaxg16zM8McZ0UHaIHUou8Ey/1Csuzj0gm8IM0hfWoNTdsjaJR6bGJvx8p5f4BH4UYsE4iMMt4S0LdtdN/3T7kcrpnt8xLyxUflAWHECw5SZsia0npsqLWM+d2YwQgVg8WOJdPyTAsBdI76IxKLjbnFOJ/74gT4hNzX28/lx53SfYifKr65DjyurpIDTOYXg94529B13yJ2dqzMy3xW/AjGtBl/tTvYnNPlNSDubKMUY86CmLz7u8NYUYdem7f3yZbCnt4TedFgwznx7vL8m07TAaxZOvYwl8X6zbi2tfcsOQb1vGYmIbu2ujVZAB25L8DqTh2BeILM80ZvDyS5D5WETfOjOLqhdwjFGxRiEPCmAQQsgvVuqQ7yUEtSjuzwSR1j+P/Tj1yQMDZui5lEFIadTMcoruevRilq/DJYDw2xFN1a0GxCbKmUp9aFx0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57de1ac0-6172-44bd-4f44-08dcd94ce78c X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2024 08:19:10.6814 (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: zkzRWAa5aFpJm74WQCE0MuR3AytyF6rvKl1BgAmVlZs5qM1tAMAz4lfrXCc6SpxHugoPT/tVcbeS8/kggKtL18500uHjdkkp5bwUuBMEIhA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6037 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-20_03,2024-09-19_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409200058 X-Proofpoint-GUID: s7zCS-Wit7Fqx3RItXxyHCQu69gnAymX X-Proofpoint-ORIG-GUID: s7zCS-Wit7Fqx3RItXxyHCQu69gnAymX Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire --- dutil.c | 14 +++++++++++--- dutil.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dutil.c b/dutil.c index 97c4474..14f1340 100644 --- a/dutil.c +++ b/dutil.c @@ -207,13 +207,21 @@ 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 (!sec) + return NULL; + if (!gelf_getshdr(sec, shp)) + return NULL; + if (name_out) { + if (elf_getshdrstrndx(elf, &str_idx)) + return NULL; + *name_out = elf_strptr(elf, str_idx, shp->sh_name); + } return sec; } diff --git a/dutil.h b/dutil.h index 335a17c..ff78aa6 100644 --- a/dutil.h +++ b/dutil.h @@ -328,7 +328,7 @@ void *zalloc(const size_t size); Elf_Scn *elf_section_by_name(Elf *elf, GElf_Shdr *shp, const char *name, size_t *index); -Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx); +Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx, const char **name_out); #ifndef SHT_GNU_ATTRIBUTES /* Just a way to check if we're using an old elfutils version */ From patchwork Fri Sep 20 08:18:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13808259 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA62D76035; Fri, 20 Sep 2024 08:19:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820363; cv=fail; b=KJk4/FMqo0wTvCwtRUsAGdtjn8eXCJGFgI8ENxkH2iswA4Ra+tX2++dK4wrDnaIA5ayAMvwjoKHCk87e3/PFBW1P91jPsCahzrka0KCxgrjH/b9zhqFZ0VmKFa6Lvty5CmojL+O40vjPGU9hJ/R9v27krogNIrWHZxrpqOMUYbg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820363; c=relaxed/simple; bh=FFvPv/OjEoL4QM1kX5dmFmzN/Bn1THlrPH6RYc8X0F8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=DUw5EjK/1i7W1yGXw2hzw0DzYiLu2hkEaEieKRisEfAVkb670+Jh06jhr4lyt2L53s+rzYAYbYVGbjDaXXq7A0YPCVT1S/TFZK3/EaztaN5nqBv2VpwWAB+kj8Q1LJB+pLzgvbqHbKtoipi8OfK6iJuQrrg3kxGBFCQPQyxV7CQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=AIDLBuDV; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=fT4KqRSe; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="AIDLBuDV"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="fT4KqRSe" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48K7tcY8019530; Fri, 20 Sep 2024 08:19:18 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-2023-11-20; bh=ZRg+DJm/XEjnm0VM5nYr6UKD/fYTWZRXBdwbO8mdu0Q=; b= AIDLBuDVuoLrWlcpn9v+Cxh2YwVHyGkB1KdjigGZ36LRJ8c8XFrApfTWPzWS2sHO hpyHt0Ljy+/e4K9WvhCSEXTvS7Y30RZ+x9KVNQcOVURTX+5zn/TEWZoTI4io5Phq OcdxDpAA3TJTcQDP5dzaJI0wlaAdr2nBAXQm4ZC1N74jEDva18PLUuvOvm5heivX 7IKXTJ5Sbqdsd61DlJLrH3XQrwTQhRCqN+aovCCJWS1VslB7ultRaRDTV2wUpXsX B9n3XknkLYmEjNlFdFBX58b94Z1NNHqeutoUWKUwCTp9akq0wxjjNs4c2bUGtAQk SiA/wp3azV12So5PIpWkRg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41n3pdwtde-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Sep 2024 08:19:18 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48K80jwb017909; Fri, 20 Sep 2024 08:19:17 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41nyd1jn25-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Sep 2024 08:19:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uNqvxBrR2kZf9VCxH10PPWuf8IuEWZhur3QBJAXuKb6QWLtg/0VeTEOGnG4ihjQPJJrfMiZ7v7CQnpBPiYwG+fScLyX4PSPtbKzIIttzYTFTp708tc+tAZiiO5lpPNKAJ4OwkwcyUy61neu6CN9FSJDUXfcBus+oqtatxbyrPav5fO7n2u/g3CJ3/rCd8QaLdRbMOR+eKjD2JZ090kFnby69kIV20m+s+51S0b5xzY299IXPiUvzfS2ok+u9bMW3fb5NUEYSeKQkXO8qBNNxSF87O8+oGgp4zdI+ESSrCwe0GFgVWxcFofC8rqu6fQDirZXSLckh3B86GDFBWNjvLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZRg+DJm/XEjnm0VM5nYr6UKD/fYTWZRXBdwbO8mdu0Q=; b=gsTN7jLve6nAx+21K5u75win9NeACRR6T99mJJWbqa3iSoAUc8VV+LuXvz5Eu2z66+dhBiFHnEEj6/KtRYAMjVHGWw60wfsBqYGzo0rVpc67PGbGJ2wc0wKjy9jimusxrdRnV+1gLyAPhNaM5wZxs+CJcSHEniyMqhB6ksC1sXqMPnj6475ioLKItE8Or7rgviveqiNBwLNOiJZugpEdb7jJVEvVsJ4aZSgqGL0UVlO7Uf9newAiQJUNg0Zlc7RMYV3RRmO23E3JHLA2EoovlDcpbD90z8TgXXOAVO6ovWvjNl58eqJuJYRArTT8Eht6kaph44soIRR9el6DvlAmWA== 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=ZRg+DJm/XEjnm0VM5nYr6UKD/fYTWZRXBdwbO8mdu0Q=; b=fT4KqRSeghEzNtbS33e5foK83CH6gTNSVygSAXhBW+1aefCKCojHj30g05gSOZFDTBb4ncISGbuIUJ6GljHl0PmltCTJt4e6XEcemHVCyidspAigUcPtldhPxFuedrcBgHxIRXpEU0VXBnCIoeyenupL1Jk+MjaBPUlSKcI8HtQ= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by DM4PR10MB6037.namprd10.prod.outlook.com (2603:10b6:8:bb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.9; Fri, 20 Sep 2024 08:19:14 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8005.006; Fri, 20 Sep 2024 08:19:14 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v2 2/4] dwarf_loader: add "artificial" and "top_level" variable flags Date: Fri, 20 Sep 2024 01:18:59 -0700 Message-ID: <20240920081903.13473-3-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240920081903.13473-1-stephen.s.brennan@oracle.com> References: <20240920081903.13473-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: VI1PR07CA0148.eurprd07.prod.outlook.com (2603:10a6:802:16::35) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|DM4PR10MB6037:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e31cc1e-3ab0-4571-6cbe-08dcd94ce9cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: yOs3Sm4xIKdM1PERsqrShLfYSfXM0XI0Zw4eobF73yfPhcvnLKNDzMCYjRHdsQTONzjpSqDwkNZdTHos7ZCRGFSaFVEdwCEXCAc3buvLIy+jl0ySshnIocKKww0rjEdaeaXulR2MENodU3GOO8Vut/lcxw1zxCPcAlZXgq0lO1kJmp/MvwCqXMjWz+vuNS/goGriu8vYU4J5dAb4TaKl9ULpYraUUAl80+KK5496nFD6JO2tvHykSMBFh2fv5MqAbrhBrvL84DXYGU+cGlXTrNPGZ1GFLcnzxra0F59MGZjLQrlB1NjuNTvioUNpAa83+otFwaKY/vOLUG33MABIwTOazL7frseiudKYXterEd9Paarc1BDxhBom/kCzitVRM1v5QEkMGc/Xb14SEo2O9mKk42ZA6iRhf5CCa91RR/gwbP3NWyt6M/KWdc6tX9UT9S4/2EE4i4VDFObZt6lDdAmqvCuEkjIbX+hQtQ5xWgx6sXTYCR0TbRpyTCNRvhBAnrOd1zahyta3BVjYI2xlzeT5cnCs2ndOc1Rn71l9+QDntoJoYFYG3WJShmbOLLYTq3n7yxLHo8i59LkQ+FFl0TifxVVaVjsu8/PX1qvnhxmEQlXNYufLp3usdXN0HkZze4a2j3857Q0/lLqHfasGCPfW1q8PV4isqhTIXEOlxu6hX6aAYTg0BlUIZvNxNkJ3pk4M8H9tYqNDHNS6xNyKBAmSKCNvoeBGUq2BmgkxT7kYr5pPNNTVSTp+/A/LUfN8dUpWRbCKq54XQ2QWh/nGTCp1kdUJMd48WOKb4ckM+qOTGMCJu/U5FZkvvOgUnWdmp8Y5QRx/E8ph1JFST3fus+WrAASoMlFBbW7sIei1zI2HAKEFivoJqECluhK271XAgvO1BaBT0jt7CIWNVi+X5UcBxG8686mhdQFzuXNnh+JmngZrH8KvM2uVy3N0ZHQBsfgkYgAmGTdYFYsliJXrssVhUdVZcXPL0g1ELTP6va7p0G4+dnSLTjVARbaci8G2rtnuXCn8JWAylHFUeH1RgQyZAc58CVav4srYdhkZPQt9Azc9j6F4gSrp3zf/Bx1TX3TwLxyqak7s0bNYa0x0jm2Vaety2zznlPSsKJku9EHM0OFj47aLJY+HyeodL7i/r+PYFQyZbdQmykc+Y/Vf6mXpO49aM727xQo2KE69httZloi1g06NOcY9Bgv65AgI6KP7FPvqcwgv3jNjwmvpddGzaEziDN1ZF5xpcdqp2+9NRskHq8S/o7HaXW4B/zty0KekVvKTSjLxTbUHN13h7A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 08vsfvLa4XBFVT4sLLqsVh7RVH0c6NvE6HNtJ9C0kPOyGwrhoPE2+4LuhyBj5ULSNfZg8F3T5IKUPs55qRccL/OYQWJtSN1ql2YiO1xVPmLeka7/HY8xsEfskI9NoWrYg+NctcUcBhwSUIv014LB9xOTbYwUxm7xzcTS4WJrrwvbpqjHRgUzJJvouswex20tTBN93iAPeFVAhFfLUlvl7H6LP51YSLFVuX1PbEVZA1SlXNYJT5q82wqsR2m2LclkyvIjIUbSRevRcM0UuhksjxCPug6pJ/iOFwnRiorzTRvjBijCnaUUJfHRdXU56z/MnOI1gVdbGBgVTB/3w01SV6VuSgTlxx0C4/3NhPJUr6P58anpc9oRGqPEPRxL7BKt1hCGEOzK4JSAEH6Xy28XWP464q46g21f3iexBOOcLKRExacwcy8UyRF4M/rebBVG/bewaKi0ljv9Rz7R3VchYNN0eIKmgJLsvFdm1AXKq/Gpwiancd/GZx/maDD46CfBZI3UCXllI225++e8xC5APpSe5W0ZFcXHWbYhv67fYLSuoucllwKF2FtmXHtoCn1iottYsqfjBuyJ/0X/xSmozMtW66gDctD7hJQ9BYZDd1FQ3RZt9dLfnZF57Fd3gOUrh5obIPKxYccTAHoO64OBdl4ZnEfsCY5jFMeU1yoeDJal1fGFmMF0KiCOd3+/orrtx2XNEAoeTglS1EcuyyEWvL3aMSDe0/TMWTh3zAm85fNY4B+1AxqTVHi8Y4PWCKvn+Rq0q2m7U6LHg0+/usskSt2okEzGfCXgfhEwmCwOWteXBvXrUEQKEFYFkziSHmBzoA1hRP+GifWeqPGu64Tzpe7+veZwZTDPEf+YLll4+leyKW4VPJgsL1+jRWcR3ZZeNjo6+SH5KaLwAJQR2zvDInvGb2cHFfKMVmt+sw2GbrKBmrsyOf49Opbj42agjb3TM6CJqCttCFFC5kOLtWxBCqUfB6575YgIh7+v8/u9bFfqIrY1B9xf9CqNXRtQm3geQqXnZoDx0p1xpI+XXl2Bxta6i5xW8570KkEYHv1r0FRo2Q0EXVjQPY6hHFOJy3fujCQ9LtD51nB9HFaq1L6FFly+03eZKIuA3BQf9Ryfl8c2jf1A3quzZKJPNFPNgAvrbrONXY70VjR1RTmC9p5K5NXZD6gAKE5Qn6IsSf/lnk+nFaImyDnmlNEe03cCQrlCnMMyMhz6zo/wgDU+WBI7CgCdGzm84fXIXtaasWLv/tAKgq2mvdSGuqoeKvQ6UIrXZDeH0nV+RZNqYsLtGDyNoYbH9m8mA22FnVRVMpFvxOlfLw8CKS67MT8qQwX596B/Q6ReZ/y8JtbEEOg38Acxz/XBbP+F/MStcAFfht+QQEh9DLoZfK1Lgz/qOQ1099Prb3vADMbojClKsi3OsZ0J9MR2eZP5lhQVOhOrqbkFop+chg0Vk0xHYz6BsrK5ocK0acdvYXA/yzoM9GAiB5RcVMGBn1wRDrf4Kcm1iRdguC//14/wMQtF2bFiejdEnl8uJL3M9pEiGFk0m4PYki2RkgbyQl1BNJOTBtpSykK3DMGODMztLQkfIQI3FV32HI0l8RlFW/e+KVUstuC9+i/dDQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: fCoFjfroKbIiXhouy4gmDOEVa6uXzEAY9/ab4FlYwR8169g59mTMZFxVFlnKhMpYAAd8fnJ4QLD14GC1Ww6RLPwEKsDo/YDyQZHjlY1k1yJ/WLGwNkZ1QjjCCsfA6WM33rJ+gvmlv5DaCSjYQ7T2HyO8OnuutMKsfLx0vhdaG97laCM3UswaqmU9rjbOO/yUTu4lOIRu/g28AwgMjzjxjE6wYiG4o53xK0+If6aWdENz+1wdC47fvlFJokqI0c4pdP88Lgwa8fDs7a9mMMR7rwGtnX6tkhcVn2a/bGO7Cw3saAMLXGWmgs9b43OLu5D+MQ2KtHu0XdCgzgizbuJRhpPU1sVDsd5GiNRVFHFS/7nqefPsV3dxrEIVXu2uXdDbrBJ1S8yc5OQPDLKTirHgWkDkjEZqU+Je7Q9x5abLioVuNjeKdmcYezBrIT/2pwsfjnMj4v8WYy/LJ8v1tJ/BdSWJHk2+pjDMCrs7qoE4S8yHBnV7sBMDoygAagpqXCCyVhOz/NzdGNuwOm9D4YVSFpZgLp0+8g0VngaBfic8uEhCeDVB52FPPmOC8PXlFWAmDDZWffSoTQlUhXzRZ+AtJXrQVX2sQj0mURFP3TM3BjE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e31cc1e-3ab0-4571-6cbe-08dcd94ce9cd X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2024 08:19:14.8195 (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: rum386EyNrg5LwBXHp3ErazqxOCsod3r6NzXFT+VV6/NBfCubZmxmQ5R6U/k/vGKIt8mjKipNjneiQHN2l8J3Sf3dgRlrvOODt9oOZKx1JY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6037 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-20_03,2024-09-19_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 malwarescore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409200058 X-Proofpoint-GUID: --2glNFYVE3hB4GVpeTfwIBYgT4GUo10 X-Proofpoint-ORIG-GUID: --2glNFYVE3hB4GVpeTfwIBYgT4GUo10 The "artificial" flag corresponds directly to DW_AT_artificial, which indicates a compiler-generated variable (e.g. __func__) which shouldn't be included in the output. The "top_level" flag is intended to be a better proxy for global scoped variables. It indicates that a variable was a direct child of a compilation unit, rather than a child of a subroutine or lexical block. Currently, the DWARF loader examines the DWARF location expression, and if the location is found to be at a constant memory address (not stack, register, etc), then the variable is assumed to be globally scoped. However, this includes a variety of variables that aren't truly globally scoped: most commonly, static local variables of functions. Their locations may be static, but they're not globally accessible in any useful way. These flags will be used by the BTF encoder to select global variables. Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire --- dwarf_loader.c | 12 +++++++----- dwarves.h | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 065ed4d..d162214 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -730,7 +730,7 @@ const char *variable__scope_str(const struct variable *var) return "unknown"; } -static struct variable *variable__new(Dwarf_Die *die, struct cu *cu, struct conf_load *conf) +static struct variable *variable__new(Dwarf_Die *die, struct cu *cu, struct conf_load *conf, int top_level) { bool has_specification = dwarf_hasattr(die, DW_AT_specification); struct variable *var = tag__alloc(cu, sizeof(*var)); @@ -743,6 +743,8 @@ static struct variable *variable__new(Dwarf_Die *die, struct cu *cu, struct conf /* non-defining declaration of an object */ var->declaration = dwarf_hasattr(die, DW_AT_declaration); var->has_specification = has_specification; + var->artificial = dwarf_hasattr(die, DW_AT_artificial); + var->top_level = top_level; var->scope = VSCOPE_UNKNOWN; INIT_LIST_HEAD(&var->annots); var->ip.addr = 0; @@ -1767,9 +1769,9 @@ static struct tag *die__create_new_label(Dwarf_Die *die, return &label->ip.tag; } -static struct tag *die__create_new_variable(Dwarf_Die *die, struct cu *cu, struct conf_load *conf) +static struct tag *die__create_new_variable(Dwarf_Die *die, struct cu *cu, struct conf_load *conf, int top_level) { - struct variable *var = variable__new(die, cu, conf); + struct variable *var = variable__new(die, cu, conf, top_level); if (var == NULL || add_child_llvm_annotations(die, -1, conf, &var->annots)) return NULL; @@ -2243,7 +2245,7 @@ static int die__process_function(Dwarf_Die *die, struct ftype *ftype, tag = die__create_new_parameter(die, ftype, lexblock, cu, conf, param_idx++); break; case DW_TAG_variable: - tag = die__create_new_variable(die, cu, conf); + tag = die__create_new_variable(die, cu, conf, 0); if (tag == NULL) goto out_enomem; lexblock__add_variable(lexblock, tag__variable(tag)); @@ -2367,7 +2369,7 @@ static struct tag *__die__process_tag(Dwarf_Die *die, struct cu *cu, case DW_TAG_union_type: tag = die__create_new_union(die, cu, conf); break; case DW_TAG_variable: - tag = die__create_new_variable(die, cu, conf); break; + tag = die__create_new_variable(die, cu, conf, top_level); break; case DW_TAG_constant: // First seen in a Go CU tag = die__create_new_constant(die, cu, conf); break; default: diff --git a/dwarves.h b/dwarves.h index f2d3988..0fede91 100644 --- a/dwarves.h +++ b/dwarves.h @@ -848,6 +848,8 @@ struct variable { uint8_t external:1; uint8_t declaration:1; uint8_t has_specification:1; + uint8_t artificial:1; + uint8_t top_level:1; enum vscope scope; struct location location; struct hlist_node tool_hnode; From patchwork Fri Sep 20 08:19:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13808260 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B5406A332; Fri, 20 Sep 2024 08:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820367; cv=fail; b=D3dlTOhFlCSUMGt/oNooGWp1c1fZJ5FgqNf5uBWBN8nP4V7q577vCSf83LiwYxOlPd9tZ5SKCuvL7lWKsPaZaA8Qyt1aVsBA3A2R8Vl27BSDjL8M3S7skzTaKxkrxIKsYWUajp3DEsUteAxMsQg8yOvre5K82jXTYoocGkfslNU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820367; c=relaxed/simple; bh=apLBnC35b1U86vkBKLRaWCrqwHhchPNf4gAluzq0wjk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=NWFgOqm+98JkrZ6jum+daKNLkAcb0kOj+LMnqjoyaYERAP1XsDDRrCVw+dM8jvmtqEUsgUkVjwtT9dP3vM75g1PR3wZPex5SocslBcjfU56ScjzsE4PgQcgmFKnMrv+1p31tiPHBQSD72S5A0E5suIx2/Ss813SpI9NzSXptG2Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=BrYRdM2A; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=n1UhQfnY; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="BrYRdM2A"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="n1UhQfnY" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48K7tXa9027910; Fri, 20 Sep 2024 08:19: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-2023-11-20; bh=CGT/ZXOo6Rs/UZk68eq5Zsi9fWGrIPj8Q7JTm7xwILM=; b= BrYRdM2AGNcpiM/D0WUEnxv9rgiu7iGp0/u9vPnx1Ffxow5pX+XG+kK/Zn0iwaJb fNtHHg4esXPnLb14NXGLNVOKkwO5uxJl2pjFycHzLuRUXWONx2A+siyW8FOVC32M MUthT9glgSz2WcLasLmtMjDkMZFibtHGilLr09aNkW8dF9Fyp7ufP07DKuy2+mMB uivsu4UZylKX0yo09MY75DMcfHfASQyWFzI2o4YNknA79xElTJA0UFK1GCzIkd1M Lps/cGvhQl13CU8tEHlkQvVpbtBCYXyC9ySL/O9F1Xg8XAZNHNhqPIWvCkGb/ZJ6 sPppgIVK8+rScK6ZSr0jiw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41n3rx62jc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Sep 2024 08:19:21 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48K84aps017770; Fri, 20 Sep 2024 08:19:20 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2177.outbound.protection.outlook.com [104.47.57.177]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41nyd1jn3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Sep 2024 08:19:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NN+cnmCC7v9CTvGMCxJcTFP7M/zVbIZQ60s5O8Mwtsce8Giv8UAtZtWJI9ou+ol72+Lg3C6KzTV+2xzHhLCjtVhxZkaDwTmBTBhSAvLudEtrE2wwofQmegHwj2RQoJ3pDGXPfrzTJ/ZuJK9c3MgvcCE574Nqc6G7fPduGrhhSRvTDMytxISFRfD8X5Zs71ehkq+di8bogySWEQsiUeQiLvlvkmkAc5pMoxELEsVX84jaiKBd4N6ZBxyfXR+0QF1cEl9IF//wNpTJraUmcdn4Rgu7KObB2EpR8KMsKDriCNYo/tc83KJO5kX/FygPmNlcQccD5hOTn1tTX//nRReYhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CGT/ZXOo6Rs/UZk68eq5Zsi9fWGrIPj8Q7JTm7xwILM=; b=qSG2ESOt0A1YRo2tLYxTiQbGWDPk/xfX5CYYfnck0CADjRZjkx79tJ9vPIrjOzoX8Dt3wOkmZSDncg8h/Sbtv8NWFdJgDLxuUcmLG+Tp45ABxTvnXzZFVx/p1xw0aJjOOYaabRiMAXNeVtvQ+HW2ZtSPzw/ZNIiMy7VPrTqR9qiOyqEt2FbZ4SbbxsJTm3RS4dvOYcHhBaEYqDyVmuMJnaNQN5z0sNysKrZExYg2T01Ra3GjHDqkrTVQE524oy+lS124/s4Z4XN/K1FEuVSJ8LMeI2/3izsUXLj/7YdJciDBXhegDOJBSAi9HWZHi+qNRXUmid72eDwbmT888fDouQ== 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=CGT/ZXOo6Rs/UZk68eq5Zsi9fWGrIPj8Q7JTm7xwILM=; b=n1UhQfnYbvbro51M6M7N/ZfABz0syFRNnmnmOs8lnY++buOX4+pkL99vHuqEnnYozQcTBY7s4bPU3G3LwnmtBFWpTrgzB8ZMp43oNEk+3NuIFVJXJESAIwf7JWCZD2YOjn3DgQWwxs4zusAQ2FjWLhkm98e1i/3asIKNkODf3mQ= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by DM4PR10MB6037.namprd10.prod.outlook.com (2603:10b6:8:bb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.9; Fri, 20 Sep 2024 08:19:18 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8005.006; Fri, 20 Sep 2024 08:19:18 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v2 3/4] btf_encoder: cache all ELF section info Date: Fri, 20 Sep 2024 01:19:00 -0700 Message-ID: <20240920081903.13473-4-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240920081903.13473-1-stephen.s.brennan@oracle.com> References: <20240920081903.13473-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: VI1PR0102CA0104.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::45) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|DM4PR10MB6037:EE_ X-MS-Office365-Filtering-Correlation-Id: 699f4f89-f2f2-413c-3998-08dcd94cec1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: wQVqp8fubPyV3IT6HbeiobL94nzmpndILBJe5jgsxf3kQke4YMVe1ftLi1w2NH7lbFyrdB1xuxjcQkTur3Qp/EX8y+5HjXZ6twsY7EFHWslXWGQlQ2Py6QqO1oQ633ZZlvvqQqq7ynjmSnEHN2k6uwgAA52Q/4iUcGxCCQdBILRgn2YvvKdzS4WEvsQ5sa7t/2P3RHJFDFTmKce5BweFiglCTvDeY51A5IIJld1JtMi48F1Owyq/THpQ7m/zbmbRvX7zAGZhc+sC+NY/ulsFDu0p/4LfeEgw1INWkuavsyqOB6ln7d41aAA+z2IUztu/x80kEjo7hGZGMJQJzD/LfPl71se0shZHincUBmeJR8trr5ZsQkR3ghNhVH87LjTC7T9CmqXDlEK5axBFeeZFDcQwwDAlt3X2tSb//C82LiYyAc1jiMKgLTZO1Fe6wsA7AKT8QEr6EwzloDoayr8nEAl2ov4OykkESYNe9rczQxgUO4bygW+8DYFDm5h8Dnld9sR05Mqv3F4WPQlqFJnxX69BSq5v/Z+f2uF0V2UCkZAgBS258rQlm+P2A4mpZHAX2AuW0PjnGIMfcCK68oN9PWlD15kLy/Eh/I3W1JTojqEOtMmNMzP5lOJW82Bb++tsuLQGhoxgVKrP9K1a8mdQO1IQJnUGyOKFxoV+exkmArc7qsooHGoGW7RwJJ/7MO1b7X199wTonp7dIQZMAsdQUEkZJchOCUYWSfyicl0Kfu6kWgWNTguNVdHnGXz5qYSh+iG/BbJE+2qdflpnWEgS6b4HXZFrWio8YNms53w9M6fpPEwwW27Cgj3+/+BYzA6TCZw+0OoC6NUbUAhq4cJd9go3k+U6G/OKlGOE4bc7vdcDVcwGYDhRC5NAdIb+VxbOn/tqd4vxexR3vyvsMe4/wCvHsJbViaHWrvfgFZ45D4qIErrppYts6O8vRoY1+g96UGsiZdj0c6Y+M2PkdkZgr+ELc/JgvhhEuQsWVci8TgG9UE2fvNYl+mjjY/w+yoh4UV4vD3yIaS8Tfhc5PM51/skaKsGqcsYLPmJbhjdqS1oNiRilfb07aCUaiguJkyKbAVDNiPp7oSifP8n8OMZ5v4SYSuTdE0c08kl/VYKmmQsGWU/odwZ/4/ICu46aHHhim1ffR2LWdFJy1Qg8irVq7Sw8xhH2grPb/P62cEAVXljbgaNr42qwdMXd/gefKzfqOQKe6ENdPuTlFYK5HSCKg7ct8jGs20bJjvc6rAuSqoEUGrg7FOtK8sTfJxg7dKI2E6llk8Aj5QojGUcCt8Oofg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DCx3/QClxUGhKbLRq3bY7osw18SFzPm+Npt6n8ac+IEHhTvkhQydGResxrGQhrKH/t/mpxior3fNvPmuM9lU+eOEloqW0n2MgOGjNLHR22kNF1bbsLTNkvv3JHpR5zkjtJH2LVXA3NU7ARU61hHIro8QEfcAz33mc7fxd1sSzAUhXkCXMKV8w5uK4KcsFNZQ+MZggDNO8V4/b8w7dIQ0lvbFn6C+GyVjpCZcYBzlaIUarNNQEjuSHJFypAbHQBq2RSiBBWe82sPpuGg6eDLNPwYoTr0brA5jAZk3Y7spq0MpMlock5tSw+LoCDdRd4cyQN0qSsCv2HUrG6Av9rye8W86rMI7uQkHZdGjBzwAj4ltPlrR8HskbKDZap4g5eZXnqT4pQcggGJH/YT5fy8WVLc14EDGWqVIcfYdXWrJrVQsTRC+aggU4CN7lQsm3yywyyJe4dMMX+sTDf5crkYp8pJb2Wzb+4BAq37NP+Lw/woOwry3qeMv+4PWtl8ao+gQ4NCgUcl7f6dOCY/wT45AsdDveLU4xCqLb/yqevhwja8c3uutmN9oEsVbSs/zlFV6n+moGinNu9Rwxh3o/ol2mc5RLCDZRE8TuNRYibXgtI2D0HiKPFpRm//T41MIn3btIF8oia2ynCg910aFTu943hJ/SO+5OjfsLILAXpaCXT+iKh8oxr8UJYuhJcFsmYKxL/nJwi65RAeVmp8xo+li77T5KsoHoJzZP/ynYhUMTB0o7LxZpUGTG+zbnysS/PBrmAXT+AY6WyM4msszBafG5tw8UeR4AyZjEg2dBi3LJji0K/t3reNVmrE3Ts636X4JRIz4tK849hnSdp6gbxe+RgQQqG4zb4khchc8XMqwe61YGVIhcyQfPjp8ehECBehS6Cn0ZSU6BX3d+HSnWoRsrJd4h3KYMsgxPYNBanTrGz9b0KxQnIdFQFtVXgvMZY8lQbOe0duRoAkqxGeBR2dtARLDL8KqDxkiyI6xz0lThCCaqY1PwS6u5J1WCwCgovHACqp78yXHN/KhDdYkidiFXUlSFP0b5syQA0ea1BeSR1XqzosT0EfJrHbgCBBK2LiZmYvIydknhauVVHy5ypRihEiXFwIVVtLSpI6SzaYa4NxVnyrYQDrmcbeDTFttrfTeem03eR7tBdTOvy1DlMfvRIHdfzNqB6aVlWFEIghDI2WQAlZgWDD5EO5AGm9a5Z71vA0JzWutLmf6KYygacLl+DXylIu8+CXdql8oIMxszqFU0b7lYQAmd1a87AsnfArVM5IPG4ekxpB0dxdOLmQdVwpyGrvU9C7TUa29Jk4vUBY68Vnro4t92t+znHtkEuLzD96WWCJb5S6oyre4gJp3KWmXMoaADxpZbZLlQditc8woHCCYlQs9NA1YGA92k+OdX6BxtIXb2CMC0IZFJlrzg+nRCt04TOPTrBWmyu9Vf3eVveqCjkJ7NtZd6EKxrLr3cyik9+6NiM+JAySJrZ1wFeu+3SGV4JlUzlsEtZbZT1EVxSeP/kakmbRNGmZleLwaGBW1ZqzRGCWIjhsb+eESDmLh/SBI17qu3mpE1kgEoQ2fRjimoUtfgmUVICQU26INrX769lx45RVYZCB+KLZCLQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: kwKtam87kYKnWmfRyNgj4jnYsAPmeBe7p9pDwW62n15RK8i5hrHUbNbR06xT2LX3ePuP7D9ifBY6FLAQcP4nXIS72ieIdbU/P9ZVD+3+GRJaVDjvSTqYov1u4iw671DZTjuchA0lonPQRPeV4TtPC6BMH3zJsBFyCrxKDKbg1rmg9WW/2lDxOoBPH0j/+zncIOgm/RbbqvLmB7oUrUUbTo6sRJPzKY3xdGcS1g7sFd3rlHs7E5RFS4E8b9GvM/P8fkTS9zu+mauozfE9gqDr+2dh5Sny8UdBQUIg/eGHrz7g3PHO7VFkVa+kycbe6d0u6+rva+VVFfFw/0XxqMJf5JGoX3J3nxB72I0zxMOnyBifTqR3TsP/wxKw8t2iibxVzSgHsjbim/+gHTdThyHqyv59j3RXkP6nNi4DvYyKrEnMaT58A3P0W177k6gOBBIFWwHlPlbqkvWXA6wroT2jcGIBTd+JSQLjhUojaIsLsZL2U9n/0pDvxBAHO4nbFzGwA0eIVTPLelMTUNIY72uMs/JEoRMogMFdguAWlY2+ElGZGmRqjgC4VtfKCwe+5+qe7DQEVDRT9R4ACZVgQ72J1tI3akfJZJ2WmGwII3imTO0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 699f4f89-f2f2-413c-3998-08dcd94cec1e X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2024 08:19:18.4376 (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: XCsBi9CFc2TRVWcuI5GRkTEW0Pg2Fxa7N+hyvdT1XMMkWfG/K/tGxSUdC8PxAPoaJ4mNgEu/S0AjK19CnW8allDuMnSsms9ODAwndv4+Qig= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6037 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-20_03,2024-09-19_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 malwarescore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409200058 X-Proofpoint-GUID: GsVqYUmBhrigi7Arr-NB1IRjK2_gJl9d X-Proofpoint-ORIG-GUID: GsVqYUmBhrigi7Arr-NB1IRjK2_gJl9d 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, not just the percpu section. Signed-off-by: Stephen Brennan --- btf_encoder.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 8a2d92e..97d35e0 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -71,6 +71,12 @@ struct var_info { uint32_t sz; }; +struct elf_secinfo { + uint64_t addr; + const char *name; + uint64_t sz; +}; + /* * cu: cu being processed. */ @@ -95,13 +101,13 @@ struct btf_encoder { is_rel, gen_distilled_base; uint32_t array_index_id; + struct elf_secinfo *secinfo; + size_t seccnt; struct { struct var_info *vars; int var_cnt; int allocated; uint32_t shndx; - uint64_t base_addr; - uint64_t sec_sz; } percpu; struct { struct elf_function *entries; @@ -1849,7 +1855,7 @@ 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->secinfo[encoder->percpu.shndx].addr; if (encoder->percpu.var_cnt == encoder->percpu.allocated) { struct var_info *new; @@ -1923,6 +1929,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) uint32_t core_id; struct tag *pos; int err = -1; + struct elf_secinfo *pcpu_scn = &encoder->secinfo[encoder->percpu.shndx]; if (encoder->percpu.shndx == 0 || !encoder->symtab) return 0; @@ -1954,9 +1961,9 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) * 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 < pcpu_scn->addr || addr >= pcpu_scn->addr + pcpu_scn->sz) continue; - addr -= encoder->percpu.base_addr; + addr -= pcpu_scn->addr; if (!btf_encoder__percpu_var_exists(encoder, addr, &size, &name)) continue; /* not a per-CPU variable */ @@ -2099,20 +2106,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; + encoder->secinfo = calloc(encoder->seccnt, sizeof(*encoder->secinfo)); + if (!encoder->secinfo) { + fprintf(stderr, "%s: error allocating memory for %zu ELF sections\n", + __func__, encoder->seccnt); + goto out_delete; + } - if (!sec) { - 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; + 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->percpu.shndx = shndx; } + if (!encoder->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 Sep 20 08:19:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13808261 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE66C7580C; Fri, 20 Sep 2024 08:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820374; cv=fail; b=tvTJCokqi/2xowYu5miejKjXcflwYY4LHInWDNc3W9aTuVcSd92xR+oKmllt9Nl4R3VGzXaPy4GeFUuoMagBQ0qMqOCjV3IMmpZhKeFjDz8h2XhgcTewblQxb1mVLigfjYUYZDkq/BIQ0fn45RAFNiVGJgl38WXM+z7INuFiAkY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820374; c=relaxed/simple; bh=+hVI9CCNXTLrdP/Wfj6K9tBJjE+b70DlyWPy6Tj2jlM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Dvian/n5nqKF3VOhVQGndKhYLugy/FzhGtrji9v8tzEmmFsRK0MKV4p0lN98cEQ4FBdYkjeDN2NU+GNoiM1Xg/rLZI4DlJ60ZPmVJqr9D2rwiMHXbOyZun6UAa3b7HpA1SmC9VGKyurtRcHa/B0GocoPi3yFWMM7Mescv5S6lLA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=L7W21la6; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=B/i9nONs; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="L7W21la6"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="B/i9nONs" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48K7tud9028367; Fri, 20 Sep 2024 08:19:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=B8N+iE2ZNu8qW+odU4f7ob/QPwJTZn4AOgstjjH4hG8=; b= L7W21la6zKGc6KOMpNj0JEeY/ZCTxqAw1skBsmDhGxTVuqehT/fARFaYu5pMHNmk waNFVREDPPd954879Ebnh7L5Dm2Zp8D2mllUEQmNkpSX1hW5Bvre0pAUxWq4aRV1 59qWxmcySIXs4c6YxB/DRWSKlDoDO8bdCSRma6eeOBrNLgbipRwfEIMjshlRMpsO lyxqIFI7UTTPm+hkYuMdaP0idp8wuTrwOfKRu9hPuet/R5nRIGziXL/BFqk2KR0x LMxQcbtGlzIYlUxphC/C8m+f+eqVlZlLoUsDfOPr6dzKEDkYJ+udmkBbBAUfQ4lc BsScKqYaJ+vTXB67+d6sAQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41n3rk5y0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Sep 2024 08:19:27 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48K6Buck010334; Fri, 20 Sep 2024 08:19:26 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2171.outbound.protection.outlook.com [104.47.57.171]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41nybatc4g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Sep 2024 08:19:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tAvnWEKwP0Q6VD/SAcgKY7r82FvIPpPFWWb+Powa4t4Nua2YpzQ4CP41ewbJ4hl+7t6hV0ffRHYaNViELhuTfhoWpBr6waGmxzWDzqPoTTM6OZ37KwxcGYTxB+Dqyl4Sk/CU2QCe1h8cVjmRppDAo4UMQCdz7zSxbcS0Y4Vb/g2tkq8W+JTQfr20qW6iuccICnRXnKcLoQLKLqGa5WAd0rBsQPykM72PGi8tPmazL+BRTtNaBIukPXCASwvz58TSDpUmGWs2/74z6Z0fZSYB5eun8UqWF20zyduVFFOlg+bGLOp4hHJ8jl08quIYBUcQMSZ2bFjY9wPN/h2yYuegaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=B8N+iE2ZNu8qW+odU4f7ob/QPwJTZn4AOgstjjH4hG8=; b=rVEtbW/YZkY2gCKEloQp2/xI7dl5AHzCSkPPvhdK1l8PDS/C2XZreAluuHyknSizRw11abmVWcE7s/azsPnFhnv2f07AVTtIsivxLlI5KRKDrs+K0d+R+NWeloDVqKBCd9cJk/2/KqeykGTkSgcAE84BjXHougyCLMOW15EKup3z6G3ugPtq0JJbevTr3WaJ9Vefg9GZYevyYqmWyd4g5TD8l0RuJSX8h5ec1k1ea27e6Jt+GMlx9OYds778ojGo3uc/NT4UiIkzApZ3Ck1z10Dy4p2fSz/8WUjaCD+mR0QD07g7QlzbGCPfR3A6JnOTptq40v4LE7PNHRLyJim8PA== 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=B8N+iE2ZNu8qW+odU4f7ob/QPwJTZn4AOgstjjH4hG8=; b=B/i9nONsyRYinv1kVSh6R8KMBmzyBzQFyaptEfua/g4HAc23kqdJ2VoUaRKYNXDKQePpv+LD6Jyp6B9RH2g2phCkgEVP+sn+7m27i0ytg62k0fioBf7Bu/VSoSWyZ8HbWV8y0d0L/Gfwj48pRgvwY9Y+GUf4/NGR1pM6GbSE7AA= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by DM4PR10MB6037.namprd10.prod.outlook.com (2603:10b6:8:bb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.9; Fri, 20 Sep 2024 08:19:23 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8005.006; Fri, 20 Sep 2024 08:19:23 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v2 4/4] btf_encoder: add global_var feature to encode globals Date: Fri, 20 Sep 2024 01:19:01 -0700 Message-ID: <20240920081903.13473-5-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240920081903.13473-1-stephen.s.brennan@oracle.com> References: <20240920081903.13473-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: VI1PR0102CA0089.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::30) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|DM4PR10MB6037:EE_ X-MS-Office365-Filtering-Correlation-Id: cc196f4d-c24b-46db-3839-08dcd94cef0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: 8cL8whS0gCUSNowKcOBy/OOTxANC/G4o5I98Waz/b8JvZSNybf/PpiGGQNPbZ5AsfZw0WvHMBxxMmJUxGM+qWRo9xMH2ujqHjzlsIn4NKd0Wpird05dhVkBMm1Nyp//T0rZjXchBv9uxTHFMIivBHIHzvXsmMDkgssegJAcqSENQMqje5z1+tu6uZdrZvh6iK6djdAT3b/GijOiqBpAvflBR80u79zEiB8C9/svyxhwJr13A92iewPndG6ZmY446zTHV/AqHnQCKNGFK7ab51HljDGmO2UR9Rb2AivTkmWSgiwcxvODJWp3CCkUuwPjd6TkNRvXX9AVpsDpttsugdPj+4wNydnu20yIrCwiZo4K06YMsUlrCGj3XHQUrOlrJnMQC1WOK0HIdayqiS5/5h+ECvpFd9AbM6HBSeDj/p1JB4v3baq6pTPiP9EPV9F2JTwSU9u1wG5LhNw8UnMkCC7HplMQeuMtcjjL/1TR3Bq7Iw9l7IsoQRPYmvtlvafNBZzr6dK2Bj8MVp8jNnTnIZshS2bQDCIu32fOANdWuWYvsfPjQVROHoJdgbh5VYbU8ZDBoFgUrouG07GM4suz6YXmmaeMTGR2tvfy0xtxsH3vMOn1+o8JRP/8M/X5/NTadGlHt36lZT4xV/P2oxNJqOkI6/CipCwS/9S+qivGV4K3MG1LobDtHC3XltK8qfw8NNaTgcPfXR2qaMxs8B8ohvojrivHnfwUFhEYxaw95/gEIO+xZX/Pd5GsV3N+saiCIaYcj2KlhK0dCnaUf9xLVICSmKjQCdP2CgnC52yMGuDvvFqo8ubQIzyIxrV/JHDWPniJQpeLsfkXcAAGKRxD9ezC0roM5965JBCtClIpd8qBpqB+uJ1NOLj620TcqbssGNAXy1JGTG1Bl34SP86I1Vj/NfhSmrwhmDXJxumrY1qntfDJm3zAk0S1Fg/UZoRSHk0jpP50fdEu2TrIlq82oLvhWUKkwpWRiuNSdJim0eH3+odMIDRKhODvW6VIPHyAtn7ZJ71P45ML1QwU2aAYhuf/0XqPxdzPIUMfuPAC/ojHUFF+vnu31zxJh4HlwsQG0YzIdp899lqNQ/Q5r6I74KfrMWHUFDuzH1YrNK/sxzR2ymoUw5kVHl74D3BkYCRE6AxWLm44RWV5CL2z+Ua1F1H6sA4oC0ycDnu0W17d30CJH8OZRspWxTqXmpQKDQx1l/HSUg2kPU9ocLurz1PufMy5jzHiCu6o85TfxC5hc+pY6XhNY7UA9zCAnPHWjBCVs51bsJ35y2UbGbqi2jSXUdA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vXOxk6JxnfyyvklosQBZPztcuG7vja2mE90rMuloOL72t6u9EdSOkpUQtqYOtxDRaCVWhDICz+0OPtyIK9+oUVzEgzsf4IcHKx1buyF4c6ajjiUmMA9+OhhJv2B/nz6pgB0SWmC1BYL91uzPn2e4MOD28GlKP3axSu3SIQGcqeeIardbFMLJ4ZrgBYZvttxnNz8iGczbFMEhTfbzsbGGjkGyllE64CCXrkpZVRvy4JHog/Hk0yfz3AFLmi9OfDAKflKKryZDaTpX3kotZZWpwAWQDSV77Pk6eGl+hmCOWcnDDDZCi+P46OpVAEPQgpJF/8L/gjzXETvctkK9YrB/oUCigB0AnTX/rSzov7MEL84kGiDC5tme3Sybc/vGJEvOLSaN7eUrzHhPoZpKWk4rZMevj8M3fk9nnq1VlZmM3b8PXxNAC8fV1cU/7W5Kn2I+foL4mlFOO9/LyJNl+ZfOY8cRpE1p6JtIQGljtAH1srCJelYe8/qaMju20wan+XyE9Lze1SFR/4KtGZSZKnqyqYWHgH3YQ71+q7dgH+NS0ybCrkXrQg4FBeApAf8vR6NboC6TCH1BdHTOohd8HJa3lYYYes0/y8rqgbyo3f3/64nyuXH0jkOwh7QRy3Yg1QyEkXdp9FxS+c1VtXYWZD5KttUPRHZZTgXLIDZIKR2/q6T22JMRTONnyA/qhpUQ3B/isSh8XZsjK0x1xuegTzU0NwVLVdlynHels67gl+2nLUewPS7iWJndDxT8Ij/ZQiQV76vs2KO8D91NSaacoBGSOegj7ozH7lwAURWVs7u7ayPso2mqhQiVVhO6zDSMuUdWMavIV1+TO4Zao4NxX35Yr2e64aEzVm1P27JukIq9P0t4DyP335drEb0CnwoKfLaHERKiPS8HstFbg6Ozje18L4PVOMZSpayfgGEjdqMeUNviF7RjGLz22hEqBy5207GgLxtnsjWnoBQa7DndbgIC2QTGfyU3UCK3HURv7bFyCDyVzflwQVsClFnYyX3dgg1OWsBER+CxkiRzRLWfm9lOCfgeGA61CE/1+YJ+i+PIspeIYXKmKsQkay08VrWzM32a8/uywhvj8PpVnHE4BALyyPP6bSqi5JMlQNljvBNfhWNacVEqJgljI5b4USwlQwiuWUoqSN/x4UJhIq3SIwl+Sft9I5WXICXP4IyZPFZHfeSm3sr5OZhg/HWX5oVh2ZzRwNNzIXIjFPYNfiSwMzGc85jBqyTNqyS9e2IZiFgjFCWpgNZHJuoW4gmukslhnflfFyii4Z3FAiIXgB5++vQSO5jXJ9rRFJetk75EaBJ+/e6eT70VlfwIohq694CrUVGud4Rl3c10rWC+pSV18Kik31E0yw0kIQyVUHJVnveGaEYJfgNj+BTXgHDhWgJKaP2RGhY+HIAzw5/vPNM/rXi7r64To3H0N41YC8VU3eWPA1yUdhMjhXT44nuZ+R0ZfYIYD0Ri7g30fZehHQWw9bOG1L5wMXgcGjf3dfaBFTgSd0oOkWo5CyeZS2X+uenXu9N/vDJk+tXQy61F8jnFw42ciW19QfsrA6C2u1SFZMkYybHkwkamD06WLFzwNpYgmVatbNz4CKYOJZfQsB0eAcCp2A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: z+9Z2i3s+kAWsNl+RUyLoVsTiPQemcvlv5ws/h2UUYyJmrjpRKLbhnemdemmy8kyjB+W1eNSFAKqKDHteW5Oq7PNh/qOjkrQTg7aGWrDQVigd1VeOYe0/QwrsTpoYXeqDlaCu1zve9ZKUkf+vNudAaPaBRzRNGBCREiSIIXboMcnofQZRKLotUMbiWUhHu9HwUY6k43y3asNzNH+rwYOgDEW9pgWdXZz00DqK20JzZ1FEA6Xl3Yw8ldZaI6blv54o3R3zQpesVowqIEpdhQrUAwjb3LN/xNdnUwheG+3IAHkMdM9Kgg1yaDY3+jhnIkcas+xAxYEVMB4tUr6WgC2ncD8SLYMptw7RS7TbJfMn2oEqR5u+3j9Vpw/FaOSJh3nZupH1V/6oYBCcPACtjLjoTw28KlaXC999B+jTb4MZjlecs1fyuRe5JedKPh4AndXWBkYGGlbL32QX10vS6iGt95bXbfj6n54FnNFYiRzn1IyCnP9fyd9jARa+g28pd4NFNpncd4EvLK6+MZjhOSgK9Vj+V/xsd+OAWu4K1xnkaSJxeOFfBYxTAXec7ajghxTbn4UM57kVTDbbYGjzIHEY8ZCP/Qmc4USHdU3hIqxfQw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc196f4d-c24b-46db-3839-08dcd94cef0b X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2024 08:19:23.3543 (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: qKiFT0p5Ut9uvqwCQHcI76ozMG4dxUBFKzYcuj09utn/bn8q+t1hbsP4SyOXm4GPI++l2nDDyJfWUnJ9iq6elYMSOouhugwCutK+4RGRihI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6037 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-20_03,2024-09-19_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 adultscore=0 malwarescore=0 suspectscore=0 phishscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409200058 X-Proofpoint-ORIG-GUID: rj5C-ZUykS9adhi4OO28wicRtNPL4A8x X-Proofpoint-GUID: rj5C-ZUykS9adhi4OO28wicRtNPL4A8x Currently the "var" feature only encodes percpu variables. Add the ability to encode all global variables. This also drops the use of the symbol table to find variable names and compare them against DWARF names. We simply rely on the DWARF information to give us all the variables. Signed-off-by: Stephen Brennan Tested-by: Alan Maguire --- btf_encoder.c | 347 +++++++++++++++++++++------------------------ btf_encoder.h | 8 ++ dwarves.h | 1 + man-pages/pahole.1 | 8 +- pahole.c | 11 +- 5 files changed, 183 insertions(+), 192 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 97d35e0..d3a66a0 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -65,16 +65,13 @@ struct elf_function { struct btf_encoder_state state; }; -struct var_info { - uint64_t addr; - const char *name; - uint32_t sz; -}; - struct elf_secinfo { uint64_t addr; const char *name; uint64_t sz; + bool include; + uint32_t type; + struct gobuffer secinfo; }; /* @@ -84,31 +81,24 @@ struct btf_encoder { struct list_head node; struct btf *btf; struct cu *cu; - struct gobuffer percpu_secinfo; const char *source_filename; const char *filename; struct elf_symtab *symtab; uint32_t type_id_off; bool has_index_type, need_index_type, - skip_encoding_vars, raw_output, verbose, force, gen_floats, skip_encoding_decl_tag, tag_kfuncs, - is_rel, gen_distilled_base; uint32_t array_index_id; struct elf_secinfo *secinfo; size_t seccnt; - struct { - struct var_info *vars; - int var_cnt; - int allocated; - uint32_t shndx; - } percpu; + int encode_vars; + uint32_t percpu_shndx; struct { struct elf_function *entries; int allocated; @@ -735,46 +725,56 @@ static int32_t btf_encoder__add_var(struct btf_encoder *encoder, uint32_t type, return id; } -static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, uint32_t type, - uint32_t offset, uint32_t size) +static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, int shndx, + uint32_t type, unsigned long addr, uint32_t size) { struct btf_var_secinfo si = { .type = type, - .offset = offset, + .offset = addr, .size = size, }; - return gobuffer__add(&encoder->percpu_secinfo, &si, sizeof(si)); + return gobuffer__add(&encoder->secinfo[shndx].secinfo, &si, sizeof(si)); } int32_t btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other) { - struct gobuffer *var_secinfo_buf = &other->percpu_secinfo; - size_t sz = gobuffer__size(var_secinfo_buf); - uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo); - uint32_t type_id; - uint32_t next_type_id = btf__type_cnt(encoder->btf); - int32_t i, id; - struct btf_var_secinfo *vsi; - + int shndx; if (encoder == other) return 0; btf_encoder__add_saved_funcs(other); - for (i = 0; i < nr_var_secinfo; i++) { - vsi = (struct btf_var_secinfo *)var_secinfo_buf->entries + i; - type_id = next_type_id + vsi->type - 1; /* Type ID starts from 1 */ - id = btf_encoder__add_var_secinfo(encoder, type_id, vsi->offset, vsi->size); - if (id < 0) - return id; + for (shndx = 0; shndx < other->seccnt; shndx++) { + struct gobuffer *var_secinfo_buf = &other->secinfo[shndx].secinfo; + size_t sz = gobuffer__size(var_secinfo_buf); + uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo); + uint32_t type_id; + uint32_t next_type_id = btf__type_cnt(encoder->btf); + int32_t i, id; + struct btf_var_secinfo *vsi; + + if (strcmp(encoder->secinfo[shndx].name, other->secinfo[shndx].name)) { + fprintf(stderr, "mismatched ELF sections at index %d: \"%s\", \"%s\"\n", + shndx, encoder->secinfo[shndx].name, other->secinfo[shndx].name); + return -1; + } + + for (i = 0; i < nr_var_secinfo; i++) { + vsi = (struct btf_var_secinfo *)var_secinfo_buf->entries + i; + type_id = next_type_id + vsi->type - 1; /* Type ID starts from 1 */ + id = btf_encoder__add_var_secinfo(encoder, shndx, type_id, vsi->offset, vsi->size); + if (id < 0) + return id; + } } return btf__add_btf(encoder->btf, other->btf); } -static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, const char *section_name) +static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, int shndx) { - struct gobuffer *var_secinfo_buf = &encoder->percpu_secinfo; + struct gobuffer *var_secinfo_buf = &encoder->secinfo[shndx].secinfo; + const char *section_name = encoder->secinfo[shndx].name; struct btf *btf = encoder->btf; size_t sz = gobuffer__size(var_secinfo_buf); uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo); @@ -1741,13 +1741,14 @@ out: int btf_encoder__encode(struct btf_encoder *encoder) { bool should_tag_kfuncs; - int err; + int err, shndx; /* for single-threaded case, saved funcs are added here */ btf_encoder__add_saved_funcs(encoder); - if (gobuffer__size(&encoder->percpu_secinfo) != 0) - btf_encoder__add_datasec(encoder, PERCPU_SECTION); + for (shndx = 0; shndx < encoder->seccnt; shndx++) + if (gobuffer__size(&encoder->secinfo[shndx].secinfo)) + btf_encoder__add_datasec(encoder, shndx); /* Empty file, nothing to do, so... done! */ if (btf__type_cnt(encoder->btf) == 1) @@ -1797,111 +1798,18 @@ int btf_encoder__encode(struct btf_encoder *encoder) return err; } -static int percpu_var_cmp(const void *_a, const void *_b) -{ - const struct var_info *a = _a; - const struct var_info *b = _b; - - if (a->addr == b->addr) - return 0; - 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) -{ - 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); - if (!p) - return false; - - *sz = p->sz; - *name = p->name; - return true; -} - -static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym *sym, size_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->percpu.shndx) - return 0; - if (elf_sym__type(sym) != STT_OBJECT) - return 0; - - addr = elf_sym__value(sym); - - size = elf_sym__size(sym); - if (!size) - return 0; /* ignore zero-sized symbols */ - - sym_name = elf_sym__name(sym, encoder->symtab); - if (!btf_name_valid(sym_name)) { - dump_invalid_symbol("Found symbol of invalid name when encoding btf", - sym_name, encoder->verbose, encoder->force); - if (encoder->force) - return 0; - return -1; - } - - 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. - */ - if (!encoder->is_rel) - addr -= encoder->secinfo[encoder->percpu.shndx].addr; - - if (encoder->percpu.var_cnt == encoder->percpu.allocated) { - struct var_info *new; - - new = reallocarray_grow(encoder->percpu.vars, - &encoder->percpu.allocated, - sizeof(*encoder->percpu.vars)); - if (!new) { - fprintf(stderr, "Failed to allocate memory for variables\n"); - return -1; - } - encoder->percpu.vars = new; - } - 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++; - - 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) { - Elf32_Word sym_sec_idx; + uint32_t sym_sec_idx; uint32_t core_id; GElf_Sym sym; - /* cache variables' addresses, preparing for searching in symtab. */ - encoder->percpu.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_percpu_var(encoder, &sym, sym_sec_idx)) - return -1; if (btf_encoder__collect_function(encoder, &sym)) return -1; } - 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->verbose) - printf("Found %d per-CPU variables!\n", encoder->percpu.var_cnt); - } - if (encoder->functions.cnt) { qsort(encoder->functions.entries, encoder->functions.cnt, sizeof(encoder->functions.entries[0]), functions_cmp); @@ -1923,75 +1831,128 @@ static bool ftype__has_arg_names(const struct ftype *ftype) return true; } +static int get_elf_section(struct btf_encoder *encoder, unsigned long addr) +{ + /* Start at index 1 to ignore initial SHT_NULL section */ + for (int i = 1; i < encoder->seccnt; i++) + /* Variables are only present in PROGBITS or NOBITS (.bss) */ + if ((encoder->secinfo[i].type == SHT_PROGBITS || + encoder->secinfo[i].type == SHT_NOBITS) && + encoder->secinfo[i].addr <= addr && + (addr - encoder->secinfo[i].addr) < encoder->secinfo[i].sz) + return i; + return -ENOENT; +} + +/* + * Filter out variables / symbol names with common prefixes and no useful + * values. Prefixes should be added sparingly, and it should be objectively + * obvious that they are not useful. + */ +static bool filter_variable_name(const char *name) +{ + static const struct { char *s; size_t len; } skip[] = { + #define X(str) {str, sizeof(str) - 1} + X("__UNIQUE_ID"), + X("__tpstrtab_"), + X("__exitcall_"), + X("__func_stack_frame_non_standard_") + #undef X + }; + int i; + + if (*name != '_') + return false; + + for (i = 0; i < ARRAY_SIZE(skip); i++) { + if (strncmp(name, skip[i].s, skip[i].len) == 0) + return true; + } + return false; +} + static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) { struct cu *cu = encoder->cu; uint32_t core_id; struct tag *pos; int err = -1; - struct elf_secinfo *pcpu_scn = &encoder->secinfo[encoder->percpu.shndx]; - if (encoder->percpu.shndx == 0 || !encoder->symtab) + if (!encoder->symtab) return 0; if (encoder->verbose) - printf("search cu '%s' for percpu global variables.\n", cu->name); + printf("search cu '%s' for global variables.\n", cu->name); 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 *name; struct llvm_annotation *annot; const struct tag *tag; + int shndx; + struct elf_secinfo *sec = NULL; uint64_t addr; int id; + unsigned long size; + /* Skip incomplete (non-defining) declarations */ if (var->declaration && !var->spec) continue; - /* percpu variables are allocated in global space */ - if (variable__scope(var) != VSCOPE_GLOBAL && !var->spec) + /* + * top_level: indicates that the variable is declared at the top + * level of the CU, and thus it is globally scoped. + * artificial: indicates that the variable is a compiler-generated + * "fake" variable that doesn't appear in the source. + * scope: set by pahole to indicate the type of storage the + * variable has. GLOBAL indicates it is stored in static + * memory (as opposed to a stack variable or register) + * + * Some variables are "top_level" but not GLOBAL: + * e.g. current_stack_pointer, which is a register variable, + * despite having global CU-declarations. We don't want that, + * since no code could actually find this variable. + * Some variables are GLOBAL but not top_level: + * e.g. function static variables + */ + if (!var->top_level || var->artificial || var->scope != VSCOPE_GLOBAL) continue; /* addr has to be recorded before we follow spec */ 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 < pcpu_scn->addr || addr >= pcpu_scn->addr + pcpu_scn->sz) + /* Get the ELF section info for the variable */ + shndx = get_elf_section(encoder, addr); + if (shndx >= 0 && shndx < encoder->seccnt) + sec = &encoder->secinfo[shndx]; + if (!sec || !sec->include) continue; - addr -= pcpu_scn->addr; - if (!btf_encoder__percpu_var_exists(encoder, addr, &size, &name)) - continue; /* not a per-CPU variable */ + /* Convert addr to section relative */ + addr -= sec->addr; - /* 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 - * them, additionally compare DWARF and ELF symbol names. If - * DWARF doesn't provide proper name, pessimistically assume - * bad variable. - * - * Examples of such special variables are: - * - * 1. __ADDRESSABLE(sym), which are forcely emitted as symbols. - * 2. __UNIQUE_ID(prefix), which are introduced to generate unique ids. - * 3. __exitcall(fn), functions which are labeled as exit calls. - * - * This is relevant only for vmlinux image, as for kernel - * modules per-CPU data section has non-zero offset so all - * per-CPU symbols have non-zero values. - */ - if (var->ip.addr == 0) { - if (!dwarf_name || strcmp(dwarf_name, name)) + /* DWARF specification reference should be followed, because + * information like the name & type may not be present on var */ + if (var->spec) + var = var->spec; + + name = variable__name(var); + if (!name) + continue; + + /* Check for invalid BTF names */ + if (!btf_name_valid(name)) { + dump_invalid_symbol("Found invalid variable name when encoding btf", + name, encoder->verbose, encoder->force); + if (encoder->force) continue; + else + return -1; } - if (var->spec) - var = var->spec; + if (filter_variable_name(name)) + continue; if (var->ip.tag.type == 0) { fprintf(stderr, "error: found variable '%s' in CU '%s' that has void type\n", @@ -2003,9 +1964,10 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) } tag = cu__type(cu, var->ip.tag.type); - if (tag__size(tag, cu) == 0) { + size = tag__size(tag, cu); + if (size == 0) { if (encoder->verbose) - fprintf(stderr, "Ignoring zero-sized per-CPU variable '%s'...\n", dwarf_name ?: ""); + fprintf(stderr, "Ignoring zero-sized variable '%s'...\n", name ?: ""); continue; } @@ -2035,13 +1997,14 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) } /* - * add a BTF_VAR_SECINFO in encoder->percpu_secinfo, which will be added into - * encoder->types later when we add BTF_VAR_DATASEC. + * Add the variable to the secinfo for the section it appears in. + * Later we will generate a BTF_VAR_DATASEC for all any section with + * an encoded variable. */ - id = btf_encoder__add_var_secinfo(encoder, id, addr, size); + id = btf_encoder__add_var_secinfo(encoder, shndx, id, addr, size); if (id < 0) { fprintf(stderr, "error: failed to encode section info for variable '%s' at addr 0x%" PRIx64 "\n", - name, addr); + name, addr); goto out; } } @@ -2068,7 +2031,6 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->force = conf_load->btf_encode_force; encoder->gen_floats = conf_load->btf_gen_floats; - encoder->skip_encoding_vars = conf_load->skip_encoding_btf_vars; encoder->skip_encoding_decl_tag = conf_load->skip_encoding_btf_decl_tag; encoder->tag_kfuncs = conf_load->btf_decl_tag_kfuncs; encoder->gen_distilled_base = conf_load->btf_gen_distilled_base; @@ -2076,6 +2038,11 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->has_index_type = false; encoder->need_index_type = false; encoder->array_index_id = 0; + encoder->encode_vars = 0; + if (!conf_load->skip_encoding_btf_vars) + encoder->encode_vars |= BTF_VAR_PERCPU; + if (conf_load->encode_btf_global_vars) + encoder->encode_vars |= BTF_VAR_GLOBAL; GElf_Ehdr ehdr; @@ -2085,8 +2052,6 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam goto out_delete; } - encoder->is_rel = ehdr.e_type == ET_REL; - switch (ehdr.e_ident[EI_DATA]) { case ELFDATA2LSB: btf__set_endianness(encoder->btf, BTF_LITTLE_ENDIAN); @@ -2127,15 +2092,21 @@ 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 (strcmp(secname, PERCPU_SECTION) == 0) - encoder->percpu.shndx = shndx; + encoder->secinfo[shndx].type = shdr.sh_type; + if (encoder->encode_vars & BTF_VAR_GLOBAL) + encoder->secinfo[shndx].include = true; + + if (strcmp(secname, PERCPU_SECTION) == 0) { + encoder->percpu_shndx = shndx; + if (encoder->encode_vars & BTF_VAR_PERCPU) + encoder->secinfo[shndx].include = true; + } } - if (!encoder->percpu.shndx && encoder->verbose) + if (!encoder->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) @@ -2156,7 +2127,8 @@ void btf_encoder__delete(struct btf_encoder *encoder) return; btf_encoders__delete(encoder); - __gobuffer__delete(&encoder->percpu_secinfo); + for (int i = 0; i < encoder->seccnt; i++) + __gobuffer__delete(&encoder->secinfo[i].secinfo); zfree(&encoder->filename); zfree(&encoder->source_filename); btf__free(encoder->btf); @@ -2166,9 +2138,6 @@ void btf_encoder__delete(struct btf_encoder *encoder) encoder->functions.allocated = encoder->functions.cnt = 0; free(encoder->functions.entries); encoder->functions.entries = NULL; - encoder->percpu.allocated = encoder->percpu.var_cnt = 0; - free(encoder->percpu.vars); - encoder->percpu.vars = NULL; free(encoder); } @@ -2321,7 +2290,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, struct co goto out; } - if (!encoder->skip_encoding_vars) + if (encoder->encode_vars) err = btf_encoder__encode_cu_variables(encoder); /* It is only safe to delete this CU if we have not stashed any static diff --git a/btf_encoder.h b/btf_encoder.h index f54c95a..5e4d53a 100644 --- a/btf_encoder.h +++ b/btf_encoder.h @@ -16,7 +16,15 @@ struct btf; struct cu; struct list_head; +/* Bit flags specifying which kinds of variables are emitted */ +enum btf_var_option { + BTF_VAR_NONE = 0, + BTF_VAR_PERCPU = 1, + BTF_VAR_GLOBAL = 2, +}; + struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, bool verbose, struct conf_load *conf_load); + void btf_encoder__delete(struct btf_encoder *encoder); int btf_encoder__encode(struct btf_encoder *encoder); diff --git a/dwarves.h b/dwarves.h index 0fede91..fef881f 100644 --- a/dwarves.h +++ b/dwarves.h @@ -92,6 +92,7 @@ struct conf_load { bool btf_gen_optimized; bool skip_encoding_btf_inconsistent_proto; bool skip_encoding_btf_vars; + bool encode_btf_global_vars; bool btf_gen_floats; bool btf_encode_force; bool reproducible_build; diff --git a/man-pages/pahole.1 b/man-pages/pahole.1 index 0a9d8ac..4bc2d03 100644 --- a/man-pages/pahole.1 +++ b/man-pages/pahole.1 @@ -230,7 +230,10 @@ the debugging information. .TP .B \-\-skip_encoding_btf_vars -Do not encode VARs in BTF. +.TQ +.B \-\-encode_btf_global_vars +By default, VARs are encoded only for percpu variables. These options allow +to skip encoding them, or alternatively to encode all global variables too. .TP .B \-\-skip_encoding_btf_decl_tag @@ -296,7 +299,8 @@ Encode BTF using the specified feature list, or specify 'default' for all standa encode_force Ignore invalid symbols when encoding BTF; for example if a symbol has an invalid name, it will be ignored and BTF encoding will continue. - var Encode variables using BTF_KIND_VAR in BTF. + var Encode percpu variables using BTF_KIND_VAR in BTF. + global_var Encode all global variables in the same way. float Encode floating-point types in BTF. decl_tag Encode declaration tags using BTF_KIND_DECL_TAG. type_tag Encode type tags using BTF_KIND_TYPE_TAG. diff --git a/pahole.c b/pahole.c index a33490d..b123be1 100644 --- a/pahole.c +++ b/pahole.c @@ -1239,6 +1239,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version; #define ARGP_contains_enumerator 344 #define ARGP_reproducible_build 345 #define ARGP_running_kernel_vmlinux 346 +#define ARGP_encode_btf_global_vars 347 /* --btf_features=feature1[,feature2,..] allows us to specify * a list of requested BTF features or "default" to enable all default @@ -1285,6 +1286,7 @@ struct btf_feature { } btf_features[] = { BTF_DEFAULT_FEATURE(encode_force, btf_encode_force, false), BTF_DEFAULT_FEATURE(var, skip_encoding_btf_vars, true), + BTF_DEFAULT_FEATURE(global_var, encode_btf_global_vars, false), BTF_DEFAULT_FEATURE(float, btf_gen_floats, false), BTF_DEFAULT_FEATURE(decl_tag, skip_encoding_btf_decl_tag, true), BTF_DEFAULT_FEATURE(type_tag, skip_encoding_btf_type_tag, true), @@ -1720,7 +1722,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 [if this is not specified, only percpu variables are encoded. To encode global variables too, use --encode_btf_global_vars]." + }, + { + .name = "encode_btf_global_vars", + .key = ARGP_skip_encoding_btf_vars, + .doc = "Encode all global VARs in BTF [if this is not specified, only percpu variables are encoded]." }, { .name = "btf_encode_force", @@ -2047,6 +2054,8 @@ static error_t pahole__options_parser(int key, char *arg, show_supported_btf_features(stdout); exit(0); case ARGP_btf_features_strict: parse_btf_features(arg, true); break; + case ARGP_encode_btf_global_vars: + conf_load.encode_btf_global_vars = true; break; default: return ARGP_ERR_UNKNOWN; }