Dwarves debugging tools
 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] pahole: --unions shouldn't bypass struct-only options
Date: Tue,  1 Sep 2026 00:26:41 +0530	[thread overview]
Message-ID: <20260831185641.971022-1-duttaditya18@gmail.com> (raw)

class__filter() returns early for --unions before the guard for struct
only options. This results in calling functions like
print_packable_info(), which reads c->priv which doesn't exist for
unions.

  $ pahole --unions --packable m
  Segmentation fault (core dumped)

The early return also prevents other struct only option filtering.
                             before             after
  --unions --packable        segfault           (nothing)
  --unions -H 1              union u_named {}   (nothing)
  --unions --bit_holes 1     union u_named {}   (nothing)
  --unions --hole_size_ge 1  u_named            (nothing)
  --unions --padding_ge 1    union u_named {}   (nothing)
  --with_flexible_array      union u_named {}   (nothing)

These don't make sense for a union: all of its members start at offset 0,
so there are no holes to count or pack, C doesn't allow a flexible array
member in one. nr_holes, padding and has_flexible_array only exist in
'struct class', so there is nowhere to keep an answer either.

--with_flexible_array and --with_embedded_flexible_array were missing from the
struct only list, so add them too.

Fixes: 3661f17d0b2cd56b ("pahole: Introduce --unions to consider just unions")
Signed-off-by: Aditya Dutt <duttaditya18@gmail.com>
---

There are a few more CLI bugs and will be sending patches for them
soon: 'pahole -C <type> -T' segfaults etc.

Are there other things related to pahole I can contribute to? I would
also like to help with the Rust support if there is something useful I
can pick up.

 pahole.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/pahole.c b/pahole.c
index a1b3d4a..c7daa31 100644
--- a/pahole.c
+++ b/pahole.c
@@ -462,6 +462,11 @@ static void class_formatter(struct class *class, struct cu *cu, uint32_t id)
 static void print_packable_info(struct class *c, struct cu *cu, uint32_t id)
 {
 	const struct tag *t = class__tag(c);
+
+	/* unions are not packable */
+	if (!tag__is_struct(t))
+		return;
+
 	const size_t orig_size = class__size(c);
 	const size_t new_size = class__size(c->priv);
 	const size_t savings = orig_size - new_size;
@@ -716,12 +721,6 @@ static struct class *class__filter(struct class *class, struct cu *cu,
 	     strncmp(decl_exclude_prefix, tag__decl_file(tag, cu),
 		     decl_exclude_prefix_len) == 0))
 		return NULL;
-	/*
-	 * if --unions was used and we got here, its a union and we satisfy the other
-	 * filters/options, so don't filter it.
-	 */
-	if (just_unions)
-		return class;
 	/*
 	 * The following only make sense for structs, i.e. 'struct class',
 	 * and as we can get here with a union, that is represented by a 'struct type',
@@ -730,7 +729,8 @@ static struct class *class__filter(struct class *class, struct cu *cu,
 	 */
 	if (!tag__is_struct(tag))
 		return (just_structs || show_packable || nr_holes || nr_bit_holes || hole_size_ge ||
-			end_padding_ge || end_padding) ? NULL : class;
+			end_padding_ge || end_padding || show_with_flexible_array ||
+			show_with_embedded_flexible_array) ? NULL : class;
 
 	if (tag->top_level)
 		class__find_holes(class);
-- 
2.34.1


             reply	other threads:[~2026-08-31 18:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 18:56 Aditya Dutt [this message]
2026-08-31 21:35 ` [PATCH dwarves] pahole: --unions shouldn't bypass struct-only options Arnaldo Carvalho de Melo
2026-09-01 13:21   ` Aditya Dutt

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=20260831185641.971022-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox