From nobody Sun Feb 8 08:27:41 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 8674436EA9C for ; Thu, 22 Jan 2026 16:54:19 +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=1769100864; cv=none; b=BBoYsVQACzXxaE1VVvspNqXAqNTTNTBhsDzE22SXsbpxNq5yUWR7BkT3XkTnJ5VtXEoKcJFL3pO4nx0thealwLR2f8Mtv6TesKhr/Y/0GMYZqw85EmQ5TJzYK1g14y9WYwsb6ctkpKCYj9V0fgh5CPSi5RhzXd8TKvVDO5yNqeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100864; c=relaxed/simple; bh=U3CxrbAAlN8gTA3wMaXLOq+KQ2KCxALBwEtyEmQVEng=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=M1Rzz4Rat2D/2+7H6bSDBgTWlB4fq60dy3V5+z8t5kVg8rCg9HW9UrKIcgS+jhQz5GEs1T5AC+qi0p4/C16zunCymqUkP0zmaV+MxvRP5WQuSvGReK/gj+56w5VCJs+OETs0vC+IKma1PzGxdTTE+O+H/XzZjbN2dj6Zvynal5o= 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=oEImuKVd; 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="oEImuKVd" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b7155ca88cso921461eec.1 for ; Thu, 22 Jan 2026 08:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100856; x=1769705656; 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=oEImuKVdED36izjuwCT+ZZuLoE4ZtXRodRbC7Z5dfZhJO/A3UO/nxuoeLZmrvPq1n4 UwUaOVfvYxuqxx/060C3wvyLW/AATEEx3HJwYmkZFlDVpCiUDp+6xMoCImKS/mZEkxuO 58ZeIRXe83rbDmu0afEZGyIGIEnjUEAZFFInRRvK9XUCWoDBVbd/2BELtkrJbSffcvwm ojBHUKbVvZHtrPJJchO5hiydHyxNpp8dQQv5aSmAaGtpuE2jiQ9gPoNQupSpQPgBrSD0 1Ulbu8dnaPpfeshjO/QmVhhl6agiPifTUsS/qugjs3WW/ncDmCmZpqxGPGis7OIHrY/p ANaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100856; x=1769705656; 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=i6RAB2D+GyDdYy1++T4kvJUzyNd107pUAbkuuRtOtXY6D2PEFFKDKj16k9r+PGH/G9 qM8LQ53eih/HEP8YfYszIgG1TwR/CkBY0GwhpEZCF7dNBm61jZuVUT9frrSjw32nPL7d 8sSKUPlj9Sr3/OrjWgwiDlStzHttUa9isRJxTrH1uj/OHDZBde55iiKvrctspKo/q3oE 9Ls5nyMIQ3kr9mrMs0vb22VjmhlZfnuxX9UsqIjVe3tgbyibeI0gZLyITN4V3mkBmNRH pT+M/Nf2m7M/Orn1b9C4qjuSaxFa5jlIZoQLaU/kWo89xNwP+tR73Xwc68KmaAdWXLDd XXTw== X-Forwarded-Encrypted: i=1; AJvYcCVobsaiSlSOKXUeARA57LIb6EGbqIDW8dhoRrQ0DwpYXI0bPLwwyBb4Cf3t6P3EGNpJ7K0WqZMY3Y3tQB4=@vger.kernel.org X-Gm-Message-State: AOJu0YyBsvErOWp838F9+LZQTchg9pJ7d2kCHVginnGGwqlSgAvrW+yp Wh/jkEhUHN9PuCDYKOxP9fPUDevE8L8GLboSzeQzMGoE1TgrpVAEp1kx5ykeDmvmXp4SrO9EFDS gLFXwa/gp5w== X-Received: from dlbqj5.prod.google.com ([2002:a05:7022:ec05:b0:123:2b17:f461]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:4582:b0:11b:95fe:bee3 with SMTP id a92af1059eb24-1246aabf3f6mr7269627c88.37.1769100856331; Thu, 22 Jan 2026 08:54:16 -0800 (PST) Date: Thu, 22 Jan 2026 08:53:56 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-2-irogers@google.com> Subject: [PATCH v2 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") --- 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 Sun Feb 8 08:27:41 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 A753A376BF4 for ; Thu, 22 Jan 2026 16:54:25 +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=1769100875; cv=none; b=VMKGgfLS4ZNCteov33tqHBKurTVnXY5+bkSrZ7pH54FfAhNtTTN32P/RNl6gL8sHwLac+5nk/r7JPZ9eXaDvcv2vEjW9u16+FEEuBAPb0guEFjSrIefv6D2V574SfSO0Ow4KJnxsHYWxce+S6OIMqSUMiuFVlh+mVNDURgU35+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100875; c=relaxed/simple; bh=ANN7VbZ/Xm6UtamlT5mlRTMZ4rnilmOIpmNJZRsm4WY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=O+0F/UTT2VsOyODQ2J8UCe0uuFGyXTY11jQMIs6eihgSDW4VifDE83uqc9PWcvaDv7VxEYDjECOrUZzbg5ZASZOBN5KRhWBspd3BEVCpag6rfnFW88793pUhx5CXBHhmkyDHlozJsHt1zfNuvhRu6X0pROu4y/EREjqSxvl1Vmk= 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=1YBZAlsc; 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="1YBZAlsc" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b724ff60e6so982801eec.0 for ; Thu, 22 Jan 2026 08:54:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100858; x=1769705658; 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=1YBZAlscuJ3DAVNCTw1uf4si0zY4E2XTrOl+eGgYlp4E1P6rWmoHo22ibLlTJtgayJ T15JAGNBLCX4ZWOk07bdQ+RcXW1UtMbHTbO2kW+egY9sNZueN20VrRKmadxyRUqZ7geK c8KemOsWPK/maPHvBs4IuMCQKgg8sQY3aXxpKdP7nCe/myRm2nzrZa9FAed4FkpNyj0n UNxHLi4Kp0E1IBxIrqXCszT2KUZxII9zXFrE8IfTDT1yUdcKYqwS7KwihaL2BtCKUtQe /LwHh/3J+8LrHjIIKiQw/xSFST+gZGXqJQ/8Us+eu4nJcKSsTs6798DZKcsF9MyY715l ZzhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100858; x=1769705658; 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=RxHc6dJpXU1FY44Nt9wjfgxTF48CLurkQ//Yaq4wL6D/oqOw4GDVbup/iXA9umu7w9 a6ZOnn6tsDFWosu5C6IPbbAUqHqKFNhzApzLdGC5Kbh+GmyiOWw3SYk4idXdh5D2u9Mp AqR1vqN6/LtUoGSeAHkgre70pKRQ9LFAvSIO96As4T7At5sTVN57k3f6eQJNkJO0crSP IOBKylq+3sf8Q77vACEUxHGAsBms5IuDZfpxC0mvtwh19CWa8gKyKXIYDhlIjE5CxDkD 1uXlzjIoZCl5WQygBVXnvyQRHNCIDE9+ukvdhgzP2ZKpjdMZf5HiagVuiKNy2Carx5SQ ffGA== X-Forwarded-Encrypted: i=1; AJvYcCUfw1Lw33+r4k3qqSXqzYnevA/gFRkZnjhkNxXtBMVYQHtQRcX+UvjJY8DtnMW1S/cMrerLD19FR9yiCRo=@vger.kernel.org X-Gm-Message-State: AOJu0YxPSZPfTblompy9cJB5oyFb1LBOyfUSOCmbJR20PcsGtflVakYP CNikHTARyztqVZi9FJ7wSzT6gZD7VC1hN+4zuqhi76Kt9Yh8Vkl8dB2WpYx10enaVFSil9J7xoL C+Gs6AlKopg== X-Received: from dycme17.prod.google.com ([2002:a05:693c:2411:b0:2ae:4f51:beac]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:fa12:b0:2b1:7910:b0f9 with SMTP id 5a478bee46e88-2b6fd7c5909mr4676337eec.42.1769100858042; Thu, 22 Jan 2026 08:54:18 -0800 (PST) Date: Thu, 22 Jan 2026 08:53:57 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-3-irogers@google.com> Subject: [PATCH v2 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") --- .../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 Sun Feb 8 08:27:41 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 C782F36680A for ; Thu, 22 Jan 2026 16:54:26 +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=1769100881; cv=none; b=dUunAeJq9ix0vs5flGjhfwFsTUJFVNjQQ3h88oxISJs9QDT9uYyFJvFP7/LQ1iCZim9xJKWNxuYsDigmn1+KFAN1wQzvqsVwvw8V8GDVKZSt/ettzzJN8RqM9kgEq0WrSY4nrCX9ydLl9OzlYQXKc1x4NfE8S+Jq0FxvsK3GM08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100881; c=relaxed/simple; bh=WqOiFcX/heg3IGph3C/ogbRzFLpcL0diaA21e5ry5lo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ewj9r3zf+h6x3Mtu6MAuKx6sqCzGYeDW55txLkLPd1ap6oE/SJAk+fAWbgimMejQtLkuUppGNy4/iU0sSfg2ttXgvutXFyCH6qn8MkxBI76rQCYeUgNVh1V29kvkL2eZkxCBrzsK5xDU4dl3ElWLSegxiIqEmxcF+PaUP4vK39g= 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=uSOMAGss; 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="uSOMAGss" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b6f0b345e3so6299669eec.0 for ; Thu, 22 Jan 2026 08:54:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100860; x=1769705660; 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=uSOMAGssh5dmLUIRtCZrmMb7VsAbqQZI773U2nrsh6m8PA55jIRS0RSIxlIKsCJ6iK Zhz9zetOv1Nu1TWCqnEY+EPbsLXuBXCN5uamUaEsA+Av8Ca9ubrvqplOew9lZKCAABrG OB4v8bO/RrpH48a7eA/TXKHwOqWoWGRVPE6Z+scupxkZi8D/W6eUMH954qd8LCDcmY2/ 4LkK8iuqSNuvDzZRDOj0NuwtwqG/84gW1vWTdXj33Mmt5eTjsPMNmI/Uyuq6EGezVw4+ fT6h0FVyqLO/ydTVbYlAffpMZtIqzrbaAAdBrZ4vOCMEQi9l1elMNwOz7p75WaV/b1dE 7PPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100860; x=1769705660; 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=ZMDY1P2ILtjAPxfzIsTOo3/8VDRGqeb0ASfXVw02M2fFwJ0THUdIWTS7ZggYKbq+wg f+kYwX9JC2sD5y7R1sA1FnZHrrUvpJebRG+HOyX7dLHMryD27X9REVyZ4mDXEwqzbFrR FNcqjohAKMk8D+zsuIDwCo+U7eDg3Ty6l62ruN/7mIQQjirgV+st0y9OlPOe64ACW4DO U/O9q2DntO4ajMUHGZiQgOc8AEnhS0d74jeM+XZLrYHCL0o/JGY7pfktPXpWSFEjwgA7 nSoO/sfaXDYoY74hRblKa7g+SbKmDwVGnkjp9sO/u/E0/ufLRDT2J4RmnHIz1RAOJF8o 6YKQ== X-Forwarded-Encrypted: i=1; AJvYcCULrkGfyDQuyaEZe9dLGCtnoc3c2udZ4qZVdNL3I5J6GqqAwaWn6+YJyMk8pVaKMigG1wmPFPDtdNkyJgI=@vger.kernel.org X-Gm-Message-State: AOJu0YycgTHWAR06y2/5r9sAG8CJfPEEi+D6yogy7KT7ssIRkG5J/qk9 GigRaSo/fPi1P4mcwEA9pVgrzHqnwc3O7TU21B7trR34Ne7mt7jJElCSljTEll5kCtWcOcLQ/82 wLzlAG/lbFg== X-Received: from dycue4.prod.google.com ([2002:a05:7300:84:b0:2ae:5283:d72f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:7c13:b0:2ae:824e:31ba with SMTP id 5a478bee46e88-2b6b3eed5d9mr19877803eec.7.1769100860046; Thu, 22 Jan 2026 08:54:20 -0800 (PST) Date: Thu, 22 Jan 2026 08:53:58 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-4-irogers@google.com> Subject: [PATCH v2 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") --- 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 Sun Feb 8 08:27:41 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 CF584352FBF for ; Thu, 22 Jan 2026 16:54:26 +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=1769100876; cv=none; b=Yab8z8m6+l3mkGGU61I1twK2qQ2wgtBTfmuAUHz3jx8l7ZdRbfuUVzI7fMHCmvX2h9D/CNvBti9MX9jdvnOY8KlzILNXyY4DAlRfr5Xzyb2SdgeChcdnNUj5y5gk63mmCQ0SgLNqzHcV5/AHjfcqJ+YQaq6g6nEH4yucO1FTWU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100876; c=relaxed/simple; bh=IKxUvpqeaDRrmwDOL8vjDyn+1FMS+KE+94Prsf8lXdI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=sZpl6LQpAj76ns7/UuTcIUiT1LdvlYNWX4hNBY5J8kMwrRVskvrVF1RhxTDCuBS9Qa2XYCbsX8aOtFZusr+nWEUHDnF4TNgN3RA19bWPGZXN5SlNwCySGSaq8TPPEyWTC5Kow/Ty3+jv0Cbc8WfmVJWjGAjYdT0pCZ73bPJXdYA= 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=lcAuf6L6; 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="lcAuf6L6" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b724ff60e6so982854eec.0 for ; Thu, 22 Jan 2026 08:54:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100862; x=1769705662; 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=lcAuf6L6uuP8ftVM6QqpnjgklyqkUeJLegT8YCcCCYXFA78UpQgUX3V9CBXaeYYm3I nmgTq+4ydYgZulZngiU+zejSwbaLIJ29ZePqP6hAJolbGRJvwlzyHMK1Kz+gDDgq5uTC CSslXqUnKMceVdbQ8e9mO6Fs6SnLX2vJJeBVJZXc2xgTFrazVipOP7khhfLLh0ZgNAY3 r9NYmM6SQncuwOAyOOjGlFc/ElciONPR6tTlkEkXCQY2uQUf2iimEY3KytHNgk624Q2O pKS4g2tke8l4o3H85MNlZxoPdUrbTdQP8yEhjzI7YKud6V4eNXcobwbTv8ttnyz+mGUk mwbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100862; x=1769705662; 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=uFOp10UJ7Pg8H9SGL4f5vZwpdcT0H4hEyio/JWgnYWowP69T58NiTYE+3A4mEIrtcK 5me+WqRv0BhD/nBD8VYdf+Ndk4+wStIVJMm8z5Wei/dGh64XMhQeLX8acIVl0/s5PORZ 3cLIGFul6XN4KQoF+ZGBuom8dnpi4VnX7PWd/yy0Nuvq8erLD1vg+CutIywt80XWTDvc 2B6lcHz41fC1VyjrHLmjEuksRlyc9du2hB/HztjF6Ira9lEwDDBnMdgK0S30YL9TyH/z CHYVb/MzxSeknpD23hmBe8Qo3DZhJMqavjFr5kPwC19sGdC4jUZ/rbJmcKrWtixUURbI aWXg== X-Forwarded-Encrypted: i=1; AJvYcCWfPMKGzHQLW83ghDhQH47RrAc7IdQKkExSm3A0g9aJjdcMjUA2DBcaIgc/rdTPI5TjeTUmh0fEqi3CN8g=@vger.kernel.org X-Gm-Message-State: AOJu0Yx6u2G6I65Clq1ShHkDHMolrNq3cqqa5K7d8OZZGOsGszT0IbJ6 EIeCSyneankYPDAuXhoOGKDOrW23CV0+E5tMrjjzww3/4jmuRGtD7ZrMSX23CDbweCl1yxemcAF CT9apHsXi8w== X-Received: from dlbpy14.prod.google.com ([2002:a05:7022:e98e:b0:11d:cfa0:5ddf]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:1284:b0:11b:9386:a38b with SMTP id a92af1059eb24-1246aacb81amr6462562c88.46.1769100861789; Thu, 22 Jan 2026 08:54:21 -0800 (PST) Date: Thu, 22 Jan 2026 08:53:59 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-5-irogers@google.com> Subject: [PATCH v2 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 --- 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 Sun Feb 8 08:27:41 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 0806837107D for ; Thu, 22 Jan 2026 16:54:27 +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=1769100877; cv=none; b=EFEuB0hAywh1HDhm2erQ/cG1jicTKzLGgc1IAQzl1KLvvce6Zn+IsS+0UUcSVrhUXj3u4FcS5vNf0f5Twt0wT/mb7n0oBkYcBZ5nCBMnSNZB+6GuWLv/27VciQxwNsSXMXyT0V3d7hnEY9ZBICkTYRGOZDixjzlgZpA/ox5WfJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100877; c=relaxed/simple; bh=rD9vOzeeXzOTCD+l66o8DhGrmT+MJuoo1UTvO0WycIQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=X8QAWcRecOzeBAVWk+xs7qZX0+fhERk1VOh9+PICDp6YSGa0hgD3KVqtMnF2bsuXcLv8r2D4LqyjAAfLFj6KPCGD5UhGy2hnWuzUAmF9nmmKA/l5/ogJvWh4UPVKGi7XBjnTiqkzyHuqytUOh82C6DuMZ+UCjEJefmMRHy2Ii68= 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=kmBlCllM; 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="kmBlCllM" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b704019c98so1266723eec.0 for ; Thu, 22 Jan 2026 08:54:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100864; x=1769705664; 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=kmBlCllMeIKwBJfPY14u+sz/7jEtzhhRpsN+5p5Kyd4sc67xd9rGVQK3DzsOuWpxJp u3+2APA3pAgKHoVoq79cNXsBq9G/Tc2WiHcKJW/XTsLJJj9nOJfpbOgqmEQUxFKBb1T7 f8Sx1ZVpP6YipyTwK6RQ6DjBAOr6U5CzFXhELjhNkhoEIdk7MFRkCb62pydIDrnZgQvh DC31uXd6YH+CejrZ8cnnS59C10xJR7JCk/ddmi0EFU26LJh4qA/Aco6yPzMY9rSyqCyV MwZYaBOM4il2sVrQUf/YxpxFrOPlftP8WmB9xctBwGbT8m/ylL0ziTLeppLWgF05SPVV OxfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100864; x=1769705664; 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=DR7VB2wZFn1Mz1CsNBYoBPzJESjIMKMs9jK7hjYt5g+60+2cHnJrkEjIHK+r9AecSo FucYy/hKR0PyKECZnAUtOteQu7R5BZUzoIvH8E+zrUrprHbYJ8AEMXwb3as4oKW/Xr3V HBVsrrNDk8MndtfRQk6Ng6IRX/f6q7XComMh6JaKJt6G+SF6Vxmqlz29b2/DGdv5vjAt hQJPX5lXww2b7r4R/0zWneDMyA/fW/s9XrrFPOWm6eFMUwRCIf3II3UNFzGgygpnkjAP QfbbsBMRPAMVXO8/5q/wVti4xzds2Upc1h/g8t5kifelVHCVvSb9LXJnNkMbZpLxVxfm EfmA== X-Forwarded-Encrypted: i=1; AJvYcCWZ93VVGcNuBYj23xIW2eY1IYWG24EuyRIMLOI38MwOX/96qNvnL0Aw1yWsVuZYTi641rm2YRU7wSBlIYw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+HgQbM3yt6sBLHB40zvvGoNmoeimECVz1y8MsLwRgajOlNmqu 02EYhkpIuZhfGWRE1P/0pMAkcSMFsnO0uZp0/sQ+KLPmTUFsjwlTIbBdDC6Extossp5IN0MrTfO sr+F1PVcuRg== X-Received: from dyx1.prod.google.com ([2002:a05:693c:8201:b0:2ac:2109:f65f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:550:b0:2b6:a622:25f5 with SMTP id 5a478bee46e88-2b6b470d64bmr12140816eec.11.1769100863572; Thu, 22 Jan 2026 08:54:23 -0800 (PST) Date: Thu, 22 Jan 2026 08:54:00 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-6-irogers@google.com> Subject: [PATCH v2 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 --- 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 Sun Feb 8 08:27:41 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 5D1DC3EBF16 for ; Thu, 22 Jan 2026 16:54:29 +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=1769100877; cv=none; b=TkcHYG6eti2eD4Y5XxlpN6nAbuzTlgFGGd27E8Etzw6UtWVDcVtaHzCbHMBNKrfylceoXLrbjt6HDgGTzqrtx/GUOnWsAdmMbKHFDpEJsG7otcIJ+m41ZXHwdDnsMRCNWeed3l/wy0SLUIpuMgzl2Lr6/kksguxQ3b7RYnGkwHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100877; c=relaxed/simple; bh=KR5+2EshErmuRybWcBELHd/O8khmGf6P5Bg86ngz38E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ZDHuzG/K3ARx8M7yMu0lDm+9cLPmQnSoGHDWcBa286Ig78OA24wU7vXmcTiN2/SaAMtpjjgGohVHcaoccyOd/gaeMTX5/2+1Fb4o9lsPPP/9aQsOsJPVSovi5rzo/wzBbVzgyyG/RQDA3rn8FFGS/V3+/d48idpoeXtI/LwPS+Q= 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=vLLLvjm2; 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="vLLLvjm2" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b704019c98so1266762eec.0 for ; Thu, 22 Jan 2026 08:54:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100866; x=1769705666; 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=vLLLvjm2OTcAI8h0rOuRT1Dk7RwqfSamkn1ITs0RE6z8oyaeGNbdME4rI5a/KhTYlI /ZKkfQZUZA7fYz0a2JUdDrxSKuabpKH31nOuOIsvcTFpEDb2ANUNWieatwgHrSNzpIJb 0zTcMF2Rgm8KY3EIEmCH0VjTiZu7odMHvQ4bb2WeCCUFWx7MN39J5/o3TFQeng1Qbx0c 9kSBoWQxetCOHq5DaORjay2tTw91r6lQNLtNl/tRMW6eUhTwMSXSrdUCqjM/7ZmxP1YS sDc0K8CE8K6aeAtW3FrD6nfd6kO8izLFwf/oXfceN9PDI+m6LNTwF9drVjW4I5+zmIDm By2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100866; x=1769705666; 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=VlJPpBPfC6YXPa1Lis6jxWSrf+pNVls5+hn44ktbv4L+8FDljv7ELT/8UrfmzRzGyb BaqgfqZ//9sBj0yJv/LQEuT4Pz4Q5ahD/+09qk+Zl09BZfIgDVfMIcrze5i2VthT8elm vtEdrpAvrHia6iMf6Yv+V7ZF2rdD/QKKRz4btFRNfeLTD/JtsDABaXcsVP/soB9/dYMy qRhT6MBmlEwbvAaZfwYtWp4v6q44nYh46YXqM8T62fUdBYy3zTK30/iePC1tmTlk6YEo CMw8cKpKIWzm4RcrUnUQTqKhz0G1UejjITKIOz+SrUYXB2MGuUzYjb5FL3c3cGStK1bb etTw== X-Forwarded-Encrypted: i=1; AJvYcCUraAlKz8z1coTrEsi/+sicHOhmMmcZ6j+HjFZr+1v8iZpr2hcsFdJzxGZubKSqQkbtOL6mc8qlFGPs5pA=@vger.kernel.org X-Gm-Message-State: AOJu0YwlSQpHb/JeJVm61Y6V8NKsMOpcNRdYlSx+mlmEnm/OUdpdokn7 awiRNS2Nka83XwtzlB5hMjJcTkVR4Z2pcjENTmipwgVMdSpSDyKJSyKXyN0N9tCAeRvVKtZp0aJ 3MfP4hHPSmg== X-Received: from dycna11.prod.google.com ([2002:a05:7300:ea8b:b0:2b0:5418:353f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:3005:b0:2b7:13f5:43ac with SMTP id 5a478bee46e88-2b713f54696mr3598450eec.15.1769100865487; Thu, 22 Jan 2026 08:54:25 -0800 (PST) Date: Thu, 22 Jan 2026 08:54:01 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-7-irogers@google.com> Subject: [PATCH v2 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 --- 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 Sun Feb 8 08:27:41 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 7CB9B366819 for ; Thu, 22 Jan 2026 16:54:31 +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=1769100881; cv=none; b=cDy1BCnXYLHF17kToOIBm8/rEihvBU7ZtXDhmw4iqcgkOURl+w+bFwajqdCFB0E2sCso3CODp+e93i7TU7mIr4SPDBPJJoy2OMCGARupW7rZOnWxKC7R98kLnxAUnpuF3qZcChMN52iVLFBsyz7j9P9l2fPlo8afgjHSD7q4daM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100881; c=relaxed/simple; bh=sRclvWe9do8aJB1oNVcjn3sHrsa8VOSwS5xxwOFocf8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=cIAYcdLghXvkLVMqMiUrP+/Pckged6VlCEEr111qEGxoT4gdcD0cilV81B4WNnztSN3QhhN+ub/5QIIIlfL0sOLrXgg+0Dq3YS9LtjTd141oA1AN0S9H0JqnofUI/y2WTyBkZSm6F9qSaRYxYVNIsFRwtDpOk94yY/DS8OyoImY= 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=KchcVmj5; 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="KchcVmj5" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b724ff60e6so982943eec.0 for ; Thu, 22 Jan 2026 08:54:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100868; x=1769705668; 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=KchcVmj5Ms28YNpMprKIkNJ37Ln0M+9RxZ2EUBI4GqU3BUqvaBk9cdJK5tuOwzOTDL Dg6s9O44/G8FrrmbrwIpbInC/Ltf95PpDfvvk9zJaYVecHMX0clD6W2MTVSNU2Slb7K1 vThJ63PUqaEnPv1iN8bLnysmeH5OuxjNv6h3FFF3rGKtiDgLULIn3dtBJnqDNnRd3zzQ TkjF1Le38Z4cW9xwK796KKuKYehWewqFH5wO2dHbfpCY4vwjMTn/foxO06HdvtID9JeK oRU2A84XvASPihEcT6m7AJZYHmP8AuqV4H+tdlUPmY7sF/p35CJjRZuDRPQTtR6IVA9A SIZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100868; x=1769705668; 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=BG+MKIyhzq/lD+G7BpoblbS0EuE/pxccC0jA6H/J/Jrvs7Fu07BkHsTSFejzNTgk1W AcyQ4BVpPAQWNK9JwgFzMho5TY5SMOGcDJxoGfN2bD/T/Kjp6AY80ki+8WD4i6NlUBZZ aBbLgQVJT9aVjneFNvW8d0+ycz7wLa0o+3kdVO5krokXkeXzAcNbbbWCVxlWRLeOCCdP UZqy4ygzQwewWmyiSfMednWYaKYoMAhfFgAc0m8dSl2JlnzRPoQHRqY/bI9t/93yMuj6 xl9bYKyKCrmE7qsNb4EyrqV19BY1nd5rKLu0QhDD3OJ4pIiY2kAGmkjMUOzA2oTyI5F7 qKeA== X-Forwarded-Encrypted: i=1; AJvYcCXBt6G7rT47JUp4CvOw/7oPB009FIxbtSnNSUQ6jJuQf8k1g47AW90QNIc/2vrvh7JDEu6txW3Cxbskq9Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzdVQLqltc7JDsTwB0auuJicZ/tM2GqSTKyko1oJDpnFtqQYiYp jnwT8spRfe1kFcI9yWSTtt8PKE2KRbJYb6bZsMm0+jdpfkFunwB4R+5dz4oQ/v8j6WC3R3aEasv HLt57zf/+YQ== X-Received: from dycoh11.prod.google.com ([2002:a05:7301:da0b:b0:2b7:9eb:9ca9]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:8623:b0:2b0:5735:25a1 with SMTP id 5a478bee46e88-2b6fd5d816fmr6237134eec.7.1769100867496; Thu, 22 Jan 2026 08:54:27 -0800 (PST) Date: Thu, 22 Jan 2026 08:54:02 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-8-irogers@google.com> Subject: [PATCH v2 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 --- 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 Sun Feb 8 08:27:41 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 B57AD37FF43 for ; Thu, 22 Jan 2026 16:54:34 +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=1769100886; cv=none; b=str9PQPbthfnHNGuow3xbs5joN91qmUzz2FkwiTF59V2II/pQlsJZVhRJXudzM+BzPUSzNXT7fdia5dEzz6OHxKIJeYC5BkeZPVrQOacQl+AhZa+AnGKWBfO+JymWzp1rp0CSDJLWJihOjmcMqgNT8z/aGbudVj4FWpPyASRi4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100886; c=relaxed/simple; bh=491jb90fnisDDkG3+G9+p4v7Lk7B8Z252ZaXQb6NJdc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=oPWalEmke99JZOVSyht7RGxa3LsOTouozVOxzxg1/aX1+93UG76Ki7rUUdq8YzjvKbrRi4Ud5ogT8gzHms1UYmRGNXNGUeORGroIEYl0aFXHmYZhKSEMwXUF8XbErlkaT3E2GDLT10JxEplzEuwZoXJOaFy/Cqh+xg8hLuqv5fM= 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=1L9qkYaH; 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="1L9qkYaH" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12335cfaf90so240361c88.1 for ; Thu, 22 Jan 2026 08:54:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100870; x=1769705670; 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=1L9qkYaHdgmJhA3p6jpodKlp4IPLzO6Zo4a42Z2NLdvvBv4UhbGxUMO/9vl4m41cDF M6npuVLmX7lm04bCEA4oj1YjM0aytK319YOYs9V8Nhq0bF3BjGzOkb1B9h9ODzfo0BGC uJuIKd3B/kHadBTGcMiEFLq45Q4AMCittfyC7nSayQGTwrAFxyt4sHQ3V+ipkTwUd5+a UTtS/Zc1lj+P123VDN/aVu+Suer+ZI7hbt763alxzFNCl1Y7myK5VEz0c7EYYyn+dTQ5 dXoDKd+1GZpAndt8vffPN9wpgwkgizf6J29FbWiwhWjAY9sxF8f5SoZv7vexvMB9hGZT FLgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100870; x=1769705670; 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=v0vswW14iSnnBDTbXdot15VV+Z+IAve7mAL2IfJjdnTdM/oEQv+63MG8u+RXtG1dfN Y2F45/rzgl/KIO3LfmCeMD4QBa3VMjFPNPUl5uDUTDUbOdJNx2sEQJhSLSc9l0L1PATu EdUjqtZAh5AuKthEDM+kk7YW4C3cE/Rx3Z5OGl5Klhd9OlMjcTb7i1bm5tB7er0TPLhn fU+XbKEv+zlxu/wp8Y3yvYAsUOCY8r34iiGnLL9ZfN6fX+mQKFORGXAwQPoXU4o51JKF RqTEuhG8k9U44twXaE6tXP3ZVsHnBpAm1E+GqYeupDBEyKCF5W5hbOp2IhSCQYH22g0f bIrw== X-Forwarded-Encrypted: i=1; AJvYcCWeBBnYoVPVWlm9t1xMtXfr+QBbZD5DBOQZv+ASAJfBwr18J+uq/sWyRpsq/Sskv/x72dG/u+D5gZSUWdA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7pk5tfxIXp2n9QpLI1oJ2gn1eyy7V83pM5gHWAUHryIoWARGO ApqMZla+I/0M6f4uwPf78Z2LPQrA9L+mFBFfB380YkleXIQhtCNkpGilMsekzl2yT1bKSjfOhfz WFS9rOf+30w== X-Received: from dlf16.prod.google.com ([2002:a05:7022:410:b0:11f:3d13:8e65]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:488:b0:11d:fd41:62c8 with SMTP id a92af1059eb24-1247d778de2mr27365c88.13.1769100869572; Thu, 22 Jan 2026 08:54:29 -0800 (PST) Date: Thu, 22 Jan 2026 08:54:03 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-9-irogers@google.com> Subject: [PATCH v2 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 --- 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 Sun Feb 8 08:27:41 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 3B57437FF6E for ; Thu, 22 Jan 2026 16:54:35 +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=1769100888; cv=none; b=SFXEPCd7JqzdiuhTj3KngcI4DDQElO1d9eD8s9k1U1f0IFC2DnlfoLOLfSfxl3dZ0LXMmFIhkxL3ehil9Zfm/IJlkpnR41iIkZ+5G8KNib7whJZlS2GRgvgrjPYFVO9PYMzXkYQpAJm2zEU8L9pjbox9+1pNebQlg+E45rbV/nM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100888; c=relaxed/simple; bh=/4t52AvyWDIvlIx3zdnelq0uOogrQvoAgZggoWjNLIQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=RD+uG8cp9zVGJLNoxnmvuB4qi54FW+fqHUUaibf3hOWhVun8mus6FJcxJiAfOcKV/YhZpGSwVdE7BMwVRq1yAu33zqluTDVs8QJalecCdHXqhdiTaBtGY0VmDE12UtqkMg7FQEK4SKZ2ba2fIZ8pKPhff+LOzKHd3B7yRUI7sgQ= 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=U8iq+WqR; 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="U8iq+WqR" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b6f0b345e3so6300378eec.0 for ; Thu, 22 Jan 2026 08:54:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100871; x=1769705671; 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=U8iq+WqR9q9OCtAC1xAvVGELkjKGXoPFHvKqx5xuSqodKPK3evdBSoZJTJIBj1EVUj yCArAPNgZnha07ArUtLEoanecgB8G5mnO6+ZJa04ivXXDXTs3P0s1VGpmxv+DRXom8fG TFzWV+wuvLLVnAWzMGMo+AeMNzXpfeEayefmurSXOEqIlwZyL+Y+iyjnFAUfMk4hsMVz 0x/61uTCBwwubcYIIQEawEtC/6i6cFGB2e7B56yz5S488KTRhhZKTPgXuY17X55t8uUx T31Cblxw2iBAFTMH6vZ/agA27IUGSD1QQTsW5OaDxfi52UjSaukBuTFjk6vJys0DJZ6R ys1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100871; x=1769705671; 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=HhPv592eXVebVHiGFSWNiIdokDikiCZ1siX/XQ+RJmi0JtOCmEPxUhJC7gWxSUDIaJ T6YnmNQRawpaQIJhc9EUrA2UZtKztfsOlgPnAbAN6q9UYPV5vLRbTk3vZr4DoYnGB+qo fZGKs4yEodFOnKAoGLACbWm24NdV4DHsLdeYX1tn8u3WiG47me1UM4YsqFb8YE6r71Ma 6yyje67/P0gxBAGDGy5ASCj+mR9qrMHI5bS2Ylb3SzTWcmq5mCL8DepZXG7JikJAdvrZ x43BJb3FQR6gAs0fucwv0WqC8gtgxi2fZf0DBkfYT17acG+ytA8jAge9wLYsxYjgeP11 gc5A== X-Forwarded-Encrypted: i=1; AJvYcCUgy41/cPgNJhze35NWSHGTjOvAsxYd3kSMDMZrZ502S4A0MkT96WDWdyRkShGlcf0FKjicYHzgQ/TLkv4=@vger.kernel.org X-Gm-Message-State: AOJu0YwpBxBImLKl4/h8qpy/6Lsle9FX84XOvhlJ1y4aAeTnM55kqZt2 xRKpG1sOyxbPmCd/t37vKr1YYMvishhqTmGi8lxvve7RnAvfkKdjykk9wO/xdZoApPFDOK8Xru2 Nu0V1sP0pSg== X-Received: from dyer16.prod.google.com ([2002:a05:7300:2310:b0:2b0:6a03:e2bb]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:1291:b0:2b7:1744:725e with SMTP id 5a478bee46e88-2b7397a364dmr12071eec.0.1769100871210; Thu, 22 Jan 2026 08:54:31 -0800 (PST) Date: Thu, 22 Jan 2026 08:54:04 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-10-irogers@google.com> Subject: [PATCH v2 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 --- 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 Sun Feb 8 08:27:41 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 6B9093783C3 for ; Thu, 22 Jan 2026 16:54:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100901; cv=none; b=uchySTRGgDVe/Iw6RyKcVHIAkxAUCkfE7FHDhtNqJH9rZGj8LDRkVON0D6akB90qWYgwqT9wTU1g4bYSWDMq+FrzV50YPScaX5uED5TNbDHW6xXzdfipECcwVB/HU0PYcgZqPTh06/k2FzFrNn7q3Iu3ufibu9A7Yy9LoI2Ef9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100901; c=relaxed/simple; bh=Fw5zeAM2zfnnadmaZE6GhH2s1pBqPvkeHIHlR9oq9uk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ohEHkXRIHv3Fc3ywCM3WfyDZhCq0ldrE2fk/UC0fk0OHGsHAT5ci9Z4sEPBsefOsKzvHfk7TfIKaxL/SKMRDAmeZLlcFwyXA0Ci4BKnjH3qNmTI4LCbPI50LyTYORgAhf8mrwZwHNS2XDI1BcZhhKvO70mB9UBWUfmXkF5EJdNM= 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=vTAaLbmN; arc=none smtp.client-ip=74.125.82.73 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="vTAaLbmN" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-123349958b2so4890496c88.0 for ; Thu, 22 Jan 2026 08:54:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100873; x=1769705673; 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=vTAaLbmNCYOrfQFpAB+GzHKt7eJQuE51VXLZSkLl46TWr0V35cBuKAK9uUyKEW7x6v x+iD1E+7ZNpG/8A0zEu9LRZ8gBPggtDULy6bq+BQtDXOOgn3yix6BNvCu953ljh3xS7m A/sOy6pNBEgZeefqVHu9ZSuOIBcS8AnNz5OnKL1f4v7xwjYoLBlcMl6lphwRHzx1Pifd OUDmcTXRTwSaacpf3PPZk0Noq7S+kjsK2mjBbxOzHQTE+nog/nbBlO314Sj8IMFlRgHU FoovNyqe8z4m/Pg0LsHS4IBsMv4DzLNput88ZSIY08vJ5rMuMvBKqEcOWxgHrgLl3dxn e6pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100873; x=1769705673; 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=kheBDn+MuvRig5c3bQ5/qxrRdYNbXCzqMy654KZ/SAa16LwNRbI0qacjdyMj31R1Ol IFEJF/HqF4U/7obHFv83IMzCBurehENd/mbxXVvptaBU5Utr5rJ3X7QdkIQUicn7oXU2 mgOWDpWKdjYXc+Wy99YGO+TsQ8AFDcvez2KVlbyZoPXnG+5LonjZO18kIPadFw+ICiE5 Uwgk/iEo5+D0ZkO60Y4meC9WxKXQ4OJ9CQPA7VvKZRBhAvjifbcmT+mbnfcwIjLQp0ny B9z63jm4U85hxqZEijbHKkDeNhKddNbwJvLi1f0rPY4l/SbUqyW0I/DA0UgW9azVSipU o2LA== X-Forwarded-Encrypted: i=1; AJvYcCVIvC9AO2T6Fj88NlIUYBXRWyLJCxv1itHKcjSQmd2dn29VsaGF9kJji8Pq9pN2O4sU4SHr5nyLPjWulHY=@vger.kernel.org X-Gm-Message-State: AOJu0YxKUhCxWD7qJZ/JOAKRyy1fi91CNjAOQFRQkxLDQS55nen97VY2 YBVGn/FySiXvrX2OtvpH7pjgWi3rxUbh6v/tBIKJ+pGr2TioI4J6DPyg6l9TShRq1qFrm3uNif0 B1OlnSO60jg== X-Received: from dld13.prod.google.com ([2002:a05:7022:30d:b0:121:79a7:ec2d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:128b:b0:11f:3483:bbb0 with SMTP id a92af1059eb24-1244a72aef2mr18517708c88.19.1769100873225; Thu, 22 Jan 2026 08:54:33 -0800 (PST) Date: Thu, 22 Jan 2026 08:54:05 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-11-irogers@google.com> Subject: [PATCH v2 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 --- 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 Sun Feb 8 08:27:41 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 EDA1D3859D0 for ; Thu, 22 Jan 2026 16:54:39 +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=1769100892; cv=none; b=BU0PlmleNFgz1i/agONj/iTp6ltb7i6OSnYeJVbJbqwuqtkC2BYCPECQa7gDopw3eVEAnjmABOA8U71m2cmVIqc9PE08jWA6e+Al6D3IfCAtNcLoofu0hz9XHJ95MY3dZuYJJ3GN4fapLSDTNUWjr2w/bFMAaf5y19+PmSzb/gY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100892; c=relaxed/simple; bh=04sv3H0xTP77baTwCuBoezrqOp6lRqmviv9QR9g5Kc4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=XD4D3M1pN6AJYalUgqwvX5sNertVmjMy4rHJslmAjid1svB8H78C4lHatrFw4vijMyJxYWF3CExWxJHWEu4bD5AaxjlYNJZ6Ka8PDK1XtCjcdLH4LsRvNi6P0DliIu53In9VN57a71dBvkhIdy3bPqPXM9wzIizudZ8/RcjmPZw= 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=GDQ0L34l; 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="GDQ0L34l" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b70c92f404so1645359eec.0 for ; Thu, 22 Jan 2026 08:54:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100875; x=1769705675; 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=L3tfpDGgMXxO9KixeIltpKBhsTwkoWo2VIaEEFB+NJI=; b=GDQ0L34lvy/UvoRSiTTdkvy4AWTjNT49IIyTNb2SpmeYECuqdAdxbJTCbzIoNTpX9n myFXlr+GZMnfuZhfyCMCo6VZp7Rehavz4ODyL1q1yW7pC5C+0z8m5pL5nSAr2SpRPmQj PTHibyhF9bDcI19G210bkOnDba8vdA4LAmaY+n/QPq4hQ3u51QWD/UdHuPzqrGtmoa3l MiXmirehAWhud1ijxoQ6yp1RkRzkGW7Y25hNKT7RakSjmdRcWFEYPWU2EAsLNYBh8xVR pVZ/ABvZZbWvGfNUuSk/49wh3+l1Bia7Gh7M5dHs2VW+i0sd5k6+0+F4JZ4WO50YLw4q XePA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100875; x=1769705675; 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=L3tfpDGgMXxO9KixeIltpKBhsTwkoWo2VIaEEFB+NJI=; b=mQiAwU7NXoodXLKJwzlO1/KjEDnH9yoQsnYF42d/NqElSPuDQrKqLK/AJnzWhhJ5t7 2S4fakTFAbxPaSDlpuJU1o0ZKKexsPJ1aLRhNSslld83VM+FXhCdmM2g5dspv5dkQa6G XfsAAjCHGfHm1xiUgNACKD9vaSe+tDu2LcT+yuiFDZFpOvAedV8IeziTzlG+vwD2UlAC L3iWMYguYGw4KU1echQaDDbnQJXVLM+U7+8gpoqYaZVMxTaBxoDN4M/2Kh7+Kp73grX2 xzDbFz1rkNKXFmFPAQD4ghK1Sh1YN9MNRi1S2/V4DPoxHVN13Whs84jtKKHAaZGtZG24 vleQ== X-Forwarded-Encrypted: i=1; AJvYcCWCCcl/rur+NnF8VinKYci1gMC0QYuNBGNxW/yhYhBt+D9QvDmdwciHV5yruv8hllFSFCQv0Tu+vx4lCkw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3WBe5CofA1Viutz7+Ny52htsVol17oJFB88xenKa7EduGfwGm rAJjG1jILt41FPTbIxsh7RHjhgg5hxL81A6UIN8nRH1o/cayb9IAdbbF2WO43TANk+B+IuOSYnr N3OaRbKIidg== X-Received: from dybbz25.prod.google.com ([2002:a05:7300:a599:b0:2b6:c3b1:69d4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:5712:b0:2a4:3594:72d1 with SMTP id 5a478bee46e88-2b73979ff1cmr14890eec.0.1769100875149; Thu, 22 Jan 2026 08:54:35 -0800 (PST) Date: Thu, 22 Jan 2026 08:54:06 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-12-irogers@google.com> Subject: [PATCH v2 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 --- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/util/annotate-arch/annotate-arc.c | 14 +- tools/perf/util/annotate-arch/annotate-arm.c | 37 +++-- .../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 | 22 +-- .../util/annotate-arch/annotate-riscv64.c | 19 ++- tools/perf/util/annotate-arch/annotate-s390.c | 29 ++-- .../perf/util/annotate-arch/annotate-sparc.c | 17 +- 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, 278 insertions(+), 237 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..25086f5fce23 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; =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..da45c7d05757 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,44 @@ 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; + if (!arm) + 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 arm =3D zalloc(sizeof(*arm)); if (!arm) - return ENOMEM; + return NULL; =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..004e6137aa03 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; } 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..fe7a37966261 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)); + + if (!arch) + return NULL; =20 + arch->name =3D "sparc"; + arch->id =3D *id; + arch->associate_instruction_ops =3D sparc__associate_instruction_ops; + arch->objdump.comment_char =3D '#'; return 0; } 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 Sun Feb 8 08:27:41 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 BF44137883F for ; Thu, 22 Jan 2026 16:54:41 +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=1769100895; cv=none; b=d2jVgk9oRh6EhKiDPnbkbAIq+XcXV5Oz2JI5hHfB+v1XbSRJmCOdV0yPJ+XZ3IXO8JX7IP41rO9DEtK/wxPvwj0mDQ8hXDU6cjC6HEGws3Dsu2ssN514FFhSUYtgseOWMUlhlU7vGtpA0dMj3m0Oyq3ezzDy39vFpyRH4bY3Or0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100895; c=relaxed/simple; bh=DNIcWZ9QKgcap8GIm+HHaS7sytvjKF8lN4kZaGLyU7M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=L11uTGe4YrQlX1X09AQY+jrXKdPEMfPmR2/P+K+XolBetG/51GV1zXTrCHdN/hcZmi9LZXEP5n0VYT0z9YZXkUREfMB0ojZIPIjBzOBXGxraLEnIJwwZytwvHIsiVZy4qHxfFR1zu4iRqxtzStvckXc722kq+dBFj5qD1cbLzHk= 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=xt1PmwZs; 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="xt1PmwZs" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b722bc1be1so934270eec.0 for ; Thu, 22 Jan 2026 08:54:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100877; x=1769705677; 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=xt1PmwZsaUx4dgkEzsUbAq8Wq3pjhpNJofXV83Ct6qieDEbvBOPY2UI/mTXdyghxT0 f4sRXOmpmMPIe/o8THF+nmOuDhig9ghl+SkL+YSq0/rzdXw1FotT8tcVcyShI1KLp40X BmJFIB1O3NQR7S/bDNtJ+s0XGNftHQcanMg4vz1tm9icm7QtNdwOOfFDwv6BsnyP8BDY /5yeMoOAknT5XNXv5lCa+GqB/8C537g6Ubh1CS3SGRZC+Lg6ke34TDPFNxlrfICKmMHi aWDzS+KARNj1t3Qy2YfweAoFJpGSuk/3/sYYdNKRaH3O8okwaYS3V9nUtOFwZrzxFD+J ETJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100877; x=1769705677; 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=L+T/TBaczHXi7BLUSXaWIEEHtIGtCtcolnh88nanY6h2FSQtkDYmQqg3LOHjF68OgG n54JHxMtmwga2KoM4hdhdowmMr6iEGecdZAYxqaywFmCWNbTIkDjnozBHUBRv30IQvy+ LSE8YdwqumkexYqAi2ueE9h06n7YK1W9W5cDWtZX3vH98zpP0/YFKowrW6Fn797Ajhwn to3CzJBsoa1Gr4/8yY9lr8QlebXPQ2SRNy/IGzUnKOeG/iAcvUtzgdy6f9GFEor7L5DK YJfe1FPhS96gJ2SVcezj572yex+O9hU++HgZ3NfWJGAWeij6qk77FO4xjDrUfagedAjk SGvA== X-Forwarded-Encrypted: i=1; AJvYcCVoA+zhLzQF8Ur2S0wmqzA7St11K0zWUsXkQAZSCdkYa7bEUbyjoFBxBOb8u94sE3kLn/P9Pc5Do7m7GQ8=@vger.kernel.org X-Gm-Message-State: AOJu0Yyf+/UYNJdZGOfdewLAiC4Xn8FBhqXZGbs0BXR+lPpDpeNFUYJY bxFV77WR/G+HDFl3GcyrKKrXaW0iHpV8buYPZ0USKIPr0npPmVY0YCILYAhwGfJOZoNgInKHPfY yDwg5D3uNmQ== X-Received: from dlbph24.prod.google.com ([2002:a05:7022:3718:b0:121:766b:11e4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:b94:b0:11b:8f02:a876 with SMTP id a92af1059eb24-1244a75eb07mr15601672c88.23.1769100877336; Thu, 22 Jan 2026 08:54:37 -0800 (PST) Date: Thu, 22 Jan 2026 08:54:07 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-13-irogers@google.com> Subject: [PATCH v2 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 --- 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