From ac7778099a67853627c18278c9a949934460d93d Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Fri, 20 Mar 2009 13:54:04 -0300 Subject: [PATCH] pahole: Introduce --fixup_silly_bitfields $ pahole -C acpi_device_perf_flags ac.o struct acpi_device_perf_flags { u8 reserved:8; /* 0: 0 1 */ /* size: 1, cachelines: 1, members: 1 */ /* last cacheline: 1 bytes */ }; $ pahole --fixup_silly_bitfields -C acpi_device_perf_flags ac.o struct acpi_device_perf_flags { u8 reserved; /* 0 1 */ /* size: 1, cachelines: 1, members: 1 */ /* last cacheline: 1 bytes */ }; $ Used in ctfdwdiff as in CTF land we can't express such sillyness. Signed-off-by: Arnaldo Carvalho de Melo --- ctfdwdiff | 6 ++++-- dwarf_loader.c | 14 +++++++++++--- dwarves.h | 4 +++- man-pages/pahole.1 | 4 ++++ pahole.c | 12 ++++++++++-- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/ctfdwdiff b/ctfdwdiff index 72fc238..ce6c089 100755 --- a/ctfdwdiff +++ b/ctfdwdiff @@ -8,10 +8,12 @@ ctf=$dir/$obj.ctf.c dwarf=$dir/$obj.dwarf.c pahole -Z $obj pahole -F ctf $obj > $ctf -pahole --flat_arrays --show_private_classes -F dwarf $obj > $dwarf +pahole --flat_arrays \ + --show_private_classes \ + --fixup_silly_bitfields -F dwarf $obj > $dwarf diff -up $ctf $dwarf > $diff if [ -s $diff ] ; then - # vim $dir/$obj.diff + [ $# -gt 1 ] && vim $dir/$obj.diff exit 0 else rm -f $diff $ctf $dwarf diff --git a/dwarf_loader.c b/dwarf_loader.c index f1fb0fb..b79e0b2 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -1715,9 +1715,10 @@ static void die__process(Dwarf_Die *die, struct cu *cu) } static int class_member__cache_byte_size(struct tag *self, struct cu *cu, - void *cookie __unused) + void *cookie) { if (self->tag == DW_TAG_member || self->tag == DW_TAG_inheritance) { + struct conf_load *conf_load = cookie; struct class_member *member; if (member->bitfield_size != 0) { @@ -1742,8 +1743,15 @@ static int class_member__cache_byte_size(struct tag *self, struct cu *cu, */ member->byte_size = integral_bit_size / 8; - if (integral_bit_size == 0 || type_bit_size == integral_bit_size) { + if (integral_bit_size == 0) + return 0; + + if (type_bit_size == integral_bit_size) { member->bit_size = integral_bit_size; + if (conf_load && conf_load->fixup_silly_bitfields) { + member->bitfield_size = 0; + member->bitfield_offset = 0; + } return 0; } @@ -1785,7 +1793,7 @@ static int cus__load_module(struct cus *self, struct conf_load *conf, cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0; die__process(cu_die, cu); base_type_name_to_size_table__init(); - cu__for_all_tags(cu, class_member__cache_byte_size, NULL); + cu__for_all_tags(cu, class_member__cache_byte_size, conf); off = noff; if (conf && conf->steal) { switch (conf->steal(cu, conf)) { diff --git a/dwarves.h b/dwarves.h index 94a0e0f..cc56ffc 100644 --- a/dwarves.h +++ b/dwarves.h @@ -32,13 +32,15 @@ enum load_steal_kind { /** struct conf_load - load configuration * @extra_dbg_info - keep original debugging format extra info * (e.g. DWARF's decl_{line,file}, id, etc) + * @fixup_silly_bitfields - Fixup silly things such as "int foo:32;" */ struct conf_load { - bool extra_dbg_info; enum load_steal_kind (*steal)(struct cu *self, struct conf_load *conf); void *cookie; char *format_path; + bool extra_dbg_info; + bool fixup_silly_bitfields; }; /** struct conf_fprintf - hints to the __fprintf routines diff --git a/man-pages/pahole.1 b/man-pages/pahole.1 index 145d1cf..283771b 100644 --- a/man-pages/pahole.1 +++ b/man-pages/pahole.1 @@ -165,6 +165,10 @@ Flatten arrays, so that array[10][2] becomes array[20]. Useful when generating from both CTF and DWARF encodings for the same binary for testing purposes. +.TP +.B \-\-fixup_silly_bitfields +Converts silly bitfields such as "int foo:32" to plain "int foo". + .TP .B \-V, \-\-verbose be verbose diff --git a/pahole.c b/pahole.c index a46e3f8..bfca31d 100644 --- a/pahole.c +++ b/pahole.c @@ -704,8 +704,9 @@ static void print_containers(const struct cu *cu, uint16_t type, int ident) /* Name and version of program. */ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version; -#define ARGP_flat_arrays 300 -#define ARGP_show_private_classes 301 +#define ARGP_flat_arrays 300 +#define ARGP_show_private_classes 301 +#define ARGP_fixup_silly_bitfields 302 static const struct argp_option pahole__options[] = { { @@ -914,6 +915,11 @@ static const struct argp_option pahole__options[] = { .key = ARGP_show_private_classes, .doc = "Show classes that are defined inside other classes or in functions", }, + { + .name = "fixup_silly_bitfields", + .key = ARGP_fixup_silly_bitfields, + .doc = "Fix silly bitfields such as int foo:32", + }, { .name = NULL, } @@ -986,6 +992,8 @@ static error_t pahole__options_parser(int key, char *arg, case ARGP_flat_arrays: conf.flat_arrays = 1; break; case ARGP_show_private_classes: show_private_classes = true; break; + case ARGP_fixup_silly_bitfields: + conf_load.fixup_silly_bitfields = 1; break; default: return ARGP_ERR_UNKNOWN; }