[PATCH 3/5] core: Introduce class__has_embedded_flexible_array()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

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@xxxxxxxxxx>
Cc: Willy Tarreau <w@xxxxxx>
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
 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





[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux