From: Douglas RAILLARD <douglas.raillard@arm.com>
To: acme@redhat.com
Cc: dwarves@vger.kernel.org, douglas.raillard@arm.com
Subject: [PATCH v3 1/6] fprintf: Fix nested struct printing
Date: Thu, 28 Oct 2021 13:27:05 +0100 [thread overview]
Message-ID: <20211028122710.881181-2-douglas.raillard@arm.com> (raw)
In-Reply-To: <20211028122710.881181-1-douglas.raillard@arm.com>
From: Douglas Raillard <douglas.raillard@arm.com>
This code:
struct X {
struct {
} __attribute__((foo)) x __attribute__((bar));
}
Was wrongly printed as:
struct X {
struct {
} x __attribute__((foo)) __attribute__((bar));
}
This unfortunately matters a lot, since "bar" is suppose to apply to
"x", but "foo" to typeof(x). In the wrong form, both apply to "x",
leading to e.g. incorrect layout for __aligned__ attribute.
Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
---
dwarves_fprintf.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c
index c35868a..1c1d949 100644
--- a/dwarves_fprintf.c
+++ b/dwarves_fprintf.c
@@ -787,7 +787,7 @@ print_default:
(type->tag == DW_TAG_class_type &&
!tconf.classes_as_structs) ? "class" : "struct",
tconf.type_spacing - 7,
- type__name(ctype), name);
+ type__name(ctype), name ?: "");
} else {
struct class *cclass = tag__class(type);
@@ -802,7 +802,7 @@ print_default:
ctype = tag__type(type);
if (type__name(ctype) != NULL && !expand_types) {
- printed += fprintf(fp, "union %-*s %s", tconf.type_spacing - 6, type__name(ctype), name);
+ printed += fprintf(fp, "union %-*s %s", tconf.type_spacing - 6, type__name(ctype), name ?: "");
} else {
tconf.type_spacing -= 8;
printed += union__fprintf(ctype, cu, &tconf, fp);
@@ -812,7 +812,7 @@ print_default:
ctype = tag__type(type);
if (type__name(ctype) != NULL)
- printed += fprintf(fp, "enum %-*s %s", tconf.type_spacing - 5, type__name(ctype), name);
+ printed += fprintf(fp, "enum %-*s %s", tconf.type_spacing - 5, type__name(ctype), name ?: "");
else
printed += enumeration__fprintf(type, &tconf, fp);
break;
@@ -863,7 +863,21 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb
if (member->is_static)
printed += fprintf(fp, "static ");
- printed += type__fprintf(type, cu, name, &sconf, fp);
+ /* For struct-like constructs, the name of the member cannot be
+ * conflated with the name of its type, otherwise __attribute__ are
+ * printed in the wrong order.
+ */
+ if (tag__is_union(type) || tag__is_struct(type) ||
+ tag__is_enumeration(type)) {
+ printed += type__fprintf(type, cu, NULL, &sconf, fp);
+ if (name) {
+ if (!type__name(tag__type(type)))
+ printed += fprintf(fp, " ");
+ printed += fprintf(fp, "%s", name);
+ }
+ } else {
+ printed += type__fprintf(type, cu, name, &sconf, fp);
+ }
if (member->is_static) {
if (member->const_value != 0)
--
2.25.1
next prev parent reply other threads:[~2021-10-28 12:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-28 12:27 [PATCH v3 0/6] Infer BTF alignment Douglas RAILLARD
2021-10-28 12:27 ` Douglas RAILLARD [this message]
2021-10-28 12:40 ` [PATCH v3 1/6] fprintf: Fix nested struct printing Arnaldo Carvalho de Melo
2021-10-28 12:27 ` [PATCH v3 2/6] btf_loader.c: Refactor class__fixup_btf_bitfields Douglas RAILLARD
2021-10-28 13:15 ` Arnaldo Carvalho de Melo
2021-10-28 12:27 ` [PATCH v3 3/6] btf_loader.c: Infer alignment info Douglas RAILLARD
2021-10-28 13:15 ` Arnaldo Carvalho de Melo
2021-10-28 12:27 ` [PATCH v3 4/6] dwarves_fprintf: Move cacheline_size into struct conf_fprintf Douglas RAILLARD
2021-10-28 13:18 ` Arnaldo Carvalho de Melo
2021-10-28 12:27 ` [PATCH v3 5/6] btf_loader.c: Propagate struct conf_load Douglas RAILLARD
2021-10-28 13:19 ` Arnaldo Carvalho de Melo
2021-10-28 12:27 ` [PATCH v3 6/6] btf_loader.c: Use cacheline size to infer alignment Douglas RAILLARD
2021-10-28 13:24 ` Arnaldo Carvalho de Melo
2021-10-28 14:12 ` Douglas Raillard
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=20211028122710.881181-2-douglas.raillard@arm.com \
--to=douglas.raillard@arm.com \
--cc=acme@redhat.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;
as well as URLs for NNTP newsgroup(s).