Received: by 10.192.165.156 with SMTP id m28csp72564imm; Tue, 10 Apr 2018 16:41:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+coBQZqrRNI9ktqft2woR7zYDewW6DJ83Uje/QK7DZG6Gu62jOqWyo+hnKTlO60GpPLoRb X-Received: by 2002:a17:902:8685:: with SMTP id g5-v6mr2604081plo.46.1523403703036; Tue, 10 Apr 2018 16:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523403702; cv=none; d=google.com; s=arc-20160816; b=QPou0TwOrNrm19PADvmaIXtuZ83LesqZX88suCabLfPOzMFJoVouALDvDXUWe84e0b kHb9/m/AoUCwkcLXlsL74sQQdgR+nGesjKUyNeA4KdPytpevaIqgAtw6BRhWxNNoktIP UR/YFX8oMryVF6rM4i1uIXZum6gSRKRG9vh/iTS0B6DoOYu6EWRhjGnK14rdaG74snz/ gh131kZB3HP+0Vt7TKePk/lQA11yPugQXN20reFkYqFnYEbMMY7s5IjB5NiuVlp9k8NK 7ou47zDeJzmIgZ1k+zYC44563l5ku95MuTVc7a47yNr9XvKbtE1dxdAalSfK9bRoUCYe Pheg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=LDhEviO4VM1r0IE6E4bsdUKxoX3bMl9IoNxz2DYXHf4=; b=A1dTavc1YzEE96TTYsJHNosqBkXhfrFJyT4zl1kxqMtQZOV77DFmw+g310pVGDs27/ T5NgSwh4vFxzFR7YhmzYS/M9l/y2TT7QGroiiLUOEYDeL5ZsAcz4vfEs81lRHeodCG7v eyQySwExIjD2mCaycaw6BQ10PMYsTLKFUiXA3j9Y6ZPHhyaQec3HCQeQ/5iYum4PGBnv lHbi7DfMl5IHNNOooeHhMf+QE/l3sMAb0y/TiiCMcX/EyeCJuIbBmS71Cur7UM+ctbna YJYXgkz/83/JG13SLg6qC0JTEpMtVSKjSzpzmC5xHbTXWoIC0hoZxPmV9FM7nm3Ljxm8 Q6JQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w9si2876792pfl.268.2018.04.10.16.41.06; Tue, 10 Apr 2018 16:41:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754974AbeDJXg4 (ORCPT + 99 others); Tue, 10 Apr 2018 19:36:56 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37834 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753651AbeDJW1X (ORCPT ); Tue, 10 Apr 2018 18:27:23 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3BF95CC4; Tue, 10 Apr 2018 22:27:22 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masami Hiramatsu , Thomas Richter , Ravi Bangoria , Arnaldo Carvalho de Melo , Paul Clarke , bhargavb , linux-rt-users@vger.kernel.org, Sasha Levin Subject: [PATCH 4.15 009/168] perf probe: Find versioned symbols from map Date: Wed, 11 Apr 2018 00:22:31 +0200 Message-Id: <20180410212800.619524126@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212800.144079021@linuxfoundation.org> References: <20180410212800.144079021@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Masami Hiramatsu [ Upstream commit 4b3a2716dd785fabb9f6ac80c1d53cb29a88169d ] Commit d80406453ad4 ("perf symbols: Allow user probes on versioned symbols") allows user to find default versioned symbols (with "@@") in map. However, it did not enable normal versioned symbol (with "@") for perf-probe. E.g. ===== # ./perf probe -x /lib64/libc-2.25.so malloc_get_state Failed to find symbol malloc_get_state in /usr/lib64/libc-2.25.so Error: Failed to add events. ===== This solves above issue by improving perf-probe symbol search function, as below. ===== # ./perf probe -x /lib64/libc-2.25.so malloc_get_state Added new event: probe_libc:malloc_get_state (on malloc_get_state in /usr/lib64/libc-2.25.so) You can now use it in all perf tools, such as: perf record -e probe_libc:malloc_get_state -aR sleep 1 # ./perf probe -l probe_libc:malloc_get_state (on malloc_get_state@GLIBC_2.2.5 in /usr/lib64/libc-2.25.so) ===== Signed-off-by: Masami Hiramatsu Reviewed-by: Thomas Richter Acked-by: Ravi Bangoria Tested-by: Arnaldo Carvalho de Melo Cc: Paul Clarke Cc: bhargavb Cc: linux-rt-users@vger.kernel.org Link: http://lkml.kernel.org/r/151275049269.24652.1639103455496216255.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/perf/arch/powerpc/util/sym-handling.c | 8 ++++++++ tools/perf/util/probe-event.c | 20 ++++++++++++++++++-- tools/perf/util/symbol.c | 5 +++++ tools/perf/util/symbol.h | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) --- a/tools/perf/arch/powerpc/util/sym-handling.c +++ b/tools/perf/arch/powerpc/util/sym-handling.c @@ -64,6 +64,14 @@ int arch__compare_symbol_names_n(const c return strncmp(namea, nameb, n); } + +const char *arch__normalize_symbol_name(const char *name) +{ + /* Skip over initial dot */ + if (name && *name == '.') + name++; + return name; +} #endif #if defined(_CALL_ELF) && _CALL_ELF == 2 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -2792,16 +2792,32 @@ static int find_probe_functions(struct m int found = 0; struct symbol *sym; struct rb_node *tmp; + const char *norm, *ver; + char *buf = NULL; if (map__load(map) < 0) return 0; map__for_each_symbol(map, sym, tmp) { - if (strglobmatch(sym->name, name)) { + norm = arch__normalize_symbol_name(sym->name); + if (!norm) + continue; + + /* We don't care about default symbol or not */ + ver = strchr(norm, '@'); + if (ver) { + buf = strndup(norm, ver - norm); + if (!buf) + return -ENOMEM; + norm = buf; + } + if (strglobmatch(norm, name)) { found++; if (syms && found < probe_conf.max_probes) syms[found - 1] = sym; } + if (buf) + zfree(&buf); } return found; @@ -2847,7 +2863,7 @@ static int find_probe_trace_events_from_ * same name but different addresses, this lists all the symbols. */ num_matched_functions = find_probe_functions(map, pp->function, syms); - if (num_matched_functions == 0) { + if (num_matched_functions <= 0) { pr_err("Failed to find symbol %s in %s\n", pp->function, pev->target ? : "kernel"); ret = -ENOENT; --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -94,6 +94,11 @@ static int prefix_underscores_count(cons return tail - str; } +const char * __weak arch__normalize_symbol_name(const char *name) +{ + return name; +} + int __weak arch__compare_symbol_names(const char *namea, const char *nameb) { return strcmp(namea, nameb); --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -349,6 +349,7 @@ bool elf__needs_adjust_symbols(GElf_Ehdr void arch__sym_update(struct symbol *s, GElf_Sym *sym); #endif +const char *arch__normalize_symbol_name(const char *name); #define SYMBOL_A 0 #define SYMBOL_B 1