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 <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2019-04-15 15:01:53 -03:00
parent ec935ee422
commit 9a4d719304
5 changed files with 23 additions and 3 deletions

View File

@ -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

View File

@ -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;

View File

@ -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)

View File

@ -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".

View File

@ -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;