From 9a4d7193046703a3a0d18d105e02f983cbc08501 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Mon, 15 Apr 2019 15:01:53 -0300 Subject: [PATCH] fprintf: Allow suppressing the inferred __attribute__((__packed__)) We use things like DW_AT_alignment, so not all of those attributes are inferred by formats like BTF that lack that info, allow suppressing the output and make btfdiff ask for both DWARF and BTF output to have this suppressed. Signed-off-by: Arnaldo Carvalho de Melo --- btfdiff | 5 ++++- dwarves.h | 1 + dwarves_fprintf.c | 4 ++-- man-pages/pahole.1 | 8 ++++++++ pahole.c | 8 ++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/btfdiff b/btfdiff index 885142d..53b4905 100755 --- a/btfdiff +++ b/btfdiff @@ -20,8 +20,11 @@ ${pahole_bin} -F dwarf \ --flat_arrays \ --suppress_aligned_attribute \ --suppress_force_paddings \ + --suppress_packed \ --show_private_classes $file > $dwarf_output -${pahole_bin} -F btf $file > $btf_output +${pahole_bin} -F btf \ + --suppress_packed \ + $file > $btf_output diff -up $dwarf_output $btf_output diff --git a/dwarves.h b/dwarves.h index c741c55..ed83e69 100644 --- a/dwarves.h +++ b/dwarves.h @@ -79,6 +79,7 @@ struct conf_fprintf { uint8_t suppress_aligned_attribute:1; uint8_t suppress_offset_comment:1; uint8_t suppress_force_paddings:1; + uint8_t suppress_packed:1; uint8_t show_decl_info:1; uint8_t show_only_data_members:1; uint8_t no_semicolon:1; diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c index e9a00eb..cbdcc75 100644 --- a/dwarves_fprintf.c +++ b/dwarves_fprintf.c @@ -825,7 +825,7 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb int slen = cm_name ? (int)strlen(cm_name) : -1; int size_spacing = 5; - if (tag__is_struct(type) && tag__class(type)->is_packed) { + if (tag__is_struct(type) && tag__class(type)->is_packed && !conf->suppress_packed) { int packed_len = sizeof("__attribute__((__packed__))"); slen += packed_len; } @@ -1697,7 +1697,7 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu, out: printed += fprintf(fp, "%.*s}", indent, tabs); - if (class->is_packed) + if (class->is_packed && !conf->suppress_packed) printed += fprintf(fp, " __attribute__((__packed__))"); if (cconf.suffix) diff --git a/man-pages/pahole.1 b/man-pages/pahole.1 index ca5ea14..282a50f 100644 --- a/man-pages/pahole.1 +++ b/man-pages/pahole.1 @@ -182,6 +182,14 @@ Suppress bitfield forced padding at the end of structs, as this requires something like DWARF's DW_AT_alignment, so that one can compare BTF or CTF output, that don't have that info. +.TP +.B \-\-suppress_packed + +Suppress the output of the inference of __attribute__((__packed__)), so that +one can compare BTF or CTF output, the inference algorithm uses things like +DW_AT_alignment, so until it is improved to infer that as well for BTF, allow +disabling this output. + .TP .B \-\-fixup_silly_bitfields Converts silly bitfields such as "int foo:32" to plain "int foo". diff --git a/pahole.c b/pahole.c index 48d3523..eb40dd8 100644 --- a/pahole.c +++ b/pahole.c @@ -753,6 +753,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version; #define ARGP_hex_fmt 305 #define ARGP_suppress_aligned_attribute 306 #define ARGP_suppress_force_paddings 307 +#define ARGP_suppress_packed 308 static const struct argp_option pahole__options[] = { { @@ -960,6 +961,11 @@ static const struct argp_option pahole__options[] = { .key = ARGP_suppress_force_paddings, .doc = "Suppress int :N paddings at the end", }, + { + .name = "suppress_packed", + .key = ARGP_suppress_packed, + .doc = "Suppress output of inferred __attribute__((__packed__))", + }, { .name = "show_private_classes", .key = ARGP_show_private_classes, @@ -1064,6 +1070,8 @@ static error_t pahole__options_parser(int key, char *arg, conf.suppress_aligned_attribute = 1; break; case ARGP_suppress_force_paddings: conf.suppress_force_paddings = 1; break; + case ARGP_suppress_packed: + conf.suppress_packed = 1; break; case ARGP_show_private_classes: show_private_classes = true; conf.show_only_data_members = 1; break;