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/1DWl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FJatN9XFJQsx29gwOnCJYdv60DVHE/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 */