From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Willy Tarreau <w@1wt.eu>
Cc: dwarves@vger.kernel.org, Alan Maguire <alan.maguire@oracle.com>,
Jiri Olsa <jolsa@kernel.org>,
Clark Williams <williams@redhat.com>,
Kate Carcia <kcarcia@redhat.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>
Subject: [PATCH 3/5] core: Introduce class__has_embedded_flexible_array()
Date: Mon, 7 Oct 2024 17:25:29 -0300 [thread overview]
Message-ID: <20241007202531.942648-4-acme@kernel.org> (raw)
In-Reply-To: <20241007202531.942648-1-acme@kernel.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
That we will use both when pretty printing structs, as a new comment,
and with a 'pahole --with_embedded_flexible_array' to show structs with
embedded structs that have flexible arrays and thus should be used with
super extra care.
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Willy Tarreau <w@1wt.eu>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
dwarves.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
dwarves.h | 3 +++
2 files changed, 47 insertions(+)
diff --git a/dwarves.c b/dwarves.c
index f5bc9cb27adee649..2ac82956bd5ea45d 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -1737,6 +1737,50 @@ void class__find_holes(struct class *class)
class->holes_searched = true;
}
+bool class__has_embedded_flexible_array(struct class *cls, const struct cu *cu)
+{
+ struct type *ctype = &cls->type;
+ struct class_member *pos;
+
+ if (!tag__is_struct(class__tag(cls)))
+ return false;
+
+ if (cls->embedded_flexible_array_searched)
+ return cls->has_embedded_flexible_array;
+
+ type__for_each_member(ctype, pos) {
+ /* XXX for now just skip these */
+ if (pos->tag.tag == DW_TAG_inheritance &&
+ pos->virtuality == DW_VIRTUALITY_virtual)
+ continue;
+
+ if (pos->is_static)
+ continue;
+
+ struct tag *member_type = tag__strip_typedefs_and_modifiers(&pos->tag, cu);
+ if (member_type == NULL)
+ continue;
+
+ if (!tag__is_struct(member_type))
+ continue;
+
+ cls->has_embedded_flexible_array = class__has_flexible_array(tag__class(member_type), cu);
+ if (cls->has_embedded_flexible_array)
+ break;
+
+ if (member_type == class__tag(cls))
+ continue;
+
+ cls->has_embedded_flexible_array = class__has_embedded_flexible_array(tag__class(member_type), cu);
+ if (cls->has_embedded_flexible_array)
+ break;
+ }
+
+ cls->embedded_flexible_array_searched = true;
+
+ return cls->has_embedded_flexible_array;
+}
+
static size_t type__natural_alignment(struct type *type, const struct cu *cu);
size_t tag__natural_alignment(struct tag *tag, const struct cu *cu)
diff --git a/dwarves.h b/dwarves.h
index bcf701706c61b4f5..f147b2bcfd8a153e 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -1413,7 +1413,9 @@ struct class {
uint8_t bit_padding;
bool holes_searched;
bool flexible_array_verified;
+ bool embedded_flexible_array_searched;
bool has_flexible_array;
+ bool has_embedded_flexible_array;
bool is_packed;
void *priv;
};
@@ -1456,6 +1458,7 @@ static inline int class__is_struct(const struct class *cls)
return tag__is_struct(&cls->type.namespace.tag);
}
+bool class__has_embedded_flexible_array(struct class *cls, const struct cu *cu);
bool class__has_flexible_array(struct class *class, const struct cu *cu);
void class__find_holes(struct class *cls);
int class__has_hole_ge(const struct class *cls, const uint16_t size);
--
2.46.2
next prev parent reply other threads:[~2024-10-07 20:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-07 20:25 [PATCH RFC 0/5] pahole --with_embedded_flexible_array Arnaldo Carvalho de Melo
2024-10-07 20:25 ` [PATCH 1/5] core: Move class__has_flexible_array() from pahole to the core Arnaldo Carvalho de Melo
2024-10-07 20:25 ` [PATCH 2/5] core: Cache info about flexible arrays in class__has_flexible_array() Arnaldo Carvalho de Melo
2024-10-07 20:25 ` Arnaldo Carvalho de Melo [this message]
2024-10-07 20:25 ` [PATCH 4/5] fprintf: Add a comment if a member type has an embedded flexible array Arnaldo Carvalho de Melo
2024-10-07 20:25 ` [PATCH 5/5] pahole: Introduce --with_embedded_flexible_array 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=20241007202531.942648-4-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=alan.maguire@oracle.com \
--cc=dwarves@vger.kernel.org \
--cc=gustavoars@kernel.org \
--cc=jolsa@kernel.org \
--cc=kcarcia@redhat.com \
--cc=w@1wt.eu \
--cc=williams@redhat.com \
/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