From patchwork Thu Dec 15 19:28:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 33805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp559839wrn; Thu, 15 Dec 2022 11:30:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf6h6HpcaDiylUBbQJrTEslCHokUBAttkbzeqrLMjXHm+7P+E+YfTcu8nERrAWkD4MN9g6kc X-Received: by 2002:a17:907:90d4:b0:7c0:db61:dbd5 with SMTP id gk20-20020a17090790d400b007c0db61dbd5mr22095395ejb.62.1671132603005; Thu, 15 Dec 2022 11:30:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671132602; cv=none; d=google.com; s=arc-20160816; b=brnWkp3B7DYjKXwhex5f5J5Jg65+WfoDjnkrzVVpOlou5wfbNYjVpcDxiQ5LFhJ5QE Qr7+1K97e1LhI2yjEVP63/guFmRX3gLGzzpqgjuTGa4iraDEFrPArBNM6Ic2t8bt3GQZ BIGU3RtTiKsVa7ayQgevHePlIt+6eYBA3+artAGgmx146Lo7PuNrXuE6OiwZaOi9iwtl z7uQm+tgd+gaxyi6oJS3A8DhEhvhT5KWQ4CEhN0ZRXGqmrBjQmAeJyVaMpeVjaWRy56j qWSSwRr8ZEJR84MaLLqE74jdzHfvzSa0jBuHFCT0KhfbOGJT9/DJDAAzJ1worz9oJwbb rcdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=yJtu96UaLUbxmrQaw47zeCnhCw3DINxkl6YWOTS0s0A=; b=RbXfk1/+sNhP42a3pTCR4ZRnJL0UUJalRrL6ZF4dBSX1WWqdasgbAcXgkaXCO0InRL WgXiAAZ8KypEwEX80esHeIomPo2kJsIXwPlf+4/QBXP3tLfFYWzj3DI+Z3zTsKFxSbHI YepiYpfckBwp4IBgTUSJOi97P2BgGJl/R/gxNXjIJ0EmK8d62saSY1dPxHI83bTPk2eY xH+n1ydaxvjbz61DLqbT/rKqOBf08k/w6/qTd4hTbWHK+/T1fXBgQa6dXeVl8qqrkVas yuxQPcaUK00Trd7hcuyiUYoW0akhREhCDkdRPanhVbOp1QWHavi5Y/Ran8LiTn96ysZE Y36A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qhgx6fDu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn19-20020a1709070d1300b007c14e98e3a1si13267302ejc.752.2022.12.15.11.29.40; Thu, 15 Dec 2022 11:30:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qhgx6fDu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230223AbiLOT2j (ORCPT + 99 others); Thu, 15 Dec 2022 14:28:39 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752309540422973450?= X-GMAIL-MSGID: =?utf-8?q?1752309540422973450?= 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; } +bool filename__has_section(const char *filename, const char *sec) +{ + int fd; + Elf *elf; + GElf_Ehdr ehdr; + GElf_Shdr shdr; + bool found = false; + + fd = open(filename, O_RDONLY); + if (fd < 0) + return false; + + elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); + if (elf == NULL) + goto out; + + if (gelf_getehdr(elf, &ehdr) == NULL) + goto elf_out; + + found = !!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-minimal.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); struct perf_env; int symbol__init(struct perf_env *env);