From patchwork Fri Nov 8 23:45:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13869126 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86C8ED64076 for ; Sat, 9 Nov 2024 01:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/MLP9UdQUDsEdHUVlA/n4KzrILb8IirqJG/HnkBPMAA=; b=OrqERogzq3l92D k8sNB241Um0lrEXIWB95vVgBMD3lFgN+ADqwpE6gXNa+Kt96WJqOA9E7920JUAekWx/xGjfDKDHHv UlqZm/mqYikOZIBypsM/X7cMW/x5Bq0i35+2rdgGo84Oknvyib8ckMRLHX09hoCHoYa6ulPivqvUZ 2bLzq1crO3EPQMgGtEbGmCfFm6prW1hYz8jLKs9LvL5+nEXjYsYxBDU3WfLWGnmloB9nPdK/b1s7J 1S64oR+eyb0t4UNCJaeUOogsLFYlfGP4CfW8+C+uPEFf1ROOffhcqiLJ16LNlKl7EXlSBGyVqExFZ 6IbRpcovd7VTrNdOWKcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t9ZrU-0000000COVv-2UQy; Sat, 09 Nov 2024 01:02:00 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t9YgJ-0000000CF1b-1kqk for linux-riscv@lists.infradead.org; Fri, 08 Nov 2024 23:46:24 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e29135d1d0cso4598488276.1 for ; Fri, 08 Nov 2024 15:46:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731109582; x=1731714382; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=AVtWpsuHpFiBnlibbq5HoTF1wljBLHXYozEcDvYWBgA=; b=1aw2s5uYQJf86sAYqsDWimW6j7HUJGNIA7Egm3Q0vvsx/xk7DS8HBYZb5+npc131Mq sA+H6vUBapNmBsmuaaomG6xIXfoHKJ5riYRAMC6UZi+1K4WmMARS5jzyta+K1u26hObR 731lzeqfIpzh2uVEV/yFnwnDrcGEWpnUnzohC400cT0ZGT/qYXNxx8bshlnU6YRe/Q9I F47aLLQo/xy2vXMd7HqERx3RMslycfvC//Z0/2iySxCjeUWSi7L47t1kbh3G3hQlfq1f kRy6VeWE/vrIvHX2aYiE37vVfEBF351+Tkrr5L639MX05AH9tNBzaG/+031XDqHAG7X4 t9Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731109582; x=1731714382; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AVtWpsuHpFiBnlibbq5HoTF1wljBLHXYozEcDvYWBgA=; b=AXqr4HdS2byDq89ThWwlEdM7a2Lk7EiiDzK+2CRKGp6S4IHzUOZ8Z0i6BpeL3ktKPL 3rAYjuXEvrQepSwOdjh+6yoNAJkvrSg/HOMKBDID6BqJ4cdzcO1ya3H9eDtksYHlZ6CW kMQXJ6ZYMXp7s7Q44ELaDFzPSgdXu7crUh6GgaVbz3CjoogRSuMN2AaNpvWSzdrSJ7WC K3xgdkwH73UbEIvDXC0CEXVG+Ar3nMDf61Upu6IuZQF0KP/S6K7T6dJoQYlqJTgc9BCG 9tEjbpsK+DYnK/joMZxzQmsJCKKh3d88wvABNF65AtT8OUUnUoVtSrnv9Vfc0lvZCgHo UNpg== X-Forwarded-Encrypted: i=1; AJvYcCVwF0evwZxuzcRkDnVHli41WSvV2n34Bjw9EiY3JN6lE/6aaCqAPtwHqoFU/P6r1RjS2cFDWgbG//k8lQ==@lists.infradead.org X-Gm-Message-State: AOJu0Yx306dA5anDKcEBaoaiT3Qs4zOv0NH9sc0WSVdhDad7Q9x1CJRb GtR8f9RmcFuDpmufUZg3ANZVfwzLwxGzQqf6PlBxYm3FMqneolT+d6HUX0jtaRgMgr6LrG1rYXM tS5aYYw== X-Google-Smtp-Source: AGHT+IFq1UuJ7hc/ApetK/H2sFL5m2uMATjY+fqFwJq/WDc5NUWTV7ClaOKOd64kgsF/WFeRan59owDlPrau X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a25:84c9:0:b0:e33:111b:c6a4 with SMTP id 3f1490d57ef6-e337f81b835mr3397276.1.1731109581785; Fri, 08 Nov 2024 15:46:21 -0800 (PST) Date: Fri, 8 Nov 2024 15:45:50 -0800 In-Reply-To: <20241108234606.429459-1-irogers@google.com> Message-Id: <20241108234606.429459-6-irogers@google.com> Mime-Version: 1.0 References: <20241108234606.429459-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v4 05/20] perf dwarf-regs: Pass accurate disassembly machine to get_dwarf_regnum From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Nick Terrell , "Masami Hiramatsu (Google)" , Changbin Du , Guilherme Amadio , Yang Jihong , Aditya Gupta , Athira Rajeev , Masahiro Yamada , Bibo Mao , Huacai Chen , Kajol Jain , Atish Patra , Shenlin Liang , Anup Patel , Oliver Upton , "Steinar H. Gunderson" , "Dr. David Alan Gilbert" , Chen Pei , Dima Kogan , Przemek Kitszel , "David S. Miller" , Alexander Lobakin , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241108_154623_472006_1153F81C X-CRM114-Status: GOOD ( 15.88 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Rather than pass 0/EM_NONE, use the value computed in the disasm struct arch. Switch the EM_NONE case to EM_HOST, rewriting EM_NONE if it were passed to get_dwarf_regnum. Pass a flags value as architectures like csky need the flags to determine the ABI variant. Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Ian Rogers --- tools/perf/util/annotate.c | 6 +++--- tools/perf/util/dwarf-regs.c | 8 ++++++-- tools/perf/util/include/dwarf-regs.h | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 37ce43c4eb8f..b1d98da79be8 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2292,7 +2292,7 @@ static int extract_reg_offset(struct arch *arch, const char *str, if (regname == NULL) return -1; - op_loc->reg1 = get_dwarf_regnum(regname, 0); + op_loc->reg1 = get_dwarf_regnum(regname, arch->e_machine, arch->e_flags); free(regname); /* Get the second register */ @@ -2305,7 +2305,7 @@ static int extract_reg_offset(struct arch *arch, const char *str, if (regname == NULL) return -1; - op_loc->reg2 = get_dwarf_regnum(regname, 0); + op_loc->reg2 = get_dwarf_regnum(regname, arch->e_machine, arch->e_flags); free(regname); } return 0; @@ -2405,7 +2405,7 @@ int annotate_get_insn_location(struct arch *arch, struct disasm_line *dl, return -1; if (*s == arch->objdump.register_char) - op_loc->reg1 = get_dwarf_regnum(s, 0); + op_loc->reg1 = get_dwarf_regnum(s, arch->e_machine, arch->e_flags); else if (*s == arch->objdump.imm_char) { op_loc->offset = strtol(s + 1, &p, 0); if (p && p != s + 1) diff --git a/tools/perf/util/dwarf-regs.c b/tools/perf/util/dwarf-regs.c index 7c01bc4d7e5b..1321387f6948 100644 --- a/tools/perf/util/dwarf-regs.c +++ b/tools/perf/util/dwarf-regs.c @@ -70,7 +70,7 @@ __weak int get_arch_regnum(const char *name __maybe_unused) } /* Return DWARF register number from architecture register name */ -int get_dwarf_regnum(const char *name, unsigned int machine) +int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags __maybe_unused) { char *regname = strdup(name); int reg = -1; @@ -84,8 +84,12 @@ int get_dwarf_regnum(const char *name, unsigned int machine) if (p) *p = '\0'; + if (machine == EM_NONE) { + /* Generic arch - use host arch */ + machine = EM_HOST; + } switch (machine) { - case EM_NONE: /* Generic arch - use host arch */ + case EM_HOST: reg = get_arch_regnum(regname); break; default: diff --git a/tools/perf/util/include/dwarf-regs.h b/tools/perf/util/include/dwarf-regs.h index ce9f10b3282d..3c3a908b9f36 100644 --- a/tools/perf/util/include/dwarf-regs.h +++ b/tools/perf/util/include/dwarf-regs.h @@ -103,12 +103,13 @@ int get_arch_regnum(const char *name); * name: architecture register name * machine: ELF machine signature (EM_*) */ -int get_dwarf_regnum(const char *name, unsigned int machine); +int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags); #else /* HAVE_LIBDW_SUPPORT */ static inline int get_dwarf_regnum(const char *name __maybe_unused, - unsigned int machine __maybe_unused) + unsigned int machine __maybe_unused, + unsigned int flags __maybe_unused) { return -1; }