From nobody Wed Sep 17 21:00:38 2025 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 09417C4332F for ; Thu, 15 Dec 2022 19:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230233AbiLOT2l (ORCPT ); Thu, 15 Dec 2022 14:28:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbiLOT2Z (ORCPT ); Thu, 15 Dec 2022 14:28:25 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8EE547310; Thu, 15 Dec 2022 11:28:24 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id v13-20020a17090a6b0d00b00219c3be9830so122588pjj.4; Thu, 15 Dec 2022 11:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=yJtu96UaLUbxmrQaw47zeCnhCw3DINxkl6YWOTS0s0A=; b=qhgx6fDuh1uq//jERerz82Du7xXn0/9GhYjPUsjvIF1t/xm7f1Lbka9VnZKKN+VxBp cyKtsGYFN4TR/bn23IlUg/8yMNINkiqCVjUC0AWbQCjaK3ml6Flq8PlNoDgVyXtXkhVq v5acFGQ9D2WjVMuQ8pyeiwCwNIu2TLY7NLgF1tBdxT1kIRhbw5pSJUQDcp6+XnF3HXZH T07wdy/kEZFErte0xjbrzXVZCi1bizWWPc5i1rer5w2FX0Dwcfc3WiMWtmUOmbuRP6AI fFm4oPl7US12fKGCxeoDIX39wk7knGh8K2RPLkvkBu1UjduppoBwc3PYvQaBof4B7kGL UrRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yJtu96UaLUbxmrQaw47zeCnhCw3DINxkl6YWOTS0s0A=; b=HYocK/IPKds966oN+WWal8IkiBg6pwkfliLGjrCWUaUluwntnkjGx5WbVZOEeqj6Np TIU1AH2kZjgjRavnvPo6i2R9S21VH9vFSWwpSYffI5qpybYGLDvBBUsiGPPAq/ekGzFh vCzq1BISzW8Kr6PCC9vr3m4FX8Qv2VjjVmK000nnvfh21hJ21GOm1ZNnzNCAkNxHkyeq y08XayEgrW56IHtv4Ix+MM4ptYX2FcH1E+aasx7U7QRvh4j0NX89Tbo2LYRxpMh2p61A lMiL155eGRlItg81J0Uzeqzv1CC2IxfM2DDM08uIvX7chSCdx4mOJY7ry1PBR5hleO4e zLIg== X-Gm-Message-State: ANoB5pnm5pFaMd4A7xqYskuoEov8vgC734MbMkEzIwx9A5+9zh1rIsL4 jD89+a3eRPmYFC4erTovRdKnKXY8kT8= X-Google-Smtp-Source: AA0mqf6w64z3r7k1xNh6B1RM4typbb1MMllIiAWQ0juBiASb4wgSyqo809egPFI3anEFOc+DF1zJEw== X-Received: by 2002:a17:90a:9b0b:b0:219:28b7:c580 with SMTP id f11-20020a17090a9b0b00b0021928b7c580mr29605270pjp.22.1671132504206; Thu, 15 Dec 2022 11:28:24 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:ecc1:3e44:be34:129c]) by smtp.gmail.com with ESMTPSA id ep14-20020a17090ae64e00b00219cf5c3829sm3475129pjb.57.2022.12.15.11.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 11:28:23 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Andi Kleen , Milian Wolff , Leo Yan Subject: [PATCH 3/9] perf symbol: Add filename__has_section() Date: Thu, 15 Dec 2022 11:28:11 -0800 Message-Id: <20221215192817.2734573-4-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20221215192817.2734573-1-namhyung@kernel.org> References: <20221215192817.2734573-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The filename__has_section() is to check if the given section name is in the binary. It'd be used for checking debug info for srcline. Signed-off-by: Namhyung Kim --- tools/perf/util/symbol-elf.c | 28 ++++++++++++++++++++++++++++ tools/perf/util/symbol-minimal.c | 5 +++++ tools/perf/util/symbol.h | 1 + 3 files changed, 34 insertions(+) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 80345695b136..96767d1b3f1c 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -233,6 +233,34 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, return NULL; } =20 +bool filename__has_section(const char *filename, const char *sec) +{ + int fd; + Elf *elf; + GElf_Ehdr ehdr; + GElf_Shdr shdr; + bool found =3D false; + + fd =3D open(filename, O_RDONLY); + if (fd < 0) + return false; + + elf =3D elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); + if (elf =3D=3D NULL) + goto out; + + if (gelf_getehdr(elf, &ehdr) =3D=3D NULL) + goto elf_out; + + found =3D !!elf_section_by_name(elf, &ehdr, &shdr, sec, NULL); + +elf_out: + elf_end(elf); +out: + close(fd); + return found; +} + static int elf_read_program_header(Elf *elf, u64 vaddr, GElf_Phdr *phdr) { size_t i, phdrnum; diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-mini= mal.c index f9eb0bee7f15..de84da3b0d96 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -385,3 +385,8 @@ char *dso__demangle_sym(struct dso *dso __maybe_unused, { return NULL; } + +bool filename__has_section(const char *filename, const char *sec) +{ + return false; +} diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index e297de14184c..f735108c4d4e 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -165,6 +165,7 @@ int modules__parse(const char *filename, void *arg, u64 start, u64 size)); int filename__read_debuglink(const char *filename, char *debuglink, size_t size); +bool filename__has_section(const char *filename, const char *sec); =20 struct perf_env; int symbol__init(struct perf_env *env); --=20 2.39.0.314.g84b9a713c41-goog