Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5968911imm; Mon, 27 Aug 2018 07:29:48 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb4AI8Mm/fxI84uQG/CqBCulChhhd+z3asAO4ckWQkyDVjVR/xUGG98H3EvAIilMqSXm8an X-Received: by 2002:a17:902:934c:: with SMTP id g12-v6mr13426490plp.67.1535380188798; Mon, 27 Aug 2018 07:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535380188; cv=none; d=google.com; s=arc-20160816; b=OzKay6kbzeTBgzj8S4shlPXaSmcXS1Hqz5iser/cR5t93kUQkMgyV8Z9l+V6JFO+BO zHpjI0+GHUaXAzeOqUmNz1z8wimmMw+92bA9p12comrJEFsdLzn34EJsjyF3KKweA0KW PPZ7Yk/L4s4hZIv4R5EQtACnooPN17UcoHUeMuXKgQD2GBeAY/rzpj0eyhw8cvVeYc1D 1H+Y5DGYuk8rvRG/6b8TzQ79CGODUVmVW1r1ZTwufoZP71+MaMqng51pqJmAXdUux3No smWuWUdm2To3cHlzodZylPhVI95IIN/ZKwM2qotMHWjErpccBIrbM6cN5O+F0rFSvXaF DKoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :arc-authentication-results; bh=dCyjsiMeSmToWt84SxYMnRwnVZrJmz0I8F9XSWO/TKw=; b=X+Md0zjpv0on3szz2sPuhiD5WWN4rhvGGVsU3satFVPon/vCVd5e1LSEy+6e4uuwXF B67JbsuZM8gpPidrjBs8zH+36GEZec/tIH2SlagLI/p7B760zwWLXduUnEkFv1e3ZoIa jLu/QKBwme57UqRWB+ls8Gllsl/+lqjwbPhkv6kuIlRy4lzMtItBg+al+ZpPfEIXCw0e wgywesz3j16xAvCF/ImUmC8c017ak868sXyoMtkxWnimZjq/sTqTqntbm936QlrI0cZT OHsZwQbg2pAcgDX+PFIcSRjBp2/9Nzf6GS5SQwfLnfVN0oBUdydLK03E3XQ9Kpvd7+js TGqw== 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 t16-v6si13379297pgi.457.2018.08.27.07.29.32; Mon, 27 Aug 2018 07:29:48 -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 S1727493AbeH0SOz (ORCPT + 99 others); Mon, 27 Aug 2018 14:14:55 -0400 Received: from mx2.suse.de ([195.135.220.15]:49358 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726953AbeH0SOz (ORCPT ); Mon, 27 Aug 2018 14:14:55 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3B3F5AECB; Mon, 27 Aug 2018 14:28:02 +0000 (UTC) Subject: Re: [PATCH] Properly interpret indirect call in perf annotate. To: Namhyung Kim Cc: linux-perf-users@vger.kernel.org, lkml , Arnaldo Carvalho de Melo , Jiri Olsa , kernel-team@lge.com References: <20180827103715.GB8065@sejong> From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: <3e0c89cf-3e2a-5e23-7921-123a061f3558@suse.cz> Date: Mon, 27 Aug 2018 16:28:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180827103715.GB8065@sejong> Content-Type: multipart/mixed; boundary="------------6A763E9AD35B1793E37A0A8C" Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------6A763E9AD35B1793E37A0A8C Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 08/27/2018 12:37 PM, Namhyung Kim wrote: > Hello, > > On Thu, Aug 23, 2018 at 02:29:34PM +0200, Martin Liška wrote: >> The patch changes interpretation of: >> callq *0x8(%rbx) >> >> from: >> 0.26 │ → callq *8 >> to: >> 0.26 │ → callq *0x8(%rbx) >> >> in this can an address is followed by a register, thus >> one can't parse only address. > > Also there's a case with no offset like: callq *%rbx Yes. But this case is fine as strtoull returns 0 for that: 'If there were no digits at all, strtoul() stores the original value of nptr in *endptr (and returns 0).' So ops->target.addr is then 0 and it's fine. > > >> >> Signed-off-by: Martin Liška >> --- >> tools/perf/util/annotate.c | 10 ++++++++-- >> 1 file changed, 8 insertions(+), 2 deletions(-) >> >> > >> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c >> index e4268b948e0e..e32ead4744bd 100644 >> --- a/tools/perf/util/annotate.c >> +++ b/tools/perf/util/annotate.c >> @@ -246,8 +246,14 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s >> >> indirect_call: >> tok = strchr(endptr, '*'); >> - if (tok != NULL) >> - ops->target.addr = strtoull(tok + 1, NULL, 16); >> + if (tok != NULL) { >> + endptr++; >> + >> + /* Indirect call can use a non-rip register and offset: callq *0x8(%rbx). >> + * Do not parse such instruction. */ >> + if (strstr(endptr, "(%r") == NULL) >> + ops->target.addr = strtoull(endptr, NULL, 16); > > It seems too x86-specific, what about this? (not tested) It is, I'm fine with that. I've just tested that for the callq *0x8(%rbx) example. I'm sending patch for that version. Martin > > > indirect_call: > tok = strchr(endptr, '*'); > if (tok != NULL) { > endptr++; > if (!isdigit(*endptr)) > return 0; > > addr = strtoull(endptr, &endptr, 0); > if (*endptr != '(')) > ops->target.addr = addr; > > > Thanks, > Namhyung > > >> + } >> goto find_target; >> } >> >> > --------------6A763E9AD35B1793E37A0A8C Content-Type: text/x-patch; name="0001-Properly-interpret-indirect-call-in-perf-annotate.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename*0="0001-Properly-interpret-indirect-call-in-perf-annotate.patch" From 58a0eca544be8cc9e15b2ab5ecd9d9401ff4d2ec Mon Sep 17 00:00:00 2001 From: marxin Date: Thu, 23 Aug 2018 14:25:33 +0200 Subject: [PATCH] Properly interpret indirect call in perf annotate. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch changes interpretation of: callq *0x8(%rbx) from: 0.26 │ → callq *8 to: 0.26 │ → callq *0x8(%rbx) in this can an address is followed by a register, thus one can't parse only address. Signed-off-by: Martin Liška --- tools/perf/util/annotate.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index e4268b948e0e..18a8477d4664 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -212,6 +212,7 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s struct addr_map_symbol target = { .map = map, }; + u64 addr; ops->target.addr = strtoull(ops->raw, &endptr, 16); @@ -246,8 +247,15 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s indirect_call: tok = strchr(endptr, '*'); - if (tok != NULL) - ops->target.addr = strtoull(tok + 1, NULL, 16); + if (tok != NULL) { + endptr++; + if (!isdigit(*endptr)) + return 0; + + addr = strtoull(endptr, &endptr, 0); + if (*endptr != '(') + ops->target.addr = addr; + } goto find_target; } -- 2.18.0 --------------6A763E9AD35B1793E37A0A8C--