From: Eduard Zingerman <eddyz87@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, kernel-team@fb.com
Cc: Eduard Zingerman <eddyz87@gmail.com>
Subject: [PATCH bpf-next 1/2] bpftool: fix newline for struct with padding only fields
Date: Fri, 30 Sep 2022 19:49:17 +0300 [thread overview]
Message-ID: <20220930164918.342310-2-eddyz87@gmail.com> (raw)
In-Reply-To: <20220930164918.342310-1-eddyz87@gmail.com>
An update for `bpftool btf dump file ... format c`.
Add a missing newline print for structures that consist of
anonymous-only padding fields. E.g. here is struct bpf_timer from
vmlinux.h before this patch:
struct bpf_timer {
long: 64;
long: 64;};
And after this patch:
struct bpf_dynptr {
long: 64;
long: 64;
};
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
---
tools/lib/bpf/btf_dump.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 4221f73a74d0..ebbba19ac122 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -852,7 +852,7 @@ static int chip_away_bits(int total, int at_most)
return total % at_most ? : at_most;
}
-static void btf_dump_emit_bit_padding(const struct btf_dump *d,
+static bool btf_dump_emit_bit_padding(const struct btf_dump *d,
int cur_off, int m_off, int m_bit_sz,
int align, int lvl)
{
@@ -861,10 +861,10 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d,
if (off_diff <= 0)
/* no gap */
- return;
+ return false;
if (m_bit_sz == 0 && off_diff < align * 8)
/* natural padding will take care of a gap */
- return;
+ return false;
while (off_diff > 0) {
const char *pad_type;
@@ -886,6 +886,8 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d,
btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, pad_bits);
off_diff -= pad_bits;
}
+
+ return true;
}
static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
@@ -906,6 +908,7 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
bool is_struct = btf_is_struct(t);
int align, i, packed, off = 0;
__u16 vlen = btf_vlen(t);
+ bool padding_added = false;
packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0;
@@ -940,11 +943,11 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
/* pad at the end, if necessary */
if (is_struct) {
align = packed ? 1 : btf__align_of(d->btf, id);
- btf_dump_emit_bit_padding(d, off, t->size * 8, 0, align,
- lvl + 1);
+ padding_added = btf_dump_emit_bit_padding(d, off, t->size * 8, 0, align,
+ lvl + 1);
}
- if (vlen)
+ if (vlen || padding_added)
btf_dump_printf(d, "\n");
btf_dump_printf(d, "%s}", pfx(lvl));
if (packed)
--
2.37.3
next prev parent reply other threads:[~2022-09-30 16:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-30 16:49 [PATCH bpf-next 0/2] bpftool: fix newline for struct with padding only fields Eduard Zingerman
2022-09-30 16:49 ` Eduard Zingerman [this message]
2022-09-30 23:01 ` [PATCH bpf-next 1/2] " Andrii Nakryiko
2022-09-30 16:49 ` [PATCH bpf-next 2/2] selftests/bpf: verify " Eduard Zingerman
2022-09-30 23:03 ` Andrii Nakryiko
2022-09-30 22:59 ` [PATCH bpf-next 0/2] bpftool: fix " Andrii Nakryiko
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=20220930164918.342310-2-eddyz87@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.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