From patchwork Thu Oct 17 00:25:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13839190 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 5F1FED2F7D8 for ; Thu, 17 Oct 2024 01:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :References:Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=48mjrfomMuomFB22b093k885CPaCWm0H0utyyG5sq/o=; b=GD+9GE2zqdzWXzEU7V5xqcryHO Pu/f1eOFqFBTL8x/iothdETdD0emTpEKKES0/iJKXgCGU6rBoxHH3TMoufIrGtlhDv8X7pHZUOU5X +vKCr8rgYVAxrYz/iC72CdAU64Fz1znvbOqHaW58ExCb09J4wHgp0Q+lpJ1n9i3uNdic5Ct9bzITL hJ5WugmSJlfOdIryOjG0m6F2HalLuoClJR1DdOa1iN6k0a39LCwRfXpVRj6NHwLw2NDBIPG+OjRPv uiSxfr0j1QpzVY4kYa0AaauZeVobrAusGwyaJhApqhl+NfBoAKWNStz/zZcVrOlhnGQ1d8oBlDS+E JWKBIkmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1F8C-0000000DQqR-0tIo; Thu, 17 Oct 2024 01:16:48 +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 1t1EKj-0000000DKAM-3XP4 for linux-arm-kernel@lists.infradead.org; Thu, 17 Oct 2024 00:25:43 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e2928d9e615so642462276.0 for ; Wed, 16 Oct 2024 17:25:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729124740; x=1729729540; 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=48mjrfomMuomFB22b093k885CPaCWm0H0utyyG5sq/o=; b=qjylob124mXRvzPYW8GbgmoDVEl3PMToR9ysRtKT36ttVGYBqwJeuZl+bZhmrOBzm4 MZS284IP8HvFOWPr9mm8V4dyiPebzsNfS6BUwI+eqWQehkqh8sa0Wglv1DhCpcHYKefF 36mES/kd3w7PZzY8HzBYZz7v9eeysJSnhAkqK01YWXqG/ztJjxsA7OeulsMyx/ex4L9O hxe+lRrnSoVdQvDaO93LoF/8yc+tMIO2zmB0hbZgP0eltWt8ceabnlAKNtHCRFknC72a 7tqxexO0vQXOhktw5ldKL2JQuBuI33VTo1TKZnKn8LpUAfLuXZ/EHQVHcCQ4AX12vZcQ PeAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729124740; x=1729729540; 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=48mjrfomMuomFB22b093k885CPaCWm0H0utyyG5sq/o=; b=SPRoukwp8nISDMTiD00qZyNHHfz1uq/tsFbSr4WSPGUMIiX4G0YEcOhoyHb2RNR8uu fRXa/TXEePr/t5fCdUJ9tDC5A8sLxn13zEVucr0cLdYLMvB5GAhSXQg6ouC8AWzhHIYs s7w1RscNyY5z9Wo6LeuWPYP4SAM56y9EdIsQi1Jj7RMdv5gb2NZOirIM9rxZ2aI+iTuT y9SF0rE/2Su3dOzY9xk/f7LF+NqTonf13ufk/6IoCqtzuf4uRE44duuX98eiV2m+PuGy uVxW9mOYArNwLO99xXe0RKN/fISlsDg2utkuT5C3JdjZLSBLzdT1sWxZfh/f4D6yhl/m RcBQ== X-Forwarded-Encrypted: i=1; AJvYcCU1o+MZrp6ga1CYijha/Aa6zxmkKVn3FT7bdIjb/gksz+gHn1/MIIoAtUJQ+RVz5KTdzpnBZUaTGA2meJtXiT2C@lists.infradead.org X-Gm-Message-State: AOJu0YyENiLqgCyKzss886+YvIcw3H5D07kYuYzNmdzaNK7Ren3/LTAN CW0sCxJwFB0ZiATUWmLYAgZyeyWJ5ep8bCf9u9wWM1sXZ9bfeDR6Ths8vJepjfUhmW4921mx0e0 Tkommsw== X-Google-Smtp-Source: AGHT+IG8JiIQK8uXOvPdoaWI2mxht6B92+7n0NisCZoM8iJKAkzjyBLEa7nUOj+aZg/H9XU8lHqJJagHTx/j X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:dc4e:0:b0:e28:f231:1aa8 with SMTP id 3f1490d57ef6-e29782bbb03mr7731276.2.1729124739976; Wed, 16 Oct 2024 17:25:39 -0700 (PDT) Date: Wed, 16 Oct 2024 17:25:05 -0700 In-Reply-To: <20241017002520.59124-1-irogers@google.com> Message-Id: <20241017002520.59124-6-irogers@google.com> Mime-Version: 1.0 References: <20241017002520.59124-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v3 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-20241016_172541_909893_1FCE077F X-CRM114-Status: GOOD ( 17.12 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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. 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 f4f87ded5e3d..ee0a734564c7 100644 --- a/tools/perf/util/include/dwarf-regs.h +++ b/tools/perf/util/include/dwarf-regs.h @@ -93,12 +93,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; }