From 986a3b58a86984e80a7fec5234a3a4d814139aa6 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Mon, 15 Apr 2019 13:55:34 -0300 Subject: [PATCH] fprintf: Only add bitfield forced paddings when alignment info available I.e. BTF doesn't have DW_AT_alignment, so avoid emitting the bitfield for padding at the end: $ pahole -F btf -C rseq examples/tcp.o struct rseq { __u32 cpu_id_start; /* 0 4 */ __u32 cpu_id; /* 4 4 */ union { __u64 ptr64; /* 8 8 */ __u64 ptr; /* 8 8 */ } rseq_cs; /* 8 8 */ __u32 flags; /* 16 4 */ /* Force padding: */ __u32 :32; __u32 :32; __u32 :32; /* size: 32, cachelines: 1, members: 4 */ /* padding: 12 */ /* last cacheline: 32 bytes */ }; $ After: $ pahole -F btf -C rseq examples/tcp.o struct rseq { __u32 cpu_id_start; /* 0 4 */ __u32 cpu_id; /* 4 4 */ union { __u64 ptr64; /* 8 8 */ __u64 ptr; /* 8 8 */ } rseq_cs; /* 8 8 */ __u32 flags; /* 16 4 */ /* size: 32, cachelines: 1, members: 4 */ /* padding: 12 */ /* last cacheline: 32 bytes */ }; $ Signed-off-by: Arnaldo Carvalho de Melo --- dwarves_fprintf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c index 34073d1..9d493ab 100644 --- a/dwarves_fprintf.c +++ b/dwarves_fprintf.c @@ -1596,7 +1596,11 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu, last = pos; } - if (class->padding != 0 && type->alignment == 0) { + /* + * BTF doesn't have alignment info, for now use this infor from the loader + * to avoid adding the forced bitfield paddings and have btfdiff happy. + */ + if (class->padding != 0 && type->alignment == 0 && conf->has_alignment_info) { tag_pos = cu__type(cu, last->tag.type); size = tag__size(tag_pos, cu);