From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDD8B3BBA18 for ; Thu, 22 Jan 2026 21:35:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117737; cv=none; b=SiUEibLGLQ0TCAdzrxkL59etlAGOqg+lhtIOLB/B84NlxuVxYWB5e7qGAYtXGHlPQGoxVk4DfivB+BsZICbUAuCUCMdl9iSutdiCINstbGyyJD7plRuk7DDUykbx/GkQSHjJ48MF887NBl/DBWgNi2RH8HYwYYItjTi9wLN+Ano= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117737; c=relaxed/simple; bh=U3CxrbAAlN8gTA3wMaXLOq+KQ2KCxALBwEtyEmQVEng=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=IgteoOaCWT9dnlKllHABYlDSlV4Ma5FRaNUUhKhXSRujeTxXmn+bVeB4JdUCSI8DHaxdg3Oj0b6Pjqf/XA4I0OJM5GzQewTrSxM6/oYJEB1LODItTwxG47LLOVbnrPlS8XYq90ARJ4XYkEX/YAF4sm3JPp6OaRZKLDx9AMX4WU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yANl44qH; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yANl44qH" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12338749ea9so2028359c88.0 for ; Thu, 22 Jan 2026 13:35:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117725; x=1769722525; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=zalmwLrK8cPj7cYoTUj/KkGE6/xfnap/Tev3VqTduZw=; b=yANl44qHNJ1er8muLcjEqtLhDdjFZ0Qq8NLCQ4MOZqLvuO2YBZDcaI34QXWTR80iLA JwK6cpBb4R/wsWd3ylbjM9lKcr20sjCnh01segm7L/GqGTekZleJ4PR8gclcqE5u57Vy J+j/tES/8RgQ6oVhmPeRIPX//WQoe8omlk5s0ODlTw/1AMOXa7hDUhlTYIWqEuZ2mcpi PxtrAdYIcBECIn3cMxBL71wtXrc6CsunxX744SQpdUQVW/5uVaYavUJRjsGL7lK4NBH8 Ah+jCZuxoTc55Lv5Ojfmo3Tlk6kO4d1n3KjrddLnurV8zZVOipmO4BNuw6Mg1qucDPlA GwWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117725; x=1769722525; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zalmwLrK8cPj7cYoTUj/KkGE6/xfnap/Tev3VqTduZw=; b=wJpSo2qVg1CLm80UGTXKBJqTA0DmSqVHx3CnA+472crDgvXQ9m2XXzChdjnD7n5ABN P/Q2NhNVbnI6ZUNlqXzQsXO/t6UGicc7+cszCc/gmWA5zm3OfptPZJMeq9+TuUslg0iv Cv1KKNVHqee6hbfFKS2HTKiquWgRYTgfJ4PiTQGIzirdUvXN1jYH/n6JPUKuXxLFtgmv opB+0bImv3NWkl56N7wl3D9Ux/ITTHdZHam8DB1j+7nZx242cn2KwfRMjyrz6u61YSUb 2HCwF4c7x82dsfyaK0hhC/20Q9/yOBaZ4qpeUPBnYXYML6X7KJ+tG8bnUdNCJk24nHf/ 16+g== X-Forwarded-Encrypted: i=1; AJvYcCWsDMh3FSOIw5mv+gvru8TsmUlmlGSeCoHC3zzfypid2nK/XPfJToFu2KYeex1j3G/cwmGJhZPcYCMROZQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyvXgCQeudYfVGEralWSHvBqc3sPvjAUTdweU93FO8j3St1+Ndz U02jOOl9lcbllUs+lXKu/Fy5I70oaO+yzyrVi8HkIt0XowhT4rCCh/eXhBMF1sthmF9PTGkhusf bDRwTRwehKg== X-Received: from dlii17.prod.google.com ([2002:a05:7022:4191:b0:11d:cd2a:4c1b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:2397:b0:119:e56b:91ea with SMTP id a92af1059eb24-1247dbf80ecmr276440c88.27.1769117724953; Thu, 22 Jan 2026 13:35:24 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:05 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-2-irogers@google.com> Subject: [PATCH v3 01/12] perf header: Fix memory leaks in process_cpu_domain_info From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" do_read_string returns a string in allocated memory, for some reason there was unused memory allocations and unnecessary strdups. Remove these and make the "perf annotate basic tests" leak sanitizer clean. Signed-off-by: Ian Rogers Fixes: d40c68a49f69 ("perf header: Support CPU DOMAIN relation info") Reviewed-by: James Clark --- tools/perf/util/header.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 9a15dd4b7640..eefd1cd73b6a 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3634,6 +3634,7 @@ static int process_cpu_domain_info(struct feat_fd *ff= , void *data __maybe_unused if (!d_info) return -1; =20 + assert(cd_map[cpu]->domains[domain] =3D=3D NULL); cd_map[cpu]->domains[domain] =3D d_info; d_info->domain =3D domain; =20 @@ -3642,30 +3643,20 @@ static int process_cpu_domain_info(struct feat_fd *= ff, void *data __maybe_unused if (!dname) return -1; =20 - d_info->dname =3D zalloc(strlen(dname) + 1); - if (!d_info->dname) - return -1; - - d_info->dname =3D strdup(dname); + d_info->dname =3D dname; } =20 cpumask =3D do_read_string(ff); if (!cpumask) return -1; =20 - d_info->cpumask =3D zalloc(strlen(cpumask) + 1); - if (!d_info->cpumask) - return -1; - d_info->cpumask =3D strdup(cpumask); + d_info->cpumask =3D cpumask; =20 cpulist =3D do_read_string(ff); if (!cpulist) return -1; =20 - d_info->cpulist =3D zalloc(strlen(cpulist) + 1); - if (!d_info->cpulist) - return -1; - d_info->cpulist =3D strdup(cpulist); + d_info->cpulist =3D cpulist; } } =20 --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 037B03542F6 for ; Thu, 22 Jan 2026 21:35:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117741; cv=none; b=GXpbdCFecbZL6oEClkOfLwJkzp2qR4m4Cs1Rz81UGKmcTVpQMEPub+3AGZz0/D243bcX0t3t7w4UsQC7ePuDAbYM9yQc/azLep7udp0rxeLazucsye/0PV5n+ShhKALt6jmRuWY4untx/S7PoPgSaTrM4iOhYBa/2J9Ytu9z/MY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117741; c=relaxed/simple; bh=ANN7VbZ/Xm6UtamlT5mlRTMZ4rnilmOIpmNJZRsm4WY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=XnYM2uvqz/n13u+6liqnX3brxWjmFFvYXHjfQBIS3T4SA+awW1ZqOqxK/3o0FHG+kVkvSe2pPGItg9WDjwh5fhMOtuYuRBgo+afJWQIIsXYZ4f4INh9ZDYYrd1gtabbrMDzlcuZLOy+xHHnjo5uCKbL9F6LCGotFd6SbGvJdStA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yjP30E4F; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yjP30E4F" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b6f0b345e3so7790791eec.0 for ; Thu, 22 Jan 2026 13:35:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117727; x=1769722527; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=LBuhE4G4GBsctT6JHyOVnLTy18pSFx2hMEt8LFslTxA=; b=yjP30E4FemFDUS5/KQ5Y8AUCx/pFuUCiBPLmG/D0BK2Z6qSkudyTrEBJTxOcqt/DbX kWOll5CIGN60KmBjPkad5rrSSKd51v8Lp4iIxb9LrVmkA0rRfZ2J43tYfzn8OSqJGBdx 89o/f6ppM3JH3+RQ3wKkREbFM9nv14efkMr57GNmP3P78flHrKP1fJv6t1fSjnjmf2yz 3DUd06e4EGlUWGkMftcNB9QKCN+nuk1Lr4jCf0IQ7bgz4wrP+0Q4ElGsqM5KmkXUxyOP 10M1oRsU34+zTv76hrniRIgLd4aDel1yp39jUTTFbRLHNNnTDGa5OY1bjwW4SCkOGeGK CPnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117727; x=1769722527; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LBuhE4G4GBsctT6JHyOVnLTy18pSFx2hMEt8LFslTxA=; b=FLs8fILYEaHissuS/StXp0NNIFSaxkLdA/z8oONpuov4QgOMi3zYfjNCd030kcoT0/ zv9wYZxa150AU/cDGe0VSOqRXSlIeokjOV5pDhxogCjONhCa6Jlvkgu4fZSYoeXSc7so 5u+KZ3NPx2NVgaU8FTPtIcGwSKrP0rhBo+1SrOIKDkYR7OS9qj+8MOSOmY/tBc6PyLR7 9CRwCZ0ymogL8+vPMc+TSrg3TopMEmD/l6qoJHtueCzkee2zWKzZhf5Tdj4LOHTlha+n TbiqET92oe18kZPw6OaInp5nXpJKlPN+CRpH1tmXc+NOvMfJ10F0wGF0ic1bnH73CzXb IGBA== X-Forwarded-Encrypted: i=1; AJvYcCWrxrzEiGjy6HxJF9eI2D1bt/LgDoD+EGELE1dIdwocBnO6K77Z6yyJKDSGwJaWkiKy/RALGPmZA8F36go=@vger.kernel.org X-Gm-Message-State: AOJu0YzfSocL5CcOA3G7I02PyF2vW8ey2I3O3OVXAxz3d5oDIwqkcS8j /BrCE8GM9x/kqnE+lI33WYglPMdQVE8dZsMxo8a+/zu3t+PqZAieNt80LIu0CsvwjVMA51WVhFf 7IjsYU3uevg== X-Received: from dycro21.prod.google.com ([2002:a05:693c:2b15:b0:2b7:880:7a40]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:6ca8:b0:2ac:1e9f:a0ed with SMTP id 5a478bee46e88-2b739b7437cmr522257eec.25.1769117726697; Thu, 22 Jan 2026 13:35:26 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:06 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-3-irogers@google.com> Subject: [PATCH v3 02/12] perf annotate: Fix args leak of map_symbol From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" map_symbol__exit needs calling on an annotate_args.ms, however, rather than introduce proper reference count handling to symbol__annotate just switch to passing the map_symbol pointer parameter around, making the puts the caller's responsibility. Fix a number of cases to ensure the map in a map_symbol has a reference count increment and add the then necessary map_symbol_exits. Signed-off-by: Ian Rogers Fixes: 56e144fe9826 ("perf mem_info: Add and use map_symbol__exit and addr_= map_symbol__exit") Reviewed-by: James Clark --- .../arch/loongarch/annotate/instructions.c | 14 ++++---- tools/perf/arch/s390/annotate/instructions.c | 11 +++--- tools/perf/util/annotate.c | 2 +- tools/perf/util/capstone.c | 14 ++++---- tools/perf/util/disasm.c | 36 ++++++++++--------- tools/perf/util/disasm.h | 2 +- tools/perf/util/llvm.c | 6 ++-- 7 files changed, 47 insertions(+), 38 deletions(-) diff --git a/tools/perf/arch/loongarch/annotate/instructions.c b/tools/perf= /arch/loongarch/annotate/instructions.c index 70262d5f1444..1c3abb43c8d7 100644 --- a/tools/perf/arch/loongarch/annotate/instructions.c +++ b/tools/perf/arch/loongarch/annotate/instructions.c @@ -10,9 +10,7 @@ static int loongarch_call__parse(struct arch *arch, struc= t ins_operands *ops, st { char *c, *endptr, *tok, *name; struct map *map =3D ms->map; - struct addr_map_symbol target =3D { - .ms =3D { .map =3D map, }, - }; + struct addr_map_symbol target; =20 c =3D strchr(ops->raw, '#'); if (c++ =3D=3D NULL) @@ -38,12 +36,16 @@ static int loongarch_call__parse(struct arch *arch, str= uct ins_operands *ops, st if (ops->target.name =3D=3D NULL) return -1; =20 - target.addr =3D map__objdump_2mem(map, ops->target.addr); + target =3D (struct addr_map_symbol) { + .ms =3D { .map =3D map__get(map), }, + .addr =3D map__objdump_2mem(map, ops->target.addr), + }; =20 if (maps__find_ams(ms->maps, &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 + addr_map_symbol__exit(&target); return 0; } =20 @@ -58,7 +60,7 @@ static int loongarch_jump__parse(struct arch *arch, struc= t ins_operands *ops, st struct map *map =3D ms->map; struct symbol *sym =3D ms->sym; struct addr_map_symbol target =3D { - .ms =3D { .map =3D map, }, + .ms =3D { .map =3D map__get(map), }, }; const char *c =3D strchr(ops->raw, '#'); u64 start, end; @@ -90,7 +92,7 @@ static int loongarch_jump__parse(struct arch *arch, struc= t ins_operands *ops, st } else { ops->target.offset_avail =3D false; } - + addr_map_symbol__exit(&target); return 0; } =20 diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch= /s390/annotate/instructions.c index c61193f1e096..626e6d2cbc81 100644 --- a/tools/perf/arch/s390/annotate/instructions.c +++ b/tools/perf/arch/s390/annotate/instructions.c @@ -6,9 +6,7 @@ static int s390_call__parse(struct arch *arch, struct ins_o= perands *ops, { char *endptr, *tok, *name; struct map *map =3D ms->map; - struct addr_map_symbol target =3D { - .ms =3D { .map =3D map, }, - }; + struct addr_map_symbol target; =20 tok =3D strchr(ops->raw, ','); if (!tok) @@ -36,12 +34,17 @@ static int s390_call__parse(struct arch *arch, struct i= ns_operands *ops, =20 if (ops->target.name =3D=3D NULL) return -1; - target.addr =3D map__objdump_2mem(map, ops->target.addr); + + target =3D (struct addr_map_symbol) { + .ms =3D { .map =3D map__get(map), }, + .addr =3D map__objdump_2mem(map, ops->target.addr), + }; =20 if (maps__find_ams(ms->maps, &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 + addr_map_symbol__exit(&target); return 0; } =20 diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index cc7764455faf..791d60f97c23 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1031,7 +1031,7 @@ int symbol__annotate(struct map_symbol *ms, struct ev= sel *evsel, return 0; =20 args.arch =3D arch; - args.ms =3D *ms; + args.ms =3D ms; =20 if (notes->src =3D=3D NULL) { notes->src =3D annotated_source__new(); diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c index be5fd44b1f9d..2c7feab61b7b 100644 --- a/tools/perf/util/capstone.c +++ b/tools/perf/util/capstone.c @@ -143,7 +143,7 @@ static void print_capstone_detail(cs_insn *insn, char *= buf, size_t len, struct annotate_args *args, u64 addr) { int i; - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct symbol *sym; =20 /* TODO: support more architectures */ @@ -222,7 +222,7 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, { #ifdef HAVE_LIBCAPSTONE_SUPPORT struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); u64 start =3D map__rip_2objdump(map, sym->start); u64 offset; @@ -256,7 +256,7 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) @@ -268,7 +268,7 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(args->ms.maps), &handle, is_64bit, disass= embler_style) < 0) + if (capstone_init(maps__machine(args->ms->maps), &handle, is_64bit, disas= sembler_style) < 0) goto err; =20 needs_cs_close =3D true; @@ -345,7 +345,7 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, { #ifdef HAVE_LIBCAPSTONE_SUPPORT struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); struct nscookie nsc; u64 start =3D map__rip_2objdump(map, sym->start); @@ -382,7 +382,7 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(args->ms.maps), &handle, is_64bit, disass= embler_style) < 0) + if (capstone_init(maps__machine(args->ms->maps), &handle, is_64bit, disas= sembler_style) < 0) goto err; =20 needs_cs_close =3D true; @@ -408,7 +408,7 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 50b9433f3f8e..924429142631 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -269,9 +269,7 @@ static int call__parse(struct arch *arch, struct ins_op= erands *ops, struct map_s { char *endptr, *tok, *name; struct map *map =3D ms->map; - struct addr_map_symbol target =3D { - .ms =3D { .map =3D map, }, - }; + struct addr_map_symbol target; =20 ops->target.addr =3D strtoull(ops->raw, &endptr, 16); =20 @@ -296,12 +294,16 @@ static int call__parse(struct arch *arch, struct ins_= operands *ops, struct map_s if (ops->target.name =3D=3D NULL) return -1; find_target: - target.addr =3D map__objdump_2mem(map, ops->target.addr); + target =3D (struct addr_map_symbol) { + .ms =3D { .map =3D map__get(map), }, + .addr =3D map__objdump_2mem(map, ops->target.addr), + }; =20 if (maps__find_ams(ms->maps, &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 + addr_map_symbol__exit(&target); return 0; =20 indirect_call: @@ -366,7 +368,7 @@ static int jump__parse(struct arch *arch, struct ins_op= erands *ops, struct map_s struct map *map =3D ms->map; struct symbol *sym =3D ms->sym; struct addr_map_symbol target =3D { - .ms =3D { .map =3D map, }, + .ms =3D { .map =3D map__get(map), }, }; const char *c =3D strchr(ops->raw, ','); u64 start, end; @@ -440,7 +442,7 @@ static int jump__parse(struct arch *arch, struct ins_op= erands *ops, struct map_s } else { ops->target.offset_avail =3D false; } - + addr_map_symbol__exit(&target); return 0; } =20 @@ -1046,7 +1048,7 @@ static size_t disasm_line_size(int nr) struct disasm_line *disasm_line__new(struct annotate_args *args) { struct disasm_line *dl =3D NULL; - struct annotation *notes =3D symbol__annotation(args->ms.sym); + struct annotation *notes =3D symbol__annotation(args->ms->sym); int nr =3D notes->src->nr_events; =20 dl =3D zalloc(disasm_line_size(nr)); @@ -1064,7 +1066,7 @@ struct disasm_line *disasm_line__new(struct annotate_= args *args) } else if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) = < 0) goto out_free_line; =20 - disasm_line__init_ins(dl, args->arch, &args->ms); + disasm_line__init_ins(dl, args->arch, args->ms); } =20 return dl; @@ -1119,7 +1121,7 @@ static int symbol__parse_objdump_line(struct symbol *= sym, struct annotate_args *args, char *parsed_line, int *line_nr, char **fileloc) { - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct annotation *notes =3D symbol__annotation(sym); struct disasm_line *dl; char *tmp; @@ -1151,7 +1153,7 @@ static int symbol__parse_objdump_line(struct symbol *= sym, args->line =3D parsed_line; args->line_nr =3D *line_nr; args->fileloc =3D *fileloc; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); (*line_nr)++; @@ -1169,12 +1171,14 @@ static int symbol__parse_objdump_line(struct symbol= *sym, if (dl->ins.ops && ins__is_call(&dl->ins) && !dl->ops.target.sym) { struct addr_map_symbol target =3D { .addr =3D dl->ops.target.addr, - .ms =3D { .map =3D map, }, + .ms =3D { .map =3D map__get(map), }, }; =20 - if (!maps__find_ams(args->ms.maps, &target) && + if (!maps__find_ams(args->ms->maps, &target) && target.ms.sym->start =3D=3D target.al_addr) dl->ops.target.sym =3D target.ms.sym; + + addr_map_symbol__exit(&target); } =20 annotation_line__add(&dl->al, ¬es->src->source); @@ -1338,7 +1342,7 @@ static int symbol__disassemble_raw(char *filename, st= ruct symbol *sym, struct annotate_args *args) { struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); u64 start =3D map__rip_2objdump(map, sym->start); u64 end =3D map__rip_2objdump(map, sym->end); @@ -1375,7 +1379,7 @@ static int symbol__disassemble_raw(char *filename, st= ruct symbol *sym, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) @@ -1501,7 +1505,7 @@ static int symbol__disassemble_objdump(const char *fi= lename, struct symbol *sym, struct annotate_args *args) { struct annotation_options *opts =3D &annotate_opts; - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); char *command; FILE *file; @@ -1644,7 +1648,7 @@ static int symbol__disassemble_objdump(const char *fi= lename, struct symbol *sym, int symbol__disassemble(struct symbol *sym, struct annotate_args *args) { struct annotation_options *options =3D args->options; - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); char symfs_filename[PATH_MAX]; bool delete_extract =3D false; diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index d2cb555e4a3b..a3ea9d676281 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -97,7 +97,7 @@ struct ins_ops { =20 struct annotate_args { struct arch *arch; - struct map_symbol ms; + struct map_symbol *ms; struct annotation_options *options; s64 offset; char *line; diff --git a/tools/perf/util/llvm.c b/tools/perf/util/llvm.c index 2ebf1f5f65bf..4ada9a10bd93 100644 --- a/tools/perf/util/llvm.c +++ b/tools/perf/util/llvm.c @@ -118,7 +118,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, { #ifdef HAVE_LIBLLVM_SUPPORT struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); u64 start =3D map__rip_2objdump(map, sym->start); /* Malloc-ed buffer containing instructions read from disk. */ @@ -184,7 +184,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) @@ -242,7 +242,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, &line_storage_len); args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 llvm_addr2line(filename, pc, &args->fileloc, (unsigned int *)&args->line_nr, false, NULL); --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EB62314D14 for ; Thu, 22 Jan 2026 21:35:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117740; cv=none; b=PhPk0AR8Z0GjNKVpqHSB0Z89Fj1FauW0dhtrezqHVkGDm5T5wFUZdsDdAq9Q3rutUXcdFz7G6m7JfjHPPcSwSUwK4eS20EUmAyRSzpzvSM5hEbPEgD4S01I347IxqqMff2Z6OFqN0EuZ5IJM7/F3JHTMRGPx0b68vdTC93vHh3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117740; c=relaxed/simple; bh=WqOiFcX/heg3IGph3C/ogbRzFLpcL0diaA21e5ry5lo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=DeGWBd1Q78/L2MpFfSM9ukwHbrlbAMglFmqcUIS3tUkuB+8pwjvnqgsvlJkFS7Dc1XNYi9s/kXdhgXQCfksfS2FN1uLFndkykqmkq5H7rgYgvgvD970TYONJWSPJv8rWwpW3GxiDLdtkY/UwJeMm7nBJkOn+y5LRUkb5YuFutxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1Y8nq/S7; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1Y8nq/S7" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b71c5826fbso1481503eec.1 for ; Thu, 22 Jan 2026 13:35:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117729; x=1769722529; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=DnbHjkP7sr2MY8dvLIuI6wPgadGKGFiX6WTYohRo5Kw=; b=1Y8nq/S7wN0VV3NB0L8PwHjj08D3Y9JAraVXXMj6G/a76O2pZxgMPKygDo7kVYZOHj JgkWrADou6WXqOvhWxo3jf0iSbLAJaLH8F7jmRmMXL9wLICY2H/3+BkgFHwTnnf4gzF9 DpBbtiRxiB47KT3qNFvFt7bTvVmITCnZVHRNjfonbwiSNeRs8pqvuHkSIeiX7eFvi0Vw yZlvsjOVqJZ1oAVBZLO6ltwjY1N4yUoD0bbeLoAo/A/EsSV0Zu9zBYjGgqnJqgTjOSq5 6qX7pZxUDZJd/3JbvKFrB/w05O381VUMhDmxgBSzBCuA+imfuhgEp58v3u9mujeL5mo1 NRQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117729; x=1769722529; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DnbHjkP7sr2MY8dvLIuI6wPgadGKGFiX6WTYohRo5Kw=; b=ScIDcNRHtWg6mLSDZbRlCHCw0aOQRbj0mcOMR88PgbwdTYVuTVLCLpQIu7e8ItekC0 wP8RbCo/7lXLDVOFvxf7hYqFTcT2vqb4KgKC1lXNbFcEo85jq5IpxL8Y4fXGPJNO8O0u pg2opORclUwAF8TFpkPzzKtYEmiZpnAmjDC5wQsZHRaBx+y/cwKv31hcxks8X1I38Vco FJac9nhW2/tEF6542opdqRlVKzMvdLy081XDWdUwUwjk78sRtxIKmw4/KwVbMq1JRUej tiv/QKrF8O66HtvG0RjI9Te7algT9rqKWhYay14888Npfb8WAyvQcLs3I4igbtYMloM6 o3OQ== X-Forwarded-Encrypted: i=1; AJvYcCW6EnJrRYUBMqxs3omE4bKWtOWig2gqDt7nhLSbVb7r9Wn4SbtLcJyAk9KWQr035FYb6lq9NJajR+i/LIk=@vger.kernel.org X-Gm-Message-State: AOJu0YxTZ3/IPBiD7684J8FsFmdSG6iQ+h07ftU7iFzzkMvDYcodzpXY 32jOQD2gkVHGF/jGjDG6fYDqha2SSjvJ2fIb5W+aUsH7fr+4ly1DxJmucTnW4Rf6GTmFIpOoo7v /03Dqm99WxQ== X-Received: from dycok8.prod.google.com ([2002:a05:7301:db08:b0:2ac:32e7:3ccd]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:4084:b0:2b7:2263:3d3c with SMTP id 5a478bee46e88-2b739b6d29fmr262486eec.24.1769117728705; Thu, 22 Jan 2026 13:35:28 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:07 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-4-irogers@google.com> Subject: [PATCH v3 03/12] perf maps: Fix reference count leak in maps__find_ams From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ams and so ams->ms.map is an in argument, however, it is also overwritten. As a map is reference counted, ensure a map__put is done before overwriting it. Signed-off-by: Ian Rogers Fixes: 42fd623b58db ("perf maps: Get map before returning in maps__find") Reviewed-by: James Clark --- tools/perf/util/maps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 8ccc46d515b6..4092211cff62 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -708,6 +708,7 @@ int maps__find_ams(struct maps *maps, struct addr_map_s= ymbol *ams) if (ams->addr < map__start(ams->ms.map) || ams->addr >=3D map__end(ams->m= s.map)) { if (maps =3D=3D NULL) return -1; + map__put(ams->ms.map); ams->ms.map =3D maps__find(maps, ams->addr); if (ams->ms.map =3D=3D NULL) return -1; --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F40682737FC for ; Thu, 22 Jan 2026 21:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117747; cv=none; b=NvkuWjHfUK7+4XvZW/U0wGg1oI2CzjF3pdaAQ4igpaa1T3+g9BKakX9KnZXcUxhIPIbYxWHe9jjB6z+yAuCX765r9eMdck+OBvuCdZHP+Um97yzeviVE76WFuW6vJ3jxKO6SrJnxOYyubS0niuZR4CTmpLq85pkw5yw5XpkVw9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117747; c=relaxed/simple; bh=IKxUvpqeaDRrmwDOL8vjDyn+1FMS+KE+94Prsf8lXdI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=lOTuGPJ+qK4ONaXSRYkxLsYLsUdOwbiNVhTnFusRXpjVvz6xOXhNvzqmuZ1yN0Bgc2gswYE0IomQbmReiDDoMoIQ7c0X5p07+La/sHHnbglG3C/I+JYFBpG1XfDxLiAwT39fy47m2ibhHZypeafBjfy1s4Z4graRAaWkdVnNBUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xZhEFZOH; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xZhEFZOH" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12339e20b66so2022644c88.0 for ; Thu, 22 Jan 2026 13:35:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117731; x=1769722531; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=CaWbewelcoZI5s3t7J3uxiLpveJf3lfY5rNIyg6IXOI=; b=xZhEFZOHajnTms/BAHycBuoSckSNvkAQn6Xp512Aco+ElsnesZXaFblTjzrm6TXMQ1 8KoFXhzywH5hpQ2uVgh76ssH40YO089mgjCno7JD0auiJ9z+pTSzf1D/a1dKXacCGl8D rkEv5XE0EDsGoHKg48kLzCYiC+Myt4tRxnqTnkyCYCY57HrYhVFfXPD2RRd3ZGBrxKoz 89bxOR7UICo2spsQlhg3liKP+f8XmjehRSXGGYwbJMnbfg2snFu1PO4bjd6bPLuq6/0S Jzs64l2z7H9OEHJ+bS0PgHCYHg8vOw2PnIuZPGN3oasUOkdVYMUR528vss6qW7W1bPe2 TllQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117731; x=1769722531; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CaWbewelcoZI5s3t7J3uxiLpveJf3lfY5rNIyg6IXOI=; b=DX5CUi4ABueIMrgzR3pXXJ3U57ZSyKwWSPTgj/04oAafYcICjbPc9jG7Lt+FXphaHB OAGr3bMX/87lPEJ5Q+Wd34bmqPuQCES4P3Pk7F1KNbrdY3GUP/K6RtGHJcTceyULN7Ve uQxqei7AKmoTMx2LHjPyt4rs+FvlGL32Iq4jkbLQjPgHeYa/JQOVnBzeHHlDyINQEtgL sB4y6rPJofqA8+8XwIR/QN+wvh3DTPIwo2Cnt5fBKBTj+YI5ryNQShYQMuncZElP1auH MIXafi5IJiHJgzGFn7YJyvYH4VeyHTzVedqPQpcWi+e5tKMAjrhggd/bpxlIxEF0cGPK avHw== X-Forwarded-Encrypted: i=1; AJvYcCVQOsmmROb+3k2DwlR+aLLhukPRoc953TlPVyiVrjUhl6WfBvOtz0hBb+z/YK99VOLkHMp6Jn4c51TUA9M=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1jBhZQ+pm5tbAe5NmorMYdpcsrT+l7GOFD7+Sm9MyskwWIskR dgZVo/8PYXsCd2RMyHSNxZqxzkS5fImcJq2o4/5XwL099QdfwbHRzcio5IgzoT8chNi15i0PI7F nUOzm981pZg== X-Received: from dlbsi10.prod.google.com ([2002:a05:7022:b88a:b0:124:74d4:872e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:1605:b0:11a:37a7:3d2f with SMTP id a92af1059eb24-1247dc08325mr339907c88.37.1769117730901; Thu, 22 Jan 2026 13:35:30 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:08 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-5-irogers@google.com> Subject: [PATCH v3 04/12] perf disasm: Constify use of struct arch From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The struct arch holds variables that are read but not written, except during some initialization. Change most uses to be for a "const struct arch *" version to capture this immutability. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/arch/arm64/annotate/instructions.c | 2 +- .../arch/loongarch/annotate/instructions.c | 12 ++++-- tools/perf/arch/s390/annotate/instructions.c | 7 ++-- tools/perf/arch/x86/annotate/instructions.c | 4 +- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/util/annotate-data.c | 2 +- tools/perf/util/annotate-data.h | 2 +- tools/perf/util/annotate.c | 28 ++++++------- tools/perf/util/annotate.h | 10 ++--- tools/perf/util/disasm.c | 42 ++++++++++--------- tools/perf/util/disasm.h | 14 +++---- 11 files changed, 67 insertions(+), 58 deletions(-) diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/arc= h/arm64/annotate/instructions.c index 16cb62d40bd9..5099fa36180d 100644 --- a/tools/perf/arch/arm64/annotate/instructions.c +++ b/tools/perf/arch/arm64/annotate/instructions.c @@ -10,7 +10,7 @@ struct arm64_annotate { jump_insn; }; =20 -static int arm64_mov__parse(struct arch *arch __maybe_unused, +static int arm64_mov__parse(const struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unused) diff --git a/tools/perf/arch/loongarch/annotate/instructions.c b/tools/perf= /arch/loongarch/annotate/instructions.c index 1c3abb43c8d7..5ebfe629ea68 100644 --- a/tools/perf/arch/loongarch/annotate/instructions.c +++ b/tools/perf/arch/loongarch/annotate/instructions.c @@ -5,8 +5,10 @@ * Copyright (C) 2020-2023 Loongson Technology Corporation Limited */ =20 -static int loongarch_call__parse(struct arch *arch, struct ins_operands *o= ps, struct map_symbol *ms, - struct disasm_line *dl __maybe_unused) +static int loongarch_call__parse(const struct arch *arch, struct ins_opera= nds *ops, + struct map_symbol *ms, + struct disasm_line *dl __maybe_unused) + { char *c, *endptr, *tok, *name; struct map *map =3D ms->map; @@ -54,8 +56,10 @@ static struct ins_ops loongarch_call_ops =3D { .scnprintf =3D call__scnprintf, }; =20 -static int loongarch_jump__parse(struct arch *arch, struct ins_operands *o= ps, struct map_symbol *ms, - struct disasm_line *dl __maybe_unused) +static int loongarch_jump__parse(const struct arch *arch, struct ins_opera= nds *ops, + struct map_symbol *ms, + struct disasm_line *dl __maybe_unused) + { struct map *map =3D ms->map; struct symbol *sym =3D ms->sym; diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch= /s390/annotate/instructions.c index 626e6d2cbc81..37c1b62641d8 100644 --- a/tools/perf/arch/s390/annotate/instructions.c +++ b/tools/perf/arch/s390/annotate/instructions.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 #include =20 -static int s390_call__parse(struct arch *arch, struct ins_operands *ops, - struct map_symbol *ms, struct disasm_line *dl __maybe_unused) +static int s390_call__parse(const struct arch *arch, struct ins_operands *= ops, + struct map_symbol *ms, + struct disasm_line *dl __maybe_unused) { char *endptr, *tok, *name; struct map *map =3D ms->map; @@ -53,7 +54,7 @@ static struct ins_ops s390_call_ops =3D { .scnprintf =3D call__scnprintf, }; =20 -static int s390_mov__parse(struct arch *arch __maybe_unused, +static int s390_mov__parse(const struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unused) diff --git a/tools/perf/arch/x86/annotate/instructions.c b/tools/perf/arch/= x86/annotate/instructions.c index 803f9351a3fb..24b388bacdae 100644 --- a/tools/perf/arch/x86/annotate/instructions.c +++ b/tools/perf/arch/x86/annotate/instructions.c @@ -119,7 +119,7 @@ static struct ins x86__instructions[] =3D { { .name =3D "xorps", .ops =3D &mov_ops, }, }; =20 -static bool amd__ins_is_fused(struct arch *arch, const char *ins1, +static bool amd__ins_is_fused(const struct arch *arch, const char *ins1, const char *ins2) { if (strstr(ins2, "jmp")) @@ -142,7 +142,7 @@ static bool amd__ins_is_fused(struct arch *arch, const = char *ins1, return false; } =20 -static bool intel__ins_is_fused(struct arch *arch, const char *ins1, +static bool intel__ins_is_fused(const struct arch *arch, const char *ins1, const char *ins2) { if (arch->family !=3D 6 || arch->model < 0x1e || strstr(ins2, "jmp")) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 36aca8d6d003..3df61cd46652 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -30,7 +30,7 @@ struct annotate_browser { struct rb_root entries; struct rb_node *curr_hot; struct annotation_line *selection; - struct arch *arch; + const struct arch *arch; /* * perf top can delete hist_entry anytime. Callers should make sure * its lifetime. diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 07cf9c334be0..edfcd6e9df9c 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -160,7 +160,7 @@ bool has_reg_type(struct type_state *state, int reg) return (unsigned)reg < ARRAY_SIZE(state->regs); } =20 -static void init_type_state(struct type_state *state, struct arch *arch) +static void init_type_state(struct type_state *state, const struct arch *a= rch) { memset(state, 0, sizeof(*state)); INIT_LIST_HEAD(&state->stack_vars); diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-dat= a.h index 869307c7f130..9b222869e42d 100644 --- a/tools/perf/util/annotate-data.h +++ b/tools/perf/util/annotate-data.h @@ -117,7 +117,7 @@ extern struct annotated_data_type canary_type; */ struct data_loc_info { /* These are input field, should be filled by caller */ - struct arch *arch; + const struct arch *arch; struct thread *thread; struct map_symbol *ms; u64 ip; diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 791d60f97c23..132af2556aec 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -761,7 +761,7 @@ static int disasm_line__print(struct disasm_line *dl, u= 64 start, int addr_fmt_wi } =20 static struct annotated_data_type * -__hist_entry__get_data_type(struct hist_entry *he, struct arch *arch, +__hist_entry__get_data_type(struct hist_entry *he, const struct arch *arch, struct debuginfo *dbg, struct disasm_line *dl, int *type_offset); =20 @@ -980,11 +980,11 @@ void symbol__calc_percent(struct symbol *sym, struct = evsel *evsel) annotation__calc_percent(notes, evsel, symbol__size(sym)); } =20 -int evsel__get_arch(struct evsel *evsel, struct arch **parch) +int evsel__get_arch(struct evsel *evsel, const struct arch **parch) { struct perf_env *env =3D evsel__env(evsel); const char *arch_name =3D perf_env__arch(env); - struct arch *arch; + const struct arch *arch; int err; =20 if (!arch_name) { @@ -999,7 +999,7 @@ int evsel__get_arch(struct evsel *evsel, struct arch **= parch) } =20 if (arch->init) { - err =3D arch->init(arch, env ? env->cpuid : NULL); + err =3D arch->init((struct arch *)arch, env ? env->cpuid : NULL); if (err) { pr_err("%s: failed to initialize %s arch priv area\n", __func__, arch->name); @@ -1010,14 +1010,14 @@ int evsel__get_arch(struct evsel *evsel, struct arc= h **parch) } =20 int symbol__annotate(struct map_symbol *ms, struct evsel *evsel, - struct arch **parch) + const struct arch **parch) { struct symbol *sym =3D ms->sym; struct annotation *notes =3D symbol__annotation(sym); struct annotate_args args =3D { .options =3D &annotate_opts, }; - struct arch *arch =3D NULL; + const struct arch *arch =3D NULL; int err, nr; =20 err =3D evsel__get_arch(evsel, &arch); @@ -2204,7 +2204,7 @@ void annotation_line__write(struct annotation_line *a= l, struct annotation *notes } =20 int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel, - struct arch **parch) + const struct arch **parch) { struct symbol *sym =3D ms->sym; struct annotation *notes =3D symbol__annotation(sym); @@ -2457,7 +2457,7 @@ int annotate_check_args(void) * to revisit the format when it handles different architecture. * Fills @reg and @offset when return 0. */ -static int extract_reg_offset(struct arch *arch, const char *str, +static int extract_reg_offset(const struct arch *arch, const char *str, struct annotated_op_loc *op_loc) { char *p; @@ -2538,7 +2538,7 @@ static int extract_reg_offset(struct arch *arch, cons= t char *str, * # dst_reg1 =3D rbx, dst_reg2 =3D rcx, dst_= mem =3D 1 * # dst_multi_regs =3D 1, dst_offset =3D 8 */ -int annotate_get_insn_location(struct arch *arch, struct disasm_line *dl, +int annotate_get_insn_location(const struct arch *arch, struct disasm_line= *dl, struct annotated_insn_loc *loc) { struct ins_operands *ops; @@ -2673,7 +2673,7 @@ static struct annotated_item_stat *annotate_data_stat= (struct list_head *head, return istat; } =20 -static bool is_stack_operation(struct arch *arch, struct disasm_line *dl) +static bool is_stack_operation(const struct arch *arch, struct disasm_line= *dl) { if (arch__is(arch, "x86")) { if (!strncmp(dl->ins.name, "push", 4) || @@ -2686,7 +2686,7 @@ static bool is_stack_operation(struct arch *arch, str= uct disasm_line *dl) return false; } =20 -static bool is_stack_canary(struct arch *arch, struct annotated_op_loc *lo= c) +static bool is_stack_canary(const struct arch *arch, struct annotated_op_l= oc *loc) { /* On x86_64, %gs:40 is used for stack canary */ if (arch__is(arch, "x86")) { @@ -2702,7 +2702,7 @@ static bool is_stack_canary(struct arch *arch, struct= annotated_op_loc *loc) * Returns true if the instruction has a memory operand without * performing a load/store */ -static bool is_address_gen_insn(struct arch *arch, struct disasm_line *dl) +static bool is_address_gen_insn(const struct arch *arch, struct disasm_lin= e *dl) { if (arch__is(arch, "x86")) { if (!strncmp(dl->ins.name, "lea", 3)) @@ -2791,7 +2791,7 @@ void debuginfo_cache__delete(void) } =20 static struct annotated_data_type * -__hist_entry__get_data_type(struct hist_entry *he, struct arch *arch, +__hist_entry__get_data_type(struct hist_entry *he, const struct arch *arch, struct debuginfo *dbg, struct disasm_line *dl, int *type_offset) { @@ -2895,7 +2895,7 @@ struct annotated_data_type *hist_entry__get_data_type= (struct hist_entry *he) { struct map_symbol *ms =3D &he->ms; struct evsel *evsel =3D hists_to_evsel(he->hists); - struct arch *arch; + const struct arch *arch; struct disasm_line *dl; struct annotated_data_type *mem_type; struct annotated_item_stat *istat; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index d4990bff29a7..58eaf4b2fa65 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -202,7 +202,7 @@ struct annotation_write_ops { struct annotation_print_data { struct hist_entry *he; struct evsel *evsel; - struct arch *arch; + const struct arch *arch; struct debuginfo *dbg; /* save data type info keyed by al->offset */ struct hashmap *type_hash; @@ -441,10 +441,10 @@ void symbol__annotate_zero_histograms(struct symbol *= sym); =20 int symbol__annotate(struct map_symbol *ms, struct evsel *evsel, - struct arch **parch); + const struct arch **parch); int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel, - struct arch **parch); + const struct arch **parch); =20 enum symbol_disassemble_errno { SYMBOL_ANNOTATE_ERRNO__SUCCESS =3D 0, @@ -546,7 +546,7 @@ struct annotated_insn_loc { i++, op_loc++) =20 /* Get detailed location info in the instruction */ -int annotate_get_insn_location(struct arch *arch, struct disasm_line *dl, +int annotate_get_insn_location(const struct arch *arch, struct disasm_line= *dl, struct annotated_insn_loc *loc); =20 /* Returns a data type from the sample instruction (if any) */ @@ -586,5 +586,5 @@ int annotation_br_cntr_entry(char **str, int br_cntr_nr= , u64 *br_cntr, int num_aggr, struct evsel *evsel); int annotation_br_cntr_abbr_list(char **str, struct evsel *evsel, bool hea= der); =20 -int evsel__get_arch(struct evsel *evsel, struct arch **parch); +int evsel__get_arch(struct evsel *evsel, const struct arch **parch); #endif /* __PERF_ANNOTATE_H */ diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 924429142631..d92c0424e8fc 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -213,7 +213,7 @@ static void arch__sort(void) qsort(architectures, nmemb, sizeof(struct arch), arch__cmp); } =20 -struct arch *arch__find(const char *name) +const struct arch *arch__find(const char *name) { const int nmemb =3D ARRAY_SIZE(architectures); static bool sorted; @@ -226,7 +226,7 @@ struct arch *arch__find(const char *name) return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key= _cmp); } =20 -bool arch__is(struct arch *arch, const char *name) +bool arch__is(const struct arch *arch, const char *name) { return !strcmp(arch->name, name); } @@ -256,7 +256,7 @@ static int ins__scnprintf(struct ins *ins, char *bf, si= ze_t size, return ins__raw_scnprintf(ins, bf, size, ops, max_ins_name); } =20 -bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2) +bool ins__is_fused(const struct arch *arch, const char *ins1, const char *= ins2) { if (!arch || !arch->ins_is_fused) return false; @@ -264,7 +264,7 @@ bool ins__is_fused(struct arch *arch, const char *ins1,= const char *ins2) return arch->ins_is_fused(arch, ins1, ins2); } =20 -static int call__parse(struct arch *arch, struct ins_operands *ops, struct= map_symbol *ms, +static int call__parse(const struct arch *arch, struct ins_operands *ops, = struct map_symbol *ms, struct disasm_line *dl __maybe_unused) { char *endptr, *tok, *name; @@ -362,7 +362,7 @@ static inline const char *validate_comma(const char *c,= struct ins_operands *ops return c; } =20 -static int jump__parse(struct arch *arch, struct ins_operands *ops, struct= map_symbol *ms, +static int jump__parse(const struct arch *arch, struct ins_operands *ops, = struct map_symbol *ms, struct disasm_line *dl __maybe_unused) { struct map *map =3D ms->map; @@ -525,7 +525,7 @@ static int comment__symbol(char *raw, char *comment, u6= 4 *addrp, char **namep) return 0; } =20 -static int lock__parse(struct arch *arch, struct ins_operands *ops, struct= map_symbol *ms, +static int lock__parse(const struct arch *arch, struct ins_operands *ops, = struct map_symbol *ms, struct disasm_line *dl __maybe_unused) { ops->locked.ops =3D zalloc(sizeof(*ops->locked.ops)); @@ -592,7 +592,7 @@ static struct ins_ops lock_ops =3D { * But it doesn't care segment selectors like %gs:0x5678(%rcx), so just ch= eck * the input string after 'memory_ref_char' if exists. */ -static bool check_multi_regs(struct arch *arch, const char *op) +static bool check_multi_regs(const struct arch *arch, const char *op) { int count =3D 0; =20 @@ -613,8 +613,9 @@ static bool check_multi_regs(struct arch *arch, const c= har *op) return count > 1; } =20 -static int mov__parse(struct arch *arch, struct ins_operands *ops, struct = map_symbol *ms __maybe_unused, - struct disasm_line *dl __maybe_unused) +static int mov__parse(const struct arch *arch, struct ins_operands *ops, + struct map_symbol *ms __maybe_unused, + struct disasm_line *dl __maybe_unused) { char *s =3D strchr(ops->raw, ','), *target, *comment, prev; =20 @@ -719,7 +720,7 @@ static int arithmetic__scnprintf(struct ins *ins, char = *bf, size_t size, * - Add to Zero Extended XO-form ( Ex: addze, addzeo ) * - Subtract From Zero Extended XO-form ( Ex: subfze ) */ -static int arithmetic__parse(struct arch *arch __maybe_unused, struct ins_= operands *ops, +static int arithmetic__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, struct map_symbol *ms __maybe_unused, struct disasm_line *dl) { int opcode =3D PPC_OP(dl->raw.raw_insn); @@ -756,7 +757,7 @@ static int load_store__scnprintf(struct ins *ins, char = *bf, size_t size, * used by powerpc and since binary instruction code is used to * extract opcode, regs and offset, no other parsing is needed here */ -static int load_store__parse(struct arch *arch __maybe_unused, struct ins_= operands *ops, +static int load_store__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unu= sed) { ops->source.mem_ref =3D true; @@ -776,8 +777,9 @@ static struct ins_ops load_store_ops =3D { .scnprintf =3D load_store__scnprintf, }; =20 -static int dec__parse(struct arch *arch __maybe_unused, struct ins_operand= s *ops, struct map_symbol *ms __maybe_unused, - struct disasm_line *dl __maybe_unused) +static int dec__parse(const struct arch *arch __maybe_unused, struct ins_o= perands *ops, + struct map_symbol *ms __maybe_unused, + struct disasm_line *dl __maybe_unused) { char *target, *comment, *s, prev; =20 @@ -867,7 +869,8 @@ static void ins__sort(struct arch *arch) qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp); } =20 -static struct ins_ops *__ins__find(struct arch *arch, const char *name, st= ruct disasm_line *dl) +static struct ins_ops *__ins__find(const struct arch *arch, const char *na= me, + struct disasm_line *dl) { struct ins *ins; const int nmemb =3D arch->nr_instructions; @@ -885,8 +888,8 @@ static struct ins_ops *__ins__find(struct arch *arch, c= onst char *name, struct d } =20 if (!arch->sorted_instructions) { - ins__sort(arch); - arch->sorted_instructions =3D true; + ins__sort((struct arch *)arch); + ((struct arch *)arch)->sorted_instructions =3D true; } =20 ins =3D bsearch(name, arch->instructions, nmemb, sizeof(struct ins), ins_= _key_cmp); @@ -913,17 +916,18 @@ static struct ins_ops *__ins__find(struct arch *arch,= const char *name, struct d return ins ? ins->ops : NULL; } =20 -struct ins_ops *ins__find(struct arch *arch, const char *name, struct disa= sm_line *dl) +struct ins_ops *ins__find(const struct arch *arch, const char *name, struc= t disasm_line *dl) { struct ins_ops *ops =3D __ins__find(arch, name, dl); =20 if (!ops && arch->associate_instruction_ops) - ops =3D arch->associate_instruction_ops(arch, name); + ops =3D arch->associate_instruction_ops((struct arch *)arch, name); =20 return ops; } =20 -static void disasm_line__init_ins(struct disasm_line *dl, struct arch *arc= h, struct map_symbol *ms) +static void disasm_line__init_ins(struct disasm_line *dl, const struct arc= h *arch, + struct map_symbol *ms) { dl->ins.ops =3D ins__find(arch, dl->ins.name, dl); =20 diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index a3ea9d676281..273a9c906514 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -30,7 +30,7 @@ struct arch { unsigned int model; unsigned int family; int (*init)(struct arch *arch, char *cpuid); - bool (*ins_is_fused)(struct arch *arch, const char *ins1, + bool (*ins_is_fused)(const struct arch *arch, const char *ins1, const char *ins2); struct { char comment_char; @@ -89,14 +89,14 @@ struct ins_operands { =20 struct ins_ops { void (*free)(struct ins_operands *ops); - int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symb= ol *ms, + int (*parse)(const struct arch *arch, struct ins_operands *ops, struct ma= p_symbol *ms, struct disasm_line *dl); int (*scnprintf)(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); }; =20 struct annotate_args { - struct arch *arch; + const struct arch *arch; struct map_symbol *ms; struct annotation_options *options; s64 offset; @@ -105,14 +105,14 @@ struct annotate_args { char *fileloc; }; =20 -struct arch *arch__find(const char *name); -bool arch__is(struct arch *arch, const char *name); +const struct arch *arch__find(const char *name); +bool arch__is(const struct arch *arch, const char *name); =20 -struct ins_ops *ins__find(struct arch *arch, const char *name, struct disa= sm_line *dl); +struct ins_ops *ins__find(const struct arch *arch, const char *name, struc= t disasm_line *dl); =20 bool ins__is_call(const struct ins *ins); bool ins__is_jump(const struct ins *ins); -bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2); +bool ins__is_fused(const struct arch *arch, const char *ins1, const char *= ins2); bool ins__is_ret(const struct ins *ins); bool ins__is_lock(const struct ins *ins); =20 --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5614D2727FA for ; Thu, 22 Jan 2026 21:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117746; cv=none; b=HHaMx/9eo0DBtNw07EY4C0wtKzCVhGEtDQuFUR4FSpknOByVZoJYgOjSlZRcxnH3PZ3zDwN1txis605tH6oy3tpy348EegPZG+py27/aRrErzCuFGfTVtf2U3gHUZI1BNamJPq59iShqBPr0sap3GiQTO5K9CUw2QYloAMqBUqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117746; c=relaxed/simple; bh=rD9vOzeeXzOTCD+l66o8DhGrmT+MJuoo1UTvO0WycIQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=V7pzRBIs6Zhet4yKx2wSo5xeQiNihq3Osa1UEwnBCWn7QltGRjJKmYj7f96907mvpGFf+UORnGatn3io4UY1bo650hTHja8o830FrkIDFpC2WMDl4/roP6YxIoVuBkf/SizZHcCDc1yn0W01BRl/CpZ0Euz+hObO+/m9xutybO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uvKaPtCK; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uvKaPtCK" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b722bc1be1so2289133eec.0 for ; Thu, 22 Jan 2026 13:35:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117733; x=1769722533; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=ANZB4nsW0oD2Yy9bdDZ7x29IcTZAs2bHCHMIwFReZjE=; b=uvKaPtCKe70K8aIxJisFIw+ipubxOKisFYj9EkcyDWE7JNA9XHQbdS6i4wgDHkULqk lYWOdQGjFB3O16ivmNK/Ks/YXepic/t+vszpwOH92wYcaJmQ39urDcacpnhz4Arbvq6A NWldgxrpy83/8x7Rygact2OZ7Ui1sKXxZIU3TJeDHjFdxmUH9XVh0OQob/2vSAloZN9k skv8IMvS75grES6VtNdR0vc7wUXSnyrG7orn7aFTMsJ3+adPqjk60N8HJ5k97FBdO/T9 UA3+zdbU4Y+U6ubdKu/v8bPY7paKYc3eafzrE3aBn4/aJYBPnqdYkNwYKl6zszANH0Q0 HVFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117733; x=1769722533; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ANZB4nsW0oD2Yy9bdDZ7x29IcTZAs2bHCHMIwFReZjE=; b=lAZySaWa6k7sSDv93k2vYp+O1PpWXOiec+ssJqrTFcQdYxmvxOz5oqj51LOaxfAnVe yDkgcKFEA/hdxDUd4+SyMzH0P6pW5MqML30om/A7k7I/yMWghtBRExiJf7nQvtYUb2O2 MGwZQnSMKJVQrtLXzlneyuo9JyD6zpIwwnLTCGno6OSxHY2IAG9mUwuppke4/zQ5msbh Uw02QlFi7ttXEP+BbRh4JGYpfKauQGe5eVJNAiCMTkrJZ1NK8lQOSuRbVHfBj/Q981bh mDjc64jevBCi7vOLUY1ENTSRD7NmTvkqfk1TpeROpzgEYGTacRosvz+29SuReLZrwZaG ap0A== X-Forwarded-Encrypted: i=1; AJvYcCWexhWE0uQFKE2JIcD8nSY57hJRpnhI1KIFOxSiQwf1ZMypkD/U5YZY1Wb18s78rnS1DDwb+AjR05ScwEo=@vger.kernel.org X-Gm-Message-State: AOJu0YxqCKhB3n/Pn7X7eIA13ZyhhprlflOP+tzQqGxi7ZKfOWU7zy2t /tbI8buXDVg/oJHWwmfCZpqqz6EYu8qJ2RZu19Em8pXQb4yReY9tpMIuOLp4wzMlmwJA+QJlOQM HtT4v0HDPmw== X-Received: from dlb34.prod.google.com ([2002:a05:7022:622:b0:123:35cc:b60f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:ec15:b0:2b7:3281:6c33 with SMTP id 5a478bee46e88-2b739997aafmr446745eec.12.1769117733358; Thu, 22 Jan 2026 13:35:33 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:09 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-6-irogers@google.com> Subject: [PATCH v3 05/12] perf disasm: Constify use of struct ins_op From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The struct ins_op holds variables to function pointers that are read but not written. Change uses to be for a "const struct ins_op *" version to capture this immutability. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/arch/arm/annotate/instructions.c | 4 +- tools/perf/arch/arm64/annotate/instructions.c | 6 +-- tools/perf/arch/csky/annotate/instructions.c | 6 +-- .../arch/loongarch/annotate/instructions.c | 8 ++-- tools/perf/arch/mips/annotate/instructions.c | 4 +- .../perf/arch/powerpc/annotate/instructions.c | 6 +-- .../perf/arch/riscv64/annotate/instructions.c | 4 +- tools/perf/arch/s390/annotate/instructions.c | 8 ++-- tools/perf/arch/sparc/annotate/instructions.c | 4 +- tools/perf/util/disasm.c | 46 +++++++++---------- tools/perf/util/disasm.h | 6 +-- 11 files changed, 51 insertions(+), 51 deletions(-) diff --git a/tools/perf/arch/arm/annotate/instructions.c b/tools/perf/arch/= arm/annotate/instructions.c index 5e667b0f5512..b997d127fedd 100644 --- a/tools/perf/arch/arm/annotate/instructions.c +++ b/tools/perf/arch/arm/annotate/instructions.c @@ -11,10 +11,10 @@ struct arm_annotate { jump_insn; }; =20 -static struct ins_ops *arm__associate_instruction_ops(struct arch *arch, c= onst char *name) +static const struct ins_ops *arm__associate_instruction_ops(struct arch *a= rch, const char *name) { struct arm_annotate *arm =3D arch->priv; - struct ins_ops *ops; + const struct ins_ops *ops; regmatch_t match[2]; =20 if (!regexec(&arm->call_insn, name, 2, match, 0)) diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/arc= h/arm64/annotate/instructions.c index 5099fa36180d..363af2f55122 100644 --- a/tools/perf/arch/arm64/annotate/instructions.c +++ b/tools/perf/arch/arm64/annotate/instructions.c @@ -63,15 +63,15 @@ static int arm64_mov__parse(const struct arch *arch __m= aybe_unused, static int mov__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); =20 -static struct ins_ops arm64_mov_ops =3D { +static const struct ins_ops arm64_mov_ops =3D { .parse =3D arm64_mov__parse, .scnprintf =3D mov__scnprintf, }; =20 -static struct ins_ops *arm64__associate_instruction_ops(struct arch *arch,= const char *name) +static const struct ins_ops *arm64__associate_instruction_ops(struct arch = *arch, const char *name) { struct arm64_annotate *arm =3D arch->priv; - struct ins_ops *ops; + const struct ins_ops *ops; regmatch_t match[2]; =20 if (!regexec(&arm->jump_insn, name, 2, match, 0)) diff --git a/tools/perf/arch/csky/annotate/instructions.c b/tools/perf/arch= /csky/annotate/instructions.c index 14270311d215..4a55c84a320a 100644 --- a/tools/perf/arch/csky/annotate/instructions.c +++ b/tools/perf/arch/csky/annotate/instructions.c @@ -3,10 +3,10 @@ =20 #include =20 -static struct ins_ops *csky__associate_ins_ops(struct arch *arch, - const char *name) +static const struct ins_ops *csky__associate_ins_ops(struct arch *arch, + const char *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 /* catch all kind of jumps */ if (!strcmp(name, "bt") || diff --git a/tools/perf/arch/loongarch/annotate/instructions.c b/tools/perf= /arch/loongarch/annotate/instructions.c index 5ebfe629ea68..5010d5d58375 100644 --- a/tools/perf/arch/loongarch/annotate/instructions.c +++ b/tools/perf/arch/loongarch/annotate/instructions.c @@ -51,7 +51,7 @@ static int loongarch_call__parse(const struct arch *arch,= struct ins_operands *o return 0; } =20 -static struct ins_ops loongarch_call_ops =3D { +static const struct ins_ops loongarch_call_ops =3D { .parse =3D loongarch_call__parse, .scnprintf =3D call__scnprintf, }; @@ -100,15 +100,15 @@ static int loongarch_jump__parse(const struct arch *a= rch, struct ins_operands *o return 0; } =20 -static struct ins_ops loongarch_jump_ops =3D { +static const struct ins_ops loongarch_jump_ops =3D { .parse =3D loongarch_jump__parse, .scnprintf =3D jump__scnprintf, }; =20 static -struct ins_ops *loongarch__associate_ins_ops(struct arch *arch, const char= *name) +const struct ins_ops *loongarch__associate_ins_ops(struct arch *arch, cons= t char *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 if (!strcmp(name, "bl")) ops =3D &loongarch_call_ops; diff --git a/tools/perf/arch/mips/annotate/instructions.c b/tools/perf/arch= /mips/annotate/instructions.c index b50b46c613d6..0fbe0a7df95a 100644 --- a/tools/perf/arch/mips/annotate/instructions.c +++ b/tools/perf/arch/mips/annotate/instructions.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 =20 static -struct ins_ops *mips__associate_ins_ops(struct arch *arch, const char *nam= e) +const struct ins_ops *mips__associate_ins_ops(struct arch *arch, const cha= r *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 if (!strncmp(name, "bal", 3) || !strncmp(name, "bgezal", 6) || diff --git a/tools/perf/arch/powerpc/annotate/instructions.c b/tools/perf/a= rch/powerpc/annotate/instructions.c index ca567cfdcbdb..d1be55425e35 100644 --- a/tools/perf/arch/powerpc/annotate/instructions.c +++ b/tools/perf/arch/powerpc/annotate/instructions.c @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 #include =20 -static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arc= h, const char *name) +static const struct ins_ops *powerpc__associate_instruction_ops(struct arc= h *arch, const char *name) { int i; - struct ins_ops *ops; + const struct ins_ops *ops; =20 /* * - Interested only if instruction starts with 'b'. @@ -189,7 +189,7 @@ static int cmp_offset(const void *a, const void *b) return (val1->value - val2->value); } =20 -static struct ins_ops *check_ppc_insn(struct disasm_line *dl) +static const struct ins_ops *check_ppc_insn(struct disasm_line *dl) { int raw_insn =3D dl->raw.raw_insn; int opcode =3D PPC_OP(raw_insn); diff --git a/tools/perf/arch/riscv64/annotate/instructions.c b/tools/perf/a= rch/riscv64/annotate/instructions.c index 55cf911633f8..a34798864fab 100644 --- a/tools/perf/arch/riscv64/annotate/instructions.c +++ b/tools/perf/arch/riscv64/annotate/instructions.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 =20 static -struct ins_ops *riscv64__associate_ins_ops(struct arch *arch, const char *= name) +const struct ins_ops *riscv64__associate_ins_ops(struct arch *arch, const = char *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 if (!strncmp(name, "jal", 3) || !strncmp(name, "jr", 2) || diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch= /s390/annotate/instructions.c index 37c1b62641d8..1b22e6276e7d 100644 --- a/tools/perf/arch/s390/annotate/instructions.c +++ b/tools/perf/arch/s390/annotate/instructions.c @@ -49,7 +49,7 @@ static int s390_call__parse(const struct arch *arch, stru= ct ins_operands *ops, return 0; } =20 -static struct ins_ops s390_call_ops =3D { +static const struct ins_ops s390_call_ops =3D { .parse =3D s390_call__parse, .scnprintf =3D call__scnprintf, }; @@ -103,14 +103,14 @@ static int s390_mov__parse(const struct arch *arch __= maybe_unused, } =20 =20 -static struct ins_ops s390_mov_ops =3D { +static const struct ins_ops s390_mov_ops =3D { .parse =3D s390_mov__parse, .scnprintf =3D mov__scnprintf, }; =20 -static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const ch= ar *name) +static const struct ins_ops *s390__associate_ins_ops(struct arch *arch, co= nst char *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 /* catch all kind of jumps */ if (strchr(name, 'j') || diff --git a/tools/perf/arch/sparc/annotate/instructions.c b/tools/perf/arc= h/sparc/annotate/instructions.c index 68c31580ccfc..a08d8734c883 100644 --- a/tools/perf/arch/sparc/annotate/instructions.c +++ b/tools/perf/arch/sparc/annotate/instructions.c @@ -117,9 +117,9 @@ static int is_branch_float_cond(const char *cond) return 0; } =20 -static struct ins_ops *sparc__associate_instruction_ops(struct arch *arch,= const char *name) +static const struct ins_ops *sparc__associate_instruction_ops(struct arch = *arch, const char *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 if (!strcmp(name, "call") || !strcmp(name, "jmp") || diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index d92c0424e8fc..9bc9b1de98db 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -33,15 +33,15 @@ static regex_t file_lineno; =20 /* These can be referred from the arch-dependent code */ -static struct ins_ops call_ops; -static struct ins_ops dec_ops; -static struct ins_ops jump_ops; -static struct ins_ops mov_ops; -static struct ins_ops nop_ops; -static struct ins_ops lock_ops; -static struct ins_ops ret_ops; -static struct ins_ops load_store_ops; -static struct ins_ops arithmetic_ops; +static const struct ins_ops call_ops; +static const struct ins_ops dec_ops; +static const struct ins_ops jump_ops; +static const struct ins_ops mov_ops; +static const struct ins_ops nop_ops; +static const struct ins_ops lock_ops; +static const struct ins_ops ret_ops; +static const struct ins_ops load_store_ops; +static const struct ins_ops arithmetic_ops; =20 static int jump__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); @@ -85,7 +85,7 @@ static int arch__grow_instructions(struct arch *arch) goto out_update_instructions; } =20 -static int arch__associate_ins_ops(struct arch* arch, const char *name, st= ruct ins_ops *ops) +static int arch__associate_ins_ops(struct arch *arch, const char *name, co= nst struct ins_ops *ops) { struct ins *ins; =20 @@ -334,7 +334,7 @@ static int call__scnprintf(struct ins *ins, char *bf, s= ize_t size, return scnprintf(bf, size, "%-*s *%" PRIx64, max_ins_name, ins->name, ops= ->target.addr); } =20 -static struct ins_ops call_ops =3D { +static const struct ins_ops call_ops =3D { .parse =3D call__parse, .scnprintf =3D call__scnprintf, }; @@ -487,7 +487,7 @@ static void jump__delete(struct ins_operands *ops __may= be_unused) */ } =20 -static struct ins_ops jump_ops =3D { +static const struct ins_ops jump_ops =3D { .free =3D jump__delete, .parse =3D jump__parse, .scnprintf =3D jump__scnprintf, @@ -579,7 +579,7 @@ static void lock__delete(struct ins_operands *ops) zfree(&ops->target.name); } =20 -static struct ins_ops lock_ops =3D { +static const struct ins_ops lock_ops =3D { .free =3D lock__delete, .parse =3D lock__parse, .scnprintf =3D lock__scnprintf, @@ -688,7 +688,7 @@ static int mov__scnprintf(struct ins *ins, char *bf, si= ze_t size, ops->target.name ?: ops->target.raw); } =20 -static struct ins_ops mov_ops =3D { +static const struct ins_ops mov_ops =3D { .parse =3D mov__parse, .scnprintf =3D mov__scnprintf, }; @@ -738,7 +738,7 @@ static int arithmetic__parse(const struct arch *arch __= maybe_unused, struct ins_ return 0; } =20 -static struct ins_ops arithmetic_ops =3D { +static const struct ins_ops arithmetic_ops =3D { .parse =3D arithmetic__parse, .scnprintf =3D arithmetic__scnprintf, }; @@ -772,7 +772,7 @@ static int load_store__parse(const struct arch *arch __= maybe_unused, struct ins_ return 0; } =20 -static struct ins_ops load_store_ops =3D { +static const struct ins_ops load_store_ops =3D { .parse =3D load_store__parse, .scnprintf =3D load_store__scnprintf, }; @@ -813,7 +813,7 @@ static int dec__scnprintf(struct ins *ins, char *bf, si= ze_t size, ops->target.name ?: ops->target.raw); } =20 -static struct ins_ops dec_ops =3D { +static const struct ins_ops dec_ops =3D { .parse =3D dec__parse, .scnprintf =3D dec__scnprintf, }; @@ -824,11 +824,11 @@ static int nop__scnprintf(struct ins *ins __maybe_unu= sed, char *bf, size_t size, return scnprintf(bf, size, "%-*s", max_ins_name, "nop"); } =20 -static struct ins_ops nop_ops =3D { +static const struct ins_ops nop_ops =3D { .scnprintf =3D nop__scnprintf, }; =20 -static struct ins_ops ret_ops =3D { +static const struct ins_ops ret_ops =3D { .scnprintf =3D ins__raw_scnprintf, }; =20 @@ -869,7 +869,7 @@ static void ins__sort(struct arch *arch) qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp); } =20 -static struct ins_ops *__ins__find(const struct arch *arch, const char *na= me, +static const struct ins_ops *__ins__find(const struct arch *arch, const ch= ar *name, struct disasm_line *dl) { struct ins *ins; @@ -880,7 +880,7 @@ static struct ins_ops *__ins__find(const struct arch *a= rch, const char *name, * For powerpc, identify the instruction ops * from the opcode using raw_insn. */ - struct ins_ops *ops; + const struct ins_ops *ops; =20 ops =3D check_ppc_insn(dl); if (ops) @@ -916,9 +916,9 @@ static struct ins_ops *__ins__find(const struct arch *a= rch, const char *name, return ins ? ins->ops : NULL; } =20 -struct ins_ops *ins__find(const struct arch *arch, const char *name, struc= t disasm_line *dl) +const struct ins_ops *ins__find(const struct arch *arch, const char *name,= struct disasm_line *dl) { - struct ins_ops *ops =3D __ins__find(arch, name, dl); + const struct ins_ops *ops =3D __ins__find(arch, name, dl); =20 if (!ops && arch->associate_instruction_ops) ops =3D arch->associate_instruction_ops((struct arch *)arch, name); diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index 273a9c906514..dc5233f2a773 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -22,7 +22,7 @@ struct arch { struct ins *instructions; size_t nr_instructions; size_t nr_instructions_allocated; - struct ins_ops *(*associate_instruction_ops)(struct arch *arch, const ch= ar *name); + const struct ins_ops *(*associate_instruction_ops)(struct arch *arch, co= nst char *name); bool sorted_instructions; bool initialized; const char *insn_suffix; @@ -52,7 +52,7 @@ struct arch { =20 struct ins { const char *name; - struct ins_ops *ops; + const struct ins_ops *ops; }; =20 struct ins_operands { @@ -108,7 +108,7 @@ struct annotate_args { const struct arch *arch__find(const char *name); bool arch__is(const struct arch *arch, const char *name); =20 -struct ins_ops *ins__find(const struct arch *arch, const char *name, struc= t disasm_line *dl); +const struct ins_ops *ins__find(const struct arch *arch, const char *name,= struct disasm_line *dl); =20 bool ins__is_call(const struct ins *ins); bool ins__is_jump(const struct ins *ins); --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 821FB385EF9 for ; Thu, 22 Jan 2026 21:35:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117751; cv=none; b=SXMB6bw/ZJ/zb8+d2NXOd7T7q5ImdGPOE9Vv6qDzc/f+CK96A2np0wmgjuU5j6nbU7LXjGARcuPCeZaclF1OgdlSU3tssn5/PUwENLVgyUkP+5jcDGzSq79MIC1W561m50GusVkaS8qWrCMB8lDfVXcH4cZGfakg3GiBXP2qD5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117751; c=relaxed/simple; bh=KR5+2EshErmuRybWcBELHd/O8khmGf6P5Bg86ngz38E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=P/T007MMJpbR/4R0yvJsBqiseYRKx4A1w9dvBPcLSkyslASFPFPA+wn+BXoT6FniOKBiwO88bSg0gAbOUSDeu8qaP8+LXwoFkpGyKd/6JZ8w95wI4zX7faZAIalVNXGH4KtGuLmeXL5XwTgH8KYkXtVWL+ypwac6TYgbjMvtYb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ptx4KyC9; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ptx4KyC9" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b72a9a9715so4557326eec.1 for ; Thu, 22 Jan 2026 13:35:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117735; x=1769722535; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=LJvCENf9OUao4NjSk9nvAVIfxbnn+tkq0I5XRhSJkfA=; b=ptx4KyC9YqbKKN1hWD02roKtoCjpmDJotFIn0Y9KpzRtS9nTBDqmAiXR+JgcE6vKmO XP2i6cBjvLIhgXxAcRciXknUDpGvM5oEZNF1dEWVB/IUwlJuCDnOIH8J8+dXmwQkWeb/ 8HXg5nyP3sf7BbHdurmrT4h+wAndulYmrbzEUkVP55xJV4+OnDd5c84WwxEPTUT1FpwF H/pTgLrBayTf5OlcJvv0gdZ0pRFAXDaM/TKJzrseASLicwiAkI243jkzmQBiG3v1NQ10 er8CsWnwd8D69vO56w0dfrgwMbMn1IN7yv88ay+Zx+n98JrvUfDK0qxoHuoBV2QkG6sd Cy+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117735; x=1769722535; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LJvCENf9OUao4NjSk9nvAVIfxbnn+tkq0I5XRhSJkfA=; b=cIJ7usrhQONeW51wIez/fCNIM9dbEOomko7yoVSGqUAFsFscgAq4WkGIoZzxc0JomL 8+Cd+EOG5aJ89gBSzG1DyqhuolG/c+P9j8UtURi+vO8vP+YUsbeag1SVatDocqDum27F SWWm0PV/+cOg4G7EVxWQjKwGnhuAvxTnlGpevBOaI9WhWju4IZQZuY8JR49wK4ULpD5B 31p+I4BSso8nDUTP+XGTAJaP2ATVdtsmVQuG3yvxyGRoOU+Rmtj5rdZYI4UHfiz4n6A5 nJrhscNZTpczoM4TjtIVSxvGQGUBiTX7h43ga1AAqlUL0CaQkK1iNonvKQM6+wJv4HyT uHLQ== X-Forwarded-Encrypted: i=1; AJvYcCXpPqk/0moa/JqQ8JRf/C5P/n3tAq+mj9GTqe2aVLHPGxZdRLC4tE2AxPTOWimBPLnYcVgCGSHr3eM4cJo=@vger.kernel.org X-Gm-Message-State: AOJu0YxSnOIVvqF5o4lMDKLEgRLho0/gZlEjSXF701L0PoDbsr69A867 Ysc+uD71q/B9IPbusgm5YYZegUqtw9mnmJ9WgpenP36VqaNS6Ik+EdJ0NVq2yBJh019H8v67DOo 2/UByCmSFJQ== X-Received: from dybdr40.prod.google.com ([2002:a05:7300:b2a8:b0:2ab:9e42:f552]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:5707:b0:2ae:55ac:3ff6 with SMTP id 5a478bee46e88-2b739964db9mr421136eec.1.1769117735061; Thu, 22 Jan 2026 13:35:35 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:10 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-7-irogers@google.com> Subject: [PATCH v3 06/12] perf disasm: Constify use of struct ins From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The struct ins holds variables that are read but not written, except during some initialization. Change most uses to be for a "const struct ins *" version to capture this immutability. So the x86__instructions can be const pre-sort it and make the sorted variable true. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/arch/arm64/annotate/instructions.c | 2 +- tools/perf/arch/x86/annotate/instructions.c | 26 +++++++++++---- tools/perf/util/disasm.c | 32 ++++++++++--------- tools/perf/util/disasm.h | 4 +-- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/arc= h/arm64/annotate/instructions.c index 363af2f55122..44db33854dba 100644 --- a/tools/perf/arch/arm64/annotate/instructions.c +++ b/tools/perf/arch/arm64/annotate/instructions.c @@ -60,7 +60,7 @@ static int arm64_mov__parse(const struct arch *arch __may= be_unused, return -1; } =20 -static int mov__scnprintf(struct ins *ins, char *bf, size_t size, +static int mov__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); =20 static const struct ins_ops arm64_mov_ops =3D { diff --git a/tools/perf/arch/x86/annotate/instructions.c b/tools/perf/arch/= x86/annotate/instructions.c index 24b388bacdae..ffca3029388b 100644 --- a/tools/perf/arch/x86/annotate/instructions.c +++ b/tools/perf/arch/x86/annotate/instructions.c @@ -7,7 +7,7 @@ * So this table should not have entries with the suffix unless it's * a complete different instruction than ones without the suffix. */ -static struct ins x86__instructions[] =3D { +static const struct ins x86__instructions[] =3D { { .name =3D "adc", .ops =3D &mov_ops, }, { .name =3D "add", .ops =3D &mov_ops, }, { .name =3D "addsd", .ops =3D &mov_ops, }, @@ -19,9 +19,9 @@ static struct ins x86__instructions[] =3D { { .name =3D "btr", .ops =3D &mov_ops, }, { .name =3D "bts", .ops =3D &mov_ops, }, { .name =3D "call", .ops =3D &call_ops, }, + { .name =3D "cmovae", .ops =3D &mov_ops, }, { .name =3D "cmovbe", .ops =3D &mov_ops, }, { .name =3D "cmove", .ops =3D &mov_ops, }, - { .name =3D "cmovae", .ops =3D &mov_ops, }, { .name =3D "cmp", .ops =3D &mov_ops, }, { .name =3D "cmpxch", .ops =3D &mov_ops, }, { .name =3D "cmpxchg", .ops =3D &mov_ops, }, @@ -73,23 +73,23 @@ static struct ins x86__instructions[] =3D { { .name =3D "movaps", .ops =3D &mov_ops, }, { .name =3D "movdqa", .ops =3D &mov_ops, }, { .name =3D "movdqu", .ops =3D &mov_ops, }, + { .name =3D "movsb", .ops =3D &mov_ops, }, { .name =3D "movsd", .ops =3D &mov_ops, }, + { .name =3D "movsl", .ops =3D &mov_ops, }, { .name =3D "movss", .ops =3D &mov_ops, }, - { .name =3D "movsb", .ops =3D &mov_ops, }, { .name =3D "movsw", .ops =3D &mov_ops, }, - { .name =3D "movsl", .ops =3D &mov_ops, }, { .name =3D "movupd", .ops =3D &mov_ops, }, { .name =3D "movups", .ops =3D &mov_ops, }, { .name =3D "movzb", .ops =3D &mov_ops, }, - { .name =3D "movzw", .ops =3D &mov_ops, }, { .name =3D "movzl", .ops =3D &mov_ops, }, + { .name =3D "movzw", .ops =3D &mov_ops, }, { .name =3D "mulsd", .ops =3D &mov_ops, }, { .name =3D "mulss", .ops =3D &mov_ops, }, { .name =3D "nop", .ops =3D &nop_ops, }, { .name =3D "or", .ops =3D &mov_ops, }, { .name =3D "orps", .ops =3D &mov_ops, }, - { .name =3D "pand", .ops =3D &mov_ops, }, { .name =3D "paddq", .ops =3D &mov_ops, }, + { .name =3D "pand", .ops =3D &mov_ops, }, { .name =3D "pcmpeqb", .ops =3D &mov_ops, }, { .name =3D "por", .ops =3D &mov_ops, }, { .name =3D "rcl", .ops =3D &mov_ops, }, @@ -202,6 +202,20 @@ static int x86__annotate_init(struct arch *arch, char = *cpuid) if (x86__cpuid_parse(arch, cpuid)) err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; } + +#ifndef NDEBUG + { + static bool sorted_check; + + if (!sorted_check) { + for (size_t i =3D 0; i < arch->nr_instructions - 1; i++) { + assert(strcmp(arch->instructions[i].name, + arch->instructions[i + 1].name) <=3D 0); + } + sorted_check =3D true; + } + } +#endif arch->e_machine =3D EM_X86_64; arch->e_flags =3D 0; arch->initialized =3D true; diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 9bc9b1de98db..2793697ce75c 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -43,9 +43,9 @@ static const struct ins_ops ret_ops; static const struct ins_ops load_store_ops; static const struct ins_ops arithmetic_ops; =20 -static int jump__scnprintf(struct ins *ins, char *bf, size_t size, +static int jump__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); -static int call__scnprintf(struct ins *ins, char *bf, size_t size, +static int call__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); =20 static void ins__sort(struct arch *arch); @@ -66,7 +66,8 @@ static int arch__grow_instructions(struct arch *arch) goto grow_from_non_allocated_table; =20 new_nr_allocated =3D arch->nr_instructions_allocated + 128; - new_instructions =3D realloc(arch->instructions, new_nr_allocated * sizeo= f(struct ins)); + new_instructions =3D realloc((void *)arch->instructions, + new_nr_allocated * sizeof(struct ins)); if (new_instructions =3D=3D NULL) return -1; =20 @@ -93,7 +94,7 @@ static int arch__associate_ins_ops(struct arch *arch, con= st char *name, const st arch__grow_instructions(arch)) return -1; =20 - ins =3D &arch->instructions[arch->nr_instructions]; + ins =3D (struct ins *)&arch->instructions[arch->nr_instructions]; ins->name =3D strdup(name); if (!ins->name) return -1; @@ -146,6 +147,7 @@ static struct arch architectures[] =3D { .init =3D x86__annotate_init, .instructions =3D x86__instructions, .nr_instructions =3D ARRAY_SIZE(x86__instructions), + .sorted_instructions =3D true, .insn_suffix =3D "bwlq", .objdump =3D { .comment_char =3D '#', @@ -241,13 +243,13 @@ static void ins_ops__delete(struct ins_operands *ops) zfree(&ops->target.name); } =20 -static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size, +static int ins__raw_scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->raw); } =20 -static int ins__scnprintf(struct ins *ins, char *bf, size_t size, +static int ins__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { if (ins->ops->scnprintf) @@ -319,7 +321,7 @@ static int call__parse(const struct arch *arch, struct = ins_operands *ops, struct goto find_target; } =20 -static int call__scnprintf(struct ins *ins, char *bf, size_t size, +static int call__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { if (ops->target.sym) @@ -446,7 +448,7 @@ static int jump__parse(const struct arch *arch, struct = ins_operands *ops, struct return 0; } =20 -static int jump__scnprintf(struct ins *ins, char *bf, size_t size, +static int jump__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { const char *c; @@ -551,7 +553,7 @@ static int lock__parse(const struct arch *arch, struct = ins_operands *ops, struct return 0; } =20 -static int lock__scnprintf(struct ins *ins, char *bf, size_t size, +static int lock__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { int printed; @@ -680,7 +682,7 @@ static int mov__parse(const struct arch *arch, struct i= ns_operands *ops, return -1; } =20 -static int mov__scnprintf(struct ins *ins, char *bf, size_t size, +static int mov__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s,%s", max_ins_name, ins->name, @@ -699,7 +701,7 @@ static const struct ins_ops mov_ops =3D { #define ADD_ZERO_EXT_XO_FORM 202 #define SUB_ZERO_EXT_XO_FORM 200 =20 -static int arithmetic__scnprintf(struct ins *ins, char *bf, size_t size, +static int arithmetic__scnprintf(const struct ins *ins, char *bf, size_t s= ize, struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, @@ -743,7 +745,7 @@ static const struct ins_ops arithmetic_ops =3D { .scnprintf =3D arithmetic__scnprintf, }; =20 -static int load_store__scnprintf(struct ins *ins, char *bf, size_t size, +static int load_store__scnprintf(const struct ins *ins, char *bf, size_t s= ize, struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, @@ -806,7 +808,7 @@ static int dec__parse(const struct arch *arch __maybe_u= nused, struct ins_operand return 0; } =20 -static int dec__scnprintf(struct ins *ins, char *bf, size_t size, +static int dec__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, @@ -818,7 +820,7 @@ static const struct ins_ops dec_ops =3D { .scnprintf =3D dec__scnprintf, }; =20 -static int nop__scnprintf(struct ins *ins __maybe_unused, char *bf, size_t= size, +static int nop__scnprintf(const struct ins *ins __maybe_unused, char *bf, = size_t size, struct ins_operands *ops __maybe_unused, int max_ins_name) { return scnprintf(bf, size, "%-*s", max_ins_name, "nop"); @@ -866,7 +868,7 @@ static void ins__sort(struct arch *arch) { const int nmemb =3D arch->nr_instructions; =20 - qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp); + qsort((void *)arch->instructions, nmemb, sizeof(struct ins), ins__cmp); } =20 static const struct ins_ops *__ins__find(const struct arch *arch, const ch= ar *name, diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index dc5233f2a773..4f5c9a985786 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -19,7 +19,7 @@ struct disasm_line; =20 struct arch { const char *name; - struct ins *instructions; + const struct ins *instructions; size_t nr_instructions; size_t nr_instructions_allocated; const struct ins_ops *(*associate_instruction_ops)(struct arch *arch, co= nst char *name); @@ -91,7 +91,7 @@ struct ins_ops { void (*free)(struct ins_operands *ops); int (*parse)(const struct arch *arch, struct ins_operands *ops, struct ma= p_symbol *ms, struct disasm_line *dl); - int (*scnprintf)(struct ins *ins, char *bf, size_t size, + int (*scnprintf)(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); }; =20 --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D308D3C1FD5 for ; Thu, 22 Jan 2026 21:35:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117754; cv=none; b=AJeiqLH5cO0JKfDYg6TqH1rjw7AecmnN1DOexX4JD8nxWitLAdv+w+zPp30CbxyO+5oDJaJs5uQvD9/MfOvmEUEWSLalPxZRLnqjPl8Ohj6h2H80F6JVts6/0nci+3/frIuRsqG5ABjKcFD/PVGb42h81T81FKpqzGTIVC9IFXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117754; c=relaxed/simple; bh=sRclvWe9do8aJB1oNVcjn3sHrsa8VOSwS5xxwOFocf8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=VrROJskpqOpJfmqgYquvW1FyCGY1GopFVQFGzu8erJ9ijDDWd2KIFDz/L22Jls3FmMCEPocx8x+BiZzD6wl/cWoMdTIkUdnkYIhrISE5uoLw0od+deGo0OWCTpyETSEIHhJRhhzmOAawJ0Ebx5SmEIffCQlgZ2b5kXOvpGZpTD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=euO0eIMd; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="euO0eIMd" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12338749ea9so2028535c88.0 for ; Thu, 22 Jan 2026 13:35:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117737; x=1769722537; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=mohShwdVVANhhguIax08ioRiqfRGyb+9L7Fn7SVEHWE=; b=euO0eIMdZW3aPub6QrBQ2uNNwjG8e+dHznjQv+6VGeh2WBTwHgozFyEwmas9g6z2ap MrrDaLafGcLmDjSG7xIncWtg1sBL3CPoHShPoe3S7JPBTTOaE1G6eMDgYebxcSf9x6Ii FCWPzX4sc+YGvAx0zPxXC/E/2JjbOxbUd5M/BD3v+IlNDwiKaD8FxZ17X7nQJ9pOYcFb g5lgcX2JwABmwJ3XXSP97aKldHBKX8JDAb6Gp+S8I/1WAUTqJkMdTz7QSSG7VhfjrzY5 wEPxaHrNLHnP6VnfbCBdvnVkKMVUR8/T5hQIHuUnXBoEete7GzV+w0qrjzqnxcJ5ZE/8 J1aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117737; x=1769722537; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mohShwdVVANhhguIax08ioRiqfRGyb+9L7Fn7SVEHWE=; b=KjnTC2Q4pgo/ypXgzoUOR7N3MwUO1dfRrWHufLV5AiaitxXgCwbSQzrSVH3jB8KbJI FayfSLxfm4pDhezH2JEPVqJtmlvrMsYCVYgFnFNdFZgsLMiRV6vXW7G2XONYAhEWn5Gd +4m/eIIh0uqBowttwsPTVsILq0HoNs6tGsTXWnuB6oy62ij/s1EmoRRKAPBbv6iUblMv d9LJ3+VkSyxiXeVCRHVE3Opw8MVHOCB3Xt+w6ej5cqjD/E+hvZPO0z9NAVwKrd/CuVoC bixMjUoqpCtHD9uKichK3NF3G30l4AHqFgzZmEMgzhVPYRuflD7MqjQUi6kht6PxUi+t suLQ== X-Forwarded-Encrypted: i=1; AJvYcCVKo8uzFHgN9MqHL5xCYk38gqnxGGlGcrYMxGBMCZWTlpkrBqQWhmIqvW/IqD7GCYrAr540yyeErYhzgFc=@vger.kernel.org X-Gm-Message-State: AOJu0YzoEi991j+DYGFBOqM3+22iS4Y2/CH+0SUgg4WFC+/jSzEixjOg MtwPas4tDzbTOaWg1hcR8S9i/yxFGFFUdpn1JbYGF6k/4IuZNrFH+4Jc/Cz9c2iIjcmh7pqp1tD XPrOr6eT0yw== X-Received: from dlbtu19.prod.google.com ([2002:a05:7022:3c13:b0:123:2dd9:db4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:7a6:b0:11b:9386:8257 with SMTP id a92af1059eb24-1247dc0fb54mr304915c88.44.1769117737009; Thu, 22 Jan 2026 13:35:37 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:11 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-8-irogers@google.com> Subject: [PATCH v3 07/12] perf disasm: Rework the string arch__is to use the ELF machine From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add new arch__is_x86 and arch__is_powerpc functions that avoid string comparisons and use the ELF machine. Remove arch__is that is no longer used. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/util/annotate-data.c | 10 +++++----- tools/perf/util/annotate.c | 16 ++++++++-------- tools/perf/util/capstone.c | 2 +- tools/perf/util/disasm.c | 15 ++++++++++----- tools/perf/util/disasm.h | 3 ++- tools/perf/util/llvm.c | 2 +- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index edfcd6e9df9c..44fbd41e3845 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -165,7 +165,7 @@ static void init_type_state(struct type_state *state, c= onst struct arch *arch) memset(state, 0, sizeof(*state)); INIT_LIST_HEAD(&state->stack_vars); =20 - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { state->regs[0].caller_saved =3D true; state->regs[1].caller_saved =3D true; state->regs[2].caller_saved =3D true; @@ -526,7 +526,7 @@ static enum type_match_result check_variable(struct dat= a_loc_info *dloc, needs_pointer =3D false; else if (reg =3D=3D dloc->fbreg || is_fbreg) needs_pointer =3D false; - else if (arch__is(dloc->arch, "x86") && reg =3D=3D X86_REG_SP) + else if (arch__is_x86(dloc->arch) && reg =3D=3D X86_REG_SP) needs_pointer =3D false; =20 /* Get the type of the variable */ @@ -1071,7 +1071,7 @@ static void delete_var_types(struct die_var_type *var= _types) /* should match to is_stack_canary() in util/annotate.c */ static void setup_stack_canary(struct data_loc_info *dloc) { - if (arch__is(dloc->arch, "x86")) { + if (arch__is_x86(dloc->arch)) { dloc->op->segment =3D INSN_SEG_X86_GS; dloc->op->imm =3D true; dloc->op->offset =3D 40; @@ -1311,7 +1311,7 @@ static enum type_match_result check_matching_type(str= uct type_state *state, =20 /* Direct this-cpu access like "%gs:0x34740" */ if (dloc->op->segment =3D=3D INSN_SEG_X86_GS && dloc->op->imm && - arch__is(dloc->arch, "x86")) { + arch__is_x86(dloc->arch)) { pr_debug_dtp("this-cpu var"); =20 addr =3D dloc->op->offset; @@ -1397,7 +1397,7 @@ static enum type_match_result find_data_type_insn(str= uct data_loc_info *dloc, =20 static int arch_supports_insn_tracking(struct data_loc_info *dloc) { - if ((arch__is(dloc->arch, "x86")) || (arch__is(dloc->arch, "powerpc"))) + if ((arch__is_x86(dloc->arch)) || (arch__is_powerpc(dloc->arch))) return 1; return 0; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 132af2556aec..79702072568b 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2474,7 +2474,7 @@ static int extract_reg_offset(const struct arch *arch= , const char *str, * %gs:0x18(%rbx). In that case it should skip the part. */ if (*str =3D=3D arch->objdump.register_char) { - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { /* FIXME: Handle other segment registers */ if (!strncmp(str, "%gs:", 4)) op_loc->segment =3D INSN_SEG_X86_GS; @@ -2571,7 +2571,7 @@ int annotate_get_insn_location(const struct arch *arc= h, struct disasm_line *dl, op_loc->reg2 =3D -1; =20 if (insn_str =3D=3D NULL) { - if (!arch__is(arch, "powerpc")) + if (!arch__is_powerpc(arch)) continue; } =20 @@ -2580,7 +2580,7 @@ int annotate_get_insn_location(const struct arch *arc= h, struct disasm_line *dl, * required fields for op_loc, ie reg1, reg2, offset from the * raw instruction. */ - if (arch__is(arch, "powerpc")) { + if (arch__is_powerpc(arch)) { op_loc->mem_ref =3D mem_ref; op_loc->multi_regs =3D multi_regs; get_powerpc_regs(dl->raw.raw_insn, !i, op_loc); @@ -2591,7 +2591,7 @@ int annotate_get_insn_location(const struct arch *arc= h, struct disasm_line *dl, } else { char *s, *p =3D NULL; =20 - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { /* FIXME: Handle other segment registers */ if (!strncmp(insn_str, "%gs:", 4)) { op_loc->segment =3D INSN_SEG_X86_GS; @@ -2675,7 +2675,7 @@ static struct annotated_item_stat *annotate_data_stat= (struct list_head *head, =20 static bool is_stack_operation(const struct arch *arch, struct disasm_line= *dl) { - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { if (!strncmp(dl->ins.name, "push", 4) || !strncmp(dl->ins.name, "pop", 3) || !strncmp(dl->ins.name, "call", 4) || @@ -2689,7 +2689,7 @@ static bool is_stack_operation(const struct arch *arc= h, struct disasm_line *dl) static bool is_stack_canary(const struct arch *arch, struct annotated_op_l= oc *loc) { /* On x86_64, %gs:40 is used for stack canary */ - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { if (loc->segment =3D=3D INSN_SEG_X86_GS && loc->imm && loc->offset =3D=3D 40) return true; @@ -2704,7 +2704,7 @@ static bool is_stack_canary(const struct arch *arch, = struct annotated_op_loc *lo */ static bool is_address_gen_insn(const struct arch *arch, struct disasm_lin= e *dl) { - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { if (!strncmp(dl->ins.name, "lea", 3)) return true; } @@ -2847,7 +2847,7 @@ __hist_entry__get_data_type(struct hist_entry *he, co= nst struct arch *arch, } =20 /* This CPU access in kernel - pretend PC-relative addressing */ - if (dso__kernel(map__dso(ms->map)) && arch__is(arch, "x86") && + if (dso__kernel(map__dso(ms->map)) && arch__is_x86(arch) && op_loc->segment =3D=3D INSN_SEG_X86_GS && op_loc->imm) { dloc.var_addr =3D op_loc->offset; op_loc->reg1 =3D DWARF_REG_PC; diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c index 2c7feab61b7b..ce06cfd253ef 100644 --- a/tools/perf/util/capstone.c +++ b/tools/perf/util/capstone.c @@ -147,7 +147,7 @@ static void print_capstone_detail(cs_insn *insn, char *= buf, size_t len, struct symbol *sym; =20 /* TODO: support more architectures */ - if (!arch__is(args->arch, "x86")) + if (!arch__is_x86(args->arch)) return; =20 if (insn->detail =3D=3D NULL) diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 2793697ce75c..b7523256c4ad 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -228,9 +228,14 @@ const struct arch *arch__find(const char *name) return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key= _cmp); } =20 -bool arch__is(const struct arch *arch, const char *name) +bool arch__is_x86(const struct arch *arch) { - return !strcmp(arch->name, name); + return arch->e_machine =3D=3D EM_386 || arch->e_machine =3D=3D EM_X86_64; +} + +bool arch__is_powerpc(const struct arch *arch) +{ + return arch->e_machine =3D=3D EM_PPC || arch->e_machine =3D=3D EM_PPC64; } =20 static void ins_ops__delete(struct ins_operands *ops) @@ -877,7 +882,7 @@ static const struct ins_ops *__ins__find(const struct a= rch *arch, const char *na struct ins *ins; const int nmemb =3D arch->nr_instructions; =20 - if (arch__is(arch, "powerpc")) { + if (arch__is_powerpc(arch)) { /* * For powerpc, identify the instruction ops * from the opcode using raw_insn. @@ -1066,7 +1071,7 @@ struct disasm_line *disasm_line__new(struct annotate_= args *args) goto out_delete; =20 if (args->offset !=3D -1) { - if (arch__is(args->arch, "powerpc")) { + if (arch__is_powerpc(args->arch)) { if (disasm_line__parse_powerpc(dl, args) < 0) goto out_free_line; } else if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) = < 0) @@ -1700,7 +1705,7 @@ int symbol__disassemble(struct symbol *sym, struct an= notate_args *args) * and typeoff, disassemble to mnemonic notation is not required in * case of powerpc. */ - if (arch__is(args->arch, "powerpc")) { + if (arch__is_powerpc(args->arch)) { extern const char *sort_order; =20 if (sort_order && !strstr(sort_order, "sym")) { diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index 4f5c9a985786..db7f1ee3d8e7 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -106,7 +106,8 @@ struct annotate_args { }; =20 const struct arch *arch__find(const char *name); -bool arch__is(const struct arch *arch, const char *name); +bool arch__is_x86(const struct arch *arch); +bool arch__is_powerpc(const struct arch *arch); =20 const struct ins_ops *ins__find(const struct arch *arch, const char *name,= struct disasm_line *dl); =20 diff --git a/tools/perf/util/llvm.c b/tools/perf/util/llvm.c index 4ada9a10bd93..0d126d233c01 100644 --- a/tools/perf/util/llvm.c +++ b/tools/perf/util/llvm.c @@ -146,7 +146,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, return errno; =20 init_llvm(); - if (arch__is(args->arch, "x86")) { + if (arch__is_x86(args->arch)) { const char *triplet =3D is_64bit ? "x86_64-pc-linux" : "i686-pc-linux"; =20 disasm =3D LLVMCreateDisasm(triplet, &storage, /*tag_type=3D*/0, --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 589233C1FFE for ; Thu, 22 Jan 2026 21:35:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117756; cv=none; b=m9ZR+SP84dN+9/mUQs+QwIqWxGY41NN5BOU5VAJDiNDnLWXfxH0/BCTq/928QNLcaRIjYcKQMiyJVYOkEIEUNfHvwed+v6FtxkVKidnKhHflj9XodXJ4xPzaVTWbMm3vgz2WnM9v3MzfAMEH68fZ+l08Zpr8pg90dFig4qz44Ig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117756; c=relaxed/simple; bh=491jb90fnisDDkG3+G9+p4v7Lk7B8Z252ZaXQb6NJdc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=IaJ5YfxvS8DrHEa7Ue59S07gBB4RdWMClxNxfO76KYPIojmIHadPCBdfqZa7pjg2NnRt2IdQ0THVF9LkObafIoQWvGn3h0UifcvTFDeYofCMQhylkcEQmQn9up7hou+2he3PUiKsSZmjU3yoDsvnNo58VTACfuEPCDHEwEmNTOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=3gVMe2vD; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3gVMe2vD" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b708fa4093so4324752eec.0 for ; Thu, 22 Jan 2026 13:35:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117739; x=1769722539; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=ACMl4tEoxoHusBUNvHd7v0jfYpL5OX8OF2Pn3Unqkyk=; b=3gVMe2vD1AkvTY1XiYDkQrhmLMFzkxd6QK7v95QhtjTlaWUnO84+aW2NQ9xmjlWh/p 18m4YePT4qDrKkPIDn+zzupW1NosMHoXSzHECh0RgyIyBNEhxDSWB2niqX0uGqN1MmOm XblUqVlqwUkSJc1MCuQKUV5lCiR4YLhKffZdOhAZHhdblhgeS+uR4fXDtmy4arckDU/4 EalIwQtJBi6Rjj1rXhIcnlKQpTh7T3Dr6R8uCwPidCeHYhQ+LfHYE39hlwF2ToCb20iC xXlOr2Ar1GFbREIIiDWM0B77dgA/D3jaG87rGb84LaIk61Fu+m7KsodkcWU/NhJoKVym wvSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117739; x=1769722539; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ACMl4tEoxoHusBUNvHd7v0jfYpL5OX8OF2Pn3Unqkyk=; b=XeotXrlX8+Eqn27LbgZI/sMp+C/6nAO76gNUfdoU4DwkIxsptk/8xVXYNNYy/nrXm2 r8485REZKIsr0M6L0MZpmEyXYqeGfUoNlObqtWTO9axdLOJP2R3SzSVkET0ywz3Oa0EQ jB+YP+eODXTBl+w5ANO9aNgz9uKiX7157ivZ5CSMQr4SpSmDBZiky6RtT1G8cI56eb8s Y84QqbefD3foQIMl/edaqYgjnezmDlK6He84r1TKn8Ruip1V2bLHn7Bj2KB2BdYrI5sl +yw2UG4CF7FfjBeMnff6URE9rP1KWBl4+ikJuFBvbbbWiwswYhsrSqoME7Grx3BeMs4c uiLA== X-Forwarded-Encrypted: i=1; AJvYcCVgb5zwkfpJ4zJGFQDodwrLX11I/e5ggusCjgEQ80ojdg0vLnNmccYpOoxhsXFRRgajaraOsf90wTx/Sns=@vger.kernel.org X-Gm-Message-State: AOJu0YxcFGX/yx3hkei6zYXM3mHabYCz3Knse3AYLWu8fYLT4rMwiSt6 RfTf8cFTK7OUTFHVZRwLAcuESxL1wDo89qk0jbdDJTWI2q+tv4CnYWQyEdkjjyXnrBaX2sS4vaX hl3IzVr0zGw== X-Received: from dycnm5.prod.google.com ([2002:a05:7300:d185:b0:2ac:3545:743c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:9f03:b0:2b7:1d5d:47dc with SMTP id 5a478bee46e88-2b739b8d7a7mr430086eec.22.1769117738792; Thu, 22 Jan 2026 13:35:38 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:12 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-9-irogers@google.com> Subject: [PATCH v3 08/12] perf disasm: Don't include C files from the arch directory From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the arch instructions.c files into appropriately named files in annotate-arch in the util directory. Don't #include to compile the code, switch to building the files and fix up the #includes accordingly. Move powerpc specific disasm code out of disasm.c and into annotate-powerpc.c. Declarations and static removed as appropriate for the code to compile as separate compilation units. The e_machine and e_flags set up is moved to the disasm.c architectures array so that later patches can sort by them. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/util/Build | 1 + tools/perf/util/annotate-arch/Build | 11 + .../annotate-arch/annotate-arc.c} | 5 +- .../annotate-arch/annotate-arm.c} | 9 +- .../annotate-arch/annotate-arm64.c} | 14 +- .../annotate-arch/annotate-csky.c} | 11 +- .../annotate-arch/annotate-loongarch.c} | 15 +- .../annotate-arch/annotate-mips.c} | 6 +- .../annotate-arch/annotate-powerpc.c} | 105 ++++++++- .../annotate-arch/annotate-riscv64.c} | 6 +- .../annotate-arch/annotate-s390.c} | 15 +- .../annotate-arch/annotate-sparc.c} | 7 +- .../annotate-arch/annotate-x86.c} | 85 +++++--- tools/perf/util/disasm.c | 199 ++++-------------- tools/perf/util/disasm.h | 38 ++++ 15 files changed, 289 insertions(+), 238 deletions(-) create mode 100644 tools/perf/util/annotate-arch/Build rename tools/perf/{arch/arc/annotate/instructions.c =3D> util/annotate-arc= h/annotate-arc.c} (53%) rename tools/perf/{arch/arm/annotate/instructions.c =3D> util/annotate-arc= h/annotate-arm.c} (90%) rename tools/perf/{arch/arm64/annotate/instructions.c =3D> util/annotate-a= rch/annotate-arm64.c} (90%) rename tools/perf/{arch/csky/annotate/instructions.c =3D> util/annotate-ar= ch/annotate-csky.c} (83%) rename tools/perf/{arch/loongarch/annotate/instructions.c =3D> util/annota= te-arch/annotate-loongarch.c} (93%) rename tools/perf/{arch/mips/annotate/instructions.c =3D> util/annotate-ar= ch/annotate-mips.c} (94%) rename tools/perf/{arch/powerpc/annotate/instructions.c =3D> util/annotate= -arch/annotate-powerpc.c} (76%) rename tools/perf/{arch/riscv64/annotate/instructions.c =3D> util/annotate= -arch/annotate-riscv64.c} (91%) rename tools/perf/{arch/s390/annotate/instructions.c =3D> util/annotate-ar= ch/annotate-s390.c} (91%) rename tools/perf/{arch/sparc/annotate/instructions.c =3D> util/annotate-a= rch/annotate-sparc.c} (96%) rename tools/perf/{arch/x86/annotate/instructions.c =3D> util/annotate-arc= h/annotate-x86.c} (97%) diff --git a/tools/perf/util/Build b/tools/perf/util/Build index c30ff257f8b4..b9925c6902ca 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -1,6 +1,7 @@ include $(srctree)/tools/scripts/Makefile.include include $(srctree)/tools/scripts/utilities.mak =20 +perf-util-y +=3D annotate-arch/ perf-util-y +=3D arm64-frame-pointer-unwind-support.o perf-util-y +=3D addr2line.o perf-util-y +=3D addr_location.o diff --git a/tools/perf/util/annotate-arch/Build b/tools/perf/util/annotate= -arch/Build new file mode 100644 index 000000000000..23316743fdc5 --- /dev/null +++ b/tools/perf/util/annotate-arch/Build @@ -0,0 +1,11 @@ +perf-util-y +=3D annotate-arc.o +perf-util-y +=3D annotate-arm.o +perf-util-y +=3D annotate-arm64.o +perf-util-y +=3D annotate-csky.o +perf-util-y +=3D annotate-loongarch.o +perf-util-y +=3D annotate-mips.o +perf-util-y +=3D annotate-x86.o +perf-util-y +=3D annotate-powerpc.o +perf-util-y +=3D annotate-riscv64.o +perf-util-y +=3D annotate-s390.o +perf-util-y +=3D annotate-sparc.o diff --git a/tools/perf/arch/arc/annotate/instructions.c b/tools/perf/util/= annotate-arch/annotate-arc.c similarity index 53% rename from tools/perf/arch/arc/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-arc.c index e5619770a1af..d7ca08ca5600 100644 --- a/tools/perf/arch/arc/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-arc.c @@ -1,11 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include "../disasm.h" =20 -static int arc__annotate_init(struct arch *arch, char *cpuid __maybe_unuse= d) +int arc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { arch->initialized =3D true; arch->objdump.comment_char =3D ';'; - arch->e_machine =3D EM_ARC; - arch->e_flags =3D 0; return 0; } diff --git a/tools/perf/arch/arm/annotate/instructions.c b/tools/perf/util/= annotate-arch/annotate-arm.c similarity index 90% rename from tools/perf/arch/arm/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-arm.c index b997d127fedd..08c49067c3c9 100644 --- a/tools/perf/arch/arm/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-arm.c @@ -1,10 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include -#include #include -#include +#include "../annotate.h" +#include "../disasm.h" =20 struct arm_annotate { regex_t call_insn, @@ -28,7 +29,7 @@ static const struct ins_ops *arm__associate_instruction_o= ps(struct arch *arch, c return ops; } =20 -static int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unuse= d) +int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { struct arm_annotate *arm; int err; @@ -54,8 +55,6 @@ static int arm__annotate_init(struct arch *arch, char *cp= uid __maybe_unused) arch->associate_instruction_ops =3D arm__associate_instruction_ops; arch->objdump.comment_char =3D ';'; arch->objdump.skip_functions_char =3D '+'; - arch->e_machine =3D EM_ARM; - arch->e_flags =3D 0; return 0; =20 out_free_call: diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/uti= l/annotate-arch/annotate-arm64.c similarity index 90% rename from tools/perf/arch/arm64/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-arm64.c index 44db33854dba..d2ea32984b0d 100644 --- a/tools/perf/arch/arm64/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-arm64.c @@ -1,9 +1,12 @@ // SPDX-License-Identifier: GPL-2.0 #include #include -#include -#include #include +#include +#include +#include +#include "../annotate.h" +#include "../disasm.h" =20 struct arm64_annotate { regex_t call_insn, @@ -60,9 +63,6 @@ static int arm64_mov__parse(const struct arch *arch __may= be_unused, return -1; } =20 -static int mov__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name); - static const struct ins_ops arm64_mov_ops =3D { .parse =3D arm64_mov__parse, .scnprintf =3D mov__scnprintf, @@ -87,7 +87,7 @@ static const struct ins_ops *arm64__associate_instruction= _ops(struct arch *arch, return ops; } =20 -static int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unu= sed) +int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { struct arm64_annotate *arm; int err; @@ -114,8 +114,6 @@ static int arm64__annotate_init(struct arch *arch, char= *cpuid __maybe_unused) arch->associate_instruction_ops =3D arm64__associate_instruction_ops; arch->objdump.comment_char =3D '/'; arch->objdump.skip_functions_char =3D '+'; - arch->e_machine =3D EM_AARCH64; - arch->e_flags =3D 0; return 0; =20 out_free_call: diff --git a/tools/perf/arch/csky/annotate/instructions.c b/tools/perf/util= /annotate-arch/annotate-csky.c similarity index 83% rename from tools/perf/arch/csky/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-csky.c index 4a55c84a320a..0b0b09b068ec 100644 --- a/tools/perf/arch/csky/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-csky.c @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. - +#include #include +#include "../disasm.h" =20 static const struct ins_ops *csky__associate_ins_ops(struct arch *arch, const char *name) @@ -38,16 +39,10 @@ static const struct ins_ops *csky__associate_ins_ops(st= ruct arch *arch, return ops; } =20 -static int csky__annotate_init(struct arch *arch, char *cpuid __maybe_unus= ed) +int csky__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { arch->initialized =3D true; arch->objdump.comment_char =3D '/'; arch->associate_instruction_ops =3D csky__associate_ins_ops; - arch->e_machine =3D EM_CSKY; -#if defined(__CSKYABIV2__) - arch->e_flags =3D EF_CSKY_ABIV2; -#else - arch->e_flags =3D EF_CSKY_ABIV1; -#endif return 0; } diff --git a/tools/perf/arch/loongarch/annotate/instructions.c b/tools/perf= /util/annotate-arch/annotate-loongarch.c similarity index 93% rename from tools/perf/arch/loongarch/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-loongarch.c index 5010d5d58375..32df10f6fed5 100644 --- a/tools/perf/arch/loongarch/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-loongarch.c @@ -4,11 +4,17 @@ * * Copyright (C) 2020-2023 Loongson Technology Corporation Limited */ +#include +#include +#include +#include "../disasm.h" +#include "../map.h" +#include "../maps.h" +#include "../symbol.h" =20 static int loongarch_call__parse(const struct arch *arch, struct ins_opera= nds *ops, struct map_symbol *ms, struct disasm_line *dl __maybe_unused) - { char *c, *endptr, *tok, *name; struct map *map =3D ms->map; @@ -51,7 +57,7 @@ static int loongarch_call__parse(const struct arch *arch,= struct ins_operands *o return 0; } =20 -static const struct ins_ops loongarch_call_ops =3D { +const struct ins_ops loongarch_call_ops =3D { .parse =3D loongarch_call__parse, .scnprintf =3D call__scnprintf, }; @@ -100,7 +106,7 @@ static int loongarch_jump__parse(const struct arch *arc= h, struct ins_operands *o return 0; } =20 -static const struct ins_ops loongarch_jump_ops =3D { +const struct ins_ops loongarch_jump_ops =3D { .parse =3D loongarch_jump__parse, .scnprintf =3D jump__scnprintf, }; @@ -130,15 +136,12 @@ const struct ins_ops *loongarch__associate_ins_ops(st= ruct arch *arch, const char return ops; } =20 -static int loongarch__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { if (!arch->initialized) { arch->associate_instruction_ops =3D loongarch__associate_ins_ops; arch->initialized =3D true; arch->objdump.comment_char =3D '#'; - arch->e_machine =3D EM_LOONGARCH; - arch->e_flags =3D 0; } =20 return 0; diff --git a/tools/perf/arch/mips/annotate/instructions.c b/tools/perf/util= /annotate-arch/annotate-mips.c similarity index 94% rename from tools/perf/arch/mips/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-mips.c index 0fbe0a7df95a..f14b34ed77d3 100644 --- a/tools/perf/arch/mips/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-mips.c @@ -1,4 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include "../disasm.h" =20 static const struct ins_ops *mips__associate_ins_ops(struct arch *arch, const cha= r *name) @@ -33,15 +36,12 @@ const struct ins_ops *mips__associate_ins_ops(struct ar= ch *arch, const char *nam return ops; } =20 -static int mips__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { if (!arch->initialized) { arch->associate_instruction_ops =3D mips__associate_ins_ops; arch->initialized =3D true; arch->objdump.comment_char =3D '#'; - arch->e_machine =3D EM_MIPS; - arch->e_flags =3D 0; } =20 return 0; diff --git a/tools/perf/arch/powerpc/annotate/instructions.c b/tools/perf/u= til/annotate-arch/annotate-powerpc.c similarity index 76% rename from tools/perf/arch/powerpc/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-powerpc.c index d1be55425e35..593c138c8104 100644 --- a/tools/perf/arch/powerpc/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-powerpc.c @@ -1,5 +1,97 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include +#include +#include "../annotate-data.h" +#include "../debug.h" +#include "../disasm.h" + +#define PPC_OP(op) (((op) >> 26) & 0x3F) +#define PPC_21_30(R) (((R) >> 1) & 0x3ff) +#define PPC_22_30(R) (((R) >> 1) & 0x1ff) + +#define MINUS_EXT_XO_FORM 234 +#define SUB_EXT_XO_FORM 232 +#define ADD_ZERO_EXT_XO_FORM 202 +#define SUB_ZERO_EXT_XO_FORM 200 + +static int arithmetic__scnprintf(const struct ins *ins, char *bf, size_t s= ize, + struct ins_operands *ops, int max_ins_name) +{ + return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, + ops->raw); +} + +/* + * Sets the fields: multi_regs and "mem_ref". + * "mem_ref" is set for ops->source which is later used to + * fill the objdump->memory_ref-char field. This ops is currently + * used by powerpc and since binary instruction code is used to + * extract opcode, regs and offset, no other parsing is needed here. + * + * Dont set multi regs for 4 cases since it has only one operand + * for source: + * - Add to Minus One Extended XO-form ( Ex: addme, addmeo ) + * - Subtract From Minus One Extended XO-form ( Ex: subfme ) + * - Add to Zero Extended XO-form ( Ex: addze, addzeo ) + * - Subtract From Zero Extended XO-form ( Ex: subfze ) + */ +static int arithmetic__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, + struct map_symbol *ms __maybe_unused, struct disasm_line *dl) +{ + int opcode =3D PPC_OP(dl->raw.raw_insn); + + ops->source.mem_ref =3D false; + if (opcode =3D=3D 31) { + if ((opcode !=3D MINUS_EXT_XO_FORM) && (opcode !=3D SUB_EXT_XO_FORM) && + (opcode !=3D ADD_ZERO_EXT_XO_FORM) && (opcode !=3D SUB_ZERO_EXT_XO_F= ORM)) + ops->source.multi_regs =3D true; + } + + ops->target.mem_ref =3D false; + ops->target.multi_regs =3D false; + + return 0; +} + +static const struct ins_ops arithmetic_ops =3D { + .parse =3D arithmetic__parse, + .scnprintf =3D arithmetic__scnprintf, +}; + +static int load_store__scnprintf(const struct ins *ins, char *bf, size_t s= ize, + struct ins_operands *ops, int max_ins_name) +{ + return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, + ops->raw); +} + +/* + * Sets the fields: multi_regs and "mem_ref". + * "mem_ref" is set for ops->source which is later used to + * fill the objdump->memory_ref-char field. This ops is currently + * used by powerpc and since binary instruction code is used to + * extract opcode, regs and offset, no other parsing is needed here + */ +static int load_store__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, + struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unu= sed) +{ + ops->source.mem_ref =3D true; + ops->source.multi_regs =3D false; + /* opcode 31 is of X form */ + if (PPC_OP(dl->raw.raw_insn) =3D=3D 31) + ops->source.multi_regs =3D true; + + ops->target.mem_ref =3D false; + ops->target.multi_regs =3D false; + + return 0; +} + +static const struct ins_ops load_store_ops =3D { + .parse =3D load_store__parse, + .scnprintf =3D load_store__scnprintf, +}; =20 static const struct ins_ops *powerpc__associate_instruction_ops(struct arc= h *arch, const char *name) { @@ -49,10 +141,6 @@ static const struct ins_ops *powerpc__associate_instruc= tion_ops(struct arch *arc return ops; } =20 -#define PPC_OP(op) (((op) >> 26) & 0x3F) -#define PPC_21_30(R) (((R) >> 1) & 0x3ff) -#define PPC_22_30(R) (((R) >> 1) & 0x1ff) - struct insn_offset { const char *name; int value; @@ -189,7 +277,7 @@ static int cmp_offset(const void *a, const void *b) return (val1->value - val2->value); } =20 -static const struct ins_ops *check_ppc_insn(struct disasm_line *dl) +const struct ins_ops *check_ppc_insn(struct disasm_line *dl) { int raw_insn =3D dl->raw.raw_insn; int opcode =3D PPC_OP(raw_insn); @@ -302,15 +390,16 @@ static void update_insn_state_powerpc(struct type_sta= te *state, } #endif /* HAVE_LIBDW_SUPPORT */ =20 -static int powerpc__annotate_init(struct arch *arch, char *cpuid __maybe_u= nused) +int powerpc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { if (!arch->initialized) { arch->initialized =3D true; arch->associate_instruction_ops =3D powerpc__associate_instruction_ops; arch->objdump.comment_char =3D '#'; annotate_opts.show_asm_raw =3D true; - arch->e_machine =3D EM_PPC; - arch->e_flags =3D 0; +#ifdef HAVE_LIBDW_SUPPORT + arch->update_insn_state =3D update_insn_state_powerpc; +#endif } =20 return 0; diff --git a/tools/perf/arch/riscv64/annotate/instructions.c b/tools/perf/u= til/annotate-arch/annotate-riscv64.c similarity index 91% rename from tools/perf/arch/riscv64/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-riscv64.c index a34798864fab..15526824037a 100644 --- a/tools/perf/arch/riscv64/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-riscv64.c @@ -1,4 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include "../disasm.h" =20 static const struct ins_ops *riscv64__associate_ins_ops(struct arch *arch, const = char *name) @@ -21,15 +24,12 @@ const struct ins_ops *riscv64__associate_ins_ops(struct= arch *arch, const char * return ops; } =20 -static int riscv64__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { if (!arch->initialized) { arch->associate_instruction_ops =3D riscv64__associate_ins_ops; arch->initialized =3D true; arch->objdump.comment_char =3D '#'; - arch->e_machine =3D EM_RISCV; - arch->e_flags =3D 0; } =20 return 0; diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/util= /annotate-arch/annotate-s390.c similarity index 91% rename from tools/perf/arch/s390/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-s390.c index 1b22e6276e7d..81db102b3e15 100644 --- a/tools/perf/arch/s390/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-s390.c @@ -1,5 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include +#include "../debug.h" +#include "../disasm.h" +#include "../map.h" +#include "../maps.h" +#include "../symbol.h" +#include "../annotate.h" +#include "../annotate-data.h" =20 static int s390_call__parse(const struct arch *arch, struct ins_operands *= ops, struct map_symbol *ms, @@ -49,7 +57,7 @@ static int s390_call__parse(const struct arch *arch, stru= ct ins_operands *ops, return 0; } =20 -static const struct ins_ops s390_call_ops =3D { +const struct ins_ops s390_call_ops =3D { .parse =3D s390_call__parse, .scnprintf =3D call__scnprintf, }; @@ -159,7 +167,7 @@ static int s390__cpuid_parse(struct arch *arch, char *c= puid) return -1; } =20 -static int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unus= ed) +int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { int err =3D 0; =20 @@ -170,8 +178,7 @@ static int s390__annotate_init(struct arch *arch, char = *cpuid __maybe_unused) if (s390__cpuid_parse(arch, cpuid)) err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; } - arch->e_machine =3D EM_S390; - arch->e_flags =3D 0; + arch->objdump.comment_char =3D '#'; } =20 return err; diff --git a/tools/perf/arch/sparc/annotate/instructions.c b/tools/perf/uti= l/annotate-arch/annotate-sparc.c similarity index 96% rename from tools/perf/arch/sparc/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-sparc.c index a08d8734c883..66a0174376dd 100644 --- a/tools/perf/arch/sparc/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-sparc.c @@ -1,4 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include "../../util/disasm.h" =20 static int is_branch_cond(const char *cond) { @@ -157,14 +160,12 @@ static const struct ins_ops *sparc__associate_instruc= tion_ops(struct arch *arch, return ops; } =20 -static int sparc__annotate_init(struct arch *arch, char *cpuid __maybe_unu= sed) +int sparc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { if (!arch->initialized) { arch->initialized =3D true; arch->associate_instruction_ops =3D sparc__associate_instruction_ops; arch->objdump.comment_char =3D '#'; - arch->e_machine =3D EM_SPARC; - arch->e_flags =3D 0; } =20 return 0; diff --git a/tools/perf/arch/x86/annotate/instructions.c b/tools/perf/util/= annotate-arch/annotate-x86.c similarity index 97% rename from tools/perf/arch/x86/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-x86.c index ffca3029388b..0c7957fe60da 100644 --- a/tools/perf/arch/x86/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-x86.c @@ -1,4 +1,16 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "../annotate-data.h" +#include "../debug.h" +#include "../disasm.h" +#include "../dso.h" +#include "../map.h" +#include "../string2.h" // strstarts +#include "../symbol.h" + /* * x86 instruction nmemonic table to parse disasm lines for annotate. * This table is searched twice - one for exact match and another for @@ -191,37 +203,6 @@ static int x86__cpuid_parse(struct arch *arch, char *c= puid) return -1; } =20 -static int x86__annotate_init(struct arch *arch, char *cpuid) -{ - int err =3D 0; - - if (arch->initialized) - return 0; - - if (cpuid) { - if (x86__cpuid_parse(arch, cpuid)) - err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; - } - -#ifndef NDEBUG - { - static bool sorted_check; - - if (!sorted_check) { - for (size_t i =3D 0; i < arch->nr_instructions - 1; i++) { - assert(strcmp(arch->instructions[i].name, - arch->instructions[i + 1].name) <=3D 0); - } - sorted_check =3D true; - } - } -#endif - arch->e_machine =3D EM_X86_64; - arch->e_flags =3D 0; - arch->initialized =3D true; - return err; -} - #ifdef HAVE_LIBDW_SUPPORT static void update_insn_state_x86(struct type_state *state, struct data_loc_info *dloc, Dwarf_Die *cu_die, @@ -795,3 +776,45 @@ static void update_insn_state_x86(struct type_state *s= tate, /* Case 4. memory to memory transfers (not handled for now) */ } #endif + +int x86__annotate_init(struct arch *arch, char *cpuid) +{ + int err =3D 0; + + if (arch->initialized) + return 0; + + if (cpuid) { + if (x86__cpuid_parse(arch, cpuid)) + err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; + } + + arch->instructions =3D x86__instructions; + arch->nr_instructions =3D ARRAY_SIZE(x86__instructions); +#ifndef NDEBUG + { + static bool sorted_check; + + if (!sorted_check) { + for (size_t i =3D 0; i < arch->nr_instructions - 1; i++) { + assert(strcmp(arch->instructions[i].name, + arch->instructions[i + 1].name) <=3D 0); + } + sorted_check =3D true; + } + } +#endif + arch->sorted_instructions =3D true; + arch->objdump.comment_char =3D '#'; + arch->objdump.register_char =3D '%'; + arch->objdump.memory_ref_char =3D '('; + arch->objdump.imm_char =3D '$'; + arch->insn_suffix =3D "bwlq"; + arch->e_machine =3D EM_X86_64; + arch->e_flags =3D 0; + arch->initialized =3D true; +#ifdef HAVE_LIBDW_SUPPORT + arch->update_insn_state =3D update_insn_state_x86; +#endif + return err; +} diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index b7523256c4ad..845c2d0f39b1 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -33,20 +33,15 @@ static regex_t file_lineno; =20 /* These can be referred from the arch-dependent code */ -static const struct ins_ops call_ops; -static const struct ins_ops dec_ops; -static const struct ins_ops jump_ops; -static const struct ins_ops mov_ops; -static const struct ins_ops nop_ops; -static const struct ins_ops lock_ops; -static const struct ins_ops ret_ops; -static const struct ins_ops load_store_ops; -static const struct ins_ops arithmetic_ops; - -static int jump__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name); -static int call__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name); +const struct ins_ops call_ops; +const struct ins_ops dec_ops; +const struct ins_ops jump_ops; +const struct ins_ops mov_ops; +const struct ins_ops nop_ops; +const struct ins_ops lock_ops; +const struct ins_ops ret_ops; +const struct ins_ops load_store_ops; +const struct ins_ops arithmetic_ops; =20 static void ins__sort(struct arch *arch); static int disasm_line__parse(char *line, const char **namep, char **rawp); @@ -86,7 +81,7 @@ static int arch__grow_instructions(struct arch *arch) goto out_update_instructions; } =20 -static int arch__associate_ins_ops(struct arch *arch, const char *name, co= nst struct ins_ops *ops) +int arch__associate_ins_ops(struct arch *arch, const char *name, const str= uct ins_ops *ops) { struct ins *ins; =20 @@ -106,90 +101,66 @@ static int arch__associate_ins_ops(struct arch *arch,= const char *name, const st return 0; } =20 -#include "arch/arc/annotate/instructions.c" -#include "arch/arm/annotate/instructions.c" -#include "arch/arm64/annotate/instructions.c" -#include "arch/csky/annotate/instructions.c" -#include "arch/loongarch/annotate/instructions.c" -#include "arch/mips/annotate/instructions.c" -#include "arch/x86/annotate/instructions.c" -#include "arch/powerpc/annotate/instructions.c" -#include "arch/riscv64/annotate/instructions.c" -#include "arch/s390/annotate/instructions.c" -#include "arch/sparc/annotate/instructions.c" - static struct arch architectures[] =3D { { .name =3D "arc", .init =3D arc__annotate_init, + .e_machine =3D EM_ARC, }, { .name =3D "arm", .init =3D arm__annotate_init, + .e_machine =3D EM_ARM, }, { .name =3D "arm64", .init =3D arm64__annotate_init, + .e_machine =3D EM_AARCH64, }, { .name =3D "csky", .init =3D csky__annotate_init, + .e_machine =3D EM_CSKY, +#if defined(__CSKYABIV2__) + .e_flags =3D EF_CSKY_ABIV2, +#else + .e_flags =3D EF_CSKY_ABIV1, +#endif }, { .name =3D "mips", .init =3D mips__annotate_init, - .objdump =3D { - .comment_char =3D '#', - }, + .e_machine =3D EM_MIPS, }, { .name =3D "x86", .init =3D x86__annotate_init, - .instructions =3D x86__instructions, - .nr_instructions =3D ARRAY_SIZE(x86__instructions), - .sorted_instructions =3D true, - .insn_suffix =3D "bwlq", - .objdump =3D { - .comment_char =3D '#', - .register_char =3D '%', - .memory_ref_char =3D '(', - .imm_char =3D '$', - }, -#ifdef HAVE_LIBDW_SUPPORT - .update_insn_state =3D update_insn_state_x86, -#endif + .e_machine =3D EM_X86_64, // TODO: EM_386 too. }, { .name =3D "powerpc", .init =3D powerpc__annotate_init, -#ifdef HAVE_LIBDW_SUPPORT - .update_insn_state =3D update_insn_state_powerpc, -#endif + .e_machine =3D EM_PPC, // TODO: EM_PPC64 too. }, { .name =3D "riscv64", .init =3D riscv64__annotate_init, + .e_machine =3D EM_RISCV, }, { .name =3D "s390", .init =3D s390__annotate_init, - .objdump =3D { - .comment_char =3D '#', - }, + .e_machine =3D EM_S390, }, { .name =3D "sparc", .init =3D sparc__annotate_init, - .objdump =3D { - .comment_char =3D '#', - }, + .e_machine =3D EM_SPARC, }, { .name =3D "loongarch", .init =3D loongarch__annotate_init, - .objdump =3D { - .comment_char =3D '#', - }, + .e_machine =3D EM_LOONGARCH, }, }; =20 @@ -248,14 +219,14 @@ static void ins_ops__delete(struct ins_operands *ops) zfree(&ops->target.name); } =20 -static int ins__raw_scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name) +int ins__raw_scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->raw); } =20 -static int ins__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name) +int ins__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) { if (ins->ops->scnprintf) return ins->ops->scnprintf(ins, bf, size, ops, max_ins_name); @@ -326,8 +297,8 @@ static int call__parse(const struct arch *arch, struct = ins_operands *ops, struct goto find_target; } =20 -static int call__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name) +int call__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) { if (ops->target.sym) return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->targ= et.sym->name); @@ -341,7 +312,7 @@ static int call__scnprintf(const struct ins *ins, char = *bf, size_t size, return scnprintf(bf, size, "%-*s *%" PRIx64, max_ins_name, ins->name, ops= ->target.addr); } =20 -static const struct ins_ops call_ops =3D { +const struct ins_ops call_ops =3D { .parse =3D call__parse, .scnprintf =3D call__scnprintf, }; @@ -453,8 +424,8 @@ static int jump__parse(const struct arch *arch, struct = ins_operands *ops, struct return 0; } =20 -static int jump__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name) +int jump__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) { const char *c; =20 @@ -494,7 +465,7 @@ static void jump__delete(struct ins_operands *ops __may= be_unused) */ } =20 -static const struct ins_ops jump_ops =3D { +const struct ins_ops jump_ops =3D { .free =3D jump__delete, .parse =3D jump__parse, .scnprintf =3D jump__scnprintf, @@ -586,7 +557,7 @@ static void lock__delete(struct ins_operands *ops) zfree(&ops->target.name); } =20 -static const struct ins_ops lock_ops =3D { +const struct ins_ops lock_ops =3D { .free =3D lock__delete, .parse =3D lock__parse, .scnprintf =3D lock__scnprintf, @@ -687,103 +658,19 @@ static int mov__parse(const struct arch *arch, struc= t ins_operands *ops, return -1; } =20 -static int mov__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name) +int mov__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s,%s", max_ins_name, ins->name, ops->source.name ?: ops->source.raw, ops->target.name ?: ops->target.raw); } =20 -static const struct ins_ops mov_ops =3D { +const struct ins_ops mov_ops =3D { .parse =3D mov__parse, .scnprintf =3D mov__scnprintf, }; =20 -#define PPC_22_30(R) (((R) >> 1) & 0x1ff) -#define MINUS_EXT_XO_FORM 234 -#define SUB_EXT_XO_FORM 232 -#define ADD_ZERO_EXT_XO_FORM 202 -#define SUB_ZERO_EXT_XO_FORM 200 - -static int arithmetic__scnprintf(const struct ins *ins, char *bf, size_t s= ize, - struct ins_operands *ops, int max_ins_name) -{ - return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, - ops->raw); -} - -/* - * Sets the fields: multi_regs and "mem_ref". - * "mem_ref" is set for ops->source which is later used to - * fill the objdump->memory_ref-char field. This ops is currently - * used by powerpc and since binary instruction code is used to - * extract opcode, regs and offset, no other parsing is needed here. - * - * Dont set multi regs for 4 cases since it has only one operand - * for source: - * - Add to Minus One Extended XO-form ( Ex: addme, addmeo ) - * - Subtract From Minus One Extended XO-form ( Ex: subfme ) - * - Add to Zero Extended XO-form ( Ex: addze, addzeo ) - * - Subtract From Zero Extended XO-form ( Ex: subfze ) - */ -static int arithmetic__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, - struct map_symbol *ms __maybe_unused, struct disasm_line *dl) -{ - int opcode =3D PPC_OP(dl->raw.raw_insn); - - ops->source.mem_ref =3D false; - if (opcode =3D=3D 31) { - if ((opcode !=3D MINUS_EXT_XO_FORM) && (opcode !=3D SUB_EXT_XO_FORM) \ - && (opcode !=3D ADD_ZERO_EXT_XO_FORM) && (opcode !=3D SUB_ZERO_EXT_XO_= FORM)) - ops->source.multi_regs =3D true; - } - - ops->target.mem_ref =3D false; - ops->target.multi_regs =3D false; - - return 0; -} - -static const struct ins_ops arithmetic_ops =3D { - .parse =3D arithmetic__parse, - .scnprintf =3D arithmetic__scnprintf, -}; - -static int load_store__scnprintf(const struct ins *ins, char *bf, size_t s= ize, - struct ins_operands *ops, int max_ins_name) -{ - return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, - ops->raw); -} - -/* - * Sets the fields: multi_regs and "mem_ref". - * "mem_ref" is set for ops->source which is later used to - * fill the objdump->memory_ref-char field. This ops is currently - * used by powerpc and since binary instruction code is used to - * extract opcode, regs and offset, no other parsing is needed here - */ -static int load_store__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, - struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unu= sed) -{ - ops->source.mem_ref =3D true; - ops->source.multi_regs =3D false; - /* opcode 31 is of X form */ - if (PPC_OP(dl->raw.raw_insn) =3D=3D 31) - ops->source.multi_regs =3D true; - - ops->target.mem_ref =3D false; - ops->target.multi_regs =3D false; - - return 0; -} - -static const struct ins_ops load_store_ops =3D { - .parse =3D load_store__parse, - .scnprintf =3D load_store__scnprintf, -}; - static int dec__parse(const struct arch *arch __maybe_unused, struct ins_o= perands *ops, struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unused) @@ -820,7 +707,7 @@ static int dec__scnprintf(const struct ins *ins, char *= bf, size_t size, ops->target.name ?: ops->target.raw); } =20 -static const struct ins_ops dec_ops =3D { +const struct ins_ops dec_ops =3D { .parse =3D dec__parse, .scnprintf =3D dec__scnprintf, }; @@ -831,11 +718,11 @@ static int nop__scnprintf(const struct ins *ins __may= be_unused, char *bf, size_t return scnprintf(bf, size, "%-*s", max_ins_name, "nop"); } =20 -static const struct ins_ops nop_ops =3D { +const struct ins_ops nop_ops =3D { .scnprintf =3D nop__scnprintf, }; =20 -static const struct ins_ops ret_ops =3D { +const struct ins_ops ret_ops =3D { .scnprintf =3D ins__raw_scnprintf, }; =20 diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index db7f1ee3d8e7..83503c5075f9 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -109,6 +109,28 @@ const struct arch *arch__find(const char *name); bool arch__is_x86(const struct arch *arch); bool arch__is_powerpc(const struct arch *arch); =20 +extern const struct ins_ops call_ops; +extern const struct ins_ops dec_ops; +extern const struct ins_ops jump_ops; +extern const struct ins_ops mov_ops; +extern const struct ins_ops nop_ops; +extern const struct ins_ops lock_ops; +extern const struct ins_ops ret_ops; + +int arch__associate_ins_ops(struct arch *arch, const char *name, const str= uct ins_ops *ops); + +int arc__annotate_init(struct arch *arch, char *cpuid); +int arm__annotate_init(struct arch *arch, char *cpuid); +int arm64__annotate_init(struct arch *arch, char *cpuid); +int csky__annotate_init(struct arch *arch, char *cpuid); +int loongarch__annotate_init(struct arch *arch, char *cpuid); +int mips__annotate_init(struct arch *arch, char *cpuid); +int powerpc__annotate_init(struct arch *arch, char *cpuid); +int riscv64__annotate_init(struct arch *arch, char *cpuid); +int s390__annotate_init(struct arch *arch, char *cpuid); +int sparc__annotate_init(struct arch *arch, char *cpuid); +int x86__annotate_init(struct arch *arch, char *cpuid); + const struct ins_ops *ins__find(const struct arch *arch, const char *name,= struct disasm_line *dl); =20 bool ins__is_call(const struct ins *ins); @@ -117,12 +139,28 @@ bool ins__is_fused(const struct arch *arch, const cha= r *ins1, const char *ins2); bool ins__is_ret(const struct ins *ins); bool ins__is_lock(const struct ins *ins); =20 +extern const struct ins_ops s390_call_ops; +extern const struct ins_ops loongarch_call_ops; +extern const struct ins_ops loongarch_jump_ops; +const struct ins_ops *check_ppc_insn(struct disasm_line *dl); + struct disasm_line *disasm_line__new(struct annotate_args *args); void disasm_line__free(struct disasm_line *dl); =20 int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name); =20 +int ins__raw_scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name); +int ins__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name); +int call__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name); +int jump__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name); +int mov__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name); + int symbol__disassemble(struct symbol *sym, struct annotate_args *args); =20 char *expand_tabs(char *line, char **storage, size_t *storage_len); --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 541D33C1FED for ; Thu, 22 Jan 2026 21:35:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117752; cv=none; b=Le8mG88wJidWQ3DpotOa9pudOQ7h16lYw8gwfPkTqwgp11qFx9e6Q8rJNoWnRbLkpwovtgLR6gsmXBTgipQGMLwZGOzfPKmTXsLrBWr1x2m/5M/M+n+DUWIndi/OQB27eYzhwmGcstmiarvciT3AgZHU3MVr+TbJPqqM760Hx5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117752; c=relaxed/simple; bh=/4t52AvyWDIvlIx3zdnelq0uOogrQvoAgZggoWjNLIQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=QO4SFS0k6JSTkILwzJOwInLgCcQDW85cAlW1WkEblAETZZcKdjlc12uoDhLOLUVa5kjdzxgvlyDmIYCXvjI8ylANDUZe10lUPIDq+sSKwhUbix0mWouRTu1GqFzmRYRWYrZI8UMGSsZV2pMecPQks7+xb7MFlP6EsfKKHLg/P7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=K5X30jG6; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="K5X30jG6" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b708fa4093so4324921eec.0 for ; Thu, 22 Jan 2026 13:35:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117741; x=1769722541; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Xlxy7gGNB7fnsuI8qX0WFdpap2bNeW5xmXABoxpIzho=; b=K5X30jG6zcPq+d8xQn4tUPtcYCXPCiWMyKIuIMN0F0vRqs3PL3F4tXC4W/UjKib34I VJD6KVgHhaGq13IYvxk7i5kgFdUaER47vwbYS2V7fhLadKI3EB1q4xv/20W4btJxsejL zGe4bv+5Y6MhcAVYR+VAWfi774hcowZmQcGyNL3bI5S7+uVLrGJ2MCClOYmXXWm78d30 WwC2n8b9FagDgjmO4KMcJcKB8hgVnEov7FyxXF7hbsQgLSE2gDGFW2Qt8buQBbAfColw JyYyDisdAYVKV37iSY2dERtDNyrCiK18EhH7zkYbgaIYk3dIO35HRtKgvwt0UJz0b2gs TUTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117741; x=1769722541; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Xlxy7gGNB7fnsuI8qX0WFdpap2bNeW5xmXABoxpIzho=; b=dcL0BQgIEprOHxNb0tutGg5K64GBLREsRe6MM5Sxr1809Gh1Xc+I4vNVT8Yt0+JgGQ t8yYZQVLZq9qd8JEIeK6bbaz0Jn7spkOGj1XFBT798rkMalL+X+/DyLDuX6+683mpEJU sYW5XmjbeYjRWvmRioFGM6T2ar4jgj0JaNzbuGfkOJ1rEfv1SMcDirQhGzO7pR7T/+BD 9d6PoV1bdVrXhzk8tcFTv5KysoiGkQJaF4n+P8ERKqmiOezNEfXEAug32xAKcDEW2v9p 6i9aqYea3BZUae4o+FBHZgXtZx95oTQ8sdPsliU023Jg4bQ/Wiisgksrr+EWl39aSAFM 926w== X-Forwarded-Encrypted: i=1; AJvYcCUYIYqDgXYMiKckjSl34aeuB23FpKwlWMbaOI2KJ0gPF3Al7yCtyRFxPXCq4qqgScwcLOOsEiCjPZ96nIA=@vger.kernel.org X-Gm-Message-State: AOJu0Yxq0BkROKr3ch4F6gfEKVAmpnrheJ4cXoBIFMTf04Y1EO4cEyua Vf0zn+t0UTfpu7hKU34aE8znc7gXui9OI6bCF7w1i5CmXW9U/jp8JB5XwNv/SOK5gqQF1I5KChX Qx5GLPg9ing== X-Received: from dybqo12.prod.google.com ([2002:a05:7301:678c:b0:2b6:b6b8:7fee]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:578e:b0:2ae:53da:9787 with SMTP id 5a478bee46e88-2b739beb0bamr355131eec.40.1769117740757; Thu, 22 Jan 2026 13:35:40 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:13 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-10-irogers@google.com> Subject: [PATCH v3 09/12] perf disasm: Refactor ins__is_call/jump to avoid exposing arch ins_ops From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add booleans indicating whether and ins_ops are call or jump and return it. This avoids exposing loongarch and s390 ins_ops for the sake of matching. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/util/annotate-arch/annotate-loongarch.c | 6 ++++-- tools/perf/util/annotate-arch/annotate-s390.c | 3 ++- tools/perf/util/disasm.c | 6 ++++-- tools/perf/util/disasm.h | 5 ++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/annotate-arch/annotate-loongarch.c b/tools/per= f/util/annotate-arch/annotate-loongarch.c index 32df10f6fed5..79dc116ade2f 100644 --- a/tools/perf/util/annotate-arch/annotate-loongarch.c +++ b/tools/perf/util/annotate-arch/annotate-loongarch.c @@ -57,9 +57,10 @@ static int loongarch_call__parse(const struct arch *arch= , struct ins_operands *o return 0; } =20 -const struct ins_ops loongarch_call_ops =3D { +static const struct ins_ops loongarch_call_ops =3D { .parse =3D loongarch_call__parse, .scnprintf =3D call__scnprintf, + .is_call =3D true, }; =20 static int loongarch_jump__parse(const struct arch *arch, struct ins_opera= nds *ops, @@ -106,9 +107,10 @@ static int loongarch_jump__parse(const struct arch *ar= ch, struct ins_operands *o return 0; } =20 -const struct ins_ops loongarch_jump_ops =3D { +static const struct ins_ops loongarch_jump_ops =3D { .parse =3D loongarch_jump__parse, .scnprintf =3D jump__scnprintf, + .is_jump =3D true, }; =20 static diff --git a/tools/perf/util/annotate-arch/annotate-s390.c b/tools/perf/uti= l/annotate-arch/annotate-s390.c index 81db102b3e15..7b2d27b62e6b 100644 --- a/tools/perf/util/annotate-arch/annotate-s390.c +++ b/tools/perf/util/annotate-arch/annotate-s390.c @@ -57,9 +57,10 @@ static int s390_call__parse(const struct arch *arch, str= uct ins_operands *ops, return 0; } =20 -const struct ins_ops s390_call_ops =3D { +static const struct ins_ops s390_call_ops =3D { .parse =3D s390_call__parse, .scnprintf =3D call__scnprintf, + .is_call =3D true, }; =20 static int s390_mov__parse(const struct arch *arch __maybe_unused, diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 845c2d0f39b1..8c3e9094600a 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -315,11 +315,12 @@ int call__scnprintf(const struct ins *ins, char *bf, = size_t size, const struct ins_ops call_ops =3D { .parse =3D call__parse, .scnprintf =3D call__scnprintf, + .is_call =3D true, }; =20 bool ins__is_call(const struct ins *ins) { - return ins->ops =3D=3D &call_ops || ins->ops =3D=3D &s390_call_ops || ins= ->ops =3D=3D &loongarch_call_ops; + return ins->ops && ins->ops->is_call; } =20 /* @@ -469,11 +470,12 @@ const struct ins_ops jump_ops =3D { .free =3D jump__delete, .parse =3D jump__parse, .scnprintf =3D jump__scnprintf, + .is_jump =3D true, }; =20 bool ins__is_jump(const struct ins *ins) { - return ins->ops =3D=3D &jump_ops || ins->ops =3D=3D &loongarch_jump_ops; + return ins->ops && ins->ops->is_jump; } =20 static int comment__symbol(char *raw, char *comment, u64 *addrp, char **na= mep) diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index 83503c5075f9..b6a2a30fdf27 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -93,6 +93,8 @@ struct ins_ops { struct disasm_line *dl); int (*scnprintf)(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); + bool is_jump; + bool is_call; }; =20 struct annotate_args { @@ -139,9 +141,6 @@ bool ins__is_fused(const struct arch *arch, const char = *ins1, const char *ins2); bool ins__is_ret(const struct ins *ins); bool ins__is_lock(const struct ins *ins); =20 -extern const struct ins_ops s390_call_ops; -extern const struct ins_ops loongarch_call_ops; -extern const struct ins_ops loongarch_jump_ops; const struct ins_ops *check_ppc_insn(struct disasm_line *dl); =20 struct disasm_line *disasm_line__new(struct annotate_args *args); --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 208143BE4BD for ; Thu, 22 Jan 2026 21:35:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117752; cv=none; b=j2+9SsJIJp3ZqMWEER9cVys6Mlh7VmEDTkRwNsQ52BP4I3Gtlg3Ez9iB2m46ZH1Paix55w6nn4GSJoazjn5CxHpxFqHhojLTNdbfuvp4gR3eVyUNX9s/tm35Ql+TpwdCja2PC854+3X48wLyJFo647LgtyaBUJtMVKYXDs1Uskg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117752; c=relaxed/simple; bh=Fw5zeAM2zfnnadmaZE6GhH2s1pBqPvkeHIHlR9oq9uk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=O2aCrHVad1m5cIenxNNrLQWRMpWneD3bhmax59qYhKjdAldn+eLK3Yc8sVnnYlKwv408qIteLTRxeIiU/ROUOdyqAJtMverzOwokQypMouwiRPMCJehHE0SC4B0ANenLluFh7fiTvxIPx6B0SFNvppIVY7R+X1a1NLDE6snj2c0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KnCAdwpL; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KnCAdwpL" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12337114f3fso2281711c88.0 for ; Thu, 22 Jan 2026 13:35:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117743; x=1769722543; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=ad2GwIvXnuBM0K5HE3V72oHuf8IYiJKy1/A8wVQtlzk=; b=KnCAdwpLsG2dVgnmxZCl6HLcWF2VccllboYK9xHyy9JatP1Qex7zPi0MKNwnt1NEPJ lrPZlTwk+GpcmMKp9+8u9USL+FbXCswUrmqBfRYQtdl1fE44aYHazOUU3HkRzm+DLqbW zgtkD10KGpJ9C0DzdLG3mxODzNdqFYK1/9Yw5484Mvn3vuVojIuItBAlC4JoSHAG9CfL wvifQFwYTE/pl4Bs2zdqzbIP0BobvJWvPuRVenSy6YMui5exXcHhtvTmGy4ZULSYei8q 0Y0PhzrZYdWlFbYuMtSmaiQXE1bIfJ/ALGeCer6Kvc6z3opvob3yxeJ4htpfCpxmk3Za fWsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117743; x=1769722543; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ad2GwIvXnuBM0K5HE3V72oHuf8IYiJKy1/A8wVQtlzk=; b=lL91Xct7t4i7yIS2ML9yFPtKWys7LNbBVAq8lEDrAqZRJdOUK+XQVfkhfWgTaTiFV0 lxSM19hbiE43FOsQupx6iouqmZpl3KWonNoUo6Rg2xrb9b1o6S+8lbmb3IVamxBUd3Dr JQ93zJh8qddHQsOrZ+hgrvjEOu8cq7QLJTPZawsBrwuf2h0FQ02GcY3cmZTIwINLzUGM G+lSWbYxu7dICOHbiEXt67ihcuy+59AOvFRiqAfbnrZjMrdFGrpUpSztJIeFkrbSqXMz YYf1ui4ii3alZ1+uWJRaizsaCD3zKIbOqy6o0VHOPbdrSSLDwLy0Ri7hWswp7I+Vsl7w kUGA== X-Forwarded-Encrypted: i=1; AJvYcCWDJakAdeDqXZbHb2x3jl1B2aeSxiHgRcvHcPrtw+5n5Y5BkK/yW6/CLswG4xJBktY7hpJxNOHYHjf6qpk=@vger.kernel.org X-Gm-Message-State: AOJu0YyeC9oYnCkLhRc/WWuN/6DCQH84R8wOuJAXWrMj1v4uPfaLO0UO hoOh4yUsCI7Afe8kySFIUG8fk+42NFbwMjAOQiony99GCNxt8lKvAsWjKldK98oDEv3j7ExOTqP iY4V21D/MFw== X-Received: from dlbbu7.prod.google.com ([2002:a05:7022:2207:b0:123:2708:9404]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:1a84:b0:11b:9b98:aa4b with SMTP id a92af1059eb24-1247dba3c37mr405972c88.6.1769117742699; Thu, 22 Jan 2026 13:35:42 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:14 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-11-irogers@google.com> Subject: [PATCH v3 10/12] perf map_symbol: Switch from holding maps to holding thread From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" maps may belong to >1 thread. In contexts like symbolization information from the thread may be useful, such as the ELF machine. As the maps can be gained from the thread switch from holding maps in struct map_symbol to holding the thread. Holding the maps in addr_location is also redundant, switch this to using thread__maps. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/ui/browsers/hists.c | 3 ++- tools/perf/util/addr_location.c | 4 ---- tools/perf/util/addr_location.h | 1 - .../util/annotate-arch/annotate-loongarch.c | 5 +++-- tools/perf/util/annotate-arch/annotate-s390.c | 3 ++- tools/perf/util/callchain.c | 12 +++++++----- tools/perf/util/capstone.c | 6 ++++-- tools/perf/util/db-export.c | 1 - tools/perf/util/disasm.c | 7 ++++--- tools/perf/util/event.c | 2 -- tools/perf/util/hist.c | 18 +++++++++--------- tools/perf/util/machine.c | 13 +++++++------ tools/perf/util/map_symbol.c | 5 +++-- tools/perf/util/map_symbol.h | 3 ++- tools/perf/util/sort.c | 2 +- tools/perf/util/unwind-libdw.c | 2 +- tools/perf/util/unwind-libunwind-local.c | 2 +- 18 files changed, 47 insertions(+), 44 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 3df61cd46652..91ded9c271ee 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -601,7 +601,7 @@ static bool annotate_browser__callq(struct annotate_bro= wser *browser, return true; } =20 - target_ms.maps =3D ms->maps; + target_ms.thread =3D ms->thread; target_ms.map =3D ms->map; target_ms.sym =3D dl->ops.target.sym; annotation__unlock(notes); diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 08fecbe28a52..cfa6386e6e1d 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -3189,7 +3189,8 @@ static int evsel__hists_browse(struct evsel *evsel, i= nt nr_events, const char *h case 'k': if (browser->selection !=3D NULL) hists_browser__zoom_map(browser, - maps__machine(browser->selection->maps)->vmlinux_map); + maps__machine(thread__maps(browser->selection->thread) + )->vmlinux_map); continue; case 'V': verbose =3D (verbose + 1) % 4; diff --git a/tools/perf/util/addr_location.c b/tools/perf/util/addr_locatio= n.c index 81a0b79c5e10..57e8217a00f9 100644 --- a/tools/perf/util/addr_location.c +++ b/tools/perf/util/addr_location.c @@ -7,7 +7,6 @@ void addr_location__init(struct addr_location *al) { al->thread =3D NULL; - al->maps =3D NULL; al->map =3D NULL; al->sym =3D NULL; al->srcline =3D NULL; @@ -30,16 +29,13 @@ void addr_location__exit(struct addr_location *al) { map__zput(al->map); thread__zput(al->thread); - maps__zput(al->maps); } =20 void addr_location__copy(struct addr_location *dst, struct addr_location *= src) { thread__put(dst->thread); - maps__put(dst->maps); map__put(dst->map); *dst =3D *src; dst->thread =3D thread__get(src->thread); - dst->maps =3D maps__get(src->maps); dst->map =3D map__get(src->map); } diff --git a/tools/perf/util/addr_location.h b/tools/perf/util/addr_locatio= n.h index 64b551025216..fdc4d3f3a68b 100644 --- a/tools/perf/util/addr_location.h +++ b/tools/perf/util/addr_location.h @@ -11,7 +11,6 @@ struct symbol; =20 struct addr_location { struct thread *thread; - struct maps *maps; struct map *map; struct symbol *sym; const char *srcline; diff --git a/tools/perf/util/annotate-arch/annotate-loongarch.c b/tools/per= f/util/annotate-arch/annotate-loongarch.c index 79dc116ade2f..6c94cb98a104 100644 --- a/tools/perf/util/annotate-arch/annotate-loongarch.c +++ b/tools/perf/util/annotate-arch/annotate-loongarch.c @@ -11,6 +11,7 @@ #include "../map.h" #include "../maps.h" #include "../symbol.h" +#include "../thread.h" =20 static int loongarch_call__parse(const struct arch *arch, struct ins_opera= nds *ops, struct map_symbol *ms, @@ -49,7 +50,7 @@ static int loongarch_call__parse(const struct arch *arch,= struct ins_operands *o .addr =3D map__objdump_2mem(map, ops->target.addr), }; =20 - if (maps__find_ams(ms->maps, &target) =3D=3D 0 && + if (maps__find_ams(thread__maps(ms->thread), &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 @@ -93,7 +94,7 @@ static int loongarch_jump__parse(const struct arch *arch,= struct ins_operands *o =20 ops->target.outside =3D target.addr < start || target.addr > end; =20 - if (maps__find_ams(ms->maps, &target) =3D=3D 0 && + if (maps__find_ams(thread__maps(ms->thread), &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 diff --git a/tools/perf/util/annotate-arch/annotate-s390.c b/tools/perf/uti= l/annotate-arch/annotate-s390.c index 7b2d27b62e6b..47573f0310c1 100644 --- a/tools/perf/util/annotate-arch/annotate-s390.c +++ b/tools/perf/util/annotate-arch/annotate-s390.c @@ -6,6 +6,7 @@ #include "../map.h" #include "../maps.h" #include "../symbol.h" +#include "../thread.h" #include "../annotate.h" #include "../annotate-data.h" =20 @@ -49,7 +50,7 @@ static int s390_call__parse(const struct arch *arch, stru= ct ins_operands *ops, .addr =3D map__objdump_2mem(map, ops->target.addr), }; =20 - if (maps__find_ams(ms->maps, &target) =3D=3D 0 && + if (maps__find_ams(thread__maps(ms->thread), &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 428e5350d7a2..515bb8b5da01 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -31,6 +31,7 @@ #include "callchain.h" #include "branch.h" #include "symbol.h" +#include "thread.h" #include "util.h" #include "../perf.h" =20 @@ -1042,7 +1043,7 @@ merge_chain_branch(struct callchain_cursor *cursor, =20 list_for_each_entry_safe(list, next_list, &src->val, list) { struct map_symbol ms =3D { - .maps =3D maps__get(list->ms.maps), + .thread =3D thread__get(list->ms.thread), .map =3D map__get(list->ms.map), }; callchain_cursor_append(cursor, list->ip, &ms, false, NULL, 0, 0, 0, lis= t->srcline); @@ -1147,10 +1148,11 @@ int hist_entry__append_callchain(struct hist_entry = *he, struct perf_sample *samp int fill_callchain_info(struct addr_location *al, struct callchain_cursor_= node *node, bool hide_unresolved) { - struct machine *machine =3D node->ms.maps ? maps__machine(node->ms.maps) = : NULL; + struct machine *machine =3D NULL; + + if (node->ms.thread) + machine =3D maps__machine(thread__maps(node->ms.thread)); =20 - maps__put(al->maps); - al->maps =3D maps__get(node->ms.maps); map__put(al->map); al->map =3D map__get(node->ms.map); al->sym =3D node->ms.sym; @@ -1163,7 +1165,7 @@ int fill_callchain_info(struct addr_location *al, str= uct callchain_cursor_node * if (al->map =3D=3D NULL) goto out; } - if (maps__equal(al->maps, machine__kernel_maps(machine))) { + if (maps__equal(thread__maps(al->thread), machine__kernel_maps(machine)))= { if (machine__is_host(machine)) { al->cpumode =3D PERF_RECORD_MISC_KERNEL; al->level =3D 'k'; diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c index ce06cfd253ef..9216916f848f 100644 --- a/tools/perf/util/capstone.c +++ b/tools/perf/util/capstone.c @@ -268,7 +268,8 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(args->ms->maps), &handle, is_64bit, disas= sembler_style) < 0) + if (capstone_init(maps__machine(thread__maps(args->ms->thread)), &handle,= is_64bit, + disassembler_style) < 0) goto err; =20 needs_cs_close =3D true; @@ -382,7 +383,8 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(args->ms->maps), &handle, is_64bit, disas= sembler_style) < 0) + if (capstone_init(maps__machine(thread__maps(args->ms->thread)), &handle,= is_64bit, + disassembler_style) < 0) goto err; =20 needs_cs_close =3D true; diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index 8f52e8cefcf3..ae9a9065aab7 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -254,7 +254,6 @@ static struct call_path *call_path_from_sample(struct d= b_export *dbe, addr_location__init(&al); al.sym =3D node->ms.sym; al.map =3D map__get(node->ms.map); - al.maps =3D maps__get(thread__maps(thread)); al.addr =3D node->ip; al.thread =3D thread__get(thread); =20 diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 8c3e9094600a..d81469db0aac 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -28,6 +28,7 @@ #include "namespaces.h" #include "srcline.h" #include "symbol.h" +#include "thread.h" #include "util.h" =20 static regex_t file_lineno; @@ -277,7 +278,7 @@ static int call__parse(const struct arch *arch, struct = ins_operands *ops, struct .addr =3D map__objdump_2mem(map, ops->target.addr), }; =20 - if (maps__find_ams(ms->maps, &target) =3D=3D 0 && + if (maps__find_ams(thread__maps(ms->thread), &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 @@ -411,7 +412,7 @@ static int jump__parse(const struct arch *arch, struct = ins_operands *ops, struct * Actual navigation will come next, with further understanding of how * the symbol searching and disassembly should be done. */ - if (maps__find_ams(ms->maps, &target) =3D=3D 0 && + if (maps__find_ams(thread__maps(ms->thread), &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 @@ -1074,7 +1075,7 @@ static int symbol__parse_objdump_line(struct symbol *= sym, .ms =3D { .map =3D map__get(map), }, }; =20 - if (!maps__find_ams(args->ms->maps, &target) && + if (!maps__find_ams(thread__maps(args->ms->thread), &target) && target.ms.sym->start =3D=3D target.al_addr) dl->ops.target.sym =3D target.ms.sym; =20 diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 2dde1044b5a7..bc045fddf7d5 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -698,7 +698,6 @@ struct map *thread__find_map(struct thread *thread, u8 = cpumode, u64 addr, struct machine *machine =3D maps__machine(maps); bool load_map =3D false; =20 - maps__zput(al->maps); map__zput(al->map); thread__zput(al->thread); al->thread =3D thread__get(thread); @@ -736,7 +735,6 @@ struct map *thread__find_map(struct thread *thread, u8 = cpumode, u64 addr, =20 return NULL; } - al->maps =3D maps__get(maps); al->map =3D maps__find(maps, al->addr); if (al->map !=3D NULL) { /* diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index ef4b569f7df4..7ffaa3d9851b 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -251,7 +251,7 @@ void hists__calc_col_len(struct hists *hists, struct hi= st_entry *h) =20 if (h->cgroup) { const char *cgrp_name =3D "unknown"; - struct cgroup *cgrp =3D cgroup__find(maps__machine(h->ms.maps)->env, + struct cgroup *cgrp =3D cgroup__find(maps__machine(thread__maps(h->ms.th= read))->env, h->cgroup); if (cgrp !=3D NULL) cgrp_name =3D cgrp->name; @@ -536,7 +536,7 @@ static int hist_entry__init(struct hist_entry *he, memset(&he->stat, 0, sizeof(he->stat)); } =20 - he->ms.maps =3D maps__get(he->ms.maps); + he->ms.thread =3D thread__get(he->ms.thread); he->ms.map =3D map__get(he->ms.map); =20 if (he->branch_info) { @@ -552,9 +552,9 @@ static int hist_entry__init(struct hist_entry *he, memcpy(he->branch_info, template->branch_info, sizeof(*he->branch_info)); =20 - he->branch_info->from.ms.maps =3D maps__get(he->branch_info->from.ms.map= s); + he->branch_info->from.ms.thread =3D thread__get(he->branch_info->from.ms= .thread); he->branch_info->from.ms.map =3D map__get(he->branch_info->from.ms.map); - he->branch_info->to.ms.maps =3D maps__get(he->branch_info->to.ms.maps); + he->branch_info->to.ms.thread =3D thread__get(he->branch_info->to.ms.thr= ead); he->branch_info->to.ms.map =3D map__get(he->branch_info->to.ms.map); } =20 @@ -810,7 +810,7 @@ __hists__add_entry(struct hists *hists, }, .cgroup =3D sample->cgroup, .ms =3D { - .maps =3D al->maps, + .thread =3D al->thread, .map =3D al->map, .sym =3D al->sym, }, @@ -890,7 +890,7 @@ struct hist_entry *hists__add_entry_block(struct hists = *hists, .block_info =3D block_info, .hists =3D hists, .ms =3D { - .maps =3D al->maps, + .thread =3D al->thread, .map =3D al->map, .sym =3D al->sym, }, @@ -1020,8 +1020,8 @@ iter_next_branch_entry(struct hist_entry_iter *iter, = struct addr_location *al) if (iter->curr >=3D iter->total) return 0; =20 - maps__put(al->maps); - al->maps =3D maps__get(bi[i].to.ms.maps); + thread__put(al->thread); + al->thread =3D thread__get(bi[i].to.ms.thread); map__put(al->map); al->map =3D map__get(bi[i].to.ms.map); al->sym =3D bi[i].to.ms.sym; @@ -1232,7 +1232,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter= *iter, .comm =3D thread__comm(al->thread), .ip =3D al->addr, .ms =3D { - .maps =3D al->maps, + .thread =3D al->thread, .map =3D al->map, .sym =3D al->sym, }, diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 30d606fbf040..5b0f5a48ffd4 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2016,7 +2016,7 @@ static void ip__resolve_ams(struct thread *thread, ams->addr =3D ip; ams->al_addr =3D al.addr; ams->al_level =3D al.level; - ams->ms.maps =3D maps__get(al.maps); + ams->ms.thread =3D thread__get(al.thread); ams->ms.sym =3D al.sym; ams->ms.map =3D map__get(al.map); ams->phys_addr =3D 0; @@ -2037,7 +2037,7 @@ static void ip__resolve_data(struct thread *thread, ams->addr =3D addr; ams->al_addr =3D al.addr; ams->al_level =3D al.level; - ams->ms.maps =3D maps__get(al.maps); + ams->ms.thread =3D thread__get(al.thread); ams->ms.sym =3D al.sym; ams->ms.map =3D map__get(al.map); ams->phys_addr =3D phys_addr; @@ -2120,7 +2120,7 @@ static int append_inlines(struct callchain_cursor *cu= rsor, struct map_symbol *ms } =20 ilist_ms =3D (struct map_symbol) { - .maps =3D maps__get(ms->maps), + .thread =3D thread__get(ms->thread), .map =3D map__get(map), }; list_for_each_entry(ilist, &inline_node->val, list) { @@ -2220,7 +2220,7 @@ static int add_callchain_ip(struct thread *thread, iter_cycles =3D iter->cycles; } =20 - ms.maps =3D maps__get(al.maps); + ms.thread =3D thread__get(al.thread); ms.map =3D map__get(al.map); ms.sym =3D al.sym; =20 @@ -2383,7 +2383,7 @@ static void save_lbr_cursor_node(struct thread *threa= d, map_symbol__exit(&lbr_stitch->prev_lbr_cursor[idx].ms); memcpy(&lbr_stitch->prev_lbr_cursor[idx], cursor->curr, sizeof(struct callchain_cursor_node)); - lbr_stitch->prev_lbr_cursor[idx].ms.maps =3D maps__get(cursor->curr->ms.m= aps); + lbr_stitch->prev_lbr_cursor[idx].ms.thread =3D thread__get(cursor->curr->= ms.thread); lbr_stitch->prev_lbr_cursor[idx].ms.map =3D map__get(cursor->curr->ms.map= ); =20 lbr_stitch->prev_lbr_cursor[idx].valid =3D true; @@ -2596,7 +2596,8 @@ static bool has_stitched_lbr(struct thread *thread, memcpy(&stitch_node->cursor, &lbr_stitch->prev_lbr_cursor[i], sizeof(struct callchain_cursor_node)); =20 - stitch_node->cursor.ms.maps =3D maps__get(lbr_stitch->prev_lbr_cursor[i]= .ms.maps); + stitch_node->cursor.ms.thread =3D + thread__get(lbr_stitch->prev_lbr_cursor[i].ms.thread); stitch_node->cursor.ms.map =3D map__get(lbr_stitch->prev_lbr_cursor[i].m= s.map); =20 if (callee) diff --git a/tools/perf/util/map_symbol.c b/tools/perf/util/map_symbol.c index 6ad2960bc289..11bc0a7f704c 100644 --- a/tools/perf/util/map_symbol.c +++ b/tools/perf/util/map_symbol.c @@ -2,10 +2,11 @@ #include "map_symbol.h" #include "maps.h" #include "map.h" +#include "thread.h" =20 void map_symbol__exit(struct map_symbol *ms) { - maps__zput(ms->maps); + thread__zput(ms->thread); map__zput(ms->map); } =20 @@ -16,7 +17,7 @@ void addr_map_symbol__exit(struct addr_map_symbol *ams) =20 void map_symbol__copy(struct map_symbol *dst, struct map_symbol *src) { - dst->maps =3D maps__get(src->maps); + dst->thread =3D thread__get(src->thread); dst->map =3D map__get(src->map); dst->sym =3D src->sym; } diff --git a/tools/perf/util/map_symbol.h b/tools/perf/util/map_symbol.h index e370bb32ed47..7437e319f4a3 100644 --- a/tools/perf/util/map_symbol.h +++ b/tools/perf/util/map_symbol.h @@ -4,12 +4,13 @@ =20 #include =20 +struct thread; struct maps; struct map; struct symbol; =20 struct map_symbol { - struct maps *maps; + struct thread *thread; struct map *map; struct symbol *sym; }; diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index f963d61ac166..01a9d73ae348 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -1016,7 +1016,7 @@ static int hist_entry__cgroup_snprintf(struct hist_en= try *he, const char *cgrp_name =3D "N/A"; =20 if (he->cgroup) { - struct cgroup *cgrp =3D cgroup__find(maps__machine(he->ms.maps)->env, + struct cgroup *cgrp =3D cgroup__find(maps__machine(thread__maps(he->ms.t= hread))->env, he->cgroup); if (cgrp !=3D NULL) cgrp_name =3D cgrp->name; diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c index c1646ef5f971..9cb0960ef905 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c @@ -161,7 +161,7 @@ static int entry(u64 ip, struct unwind_info *ui) } =20 e->ip =3D ip; - e->ms.maps =3D maps__get(al.maps); + e->ms.thread =3D thread__get(al.thread); e->ms.map =3D map__get(al.map); e->ms.sym =3D al.sym; =20 diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unw= ind-libunwind-local.c index a24b45106acd..ecf0c01fe51f 100644 --- a/tools/perf/util/unwind-libunwind-local.c +++ b/tools/perf/util/unwind-libunwind-local.c @@ -666,7 +666,7 @@ static int entry(u64 ip, struct thread *thread, e.ms.sym =3D thread__find_symbol(thread, PERF_RECORD_MISC_USER, ip, &al); e.ip =3D ip; e.ms.map =3D al.map; - e.ms.maps =3D al.maps; + e.ms.thread =3D thread__get(al.thread); =20 pr_debug("unwind: %s:ip =3D 0x%" PRIx64 " (0x%" PRIx64 ")\n", al.sym ? al.sym->name : "''", --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE1283C23C3 for ; Thu, 22 Jan 2026 21:35:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117763; cv=none; b=b6Uv9w9e/yZhC0zKBCOkwOmMsyr5HNUFuC5ljYt71efMkPQurEBKd1jT2kACd1EKKSmaeHBcfJaHayEWa3gKKgwznFPV+XQ2HlzkhjxEaQ3Ta9H+yymG6hMJ8LYaUQGL3JkcnOF2iABxRzIUxG5o/BVoO2DpauFuPk6CprBLrFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117763; c=relaxed/simple; bh=NwFGOoTcKVwwV/YH4o31FgfuzG4YYi7ZB6uRptCduAQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=I8C2gLHiaLiYhMKjJMmxQ0bHNo7eBr+A3sr/05F6yvXxi1kWDh9UMvWQKUwHJoZdsoPCiOhwdaw2F3rViOFo8hCBxjIzgUhkZa9DV815hn6Ei949N/GHM0Lp+hR83rc8aH9J3Nkc9SQJQ73FpsTvd7exdnCO7GDYUHbEb/aSAMI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ntyg4ho0; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ntyg4ho0" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b722bc1be1so2290092eec.0 for ; Thu, 22 Jan 2026 13:35:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117745; x=1769722545; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=eDcfOmFRduQB0EoLjxExuXCkRWy+uierOMTnTsI2Mjs=; b=ntyg4ho0wQeuxguPzUy42byHvmz8VzYXuSdC0DYRKjr2HVByKYDkI8JELc1jCJtRuQ PQ0RFah+lZWhXoJx+MOcogJK3DrANPjPPLvI/DXjJYBecIj2vUvTYl+i9alcFcH3OPWL 9Afldzfc1ST8sfk47wwYi3/nqGsb1TlIzP49fSmzbbn0eanI37vdzqYQ/YRe+sK0Wnv2 bZkNO/LZg2LU3gBpA2fk7yzuE9d+3XTdLBE7pygvrSoEm6sAbhZpLMT6V1IfvZeYo9vT 8HKh9DlBP6MyiAjNnigphDiM87NMADrus/1PeD/8MHD0Eqw14DJ4C41QhawZ7f0+6vlq jPHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117745; x=1769722545; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eDcfOmFRduQB0EoLjxExuXCkRWy+uierOMTnTsI2Mjs=; b=TVOacwGI3YdaAm5MJiUJ+qhUMAMGCwNNQQbYvX07iiW4R2hC79GIpgvPH39T+eIhN5 QDqegEe2ax1h0YC9x9mq1UJ0OOl41xT3h4NCLZfEwMPJpTW8C0KLn8IhXmOUlX0V2ynb oPurh+2JjuiWLu5MjWaECYecTxeGNKn0xMfH8i9Hi/c8fbq2FoobwZ4c+unUGL6W6ynu x/cOQhQlXyQiizsWTHqIA2NycQqQ8z+sWHh49uP08j8ftfqt48QDZGMOq4PkMyXd/m0G AHFIEWCvAJK/AhzKq5CTgh7I6TjZZUQr3D5nmKokMjEjgr++9J+XPsUbR02Sn6LyctEp jvPw== X-Forwarded-Encrypted: i=1; AJvYcCXaVspLDxEjDJr/yuY42ckXHoiEvgvQnP0Wnm7XIPeeGeVgRTF/bLFsEak5eCT8JlG2YKtXonXGJUdWrx4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6HpyaPei/9yC68PhoLZHFoIXj8aVmwO/yrgSkVyXFAb2Er7XQ LEKp9tIA7KLfCVGsbyncCObqkp4YAQcLK/hEhPvchbXLJDN1PHMNSreQVRfsI+zNHtO2w7kPcdW vhN5v7SlRdw== X-Received: from dybmc48.prod.google.com ([2002:a05:7301:19b0:b0:2ae:51e3:c162]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:d509:b0:2b7:2e24:d5d6 with SMTP id 5a478bee46e88-2b7399ba311mr423287eec.19.1769117744670; Thu, 22 Jan 2026 13:35:44 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:15 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-12-irogers@google.com> Subject: [PATCH v3 11/12] perf disasm: Refactor arch__find and initialization of arch structs From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch arch__find to using an ELF machine number rather than a string. Rather than an array of fixed size arch structs turn the init functions into new functions indexed by the ELF machine they correspond to. This allows data to be stored with a struct arch with the container_of trick, so the priv variable can be removed. Switch to using the thread to find the arch rather than the evsel as the evsel only has limited notions of the running thread upon which disassembly is performed. Factor out the e_machine and e_flags into their own struct to make them easier to pass around. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/util/annotate-arch/annotate-arc.c | 14 +- tools/perf/util/annotate-arch/annotate-arm.c | 39 ++--- .../perf/util/annotate-arch/annotate-arm64.c | 39 ++--- tools/perf/util/annotate-arch/annotate-csky.c | 14 +- .../util/annotate-arch/annotate-loongarch.c | 19 ++- tools/perf/util/annotate-arch/annotate-mips.c | 19 ++- .../util/annotate-arch/annotate-powerpc.c | 24 +-- .../util/annotate-arch/annotate-riscv64.c | 19 ++- tools/perf/util/annotate-arch/annotate-s390.c | 29 ++-- .../perf/util/annotate-arch/annotate-sparc.c | 19 ++- tools/perf/util/annotate-arch/annotate-x86.c | 24 +-- tools/perf/util/annotate.c | 46 +++--- tools/perf/util/annotate.h | 2 +- tools/perf/util/disasm.c | 153 ++++++++---------- tools/perf/util/disasm.h | 59 +++---- 16 files changed, 279 insertions(+), 242 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 91ded9c271ee..ea17e6d29a7e 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -1198,7 +1198,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he,= struct map_symbol *ms, ui__warning("Annotation has no source code."); } } else { - err =3D evsel__get_arch(evsel, &browser.arch); + err =3D thread__get_arch(ms->thread, &browser.arch); if (err) { annotate_browser__symbol_annotate_error(&browser, err); return -1; diff --git a/tools/perf/util/annotate-arch/annotate-arc.c b/tools/perf/util= /annotate-arch/annotate-arc.c index d7ca08ca5600..170103e383a4 100644 --- a/tools/perf/util/annotate-arch/annotate-arc.c +++ b/tools/perf/util/annotate-arch/annotate-arc.c @@ -1,10 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include "../disasm.h" =20 -int arc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_arc(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - arch->initialized =3D true; + struct arch *arch =3D zalloc(sizeof(*arch)); + + if (!arch) + return NULL; + + arch->name =3D "arc"; + arch->id =3D *id; arch->objdump.comment_char =3D ';'; - return 0; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-arm.c b/tools/perf/util= /annotate-arch/annotate-arm.c index 08c49067c3c9..afb413c80156 100644 --- a/tools/perf/util/annotate-arch/annotate-arm.c +++ b/tools/perf/util/annotate-arch/annotate-arm.c @@ -7,14 +7,15 @@ #include "../annotate.h" #include "../disasm.h" =20 -struct arm_annotate { - regex_t call_insn, - jump_insn; +struct arch_arm { + struct arch arch; + regex_t call_insn; + regex_t jump_insn; }; =20 static const struct ins_ops *arm__associate_instruction_ops(struct arch *a= rch, const char *name) { - struct arm_annotate *arm =3D arch->priv; + struct arch_arm *arm =3D container_of(arch, struct arch_arm, arch); const struct ins_ops *ops; regmatch_t match[2]; =20 @@ -29,37 +30,39 @@ static const struct ins_ops *arm__associate_instruction= _ops(struct arch *arch, c return ops; } =20 -int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_arm(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - struct arm_annotate *arm; int err; + struct arch_arm *arm =3D zalloc(sizeof(*arm)); + struct arch *arch; =20 - if (arch->initialized) - return 0; - - arm =3D zalloc(sizeof(*arm)); if (!arm) - return ENOMEM; + return NULL; + + arch =3D &arm->arch; + arch->name =3D "arm"; + arch->id =3D *id; + arch->objdump.comment_char =3D ';'; + arch->objdump.skip_functions_char =3D '+'; + arch->associate_instruction_ops =3D arm__associate_instruction_ops; =20 #define ARM_CONDS "(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl|vc|vs)" err =3D regcomp(&arm->call_insn, "^blx?" ARM_CONDS "?$", REG_EXTENDED); if (err) goto out_free_arm; + err =3D regcomp(&arm->jump_insn, "^bx?" ARM_CONDS "?$", REG_EXTENDED); if (err) goto out_free_call; #undef ARM_CONDS =20 - arch->initialized =3D true; - arch->priv =3D arm; - arch->associate_instruction_ops =3D arm__associate_instruction_ops; - arch->objdump.comment_char =3D ';'; - arch->objdump.skip_functions_char =3D '+'; - return 0; + return arch; =20 out_free_call: regfree(&arm->call_insn); out_free_arm: free(arm); - return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP; + errno =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP; + return NULL; } diff --git a/tools/perf/util/annotate-arch/annotate-arm64.c b/tools/perf/ut= il/annotate-arch/annotate-arm64.c index d2ea32984b0d..33080fdca125 100644 --- a/tools/perf/util/annotate-arch/annotate-arm64.c +++ b/tools/perf/util/annotate-arch/annotate-arm64.c @@ -8,9 +8,10 @@ #include "../annotate.h" #include "../disasm.h" =20 -struct arm64_annotate { - regex_t call_insn, - jump_insn; +struct arch_arm64 { + struct arch arch; + regex_t call_insn; + regex_t jump_insn; }; =20 static int arm64_mov__parse(const struct arch *arch __maybe_unused, @@ -70,7 +71,7 @@ static const struct ins_ops arm64_mov_ops =3D { =20 static const struct ins_ops *arm64__associate_instruction_ops(struct arch = *arch, const char *name) { - struct arm64_annotate *arm =3D arch->priv; + struct arch_arm64 *arm =3D container_of(arch, struct arch_arm64, arch); const struct ins_ops *ops; regmatch_t match[2]; =20 @@ -87,38 +88,40 @@ static const struct ins_ops *arm64__associate_instructi= on_ops(struct arch *arch, return ops; } =20 -int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_arm64(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - struct arm64_annotate *arm; int err; + struct arch_arm64 *arm =3D zalloc(sizeof(*arm)); + struct arch *arch; =20 - if (arch->initialized) - return 0; - - arm =3D zalloc(sizeof(*arm)); if (!arm) - return ENOMEM; + return NULL; + + arch =3D &arm->arch; + arch->name =3D "arm64"; + arch->id =3D *id; + arch->objdump.comment_char =3D '/'; + arch->objdump.skip_functions_char =3D '+'; + arch->associate_instruction_ops =3D arm64__associate_instruction_ops; =20 /* bl, blr */ err =3D regcomp(&arm->call_insn, "^blr?$", REG_EXTENDED); if (err) goto out_free_arm; + /* b, b.cond, br, cbz/cbnz, tbz/tbnz */ err =3D regcomp(&arm->jump_insn, "^[ct]?br?\\.?(cc|cs|eq|ge|gt|hi|hs|le|l= o|ls|lt|mi|ne|pl|vc|vs)?n?z?$", REG_EXTENDED); if (err) goto out_free_call; =20 - arch->initialized =3D true; - arch->priv =3D arm; - arch->associate_instruction_ops =3D arm64__associate_instruction_ops; - arch->objdump.comment_char =3D '/'; - arch->objdump.skip_functions_char =3D '+'; - return 0; + return arch; =20 out_free_call: regfree(&arm->call_insn); out_free_arm: free(arm); - return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP; + errno =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP; + return NULL; } diff --git a/tools/perf/util/annotate-arch/annotate-csky.c b/tools/perf/uti= l/annotate-arch/annotate-csky.c index 0b0b09b068ec..d2b18e4ea2c9 100644 --- a/tools/perf/util/annotate-arch/annotate-csky.c +++ b/tools/perf/util/annotate-arch/annotate-csky.c @@ -2,6 +2,7 @@ // Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. #include #include +#include #include "../disasm.h" =20 static const struct ins_ops *csky__associate_ins_ops(struct arch *arch, @@ -39,10 +40,17 @@ static const struct ins_ops *csky__associate_ins_ops(st= ruct arch *arch, return ops; } =20 -int csky__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_csky(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - arch->initialized =3D true; + struct arch *arch =3D zalloc(sizeof(*arch)); + + if (!arch) + return NULL; + + arch->name =3D "csky"; + arch->id =3D *id; arch->objdump.comment_char =3D '/'; arch->associate_instruction_ops =3D csky__associate_ins_ops; - return 0; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-loongarch.c b/tools/per= f/util/annotate-arch/annotate-loongarch.c index 6c94cb98a104..3aeab453a059 100644 --- a/tools/perf/util/annotate-arch/annotate-loongarch.c +++ b/tools/perf/util/annotate-arch/annotate-loongarch.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "../disasm.h" #include "../map.h" #include "../maps.h" @@ -139,13 +140,17 @@ const struct ins_ops *loongarch__associate_ins_ops(st= ruct arch *arch, const char return ops; } =20 -int loongarch__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_loongarch(const struct e_machine_and_e_flags = *id, + const char *cpuid __maybe_unused) { - if (!arch->initialized) { - arch->associate_instruction_ops =3D loongarch__associate_ins_ops; - arch->initialized =3D true; - arch->objdump.comment_char =3D '#'; - } + struct arch *arch =3D zalloc(sizeof(*arch)); =20 - return 0; + if (!arch) + return NULL; + + arch->name =3D "loongarch"; + arch->id =3D *id; + arch->associate_instruction_ops =3D loongarch__associate_ins_ops; + arch->objdump.comment_char =3D '#'; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-mips.c b/tools/perf/uti= l/annotate-arch/annotate-mips.c index f14b34ed77d3..e8d1c6c7e9f3 100644 --- a/tools/perf/util/annotate-arch/annotate-mips.c +++ b/tools/perf/util/annotate-arch/annotate-mips.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include "../disasm.h" =20 static @@ -36,13 +37,17 @@ const struct ins_ops *mips__associate_ins_ops(struct ar= ch *arch, const char *nam return ops; } =20 -int mips__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_mips(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - if (!arch->initialized) { - arch->associate_instruction_ops =3D mips__associate_ins_ops; - arch->initialized =3D true; - arch->objdump.comment_char =3D '#'; - } + struct arch *arch =3D zalloc(sizeof(*arch)); =20 - return 0; + if (!arch) + return NULL; + + arch->name =3D "mips"; + arch->id =3D *id; + arch->objdump.comment_char =3D '#'; + arch->associate_instruction_ops =3D mips__associate_ins_ops; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-powerpc.c b/tools/perf/= util/annotate-arch/annotate-powerpc.c index 593c138c8104..218207b52581 100644 --- a/tools/perf/util/annotate-arch/annotate-powerpc.c +++ b/tools/perf/util/annotate-arch/annotate-powerpc.c @@ -390,17 +390,21 @@ static void update_insn_state_powerpc(struct type_sta= te *state, } #endif /* HAVE_LIBDW_SUPPORT */ =20 -int powerpc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_powerpc(const struct e_machine_and_e_flags *i= d, + const char *cpuid __maybe_unused) { - if (!arch->initialized) { - arch->initialized =3D true; - arch->associate_instruction_ops =3D powerpc__associate_instruction_ops; - arch->objdump.comment_char =3D '#'; - annotate_opts.show_asm_raw =3D true; + struct arch *arch =3D zalloc(sizeof(*arch)); + + if (!arch) + return NULL; + + arch->name =3D "powerpc"; + arch->id =3D *id; + arch->objdump.comment_char =3D '#'; + annotate_opts.show_asm_raw =3D true; + arch->associate_instruction_ops =3D powerpc__associate_instruction_ops; #ifdef HAVE_LIBDW_SUPPORT - arch->update_insn_state =3D update_insn_state_powerpc; + arch->update_insn_state =3D update_insn_state_powerpc; #endif - } - - return 0; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-riscv64.c b/tools/perf/= util/annotate-arch/annotate-riscv64.c index 15526824037a..29a988fca8c9 100644 --- a/tools/perf/util/annotate-arch/annotate-riscv64.c +++ b/tools/perf/util/annotate-arch/annotate-riscv64.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include "../disasm.h" =20 static @@ -24,13 +25,17 @@ const struct ins_ops *riscv64__associate_ins_ops(struct= arch *arch, const char * return ops; } =20 -int riscv64__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_riscv64(const struct e_machine_and_e_flags *i= d, + const char *cpuid __maybe_unused) { - if (!arch->initialized) { - arch->associate_instruction_ops =3D riscv64__associate_ins_ops; - arch->initialized =3D true; - arch->objdump.comment_char =3D '#'; - } + struct arch *arch =3D zalloc(sizeof(*arch)); =20 - return 0; + if (!arch) + return NULL; + + arch->name =3D "riscv"; + arch->id =3D *id; + arch->objdump.comment_char =3D '#'; + arch->associate_instruction_ops =3D riscv64__associate_ins_ops; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-s390.c b/tools/perf/uti= l/annotate-arch/annotate-s390.c index 47573f0310c1..af9cabd0a586 100644 --- a/tools/perf/util/annotate-arch/annotate-s390.c +++ b/tools/perf/util/annotate-arch/annotate-s390.c @@ -148,7 +148,7 @@ static const struct ins_ops *s390__associate_ins_ops(st= ruct arch *arch, const ch return ops; } =20 -static int s390__cpuid_parse(struct arch *arch, char *cpuid) +static int s390__cpuid_parse(struct arch *arch, const char *cpuid) { unsigned int family; char model[16], model_c[16], cpumf_v[16], cpumf_a[16]; @@ -169,19 +169,22 @@ static int s390__cpuid_parse(struct arch *arch, char = *cpuid) return -1; } =20 -int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_s390(const struct e_machine_and_e_flags *id, = const char *cpuid) { - int err =3D 0; - - if (!arch->initialized) { - arch->initialized =3D true; - arch->associate_instruction_ops =3D s390__associate_ins_ops; - if (cpuid) { - if (s390__cpuid_parse(arch, cpuid)) - err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; + struct arch *arch =3D zalloc(sizeof(*arch)); + + if (!arch) + return NULL; + + arch->name =3D "s390"; + arch->id =3D *id; + arch->associate_instruction_ops =3D s390__associate_ins_ops; + if (cpuid) { + if (s390__cpuid_parse(arch, cpuid)) { + errno =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; + return NULL; } - arch->objdump.comment_char =3D '#'; } - - return err; + arch->objdump.comment_char =3D '#'; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-sparc.c b/tools/perf/ut= il/annotate-arch/annotate-sparc.c index 66a0174376dd..2f07bc7a56dd 100644 --- a/tools/perf/util/annotate-arch/annotate-sparc.c +++ b/tools/perf/util/annotate-arch/annotate-sparc.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include "../../util/disasm.h" =20 static int is_branch_cond(const char *cond) @@ -160,13 +161,17 @@ static const struct ins_ops *sparc__associate_instruc= tion_ops(struct arch *arch, return ops; } =20 -int sparc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_sparc(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - if (!arch->initialized) { - arch->initialized =3D true; - arch->associate_instruction_ops =3D sparc__associate_instruction_ops; - arch->objdump.comment_char =3D '#'; - } + struct arch *arch =3D zalloc(sizeof(*arch)); =20 - return 0; + if (!arch) + return NULL; + + arch->name =3D "sparc"; + arch->id =3D *id; + arch->associate_instruction_ops =3D sparc__associate_instruction_ops; + arch->objdump.comment_char =3D '#'; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-x86.c b/tools/perf/util= /annotate-arch/annotate-x86.c index 0c7957fe60da..eb9a649ca656 100644 --- a/tools/perf/util/annotate-arch/annotate-x86.c +++ b/tools/perf/util/annotate-arch/annotate-x86.c @@ -182,7 +182,7 @@ static bool intel__ins_is_fused(const struct arch *arch= , const char *ins1, return false; } =20 -static int x86__cpuid_parse(struct arch *arch, char *cpuid) +static int x86__cpuid_parse(struct arch *arch, const char *cpuid) { unsigned int family, model, stepping; int ret; @@ -777,18 +777,21 @@ static void update_insn_state_x86(struct type_state *= state, } #endif =20 -int x86__annotate_init(struct arch *arch, char *cpuid) +const struct arch *arch__new_x86(const struct e_machine_and_e_flags *id, c= onst char *cpuid) { - int err =3D 0; + struct arch *arch =3D zalloc(sizeof(*arch)); =20 - if (arch->initialized) - return 0; + if (!arch) + return NULL; =20 + arch->name =3D "x86"; + arch->id =3D *id; if (cpuid) { - if (x86__cpuid_parse(arch, cpuid)) - err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; + if (x86__cpuid_parse(arch, cpuid)) { + errno =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; + return NULL; + } } - arch->instructions =3D x86__instructions; arch->nr_instructions =3D ARRAY_SIZE(x86__instructions); #ifndef NDEBUG @@ -810,11 +813,8 @@ int x86__annotate_init(struct arch *arch, char *cpuid) arch->objdump.memory_ref_char =3D '('; arch->objdump.imm_char =3D '$'; arch->insn_suffix =3D "bwlq"; - arch->e_machine =3D EM_X86_64; - arch->e_flags =3D 0; - arch->initialized =3D true; #ifdef HAVE_LIBDW_SUPPORT arch->update_insn_state =3D update_insn_state_x86; #endif - return err; + return arch; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 79702072568b..c16c6dfaa959 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -980,32 +980,27 @@ void symbol__calc_percent(struct symbol *sym, struct = evsel *evsel) annotation__calc_percent(notes, evsel, symbol__size(sym)); } =20 -int evsel__get_arch(struct evsel *evsel, const struct arch **parch) +int thread__get_arch(struct thread *thread, const struct arch **parch) { - struct perf_env *env =3D evsel__env(evsel); - const char *arch_name =3D perf_env__arch(env); const struct arch *arch; - int err; + struct machine *machine; + uint16_t e_machine; =20 - if (!arch_name) { + if (!thread) { *parch =3D NULL; - return errno; + return -1; } =20 - *parch =3D arch =3D arch__find(arch_name); + machine =3D maps__machine(thread__maps(thread)); + e_machine =3D thread__e_machine(thread, machine); + arch =3D arch__find(e_machine, machine->env ? machine->env->cpuid : NULL); if (arch =3D=3D NULL) { - pr_err("%s: unsupported arch %s\n", __func__, arch_name); - return ENOTSUP; + pr_err("%s: unsupported arch %d\n", __func__, e_machine); + return errno; } + if (parch) + *parch =3D arch; =20 - if (arch->init) { - err =3D arch->init((struct arch *)arch, env ? env->cpuid : NULL); - if (err) { - pr_err("%s: failed to initialize %s arch priv area\n", - __func__, arch->name); - return err; - } - } return 0; } =20 @@ -1020,7 +1015,7 @@ int symbol__annotate(struct map_symbol *ms, struct ev= sel *evsel, const struct arch *arch =3D NULL; int err, nr; =20 - err =3D evsel__get_arch(evsel, &arch); + err =3D thread__get_arch(ms->thread, &arch); if (err) return err; =20 @@ -1268,7 +1263,7 @@ int hist_entry__annotate_printf(struct hist_entry *he= , struct evsel *evsel) =20 apd.addr_fmt_width =3D annotated_source__addr_fmt_width(¬es->src->sour= ce, notes->src->start); - evsel__get_arch(evsel, &apd.arch); + thread__get_arch(ms->thread, &apd.arch); apd.dbg =3D dso__debuginfo(dso); =20 list_for_each_entry(pos, ¬es->src->source, node) { @@ -1373,7 +1368,7 @@ static int symbol__annotate_fprintf2(struct symbol *s= ym, FILE *fp, struct annotation_line *al; =20 if (annotate_opts.code_with_type) { - evsel__get_arch(apd->evsel, &apd->arch); + thread__get_arch(apd->he->ms.thread, &apd->arch); apd->dbg =3D dso__debuginfo(map__dso(apd->he->ms.map)); } =20 @@ -2495,7 +2490,7 @@ static int extract_reg_offset(const struct arch *arch= , const char *str, if (regname =3D=3D NULL) return -1; =20 - op_loc->reg1 =3D get_dwarf_regnum(regname, arch->e_machine, arch->e_flags= ); + op_loc->reg1 =3D get_dwarf_regnum(regname, arch->id.e_machine, arch->id.e= _flags); free(regname); =20 /* Get the second register */ @@ -2508,7 +2503,7 @@ static int extract_reg_offset(const struct arch *arch= , const char *str, if (regname =3D=3D NULL) return -1; =20 - op_loc->reg2 =3D get_dwarf_regnum(regname, arch->e_machine, arch->e_flag= s); + op_loc->reg2 =3D get_dwarf_regnum(regname, arch->id.e_machine, arch->id.= e_flags); free(regname); } return 0; @@ -2607,8 +2602,11 @@ int annotate_get_insn_location(const struct arch *ar= ch, struct disasm_line *dl, if (s =3D=3D NULL) return -1; =20 - if (*s =3D=3D arch->objdump.register_char) - op_loc->reg1 =3D get_dwarf_regnum(s, arch->e_machine, arch->e_flags); + if (*s =3D=3D arch->objdump.register_char) { + op_loc->reg1 =3D get_dwarf_regnum(s, + arch->id.e_machine, + arch->id.e_flags); + } else if (*s =3D=3D arch->objdump.imm_char) { op_loc->offset =3D strtol(s + 1, &p, 0); if (p && p !=3D s + 1) diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 58eaf4b2fa65..696e36dbf013 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -586,5 +586,5 @@ int annotation_br_cntr_entry(char **str, int br_cntr_nr= , u64 *br_cntr, int num_aggr, struct evsel *evsel); int annotation_br_cntr_abbr_list(char **str, struct evsel *evsel, bool hea= der); =20 -int evsel__get_arch(struct evsel *evsel, const struct arch **parch); +int thread__get_arch(struct thread *thread, const struct arch **parch); #endif /* __PERF_ANNOTATE_H */ diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index d81469db0aac..46740d1e5858 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -102,112 +102,101 @@ int arch__associate_ins_ops(struct arch *arch, cons= t char *name, const struct in return 0; } =20 -static struct arch architectures[] =3D { - { - .name =3D "arc", - .init =3D arc__annotate_init, - .e_machine =3D EM_ARC, - }, - { - .name =3D "arm", - .init =3D arm__annotate_init, - .e_machine =3D EM_ARM, - }, - { - .name =3D "arm64", - .init =3D arm64__annotate_init, - .e_machine =3D EM_AARCH64, - }, - { - .name =3D "csky", - .init =3D csky__annotate_init, - .e_machine =3D EM_CSKY, -#if defined(__CSKYABIV2__) - .e_flags =3D EF_CSKY_ABIV2, -#else - .e_flags =3D EF_CSKY_ABIV1, -#endif - }, - { - .name =3D "mips", - .init =3D mips__annotate_init, - .e_machine =3D EM_MIPS, - }, - { - .name =3D "x86", - .init =3D x86__annotate_init, - .e_machine =3D EM_X86_64, // TODO: EM_386 too. - }, - { - .name =3D "powerpc", - .init =3D powerpc__annotate_init, - .e_machine =3D EM_PPC, // TODO: EM_PPC64 too. - }, - { - .name =3D "riscv64", - .init =3D riscv64__annotate_init, - .e_machine =3D EM_RISCV, - }, - { - .name =3D "s390", - .init =3D s390__annotate_init, - .e_machine =3D EM_S390, - }, - { - .name =3D "sparc", - .init =3D sparc__annotate_init, - .e_machine =3D EM_SPARC, - }, - { - .name =3D "loongarch", - .init =3D loongarch__annotate_init, - .e_machine =3D EM_LOONGARCH, - }, -}; +static int e_machine_and_eflags__cmp(const struct e_machine_and_e_flags *v= al1, + const struct e_machine_and_e_flags *val2) +{ + if (val1->e_machine =3D=3D val2->e_machine) { + if (val1->e_machine !=3D EM_CSKY) + return 0; + if ((val1->e_flags & EF_CSKY_ABIMASK) < (val2->e_flags & EF_CSKY_ABIMASK= )) + return -1; + return (val1->e_flags & EF_CSKY_ABIMASK) > (val2->e_flags & EF_CSKY_ABIM= ASK); + } + return val1->e_machine < val2->e_machine ? -1 : 1; +} =20 -static int arch__key_cmp(const void *name, const void *archp) +static int arch__key_cmp(const void *key, const void *archp) { - const struct arch *arch =3D archp; + const struct arch *const *arch =3D archp; =20 - return strcmp(name, arch->name); + return e_machine_and_eflags__cmp(key, &(*arch)->id); } =20 static int arch__cmp(const void *a, const void *b) { - const struct arch *aa =3D a; - const struct arch *ab =3D b; + const struct arch *const *aa =3D a; + const struct arch *const *ab =3D b; =20 - return strcmp(aa->name, ab->name); + return e_machine_and_eflags__cmp(&(*aa)->id, &(*ab)->id); } =20 -static void arch__sort(void) +const struct arch *arch__find(uint16_t e_machine, const char *cpuid) { - const int nmemb =3D ARRAY_SIZE(architectures); + static const struct arch *(*const arch_new_fn[])(const struct e_machine_a= nd_e_flags *id, + const char *cpuid) =3D { + [EM_386] =3D arch__new_x86, + [EM_ARC] =3D arch__new_arc, + [EM_ARM] =3D arch__new_arm, + [EM_AARCH64] =3D arch__new_arm64, + [EM_CSKY] =3D arch__new_csky, + [EM_LOONGARCH] =3D arch__new_loongarch, + [EM_MIPS] =3D arch__new_mips, + [EM_PPC64] =3D arch__new_powerpc, + [EM_PPC] =3D arch__new_powerpc, + [EM_RISCV] =3D arch__new_riscv64, + [EM_S390] =3D arch__new_s390, + [EM_SPARC] =3D arch__new_sparc, + [EM_SPARCV9] =3D arch__new_sparc, + [EM_X86_64] =3D arch__new_x86, + }; + static const struct arch **archs; + static size_t num_archs; + struct e_machine_and_e_flags key =3D { + .e_machine =3D e_machine, + // TODO: e_flags should really come from the same source as e_machine. + .e_flags =3D EF_HOST, + }; + const struct arch *result =3D NULL, **tmp; =20 - qsort(architectures, nmemb, sizeof(struct arch), arch__cmp); -} + if (num_archs > 0) { + tmp =3D bsearch(&key, archs, num_archs, sizeof(*archs), arch__key_cmp); + if (tmp) + result =3D *tmp; + } =20 -const struct arch *arch__find(const char *name) -{ - const int nmemb =3D ARRAY_SIZE(architectures); - static bool sorted; + if (result) + return result; =20 - if (!sorted) { - arch__sort(); - sorted =3D true; + if (e_machine >=3D ARRAY_SIZE(arch_new_fn) || arch_new_fn[e_machine] =3D= =3D NULL) { + errno =3D ENOTSUP; + return NULL; } =20 - return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key= _cmp); + tmp =3D reallocarray(archs, num_archs + 1, sizeof(*archs)); + if (!tmp) + return NULL; + + result =3D arch_new_fn[e_machine](&key, cpuid); + if (!result) { + pr_err("%s: failed to initialize %s (%u) arch priv area\n", + __func__, result->name, e_machine); + free(tmp); + return NULL; + } + archs =3D tmp; + archs[num_archs++] =3D result; + qsort(archs, num_archs, sizeof(*archs), arch__cmp); + return result; } =20 bool arch__is_x86(const struct arch *arch) { - return arch->e_machine =3D=3D EM_386 || arch->e_machine =3D=3D EM_X86_64; + return arch->id.e_machine =3D=3D EM_386 || arch->id.e_machine =3D=3D EM_X= 86_64; } =20 bool arch__is_powerpc(const struct arch *arch) { - return arch->e_machine =3D=3D EM_PPC || arch->e_machine =3D=3D EM_PPC64; + return arch->id.e_machine =3D=3D EM_PPC || arch->id.e_machine =3D=3D EM_P= PC64; } =20 static void ins_ops__delete(struct ins_operands *ops) diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index b6a2a30fdf27..2793d48aa04e 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -17,21 +17,23 @@ struct data_loc_info; struct type_state; struct disasm_line; =20 +struct e_machine_and_e_flags { + uint16_t e_machine; + uint32_t e_flags; +}; + struct arch { - const char *name; + /** @id: ELF machine and flags associated with arch. */ + struct e_machine_and_e_flags id; + /** @name: name such as "x86" or "powerpc". */ + const char *name; const struct ins *instructions; - size_t nr_instructions; - size_t nr_instructions_allocated; - const struct ins_ops *(*associate_instruction_ops)(struct arch *arch, co= nst char *name); - bool sorted_instructions; - bool initialized; - const char *insn_suffix; - void *priv; - unsigned int model; - unsigned int family; - int (*init)(struct arch *arch, char *cpuid); - bool (*ins_is_fused)(const struct arch *arch, const char *ins1, - const char *ins2); + size_t nr_instructions; + size_t nr_instructions_allocated; + bool sorted_instructions; + const char *insn_suffix; + unsigned int model; + unsigned int family; struct { char comment_char; char skip_functions_char; @@ -39,15 +41,14 @@ struct arch { char memory_ref_char; char imm_char; } objdump; + bool (*ins_is_fused)(const struct arch *arch, const char *ins1, + const char *ins2); + const struct ins_ops *(*associate_instruction_ops)(struct arch *arch, co= nst char *name); #ifdef HAVE_LIBDW_SUPPORT void (*update_insn_state)(struct type_state *state, struct data_loc_info *dloc, Dwarf_Die *cu_die, struct disasm_line *dl); #endif - /** @e_machine: ELF machine associated with arch. */ - unsigned int e_machine; - /** @e_flags: Optional ELF flags associated with arch. */ - unsigned int e_flags; }; =20 struct ins { @@ -107,7 +108,7 @@ struct annotate_args { char *fileloc; }; =20 -const struct arch *arch__find(const char *name); +const struct arch *arch__find(uint16_t e_machine, const char *cpuid); bool arch__is_x86(const struct arch *arch); bool arch__is_powerpc(const struct arch *arch); =20 @@ -121,17 +122,17 @@ extern const struct ins_ops ret_ops; =20 int arch__associate_ins_ops(struct arch *arch, const char *name, const str= uct ins_ops *ops); =20 -int arc__annotate_init(struct arch *arch, char *cpuid); -int arm__annotate_init(struct arch *arch, char *cpuid); -int arm64__annotate_init(struct arch *arch, char *cpuid); -int csky__annotate_init(struct arch *arch, char *cpuid); -int loongarch__annotate_init(struct arch *arch, char *cpuid); -int mips__annotate_init(struct arch *arch, char *cpuid); -int powerpc__annotate_init(struct arch *arch, char *cpuid); -int riscv64__annotate_init(struct arch *arch, char *cpuid); -int s390__annotate_init(struct arch *arch, char *cpuid); -int sparc__annotate_init(struct arch *arch, char *cpuid); -int x86__annotate_init(struct arch *arch, char *cpuid); +const struct arch *arch__new_arc(const struct e_machine_and_e_flags *id, c= onst char *cpuid); +const struct arch *arch__new_arm(const struct e_machine_and_e_flags *id, c= onst char *cpuid); +const struct arch *arch__new_arm64(const struct e_machine_and_e_flags *id,= const char *cpuid); +const struct arch *arch__new_csky(const struct e_machine_and_e_flags *id, = const char *cpuid); +const struct arch *arch__new_loongarch(const struct e_machine_and_e_flags = *id, const char *cpuid); +const struct arch *arch__new_mips(const struct e_machine_and_e_flags *id, = const char *cpuid); +const struct arch *arch__new_powerpc(const struct e_machine_and_e_flags *i= d, const char *cpuid); +const struct arch *arch__new_riscv64(const struct e_machine_and_e_flags *i= d, const char *cpuid); +const struct arch *arch__new_s390(const struct e_machine_and_e_flags *id, = const char *cpuid); +const struct arch *arch__new_sparc(const struct e_machine_and_e_flags *id,= const char *cpuid); +const struct arch *arch__new_x86(const struct e_machine_and_e_flags *id, c= onst char *cpuid); =20 const struct ins_ops *ins__find(const struct arch *arch, const char *name,= struct disasm_line *dl); =20 --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 18:20:10 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C1783793B7 for ; Thu, 22 Jan 2026 21:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117761; cv=none; b=AnocQB0Wg7VGSIj7XKWOgl0DFkGUCDDwrN/S+Qp8ISHkJ2l/36wivxzlHY8FpmhjM70UVFcaL1UzpDGA4sCVRM+rzP3ryx31FVSrBhaHcmczUYYC02y541FlZNN9M28pKqR7xi4aFX8ATGJHJrURpmFkED0wGeZkKu3A1K9m4GU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117761; c=relaxed/simple; bh=DNIcWZ9QKgcap8GIm+HHaS7sytvjKF8lN4kZaGLyU7M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=iRJaRurDq2miYfat5l4+TWUw9uoyIdVtGs+2LrFonWXXIxGkz4foD/WK+0SK1Fvi7jXqSP6edsbrjjSA2Q1CFkNHuZ17yjvDpk4jsjtZ/opqzOkU1zfrMJapKvkRxjIJ5QFtL3Y/2t9TzFt2EbmcNbMYoBAh+MCbuXzClPMYQN4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wKWmKvYz; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wKWmKvYz" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12454b0a1a2so5063183c88.0 for ; Thu, 22 Jan 2026 13:35:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769117746; x=1769722546; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=6zuXMW9ePaQZdk+//RX5ln7bDZ0bQbPZ3cyiYbZ9aMU=; b=wKWmKvYzy3/ctOsKHoZ2kONjlphKfLXMcsQbDkvqq0IffuJy0sKZsJ8X/3YiEOCSnj NEaGOx0tMtCnJAMGHU/6KXRhFcuBfKP5iuAMncm0hQGF7RGOYWGLQbZhlJjghPGAuFPA 2Wj2fzdPdSyDw1K1t6po3kCUlNKH9bgPZKuXE2IHvR4oi90QGyEKGxgGCc7fDFidVorE VOMGdDCT4JSClpBN6C7zxKpUdhYN2Iq1E2ZdtQnW4jKVgIoy/3jynC/Bg6CUTDc6zmZJ TBvlSQ6aHP5D1wqMK+ADHcbW5kJ7HqL/7Kk6IY43Gmcus9jLqjMd5RR0nZbTgFudBzWH pwhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769117746; x=1769722546; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6zuXMW9ePaQZdk+//RX5ln7bDZ0bQbPZ3cyiYbZ9aMU=; b=YP7tag0JeQna+aLf37i++sQdWim3B1QKmpYi1BcMdpSM0VF6t41ISl0BOja8Q6IPgw jlSorss3pi8C+aTooWTcS+cXGuHFi1ISk70fcU7SlBLNpftrR7jdHSoxZHxC2KlRq+Uh 4y0BuUYXPf4VsANo0hK5IluSBLeDixSF3t/l1W22qsg95R4q3MoVrJbDEknapByio0PM BZXv8BwZCrj+sgOKsE2d6TC8GMig/oHs8mq8s6GHlMG9tDfaNYrk1D7W0nBON/QFb66j WcLX7GE3mUCkk6K/PjvGExTU3Q1xq0kYBXWiXGuIN3V/tTR9Mu+RbDy+h7yovsuYoIuc +5uQ== X-Forwarded-Encrypted: i=1; AJvYcCUjQJOgp1AEbLQL3LC+DLvDw+p5CWrBXnY4qXCtJZWEhwtIMUeW2iZX3Y6eAjatLVYqpqenW9ANiMQMEHw=@vger.kernel.org X-Gm-Message-State: AOJu0YwWgMAqfAQmg25SGo4qTgIvryV6OBf8XVHuFEcIJVO6Y5DQT5Rv z40zsdx0yf8sV8TSwfOCjG+JZR7/Po+MWnYdmYBKw7wd9Tg4PXNwUJ/g+yE1AvEbm88wrLZvgQJ aMfOPEkZxUw== X-Received: from dlzz28.prod.google.com ([2002:a05:7022:49c:b0:123:360b:d5f6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6981:b0:11a:4ffb:9825 with SMTP id a92af1059eb24-1247dbad26bmr458271c88.6.1769117746365; Thu, 22 Jan 2026 13:35:46 -0800 (PST) Date: Thu, 22 Jan 2026 13:35:16 -0800 In-Reply-To: <20260122213516.671089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122213516.671089-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122213516.671089-13-irogers@google.com> Subject: [PATCH v3 12/12] perf disasm: Minor layout tweaks for struct arch From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pack some holes to bring down the overall struct size from 96 to 88 bytes. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/util/disasm.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index 2793d48aa04e..6a1905f9d4fc 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -18,22 +18,22 @@ struct type_state; struct disasm_line; =20 struct e_machine_and_e_flags { - uint16_t e_machine; uint32_t e_flags; + uint16_t e_machine; }; =20 struct arch { - /** @id: ELF machine and flags associated with arch. */ - struct e_machine_and_e_flags id; /** @name: name such as "x86" or "powerpc". */ const char *name; const struct ins *instructions; size_t nr_instructions; size_t nr_instructions_allocated; - bool sorted_instructions; const char *insn_suffix; unsigned int model; unsigned int family; + /** @id: ELF machine and flags associated with arch. */ + struct e_machine_and_e_flags id; + bool sorted_instructions; struct { char comment_char; char skip_functions_char; --=20 2.52.0.457.g6b5491de43-goog