Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753796AbdLHLJA (ORCPT ); Fri, 8 Dec 2017 06:09:00 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51382 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753717AbdLHLIt (ORCPT ); Fri, 8 Dec 2017 06:08:49 -0500 Subject: Re: [PATCH v2 4/5] perf-probe: Find versioned symbols from map To: Masami Hiramatsu , Arnaldo Carvalho de Melo Cc: bhargavb , linux-kernel@vger.kernel.org, Paul Clarke , Ravi Bangoria , linux-rt-users@vger.kernel.org, linux-perf-users@vger.kernel.org References: <151263115609.13843.6362262297053841418.stgit@devbox> <151263128603.13843.14383703750561651246.stgit@devbox> From: Thomas-Mich Richter Organization: IBM LTC Date: Fri, 8 Dec 2017 12:08:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <151263128603.13843.14383703750561651246.stgit@devbox> Content-Type: text/plain; charset=utf-8 Content-Language: en-IE Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 17120811-0020-0000-0000-000003D5CD70 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17120811-0021-0000-0000-0000426B5D53 Message-Id: <034765fc-975a-a210-6ed8-bebd3b1ff9b3@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-08_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712080160 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4886 Lines: 148 On 12/07/2017 08:21 AM, Masami Hiramatsu wrote: > Find versioned symbols correctly from map. > 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 > --- > tools/perf/arch/powerpc/util/sym-handling.c | 8 ++++++++ > tools/perf/util/probe-event.c | 16 +++++++++++++++- > tools/perf/util/symbol.c | 5 +++++ > tools/perf/util/symbol.h | 1 + > 4 files changed, 29 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c > index 9c4e23d8c8ce..a3613c8d97b6 100644 > --- 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 char *namea, const char *nameb, > > return strncmp(namea, nameb, n); > } > + > +const char *arch__normalize_symbol_name(const char *name) > +{ > + /* Skip over initial dot */ > + if (*name == '.') > + name++; > + return name; > +} > #endif > > #if defined(_CALL_ELF) && _CALL_ELF == 2 > diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c > index 959c4d2ef455..94acc5846e2a 100644 > --- a/tools/perf/util/probe-event.c > +++ b/tools/perf/util/probe-event.c > @@ -2801,16 +2801,30 @@ static int find_probe_functions(struct map *map, char *name, > 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); The weak default function arch__normalize_symbol_name() simply returns its parameter, so norm can be a NULL ptr when parameter sym->name is a NULL pointer. However when sym->name is a NULL pointer (or can be one) then the Powerpc version of arch__normalize_symbol_name() dereferences a NULL ptr (by checking the symbol's first character is a '.'). > + if (!norm) > + continue; > + > + /* We don't care about default symbol or not */ > + ver = strchr(norm, '@'); > + if (ver) { > + buf = strndup(norm, ver - norm); > + norm = buf; if strndup() returns a NULL pointer (due to lack of memory) then variable norm is a NULL ptr and strglobmatch() --> __match_glob() derefenences that NULL pointer (1. parameter). > + } > + if (strglobmatch(norm, name)) { > found++; > if (syms && found < probe_conf.max_probes) > syms[found - 1] = sym; > } > + if (buf) > + zfree(&buf); > } > > return found; > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c > index 1b67a8639dfe..cc065d4bfafc 100644 > --- a/tools/perf/util/symbol.c > +++ b/tools/perf/util/symbol.c > @@ -94,6 +94,11 @@ static int prefix_underscores_count(const char *str) > 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); > diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h > index a4f0075b4e5c..0563f33c1eb3 100644 > --- a/tools/perf/util/symbol.h > +++ b/tools/perf/util/symbol.h > @@ -349,6 +349,7 @@ bool elf__needs_adjust_symbols(GElf_Ehdr 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 > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- Thomas Richter, Dept 3303, IBM LTC Boeblingen Germany -- Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294