All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aditya Dutt <duttaditya18@gmail.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Aditya Dutt <duttaditya18@gmail.com>,
	dwarves@vger.kernel.org, Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH dwarves 2/2] pahole: Fix -C -T segfault
Date: Fri,  4 Sep 2026 02:26:59 +0530	[thread overview]
Message-ID: <20260903205659.1543175-3-duttaditya18@gmail.com> (raw)
In-Reply-To: <20260903205659.1543175-1-duttaditya18@gmail.com>

-T/--nr_definitions sets stats_formatter and sets formatter to NULL.
print_classes() checks for that before calling it.
The -C code path does not which results in a segfault.

Before:
  $ cat m.c
  struct named { int a; char b; };
  union u_named { int a; long b; };
  struct holey { char a; int b; };
  struct named s; union u_named u; struct holey h;

  $ pahole -C named -T m.o
  Segmentation fault (core dumped)

Reject the combination, similar to '-m -C'.

After:
  $ pahole -C named -T m.o
  pahole: -T/nr_definitions doesn't work with --class_name/-C, it shows all classes and the number of times they are defined
  $ echo $?
  1

  $ pahole -T m.o # unchanged
  named   1
  u_named 1
  holey   1

Fixes: f5857bd34b220a64 ("pahole: Honour --compile when -C is used")
Signed-off-by: Aditya Dutt <duttaditya18@gmail.com>
---
 pahole.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pahole.c b/pahole.c
index aa04d98..b2047c1 100644
--- a/pahole.c
+++ b/pahole.c
@@ -3461,7 +3461,7 @@ static enum load_steal_kind pahole_stealer(struct cu *cu, struct conf_load *conf
 			print_containers(cu, class_id, 0);
 		else if (find_pointers_in_structs)
 			print_structs_with_pointer_to(cu, class_id);
-		else if (class) {
+		else if (class && formatter != NULL) {
 			/*
 			 * We don't need to print it for every compile unit
 			 * but the previous options need
@@ -3666,6 +3666,11 @@ int main(int argc, char *argv[])
 		return rc;
 	}
 
+	if (class_name != NULL && stats_formatter == nr_definitions_formatter) {
+		fputs("pahole: -T/nr_definitions doesn't work with --class_name/-C, it shows all classes and the number of times they are defined\n", stderr);
+		return rc;
+	}
+
 	if (print_numeric_version) {
 		dwarves_print_numeric_version(stdout);
 		return 0;
-- 
2.34.1


  parent reply	other threads:[~2026-09-03 20:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03 20:56 [PATCH dwarves 0/2] pahole: Fix -C -T segfault Aditya Dutt
2026-09-03 20:56 ` [PATCH dwarves 1/2] pahole: Fix option name in the -m/-C error message Aditya Dutt
2026-09-03 20:56 ` Aditya Dutt [this message]
2026-09-04  1:33 ` [PATCH dwarves 0/2] pahole: Fix -C -T segfault Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260903205659.1543175-3-duttaditya18@gmail.com \
    --to=duttaditya18@gmail.com \
    --cc=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=dwarves@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.